remove TransformAbility

This commit is contained in:
jmlundeen 2025-12-06 14:57:54 -06:00
parent 2bcbb30954
commit 2a75aa3acc
38 changed files with 118 additions and 365 deletions

View file

@ -5,9 +5,9 @@ import mage.abilities.Ability;
import mage.abilities.StaticAbility;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.TransformAbility;
import mage.cards.Card;
import mage.constants.*;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -21,7 +21,6 @@ public class SiegeAbility extends StaticAbility {
public SiegeAbility() {
super(Zone.ALL, null);
this.addSubAbility(new TransformAbility());
this.addSubAbility(new SiegeDefeatedTriggeredAbility());
}

View file

@ -1,16 +1,13 @@
package mage.abilities.common;
import mage.MageIdentifier;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.TransformAbility;
import mage.cards.Card;
import mage.cards.TransformingDoubleFacedCard;
import mage.constants.*;
import mage.constants.SpellAbilityCastMode;
import mage.constants.SpellAbilityType;
import mage.game.Game;
import mage.game.stack.Spell;
import java.util.Set;
import java.util.UUID;
@ -21,7 +18,6 @@ import java.util.UUID;
public class SpellTransformedAbility extends SpellAbility {
protected final String manaCost; //This variable is only used for rules text
private boolean ignoreTransformEffect; // TODO: temporary while converting tdfc
public SpellTransformedAbility(Card card, String manaCost) {
super(card.getSecondFaceSpellAbility());
@ -37,11 +33,6 @@ public class SpellTransformedAbility extends SpellAbility {
this.clearManaCosts();
this.clearManaCostsToPay();
this.addCost(new ManaCostsImpl<>(manaCost));
if (!(card instanceof TransformingDoubleFacedCard)) {
this.addSubAbility(new TransformAbility());
} else {
ignoreTransformEffect = true;
}
}
public SpellTransformedAbility(final SpellAbility ability) {
@ -54,13 +45,11 @@ public class SpellTransformedAbility extends SpellAbility {
this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE;
this.setSpellAbilityCastMode(SpellAbilityCastMode.TRANSFORMED);
//when casting this way, the card must have the TransformAbility from elsewhere
}
protected SpellTransformedAbility(final SpellTransformedAbility ability) {
super(ability);
this.manaCost = ability.manaCost;
this.ignoreTransformEffect = ability.ignoreTransformEffect;
}
@Override
@ -71,14 +60,7 @@ public class SpellTransformedAbility extends SpellAbility {
@Override
public boolean activate(Game game, Set<MageIdentifier> allowedIdentifiers, boolean noMana) {
if (super.activate(game, allowedIdentifiers, noMana)) {
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getSourceId(), Boolean.TRUE);
if (ignoreTransformEffect) {
return true;
}
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
TransformedEffect effect = new TransformedEffect();
game.addEffect(effect, this);
effect.apply(game, this); //Apply the effect immediately
game.getState().setValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + getSourceId(), Boolean.TRUE);
return true;
}
return false;
@ -95,31 +77,3 @@ public class SpellTransformedAbility extends SpellAbility {
return ActivationStatus.getFalse();
}
}
class TransformedEffect extends ContinuousEffectImpl {
public TransformedEffect() {
super(Duration.WhileOnStack, Layer.CopyEffects_1, SubLayer.CopyEffects_1a, Outcome.BecomeCreature);
staticText = "";
}
private TransformedEffect(final TransformedEffect effect) {
super(effect);
}
@Override
public TransformedEffect copy() {
return new TransformedEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpell(source.getSourceId());
if (spell == null || spell.getCard().getSecondCardFace() == null) {
return false;
}
// simulate another side as new card (another code part in spell constructor)
TransformAbility.transformCardSpellDynamic(spell, spell.getCard().getSecondCardFace(), game);
return true;
}
}

View file

@ -1,13 +1,10 @@
package mage.abilities.effects;
import java.util.Locale;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.keyword.TransformAbility;
import mage.cards.Card;
import mage.cards.TransformingDoubleFacedCard;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -18,6 +15,9 @@ import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCardInGraveyard;
import java.util.Locale;
import java.util.UUID;
/**
* Cards with the Aura subtype don't change the zone they are in, if there is no
* valid target on the battlefield. Also, when entering the battlefield and it
@ -184,7 +184,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
return false;
}
// in case of transformable enchantments
if (Boolean.TRUE.equals(game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId()))
if (Boolean.TRUE.equals(game.getState().getValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + card.getId()))
&& card.getSecondCardFace() != null) {
card = card.getSecondCardFace();
}

View file

@ -9,6 +9,7 @@ import mage.abilities.costs.common.ExileSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.TransformingDoubleFacedCard;
import mage.constants.*;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
@ -59,7 +60,6 @@ public class CraftAbility extends ActivatedAbilityImpl {
super(Zone.BATTLEFIELD, new CraftEffect(), new ManaCostsImpl<>(manaString));
this.addCost(new ExileSourceCost());
this.addCost(new CraftCost(target));
this.addSubAbility(new TransformAbility());
this.timing = TimingRule.SORCERY;
this.manaString = manaString;
this.description = description;
@ -173,7 +173,7 @@ class CraftEffect extends OneShotEffect {
if (player == null || card == null || card.getZoneChangeCounter(game) != source.getStackMomentSourceZCC() + 1) {
return false;
}
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + source.getSourceId(), Boolean.TRUE);
game.getState().setValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + source.getSourceId(), Boolean.TRUE);
player.moveCards(card, Zone.BATTLEFIELD, source, game);
return true;
}

View file

@ -15,7 +15,6 @@ public class DayboundAbility extends StaticAbility {
public DayboundAbility() {
super(Zone.BATTLEFIELD, new DayboundEffect());
this.addHint(DayNightHint.instance);
this.addSubAbility(new TransformAbility());
}
private DayboundAbility(final DayboundAbility ability) {

View file

@ -1,177 +0,0 @@
package mage.abilities.keyword;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.constants.*;
import mage.game.Game;
import mage.game.MageObjectAttribute;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.game.stack.Spell;
import mage.util.CardUtil;
/**
* @author nantuko
*/
public class TransformAbility extends SimpleStaticAbility {
// this state value controls if a permanent enters the battlefield already transformed
public static final String VALUE_KEY_ENTER_TRANSFORMED = "EnterTransformed";
public TransformAbility() {
super(Zone.BATTLEFIELD, new TransformEffect());
}
private TransformAbility(final TransformAbility ability) {
super(ability);
}
@Override
public TransformAbility copy() {
return new TransformAbility(this);
}
@Override
public String getRule() {
return "";
}
/**
* Apply transform effect to permanent (copy characteristic and other things)
*/
public static boolean transformPermanent(Permanent permanent, Game game, Ability source) {
MageObject sourceCard = findSourceObjectForTransform(permanent);
if (sourceCard == null) {
return false;
}
permanent.setTransformed(true);
permanent.setName(sourceCard.getName());
permanent.getColor(game).setColor(sourceCard.getColor(game));
permanent.getManaCost().clear();
permanent.getManaCost().add(sourceCard.getManaCost().copy());
permanent.removeAllCardTypes(game);
for (CardType type : sourceCard.getCardType(game)) {
permanent.addCardType(game, type);
}
permanent.removeAllSubTypes(game);
permanent.copySubTypesFrom(game, sourceCard);
permanent.removeAllSuperTypes(game);
for (SuperType type : sourceCard.getSuperType(game)) {
permanent.addSuperType(game, type);
}
CardUtil.copySetAndCardNumber(permanent, sourceCard);
permanent.getAbilities().clear();
for (Ability ability : sourceCard.getAbilities()) {
// source == null -- call from init card (e.g. own abilities)
// source != null -- from apply effect
permanent.addAbility(ability, source == null ? permanent.getId() : source.getSourceId(), game, true);
}
permanent.getPower().setModifiedBaseValue(sourceCard.getPower().getValue());
permanent.getToughness().setModifiedBaseValue(sourceCard.getToughness().getValue());
permanent.setStartingLoyalty(sourceCard.getStartingLoyalty());
permanent.setStartingDefense(sourceCard.getStartingDefense());
return true;
}
private static MageObject findSourceObjectForTransform(Permanent permanent) {
if (permanent == null) {
return null;
}
// copies can't transform
if (permanent.isCopy()) {
return null;
}
if (permanent instanceof PermanentToken) {
return ((PermanentToken) permanent).getToken().getBackFace();
} else {
return permanent.getSecondCardFace();
}
}
public static Card transformCardSpellStatic(Card mainSide, Card otherSide, Game game) {
// workaround to simulate transformed card on the stack (example: disturb ability)
// prepare static attributes
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
Card newCard = mainSide.copy();
newCard.setName(otherSide.getName());
// mana value must be from main side only
newCard.getManaCost().clear();
newCard.getManaCost().add(mainSide.getManaCost().copy());
game.getState().getCardState(newCard.getId()).clearAbilities();
for (Ability ability : otherSide.getAbilities()) {
game.getState().addOtherAbility(newCard, ability);
}
newCard.getPower().setModifiedBaseValue(otherSide.getPower().getValue());
newCard.getToughness().setModifiedBaseValue(otherSide.getToughness().getValue());
return newCard;
}
public static void transformCardSpellDynamic(Spell spell, Card otherSide, Game game) {
// workaround to simulate transformed card on the stack (example: disturb ability)
// prepare dynamic attributes
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
MageObjectAttribute moa = game.getState().getCreateMageObjectAttribute(spell.getCard(), game);
moa.getColor().setColor(otherSide.getColor(game));
moa.getCardType().clear();
moa.getCardType().addAll(otherSide.getCardType(game));
moa.getSuperType().clear();
moa.getSuperType().addAll(otherSide.getSuperType(game));
moa.getSubtype().clear();
moa.getSubtype().addAll(otherSide.getSubtype(game));
game.getState().getCardState(spell.getCard().getId()).clearAbilities();
for (Ability ability : otherSide.getAbilities()) {
game.getState().addOtherAbility(spell.getCard(), ability);
}
}
}
class TransformEffect extends ContinuousEffectImpl {
TransformEffect() {
super(Duration.WhileOnBattlefield, Layer.CopyEffects_1, SubLayer.CopyEffects_1a, Outcome.BecomeCreature);
staticText = "";
}
private TransformEffect(final TransformEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return false;
}
// only for transformed permanents
if (!permanent.isTransformed()) {
return false;
}
return TransformAbility.transformPermanent(permanent, game, source);
}
@Override
public TransformEffect copy() {
return new TransformEffect(this);
}
@Override
public String getText(Mode mode) {
return "";
}
}

View file

@ -8,6 +8,9 @@ import java.util.UUID;
public abstract class TransformingDoubleFacedCard extends DoubleFacedCard {
// this state value controls if a permanent enters the battlefield already transformed
public static final String VALUE_KEY_ENTER_TRANSFORMED = "EnterTransformed";
public TransformingDoubleFacedCard(
UUID ownerId, CardSetInfo setInfo,
CardType[] typesLeft, SubType[] subTypesLeft, String costsLeft,

View file

@ -1,8 +1,10 @@
package mage.constants;
import mage.abilities.Ability;
import mage.abilities.keyword.TransformAbility;
import mage.cards.*;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.cards.TransformingDoubleFacedCard;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -93,7 +95,7 @@ public enum PutCards {
if (card instanceof TransformingDoubleFacedCard) {
card = ((TransformingDoubleFacedCard) card).getRightHalfCard();
}
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId(), Boolean.TRUE);
game.getState().setValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + card.getId(), Boolean.TRUE);
case BATTLEFIELD:
case EXILED:
case HAND:
@ -131,7 +133,7 @@ public enum PutCards {
case SHUFFLE:
return player.shuffleCardsToLibrary(cards, game, source);
case BATTLEFIELD_TRANSFORMED:
cards.stream().forEach(uuid -> game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + uuid, Boolean.TRUE));
cards.stream().forEach(uuid -> game.getState().setValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + uuid, Boolean.TRUE));
case BATTLEFIELD:
case EXILED:
case HAND:

View file

@ -0,0 +1,19 @@
package mage.filter.predicate.permanent;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
public enum TransformablePredicate implements Predicate<Permanent> {
instance;
@Override
public boolean apply(Permanent input, Game game) {
return input.isTransformable();
}
@Override
public String toString() {
return "Transformable";
}
}

View file

@ -1,7 +1,6 @@
package mage.game;
import mage.abilities.Ability;
import mage.abilities.keyword.TransformAbility;
import mage.cards.*;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -91,8 +90,7 @@ public final class ZonesHandler {
Card card = game.getCard(info.event.getTargetId());
if (card instanceof DoubleFacedCard || card instanceof DoubleFacedCardHalf) {
boolean forceToMainSide = false;
// TODO: move transform key or have some other identifier after tdfc rework
Boolean enterTransformed = (Boolean) game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId());
Boolean enterTransformed = (Boolean) game.getState().getValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + card.getId());
if (enterTransformed == null) {
enterTransformed = false;
}
@ -296,7 +294,7 @@ public final class ZonesHandler {
game.getPermanentsEntering().remove(permanent.getId());
break;
default:
throw new UnsupportedOperationException("to Zone " + toZone.toString() + " not supported yet");
throw new UnsupportedOperationException("to Zone " + toZone + " not supported yet");
}
}
@ -376,15 +374,13 @@ public final class ZonesHandler {
isGoodToMove = true;
} else if (event.getToZone().equals(Zone.BATTLEFIELD)) {
// non-permanents can't move to battlefield
// TODO: possible bug with Nightbound, search all usage of getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED and insert additional check Ability.checkCard
// TODO: possible bug with Nightbound, search all usage of getValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED and insert additional check Ability.checkCard
/*
* 712.14a. If a spell or ability puts a transforming double-faced card onto the battlefield "transformed"
* or "converted," it enters the battlefield with its back face up. If a player is instructed to put a card
* that isn't a transforming double-faced card onto the battlefield transformed or converted, that card stays in
* its current zone.
* 712.14a. If a spell or ability puts a double-faced card onto the battlefield "transformed" or "converted,"
* it enters the battlefield with its back face up. If a player is instructed to put a card that isn't a double-faced card
* onto the battlefield transformed or converted, that card stays in its current zone.
*/
// TODO: remove after tdfc rework
boolean wantToTransform = Boolean.TRUE.equals(game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId()));
boolean wantToTransform = Boolean.TRUE.equals(game.getState().getValue(TransformingDoubleFacedCard.VALUE_KEY_ENTER_TRANSFORMED + card.getId()));
if (wantToTransform && !(card instanceof DoubleFacedCardHalf)) {
isGoodToMove = card.isTransformable() && card.getSecondCardFace().isPermanent(game);
} else {

View file

@ -3,7 +3,6 @@ package mage.game.permanent.token;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.TransformSourceEffect;
import mage.abilities.keyword.TransformAbility;
import mage.constants.CardType;
import mage.constants.SubType;
@ -18,7 +17,6 @@ public final class IncubatorToken extends TokenImpl {
subtype.add(SubType.INCUBATOR);
this.backFace = new Phyrexian00Token();
this.addAbility(new TransformAbility());
this.addAbility(new SimpleActivatedAbility(
new TransformSourceEffect().setText("transform this artifact"), new GenericManaCost(2)
));

View file

@ -8,7 +8,6 @@ import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.keyword.BestowAbility;
import mage.abilities.keyword.PrototypeAbility;
import mage.abilities.keyword.TransformAbility;
import mage.cards.*;
import mage.constants.*;
import mage.counters.Counter;
@ -81,11 +80,6 @@ public class Spell extends StackObjectImpl implements Card {
Card affectedCard = card;
// TODO: must be removed after transform cards (one side) migrated to MDF engine (multiple sides)
if (ability.getSpellAbilityCastMode().isTransformed() && affectedCard.getSecondCardFace() != null) {
// simulate another side as new card (another code part in continues effect from disturb ability)
affectedCard = TransformAbility.transformCardSpellStatic(card, card.getSecondCardFace(), game);
}
if (ability instanceof PrototypeAbility) {
affectedCard = ((PrototypeAbility) ability).prototypeCardSpell(card);
this.prototyped = true;

View file

@ -4110,7 +4110,7 @@ public abstract class PlayerImpl implements Player, Serializable {
TransformingDoubleFacedCard mainCard = (TransformingDoubleFacedCard) object;
getPlayableFromObjectSingle(game, fromZone, mainCard.getLeftHalfCard(), mainCard.getLeftHalfCard().getAbilities(game), availableMana, output);
getPlayableFromObjectSingle(game, fromZone, mainCard, mainCard.getSharedAbilities(game), availableMana, output);
} else if (object instanceof CardWithSpellOption) {
} else if (object instanceof CardWithSpellOption) {
// adventure must use different card characteristics for different spells (main or adventure)
CardWithSpellOption cardWithSpellOption = (CardWithSpellOption) object;
getPlayableFromObjectSingle(game, fromZone, cardWithSpellOption.getSpellCard(), cardWithSpellOption.getSpellCard().getAbilities(game), availableMana, output);
@ -4952,16 +4952,6 @@ public abstract class PlayerImpl implements Player, Serializable {
for (Card card : cards) {
fromZone = game.getState().getZone(card.getId());
// 712.14a. If a spell or ability puts a transforming double-faced card onto the battlefield "transformed"
// or "converted," it enters the battlefield with its back face up. If a player is instructed to put a card
// that isn't a transforming double-faced card onto the battlefield transformed or converted, that card stays in
// its current zone.
// TODO: can probably remove/change after tdfc rework, should only be sending transformed side
Boolean enterTransformed = (Boolean) game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId());
if (enterTransformed != null && enterTransformed && !card.isTransformable() && !(card instanceof TransformingDoubleFacedCardHalf)) {
continue;
}
// 303.4g. If an Aura is entering the battlefield and there is no legal object or player for it to enchant,
// the Aura remains in its current zone, unless that zone is the stack. In that case, the Aura is put into
// its owner's graveyard instead of entering the battlefield. If the Aura is a token, it isn't created.