MCPcopy Create free account
hub / github.com/Card-Forge/forge / push

Method push

forge-game/src/main/java/forge/game/zone/MagicStack.java:525–567  ·  view source on GitHub ↗
(final SpellAbility sp, SpellAbilityStackInstance si, int id)

Source from the content-addressed store, hash-verified

523
524 // Push should only be used by add.
525 private SpellAbilityStackInstance push(final SpellAbility sp, SpellAbilityStackInstance si, int id) {
526 if (null == sp.getActivatingPlayer()) {
527 sp.setActivatingPlayer(sp.getHostCard().getController());
528 System.out.println(sp.getHostCard().getName() + " - activatingPlayer not set before adding to stack.");
529 }
530
531 if (sp.isSpell() && sp.getMayPlay() != null) {
532 sp.getMayPlay().incMayPlayTurn();
533 if (sp.getMayPlay().hasParam("ReplaceGraveyard")) {
534 PlayEffect.addReplaceGraveyardEffect(sp.getHostCard(), sp.getMayPlay().getHostCard(), sp, sp, sp.getMayPlay().getParam("ReplaceGraveyard"));
535 }
536 }
537 si = si == null ? new SpellAbilityStackInstance(sp, id) : si;
538
539 stack.addFirst(si);
540 int stackIndex = stack.size() - 1;
541
542 int distinctSources = 0;
543 Set<Integer> sources = new TreeSet<>();
544 for (SpellAbilityStackInstance s : stack) {
545 if (s.isSpell()) {
546 distinctSources++;
547 } else {
548 sources.add(s.getSourceCard().getId());
549 }
550 }
551 distinctSources += sources.size();
552 if (distinctSources > maxDistinctSources) maxDistinctSources = distinctSources;
553
554 // 2012-07-21 the following comparison needs to move below the pushes but somehow screws up priority
555 // When it's down there. That makes absolutely no sense to me, so i'm putting it back for now
556 if (!(sp.isTrigger() || (sp instanceof AbilityStatic))) {
557 // when something is added we need to setPriority
558 game.getPhaseHandler().setPriority(sp.getActivatingPlayer());
559 }
560
561 sp.getHostCard().getGame().getAction().checkStaticAbilities(false);
562 sp.getHostCard().getGame().getTriggerHandler().resetActiveTriggers();
563
564 game.updateStackForView();
565 game.fireEvent(new GameEventSpellAbilityCast(sp, si, stackIndex));
566 return si;
567 }
568
569 public final void resolveStack() {
570 // freeze the stack while we're in the middle of resolving

Callers 2

addMethod · 0.95
recordUndoableActionsMethod · 0.45

Calls 15

incMayPlayTurnMethod · 0.80
getPhaseHandlerMethod · 0.80
checkStaticAbilitiesMethod · 0.80
resetActiveTriggersMethod · 0.80
getTriggerHandlerMethod · 0.80
updateStackForViewMethod · 0.80
getHostCardMethod · 0.65
getNameMethod · 0.65
sizeMethod · 0.65
addMethod · 0.65
getIdMethod · 0.65

Tested by

no test coverage detected