GUI: fixed broken add lands and random deck dialogs in deck editor (#7562);

This commit is contained in:
Oleg Agafonov 2021-02-13 20:26:06 +04:00
parent e94fd1b456
commit eb64a7bb73
7 changed files with 34 additions and 20 deletions

View file

@ -191,7 +191,7 @@ public final class DeckGenerator {
while (count < spellCount) { while (count < spellCount) {
Card card = cardPool.get(RandomUtil.nextInt(retrievedCount)).getMockCard(); Card card = cardPool.get(RandomUtil.nextInt(retrievedCount)).getMockCard();
if (genPool.isValidSpellCard(card)) { if (genPool.isValidSpellCard(card)) {
int cardCMC = card.getManaCost().convertedManaCost(); int cardCMC = card.getConvertedManaCost();
for (DeckGeneratorCMC.CMC deckCMC : deckCMCs) { for (DeckGeneratorCMC.CMC deckCMC : deckCMCs) {
if (cardCMC >= deckCMC.min && cardCMC <= deckCMC.max) { if (cardCMC >= deckCMC.min && cardCMC <= deckCMC.max) {
int currentAmount = deckCMC.getAmount(); int currentAmount = deckCMC.getAmount();

View file

@ -473,12 +473,13 @@ public class AddLandDialog extends MageDialog {
land_number = 0; land_number = 0;
} }
for (Card cd : cards) { for (Card cd : cards) {
Mana m = cd.getManaCost().getMana(); for (String s : cd.getManaCostSymbols()) {
red += m.getRed(); if (s.contains("W")) white++;
green += m.getGreen(); if (s.contains("U")) blue++;
black += m.getBlack(); if (s.contains("B")) black++;
blue += m.getBlue(); if (s.contains("R")) red++;
white += m.getWhite(); if (s.contains("G")) green++;
}
} }
int total = red + green + black + blue + white; int total = red + green + black + blue + white;

View file

@ -238,7 +238,7 @@ public final class DeckBuilder {
} }
private int getManaCostScore(Card card, List<ColoredManaSymbol> allowedColors) { private int getManaCostScore(Card card, List<ColoredManaSymbol> allowedColors) {
int converted = card.getManaCost().convertedManaCost(); int converted = card.getConvertedManaCost();
final Map<String, Integer> singleCount = new HashMap<>(); final Map<String, Integer> singleCount = new HashMap<>();
int maxSingleCount = 0; int maxSingleCount = 0;
int multicolor = 0; int multicolor = 0;
@ -276,7 +276,7 @@ public final class DeckBuilder {
} }
public int getConvertedCost() { public int getConvertedCost() {
return this.card.getManaCost().convertedManaCost(); return this.card.getConvertedManaCost();
} }
public Card getCard() { public Card getCard() {

View file

@ -386,14 +386,14 @@ public class Commander extends Constructed {
whenYouCast |= s.contains("when you cast") || s.contains("whenever you cast"); whenYouCast |= s.contains("when you cast") || s.contains("whenever you cast");
} }
for (ManaCost cost : card.getManaCost()) { for (String s : card.getManaCostSymbols()) {
if (cost.getText().contains("X")) { if (s.contains("X")) {
xCost = true; xCost = true;
} }
} }
for (Ability a : card.getAbilities()) { for (Ability a : card.getAbilities()) {
for (ManaCost cost : a.getManaCosts()) { for (String s : a.getManaCostSymbols()) {
if (cost.getText().contains("X")) { if (s.contains("X")) {
xCost = true; xCost = true;
} }
} }

View file

@ -130,7 +130,7 @@ public class TinyLeaders extends Constructed {
* would be legal independently. * would be legal independently.
*/ */
if (commander == null || commander.getManaCost().convertedManaCost() > 3) { if (commander == null || commander.getConvertedManaCost() > 3) {
if (commander == null) { if (commander == null) {
if (deck.getName() == null) { if (deck.getName() == null) {
addError(DeckValidatorErrorType.PRIMARY, "Leader", "You have to save your deck with the leader card name entered to the DECK NAME field of the DECK EDITOR (top left) so that XMage knows your leader." addError(DeckValidatorErrorType.PRIMARY, "Leader", "You have to save your deck with the leader card name entered to the DECK NAME field of the DECK EDITOR (top left) so that XMage knows your leader."
@ -141,7 +141,7 @@ public class TinyLeaders extends Constructed {
} }
} }
if (commander != null && commander.getManaCost().convertedManaCost() > 3) { if (commander != null && commander.getConvertedManaCost() > 3) {
addError(DeckValidatorErrorType.PRIMARY, "Leader", "Commanders converted mana cost is greater than 3"); addError(DeckValidatorErrorType.PRIMARY, "Leader", "Commanders converted mana cost is greater than 3");
} }
return false; return false;
@ -201,13 +201,13 @@ public class TinyLeaders extends Constructed {
// as zero for this purpose. Split cards are legal only if both of their halves would be legal independently. // as zero for this purpose. Split cards are legal only if both of their halves would be legal independently.
List<Integer> costs = new ArrayList<>(); List<Integer> costs = new ArrayList<>();
if (card instanceof SplitCard) { if (card instanceof SplitCard) {
costs.add(((SplitCard) card).getLeftHalfCard().getManaCost().convertedManaCost()); costs.add(((SplitCard) card).getLeftHalfCard().getConvertedManaCost());
costs.add(((SplitCard) card).getRightHalfCard().getManaCost().convertedManaCost()); costs.add(((SplitCard) card).getRightHalfCard().getConvertedManaCost());
} else if (card instanceof ModalDoubleFacesCard) { } else if (card instanceof ModalDoubleFacesCard) {
costs.add(((ModalDoubleFacesCard) card).getLeftHalfCard().getManaCost().convertedManaCost()); costs.add(((ModalDoubleFacesCard) card).getLeftHalfCard().getConvertedManaCost());
costs.add(((ModalDoubleFacesCard) card).getRightHalfCard().getManaCost().convertedManaCost()); costs.add(((ModalDoubleFacesCard) card).getRightHalfCard().getConvertedManaCost());
} else { } else {
costs.add(card.getManaCost().convertedManaCost()); costs.add(card.getConvertedManaCost());
} }
return costs.stream().allMatch(cost -> { return costs.stream().allMatch(cost -> {

View file

@ -10,6 +10,7 @@ import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -99,6 +100,14 @@ public class MockCard extends CardImpl {
public MockCard(final MockCard card) { public MockCard(final MockCard card) {
super(card); super(card);
this.startingLoyalty = card.startingLoyalty;
this.manaCostLeftStr = new ArrayList<>(card.manaCostLeftStr);
this.manaCostRightStr = new ArrayList<>(card.manaCostRightStr);
this.manaCostStr = new ArrayList<>(card.manaCostStr);
this.adventureSpellName = card.adventureSpellName;
this.isModalDoubleFacesCard = card.isModalDoubleFacesCard;
this.convertedManaCost = card.convertedManaCost;
} }
@Override @Override

View file

@ -9,6 +9,7 @@ import mage.cards.SplitCard;
import mage.cards.SplitCardHalf; import mage.cards.SplitCardHalf;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -29,6 +30,9 @@ public class MockSplitCardHalf extends MockCard implements SplitCardHalf {
public MockSplitCardHalf(final MockSplitCardHalf card) { public MockSplitCardHalf(final MockSplitCardHalf card) {
super(card); super(card);
this.splitCardParent = card.splitCardParent;
this.manaCosts = card.manaCosts.copy();
this.manaCostsSymbols = new ArrayList<>(card.manaCostsSymbols);
} }
@Override @Override