fixed starting loyalty display in mock card

This commit is contained in:
Evan Kranzler 2022-03-09 20:32:48 -05:00
parent f94c79f6b4
commit 09636d7332
4 changed files with 32 additions and 37 deletions

View file

@ -32,6 +32,7 @@ import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.Token; import mage.game.permanent.token.Token;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.game.stack.StackAbility; import mage.game.stack.StackAbility;
import mage.game.stack.StackObject;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.Targets; import mage.target.Targets;
@ -40,7 +41,6 @@ import mage.util.SubTypes;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import mage.game.stack.StackObject;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -238,8 +238,8 @@ public class CardView extends SimpleCardView {
* @param card * @param card
* @param game * @param game
* @param controlled is the card view created for the card controller - used * @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 * for morph / face down cards to know which player may see information for
* the card * the card
*/ */
public CardView(Card card, Game game, boolean controlled) { public CardView(Card card, Game game, boolean controlled) {
this(card, game, controlled, false, false); this(card, game, controlled, false, false);
@ -265,12 +265,12 @@ public class CardView extends SimpleCardView {
/** /**
* @param card * @param card
* @param game * @param game
* @param controlled is the card view created for the card controller - used * @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 * for morph / face down cards to know which player may see information for
* the card * the card
* @param showFaceDownCard if true and the card is not on the battlefield, * @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 * 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. * @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) { 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()); 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(); this.frameStyle = card.getFrameStyle();
// Get starting loyalty // Get starting loyalty
this.startingLoyalty = "" + card.getStartingLoyalty(); this.startingLoyalty = CardUtil.convertStartingLoyalty(card.getStartingLoyalty());
} }
public CardView(MageObject object, Game game) { public CardView(MageObject object, Game game) {
@ -663,7 +663,7 @@ public class CardView extends SimpleCardView {
// Frame style // Frame style
this.frameStyle = object.getFrameStyle(); this.frameStyle = object.getFrameStyle();
// Starting loyalty. Must be extracted from an ability // Starting loyalty. Must be extracted from an ability
this.startingLoyalty = "" + object.getStartingLoyalty(); this.startingLoyalty = CardUtil.convertStartingLoyalty(object.getStartingLoyalty());
} }
protected CardView() { protected CardView() {

View file

@ -8,7 +8,6 @@ import mage.cards.CardImpl;
import mage.cards.ModalDoubleFacesCard; import mage.cards.ModalDoubleFacesCard;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import org.apache.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -26,7 +25,7 @@ public class MockCard extends CardImpl {
// Needs to be here, as it is normally calculated from the // Needs to be here, as it is normally calculated from the
// PlaneswalkerEntersWithLoyaltyAbility of the card... but the MockCard // PlaneswalkerEntersWithLoyaltyAbility of the card... but the MockCard
// only has MockAbilities. // only has MockAbilities.
private int startingLoyalty; private final int startingLoyalty;
// mana cost extra info for multiple mana drawing // mana cost extra info for multiple mana drawing
// warning, don't use ManaCost objects here due too much memory consumptions // warning, don't use ManaCost objects here due too much memory consumptions
@ -79,18 +78,16 @@ public class MockCard extends CardImpl {
this.isModalDoubleFacesCard = true; this.isModalDoubleFacesCard = true;
} }
if (this.isPlaneswalker()) { switch (card.getStartingLoyalty()) {
String startingLoyaltyString = card.getStartingLoyalty(); case "X":
if (startingLoyaltyString.isEmpty()) { this.startingLoyalty = -2;
} else { break;
try { case "":
this.startingLoyalty = Integer.parseInt(startingLoyaltyString); this.startingLoyalty = -1;
} catch (NumberFormatException e) { break;
Logger.getLogger(MockCard.class).warn("Planeswalker `" + this.name + "` starting loyalty in bad format: `" + startingLoyaltyString + "`."); default:
} this.startingLoyalty = Integer.parseInt(card.getStartingLoyalty());
}
} }
this.flipCardName = card.getFlipCardName(); this.flipCardName = card.getFlipCardName();
for (String ruleText : card.getRules()) { for (String ruleText : card.getRules()) {
this.addAbility(textAbilityFromString(ruleText)); this.addAbility(textAbilityFromString(ruleText));

View file

@ -243,20 +243,7 @@ public class CardInfo {
} }
// Starting loyalty // Starting loyalty
if (card.isPlaneswalker()) { this.startingLoyalty = CardUtil.convertStartingLoyalty(card.getStartingLoyalty());
switch (card.getStartingLoyalty()) {
case -2:
this.startingLoyalty = "X";
break;
case -1:
this.startingLoyalty = "";
break;
default:
this.startingLoyalty = "" + card.getStartingLoyalty();
}
} else {
this.startingLoyalty = "";
}
} }
public Card getCard() { public Card getCard() {

View file

@ -1587,4 +1587,15 @@ public final class CardUtil {
public static <T> int setOrIncrementValue(T u, Integer i) { public static <T> int setOrIncrementValue(T u, Integer i) {
return i == null ? 1 : Integer.sum(i, 1); 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;
}
}
} }