refactor: improved card info

This commit is contained in:
Oleg Agafonov 2024-02-18 22:40:30 +04:00
parent b1e4ea2790
commit ad8e7daf97
47 changed files with 84 additions and 81 deletions

View file

@ -65,7 +65,7 @@ public class ConjureCardEffect extends OneShotEffect {
}
Set<Card> cards = new HashSet<>();
for (int i = 0; i < amount; i++) {
Card card = cardInfo.getCard();
Card card = cardInfo.createCard();
cards.add(card);
}
game.loadCards(cards, source.getControllerId());

View file

@ -70,7 +70,7 @@ public class DraftFromSpellbookEffect extends OneShotEffect {
return false;
}
Set<Card> cards = new HashSet<>();
cards.add(cardInfo.getCard());
cards.add(cardInfo.createCard());
game.loadCards(cards, player.getId());
player.moveCards(cards, Zone.HAND, source, game);
return true;

View file

@ -105,7 +105,7 @@ public class MeldEffect extends OneShotEffect {
if (cardInfoList.isEmpty()) {
return false;
}
MeldCard meldCard = (MeldCard) cardInfoList.get(0).getCard().copy();
MeldCard meldCard = (MeldCard) cardInfoList.get(0).createCard().copy();
meldCard.setOwnerId(controller.getId());
meldCard.setTopHalfCard(meldWithCard, game);
meldCard.setBottomHalfCard(sourceCard, game);

View file

@ -232,7 +232,7 @@ public abstract class ExpansionSet implements Serializable {
}
CardInfo cardInfo = cards.remove(RandomUtil.nextInt(cards.size()));
Card card = cardInfo.getCard();
Card card = cardInfo.createCard();
if (card == null) {
// card with error
return;
@ -273,7 +273,7 @@ public abstract class ExpansionSet implements Serializable {
.makeBooster()
.stream()
.map(inBoosterMap::get)
.map(CardInfo::getCard)
.map(CardInfo::createCard)
.collect(Collectors.toList());
}
@ -569,7 +569,7 @@ public abstract class ExpansionSet implements Serializable {
booster.forEach(card -> {
List<CardInfo> reprints = this.savedReprints.getOrDefault(card.getName(), null);
if (reprints != null && reprints.size() > 1) {
Card newCard = reprints.get(RandomUtil.nextInt(reprints.size())).getCard();
Card newCard = reprints.get(RandomUtil.nextInt(reprints.size())).createCard();
if (newCard != null) {
finalBooster.add(newCard);
return;

View file

@ -127,7 +127,7 @@ public class Sets extends HashMap<String, ExpansionSet> {
List<Card> cardPool = new ArrayList<>();
while (count < cardsCount) {
CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
Card card = cardInfo != null ? cardInfo.getCard() : null;
Card card = cardInfo != null ? cardInfo.createCard() : null;
if (card != null) {
FilterMana manaCard = card.getColorIdentity();

View file

@ -184,9 +184,9 @@ public class Deck implements Serializable, Copyable<Deck> {
}
if (mockCards) {
return cardInfo.getMockCard();
return cardInfo.createMockCard();
} else {
return cardInfo.getCard();
return cardInfo.createCard();
}
}

View file

@ -75,7 +75,7 @@ public class MockCard extends CardImpl {
}
if (card.isModalDoubleFacedCard()) {
ModalDoubleFacedCard mdfCard = (ModalDoubleFacedCard) card.getCard();
ModalDoubleFacedCard mdfCard = (ModalDoubleFacedCard) card.createCard();
CardInfo mdfSecondSide = new CardInfo(mdfCard.getRightHalfCard());
this.secondSideCard = new MockCard(mdfSecondSide);
this.isModalDoubleFacedCard = true;

View file

@ -238,11 +238,17 @@ public class CardInfo {
this.isExtraDeckCard = card.isExtraDeckCard();
}
public Card getCard() {
/**
* Create normal card (with full abilities)
*/
public Card createCard() {
return CardImpl.createCard(className, new CardSetInfo(name, setCode, cardNumber, rarity, new CardGraphicInfo(FrameStyle.valueOf(frameStyle), variousArt)));
}
public Card getMockCard() {
/**
* Create deck editor's mock card (with text only instead real abilities)
*/
public Card createMockCard() {
if (this.splitCard) {
return new MockSplitCard(this);
} else {

View file

@ -121,7 +121,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
default:
CardInfo cardInfo = CardRepository.instance.findCard(commanderName);
if (cardInfo != null) {
commander = cardInfo.getCard();
commander = cardInfo.createCard();
}
}
}

View file

@ -44,7 +44,7 @@ public final class EmblemOfCard extends Emblem {
.orElseGet(() -> found.stream()
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No real card for " + infoTypeForError + " " + cardName)))
.getCard();
.createCard();
}
public static Card cardFromDeckInfo(DeckCardInfo info) {

View file

@ -93,7 +93,7 @@ class MomirEffect extends OneShotEffect {
if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
options.remove(index);
} else {
Card card = options.get(index).getCard();
Card card = options.get(index).createCard();
if (card != null) {
token = CopyTokenFunction.createTokenCopy(card, game);
break;

View file

@ -96,7 +96,7 @@ public abstract class DraftCube {
}
if (cardInfo != null) {
booster.add(cardInfo.getCard());
booster.add(cardInfo.createCard());
done = true;
} else {
logger.warn(new StringBuilder(this.getName()).append(" - Card not found: ").append(cardId.getName()).append(':').append(cardId.extension));

View file

@ -81,7 +81,7 @@ public class RemixedSet implements Serializable {
return;
}
CardInfo cardInfo = cards.remove(RandomUtil.nextInt(cards.size())); // so no duplicates in a booster
Card card = cardInfo.getCard();
Card card = cardInfo.createCard();
if (card == null) {
return;
}

View file

@ -73,7 +73,7 @@ public final class TournamentUtil {
List<Card> cards = new ArrayList<>();
if (!lands.isEmpty()) {
for (int i = 0; i < number; i++) {
Card land = lands.get(RandomUtil.nextInt(lands.size())).getCard();
Card land = lands.get(RandomUtil.nextInt(lands.size())).createCard();
cards.add(land);
}
}