From 01caeed2984be9d1ac0ee5d2ed6dbedabb8657af Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 13 Apr 2023 17:06:22 +0400 Subject: [PATCH] Merge fix --- .../collection/viewer/MageBook.java | 2 +- .../abilities/effects/common/CopyEffect.java | 38 ++++++++++++++++--- .../mage/game/permanent/PermanentToken.java | 4 +- .../mage/game/permanent/token/TokenImpl.java | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java index 6df3940ec2..fd98f5bbba 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java @@ -448,7 +448,7 @@ public class MageBook extends JComponent { if (cardDimension == null) { cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight()); } - PermanentToken newToken = new PermanentToken(token, null, token.getOriginalExpansionSetCode(), null); + PermanentToken newToken = new PermanentToken(token, null, null); newToken.removeSummoningSickness(); PermanentView theToken = new PermanentView(newToken, null, null, null); theToken.setInViewerOnly(true); diff --git a/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java index dfc1334244..94df74668d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java @@ -7,6 +7,7 @@ import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.Card; import mage.constants.*; import mage.game.Game; +import mage.game.command.CommandObject; import mage.game.permanent.Permanent; import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentToken; @@ -142,13 +143,38 @@ public class CopyEffect extends ContinuousEffectImpl { } // to get the image of the copied permanent copy number und expansionCode - if (copyFromObject instanceof PermanentCard) { - permanent.setCardNumber(((PermanentCard) copyFromObject).getCard().getCardNumber()); - permanent.setExpansionSetCode(((PermanentCard) copyFromObject).getCard().getExpansionSetCode()); - } else if (copyFromObject instanceof PermanentToken || copyFromObject instanceof Card) { - permanent.setCardNumber(((Card) copyFromObject).getCardNumber()); - permanent.setExpansionSetCode(((Card) copyFromObject).getExpansionSetCode()); + 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); + } + return true; } diff --git a/Mage/src/main/java/mage/game/permanent/PermanentToken.java b/Mage/src/main/java/mage/game/permanent/PermanentToken.java index 3d3b649ce9..e71a6e293a 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentToken.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentToken.java @@ -20,9 +20,8 @@ public class PermanentToken extends PermanentImpl { protected Token token; - public PermanentToken(Token token, UUID controllerId, String expansionSetCode, Game game) { + public PermanentToken(Token token, UUID controllerId, Game game) { super(controllerId, controllerId, token.getName()); - this.expansionSetCode = expansionSetCode; this.token = token.copy(); this.token.getAbilities().newOriginalId(); // neccessary if token has ability like DevourAbility() this.token.getAbilities().setSourceId(objectId); @@ -40,7 +39,6 @@ public class PermanentToken extends PermanentImpl { public PermanentToken(final PermanentToken permanent) { super(permanent); this.token = permanent.token.copy(); - this.expansionSetCode = permanent.expansionSetCode; } @Override diff --git a/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java b/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java index 3ed57fef28..36fac83855 100644 --- a/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java +++ b/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java @@ -252,7 +252,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token { for (int i = 0; i < amount; i++) { // TODO: add random setTokenType here? // use event.getPlayerId() as controller because it can be replaced by replacement effect - PermanentToken newPermanent = new PermanentToken(token, event.getPlayerId(), setCode, game); + PermanentToken newPermanent = new PermanentToken(token, event.getPlayerId(), game); game.getState().addCard(newPermanent); needTokens.add(newPermanent); game.getPermanentsEntering().put(newPermanent.getId(), newPermanent);