Copy abilities - fixed wrong copy of transformed tokens like Incubator/Phyrexian (related to #11535, #11307, #10801, #10263);

This commit is contained in:
Oleg Agafonov 2023-12-10 14:49:47 +04:00
parent 50fd029c3b
commit 00a7cc645d
7 changed files with 273 additions and 28 deletions

View file

@ -40,9 +40,13 @@ public class TransformAbility extends SimpleStaticAbility {
return "";
}
public static void transformPermanent(Permanent permanent, MageObject sourceCard, Game game, Ability source) {
/**
* 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;
return false;
}
permanent.setTransformed(true);
@ -73,6 +77,25 @@ public class TransformAbility extends SimpleStaticAbility {
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) {
@ -130,35 +153,16 @@ class TransformEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return false;
}
if (permanent.isCopy()) { // copies can't transform
return true;
}
// only for transformed permanents
if (!permanent.isTransformed()) {
// keep original card
return true;
}
MageObject card;
if (permanent instanceof PermanentToken) {
card = ((PermanentToken) permanent).getToken().getBackFace();
} else {
card = permanent.getSecondCardFace();
}
if (card == null) {
return false;
}
TransformAbility.transformPermanent(permanent, card, game, source);
return true;
return TransformAbility.transformPermanent(permanent, game, source);
}
@Override

View file

@ -602,6 +602,11 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
// mtg rules method: here
// GUI related method: search "transformable = true" in CardView
// TODO: check and fix method usage in game engine, it's must be mtg rules logic, not GUI
// 701.28c
// If a spell or ability instructs a player to transform a permanent that
// isnt represented by a transforming token or a transforming double-faced
// card, nothing happens.
return this.secondSideCardClazz != null || this.nightCard;
}

View file

@ -1972,9 +1972,12 @@ public abstract class GameImpl implements Game {
// if it was no copy of copy take the target itself
if (newBluePrint == null) {
newBluePrint = copyFromPermanent.copy();
// reset to original characteristics
newBluePrint.reset(this);
//getState().addCard(permanent);
// workaround to find real copyable characteristics of transformed/facedown/etc permanents
if (copyFromPermanent.isMorphed()
|| copyFromPermanent.isManifested()
|| copyFromPermanent.isFaceDown(this)) {
@ -1982,7 +1985,7 @@ public abstract class GameImpl implements Game {
}
newBluePrint.assignNewId();
if (copyFromPermanent.isTransformed()) {
TransformAbility.transformPermanent(newBluePrint, newBluePrint.getSecondCardFace(), this, source);
TransformAbility.transformPermanent(newBluePrint,this, source);
}
if (copyFromPermanent.isPrototyped()) {
Abilities<Ability> abilities = copyFromPermanent.getAbilities();

View file

@ -72,11 +72,13 @@ public class PermanentCard extends PermanentImpl {
if (card instanceof LevelerCard) {
maxLevelCounters = ((LevelerCard) card).getMaxLevelCounters();
}
// if transformed on ETB
if (card.isTransformable()) {
if (game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId()) != null
|| NightboundAbility.checkCard(this, game)) {
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId(), null);
TransformAbility.transformPermanent(this, getSecondCardFace(), game, null);
TransformAbility.transformPermanent(this, game, null);
}
}
}

View file

@ -32,8 +32,10 @@ public class PermanentToken extends PermanentImpl {
this.power = new MageInt(token.getPower().getModifiedBaseValue());
this.toughness = new MageInt(token.getToughness().getModifiedBaseValue());
this.copyFromToken(this.token, game, false); // needed to have at this time (e.g. for subtypes for entersTheBattlefield replacement effects)
// if transformed on ETB
if (this.token.isEntersTransformed()) {
TransformAbility.transformPermanent(this, this.token.getBackFace(), game, null);
TransformAbility.transformPermanent(this, game, null);
}
// token's ZCC must be synced with original token to keep abilities settings
@ -146,6 +148,10 @@ public class PermanentToken extends PermanentImpl {
@Override
public boolean isTransformable() {
// 701.28c
// If a spell or ability instructs a player to transform a permanent that
// isnt represented by a transforming token or a transforming double-faced card,
// nothing happens.
return token.getBackFace() != null;
}