mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Fixed images info copy in morph and other copy abilities
This commit is contained in:
parent
689b93d005
commit
1dc7dcc94c
6 changed files with 61 additions and 36 deletions
|
@ -17,6 +17,7 @@ import mage.players.Player;
|
|||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -123,7 +124,9 @@ class MetamorphicAlterationEffect extends ContinuousEffectImpl {
|
|||
permanent.setName(copied.getName());
|
||||
permanent.getManaCost().clear();
|
||||
permanent.getManaCost().addAll(copied.getManaCost());
|
||||
permanent.setExpansionSetCode(copied.getExpansionSetCode());
|
||||
|
||||
CardUtil.copySetAndCardNumber(permanent, copied);
|
||||
|
||||
permanent.getSuperType().clear();
|
||||
for (SuperType t : copied.getSuperType()) {
|
||||
permanent.addSuperType(t);
|
||||
|
|
|
@ -143,38 +143,7 @@ public class CopyEffect extends ContinuousEffectImpl {
|
|||
permanent.setFlipCardName(targetPermanent.getFlipCardName());
|
||||
}
|
||||
|
||||
// to get the image of the copied permanent copy number und expansionCode
|
||||
String needSetCode;
|
||||
String needCardNumber;
|
||||
int needTokenType;
|
||||
if (copyFromObject instanceof CommandObject) {
|
||||
needSetCode = ((CommandObject) copyFromObject).getExpansionSetCodeForImage();
|
||||
needCardNumber = "0";
|
||||
needTokenType = 0;
|
||||
} else if (copyFromObject instanceof PermanentCard) {
|
||||
needSetCode = ((PermanentCard) copyFromObject).getExpansionSetCode();
|
||||
needCardNumber = ((PermanentCard) copyFromObject).getCardNumber();
|
||||
needTokenType = 0;
|
||||
} else if (copyFromObject instanceof PermanentToken) {
|
||||
needSetCode = ((PermanentToken) copyFromObject).getToken().getOriginalExpansionSetCode();
|
||||
needCardNumber = ((PermanentToken) copyFromObject).getToken().getOriginalCardNumber();
|
||||
needTokenType = ((PermanentToken) copyFromObject).getToken().getTokenType();
|
||||
} else if (copyFromObject instanceof Card) {
|
||||
needSetCode = ((Card) copyFromObject).getExpansionSetCode();
|
||||
needCardNumber = ((Card) copyFromObject).getCardNumber();
|
||||
needTokenType = 0;
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported copyFromObject class: " + copyFromObject.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
if (permanent instanceof PermanentToken) {
|
||||
((PermanentToken) permanent).getToken().setOriginalExpansionSetCode(needSetCode);
|
||||
((PermanentToken) permanent).getToken().setExpansionSetCodeForImage(needSetCode);
|
||||
((PermanentToken) permanent).getToken().setTokenType(needTokenType);
|
||||
} else {
|
||||
permanent.setExpansionSetCode(needSetCode);
|
||||
permanent.setCardNumber(needCardNumber);
|
||||
}
|
||||
CardUtil.copySetAndCardNumber(permanent, copyFromObject);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import mage.constants.Rarity;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* 702.36. Morph
|
||||
|
@ -144,8 +145,12 @@ public class MorphAbility extends AlternativeSourceCostsImpl {
|
|||
mageObject.removeAllSubTypes(game);
|
||||
mageObject.getSuperType().clear();
|
||||
mageObject.getManaCost().clear();
|
||||
|
||||
// TODO: add morph image here?
|
||||
if (mageObject instanceof Permanent) {
|
||||
((Permanent) mageObject).setExpansionSetCode("");
|
||||
// hide image info
|
||||
CardUtil.copySetAndCardNumber((Permanent) mageObject, "", "", 0);
|
||||
// hide rarity info
|
||||
((Permanent) mageObject).setRarity(Rarity.SPECIAL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import mage.game.Game;
|
|||
import mage.game.MageObjectAttribute;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
|
@ -57,7 +58,9 @@ public class TransformAbility extends SimpleStaticAbility {
|
|||
for (SuperType type : sourceCard.getSuperType()) {
|
||||
permanent.addSuperType(type);
|
||||
}
|
||||
permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
|
||||
|
||||
CardUtil.copySetAndCardNumber(permanent, sourceCard);
|
||||
|
||||
permanent.getAbilities().clear();
|
||||
for (Ability ability : sourceCard.getAbilities()) {
|
||||
// source == null -- call from init card (e.g. own abilities)
|
||||
|
|
|
@ -138,6 +138,6 @@ public class PermanentToken extends PermanentImpl {
|
|||
|
||||
@Override
|
||||
public void setExpansionSetCode(String expansionSetCode) {
|
||||
throw new IllegalArgumentException("Wrong code usage: you can't change a token's set code");
|
||||
throw new IllegalArgumentException("Wrong code usage: you can't change a token's set code, use CardUtils.copySetAndCardNumber instead");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,11 +32,13 @@ import mage.filter.predicate.mageobject.NamePredicate;
|
|||
import mage.game.CardState;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.command.Commander;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.permanent.PermanentMeld;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
import mage.game.permanent.token.Token;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.players.Player;
|
||||
|
@ -1769,4 +1771,47 @@ public final class CardUtil {
|
|||
}
|
||||
return str.substring(0, Math.min(str.length(), maxLength));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy image related data from one object to another (card number, set code, token type)
|
||||
* Use it in copy/transform effects
|
||||
*/
|
||||
public static void copySetAndCardNumber(Permanent permanent, MageObject copyFromObject) {
|
||||
String needSetCode;
|
||||
String needCardNumber;
|
||||
int needTokenType;
|
||||
if (copyFromObject instanceof CommandObject) {
|
||||
needSetCode = ((CommandObject) copyFromObject).getExpansionSetCodeForImage();
|
||||
needCardNumber = "0";
|
||||
needTokenType = 0;
|
||||
} else if (copyFromObject instanceof PermanentCard) {
|
||||
needSetCode = ((PermanentCard) copyFromObject).getExpansionSetCode();
|
||||
needCardNumber = ((PermanentCard) copyFromObject).getCardNumber();
|
||||
needTokenType = 0;
|
||||
} else if (copyFromObject instanceof PermanentToken) {
|
||||
needSetCode = ((PermanentToken) copyFromObject).getToken().getOriginalExpansionSetCode();
|
||||
needCardNumber = ((PermanentToken) copyFromObject).getToken().getOriginalCardNumber();
|
||||
needTokenType = ((PermanentToken) copyFromObject).getToken().getTokenType();
|
||||
} else if (copyFromObject instanceof Card) {
|
||||
needSetCode = ((Card) copyFromObject).getExpansionSetCode();
|
||||
needCardNumber = ((Card) copyFromObject).getCardNumber();
|
||||
needTokenType = 0;
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported copyFromObject class: " + copyFromObject.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
copySetAndCardNumber(permanent, needSetCode, needCardNumber, needTokenType);
|
||||
}
|
||||
|
||||
public static void copySetAndCardNumber(Permanent permanent, String newSetCode, String newCardNumber, Integer newTokenType) {
|
||||
if (permanent instanceof PermanentToken) {
|
||||
((PermanentToken) permanent).getToken().setOriginalExpansionSetCode(newSetCode);
|
||||
((PermanentToken) permanent).getToken().setExpansionSetCodeForImage(newCardNumber);
|
||||
((PermanentToken) permanent).getToken().setTokenType(newTokenType);
|
||||
} else {
|
||||
permanent.setExpansionSetCode(newSetCode);
|
||||
permanent.setCardNumber(newCardNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue