From 09636d7332a09618a5c9e8dbc21e315f6809ea3d Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 9 Mar 2022 20:32:48 -0500 Subject: [PATCH] fixed starting loyalty display in mock card --- .../src/main/java/mage/view/CardView.java | 20 ++++++++-------- .../main/java/mage/cards/mock/MockCard.java | 23 ++++++++----------- .../java/mage/cards/repository/CardInfo.java | 15 +----------- Mage/src/main/java/mage/util/CardUtil.java | 11 +++++++++ 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/Mage.Common/src/main/java/mage/view/CardView.java b/Mage.Common/src/main/java/mage/view/CardView.java index 7e4ea44717..66858d24f4 100644 --- a/Mage.Common/src/main/java/mage/view/CardView.java +++ b/Mage.Common/src/main/java/mage/view/CardView.java @@ -32,6 +32,7 @@ import mage.game.permanent.PermanentToken; import mage.game.permanent.token.Token; import mage.game.stack.Spell; import mage.game.stack.StackAbility; +import mage.game.stack.StackObject; import mage.players.Player; import mage.target.Target; import mage.target.Targets; @@ -40,7 +41,6 @@ import mage.util.SubTypes; import java.util.*; import java.util.stream.Collectors; -import mage.game.stack.StackObject; /** * @author BetaSteward_at_googlemail.com @@ -238,8 +238,8 @@ public class CardView extends SimpleCardView { * @param card * @param game * @param controlled is the card view created for the card controller - used - * for morph / face down cards to know which player may see information for - * the card + * for morph / face down cards to know which player may see information for + * the card */ public CardView(Card card, Game game, boolean controlled) { this(card, game, controlled, false, false); @@ -265,12 +265,12 @@ public class CardView extends SimpleCardView { /** * @param card * @param game - * @param controlled is the card view created for the card controller - used - * for morph / face down cards to know which player may see information for - * the card + * @param controlled is the card view created for the card controller - used + * for morph / face down cards to know which player may see information for + * the card * @param showFaceDownCard if true and the card is not on the battlefield, - * also a face down card is shown in the view, face down cards will be shown - * @param storeZone if true the card zone will be set in the zone attribute. + * also a face down card is shown in the view, face down cards will be shown + * @param storeZone if true the card zone will be set in the zone attribute. */ public CardView(Card card, Game game, boolean controlled, boolean showFaceDownCard, boolean storeZone) { super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), game != null, card.getTokenDescriptor()); @@ -589,7 +589,7 @@ public class CardView extends SimpleCardView { this.frameStyle = card.getFrameStyle(); // Get starting loyalty - this.startingLoyalty = "" + card.getStartingLoyalty(); + this.startingLoyalty = CardUtil.convertStartingLoyalty(card.getStartingLoyalty()); } public CardView(MageObject object, Game game) { @@ -663,7 +663,7 @@ public class CardView extends SimpleCardView { // Frame style this.frameStyle = object.getFrameStyle(); // Starting loyalty. Must be extracted from an ability - this.startingLoyalty = "" + object.getStartingLoyalty(); + this.startingLoyalty = CardUtil.convertStartingLoyalty(object.getStartingLoyalty()); } protected CardView() { diff --git a/Mage/src/main/java/mage/cards/mock/MockCard.java b/Mage/src/main/java/mage/cards/mock/MockCard.java index cb763203f5..d8c2e22ed0 100644 --- a/Mage/src/main/java/mage/cards/mock/MockCard.java +++ b/Mage/src/main/java/mage/cards/mock/MockCard.java @@ -8,7 +8,6 @@ import mage.cards.CardImpl; import mage.cards.ModalDoubleFacesCard; import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -26,7 +25,7 @@ public class MockCard extends CardImpl { // Needs to be here, as it is normally calculated from the // PlaneswalkerEntersWithLoyaltyAbility of the card... but the MockCard // only has MockAbilities. - private int startingLoyalty; + private final int startingLoyalty; // mana cost extra info for multiple mana drawing // warning, don't use ManaCost objects here due too much memory consumptions @@ -79,18 +78,16 @@ public class MockCard extends CardImpl { this.isModalDoubleFacesCard = true; } - if (this.isPlaneswalker()) { - String startingLoyaltyString = card.getStartingLoyalty(); - if (startingLoyaltyString.isEmpty()) { - } else { - try { - this.startingLoyalty = Integer.parseInt(startingLoyaltyString); - } catch (NumberFormatException e) { - Logger.getLogger(MockCard.class).warn("Planeswalker `" + this.name + "` starting loyalty in bad format: `" + startingLoyaltyString + "`."); - } - } + switch (card.getStartingLoyalty()) { + case "X": + this.startingLoyalty = -2; + break; + case "": + this.startingLoyalty = -1; + break; + default: + this.startingLoyalty = Integer.parseInt(card.getStartingLoyalty()); } - this.flipCardName = card.getFlipCardName(); for (String ruleText : card.getRules()) { this.addAbility(textAbilityFromString(ruleText)); diff --git a/Mage/src/main/java/mage/cards/repository/CardInfo.java b/Mage/src/main/java/mage/cards/repository/CardInfo.java index 55677c9fe8..135358e268 100644 --- a/Mage/src/main/java/mage/cards/repository/CardInfo.java +++ b/Mage/src/main/java/mage/cards/repository/CardInfo.java @@ -243,20 +243,7 @@ public class CardInfo { } // Starting loyalty - if (card.isPlaneswalker()) { - switch (card.getStartingLoyalty()) { - case -2: - this.startingLoyalty = "X"; - break; - case -1: - this.startingLoyalty = ""; - break; - default: - this.startingLoyalty = "" + card.getStartingLoyalty(); - } - } else { - this.startingLoyalty = ""; - } + this.startingLoyalty = CardUtil.convertStartingLoyalty(card.getStartingLoyalty()); } public Card getCard() { diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index c618f2e1a5..f12bcab21e 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -1587,4 +1587,15 @@ public final class CardUtil { public static int setOrIncrementValue(T u, Integer i) { return i == null ? 1 : Integer.sum(i, 1); } + + public static String convertStartingLoyalty(int startingLoyalty) { + switch (startingLoyalty) { + case -2: + return "X"; + case -1: + return ""; + default: + return "" + startingLoyalty; + } + } }