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

Method changeCardState

forge-game/src/main/java/forge/game/card/Card.java:654–768  ·  view source on GitHub ↗
(final String mode, final String customState, final SpellAbility cause)

Source from the content-addressed store, hash-verified

652 }
653
654 public boolean changeCardState(final String mode, final String customState, final SpellAbility cause) {
655 if (isPhasedOut()) {
656 return false;
657 }
658 if (mode == null) {
659 return changeToState(CardStateName.smartValueOf(customState));
660 }
661
662 // flip and face-down don't overlap. That is there is no chance to turn face down a flipped permanent
663 // and then any effect have it turn upface again and demand its former flip state to be restored
664 // Proof: Morph cards never have ability that makes them flip, Ixidron does not suppose cards to be turned face up again,
665 // Illusionary Mask affects cards in hand.
666 if (mode.equals("Transform") && (isTransformable() || hasMergedCard())) {
667 if (!canTransform(cause)) {
668 return false;
669 }
670
671 // Need to remove mutated states, otherwise the changeToState() will fail
672 if (hasMergedCard()) {
673 removeMutatedStates();
674 }
675 long ts = game.getNextTimestamp();
676 CardCollectionView cards = hasMergedCard() ? getMergedCards() : new CardCollection(this);
677 boolean retResult = false;
678 for (final Card c : cards) {
679 if (!c.isTransformable()) {
680 continue;
681 }
682 c.backside = !c.backside;
683 // 613.7g A transforming double-faced permanent receives a new timestamp each time it transforms.
684 c.setLayerTimestamp(ts);
685 boolean result = c.changeToState(c.backside ? CardStateName.Backside : CardStateName.Original);
686 retResult = retResult || result;
687 }
688 if (hasMergedCard()) {
689 rebuildMutatedStates(cause);
690 }
691
692 // run valid Replacement here
693 getGame().getReplacementHandler().run(ReplacementType.Transform, AbilityKey.mapFromAffected(this));
694
695 // do the Transform trigger here, it can also happen if the resulting state doesn't change
696 // Clear old dfc trigger from the trigger handler
697 getGame().getTriggerHandler().clearActiveTriggers(this, null);
698 getGame().getTriggerHandler().registerActiveTrigger(this, false);
699
700 if (cause == null || !cause.hasParam("ETB")) {
701 final Map<AbilityKey, Object> runParams = AbilityKey.mapFromCard(this);
702 getGame().getTriggerHandler().runTrigger(TriggerType.Transformed, runParams, false);
703 }
704 setTransformedTimestamp(ts);
705
706 return retResult;
707 } else if (mode.equals("Flip")) {
708 // 709.4. Flipping a permanent is a one-way process.
709 if (isFlipped()) {
710 return false;
711 }

Callers 3

resolveMethod · 0.95

Calls 15

isPhasedOutMethod · 0.95
changeToStateMethod · 0.95
smartValueOfMethod · 0.95
isTransformableMethod · 0.95
hasMergedCardMethod · 0.95
canTransformMethod · 0.95
removeMutatedStatesMethod · 0.95
getMergedCardsMethod · 0.95
rebuildMutatedStatesMethod · 0.95
getGameMethod · 0.95
mapFromAffectedMethod · 0.95
mapFromCardMethod · 0.95

Tested by

no test coverage detected