mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
Momir: lookup token at activation
loading all the cards at game start is quite slow
This commit is contained in:
parent
cda5a06a6c
commit
c5ecb26289
2 changed files with 19 additions and 23 deletions
|
@ -74,25 +74,11 @@ public class MomirDuel extends GameImpl {
|
|||
|
||||
@Override
|
||||
protected void init(UUID choosingPlayerId) {
|
||||
// should this be random across card names, or card printings?
|
||||
Map<Integer, List<Card>> available = new HashMap<>();
|
||||
CardCriteria criteria = new CardCriteria().types(CardType.CREATURE);
|
||||
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
|
||||
|
||||
for (CardInfo card : cards) {
|
||||
List<Card> options = available.get(card.getConvertedManaCost());
|
||||
if (options == null) {
|
||||
options = new ArrayList<>();
|
||||
available.put(card.getConvertedManaCost(), options);
|
||||
}
|
||||
options.add(card.getCard());
|
||||
}
|
||||
|
||||
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Vanguard effects"));
|
||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||
Player player = getPlayer(playerId);
|
||||
if (player != null) {
|
||||
addEmblem(new MomirEmblem(available), ability, playerId);
|
||||
addEmblem(new MomirEmblem(), ability, playerId);
|
||||
}
|
||||
}
|
||||
getState().addAbility(ability, null);
|
||||
|
@ -126,11 +112,11 @@ public class MomirDuel extends GameImpl {
|
|||
// faking Vanguard as an Emblem; need to come back to this and add a new type of CommandObject
|
||||
class MomirEmblem extends Emblem {
|
||||
|
||||
public MomirEmblem(Map<Integer, List<Card>> available) {
|
||||
public MomirEmblem() {
|
||||
setName("Momir Vig, Simic Visionary");
|
||||
|
||||
// {X}, Discard a card: Put a token into play as a copy of a random creature card with converted mana cost X. Play this ability only any time you could play a sorcery and only once each turn.
|
||||
LimitedTimesPerTurnActivatedAbility ability = new LimitedTimesPerTurnActivatedAbility(Zone.COMMAND, new MomirEffect(available), new VariableManaCost());
|
||||
LimitedTimesPerTurnActivatedAbility ability = new LimitedTimesPerTurnActivatedAbility(Zone.COMMAND, new MomirEffect(), new VariableManaCost());
|
||||
ability.addCost(new DiscardCardCost());
|
||||
ability.setTiming(TimingRule.SORCERY);
|
||||
this.getAbilities().add(ability);
|
||||
|
@ -141,16 +127,13 @@ class MomirEmblem extends Emblem {
|
|||
class MomirEffect extends OneShotEffect {
|
||||
|
||||
private static final Random rnd = new Random();
|
||||
private final Map<Integer, List<Card>> available;
|
||||
|
||||
public MomirEffect(Map<Integer, List<Card>> available) {
|
||||
public MomirEffect() {
|
||||
super(Outcome.PutCreatureInPlay);
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public MomirEffect(MomirEffect effect) {
|
||||
super(effect);
|
||||
this.available = effect.available;
|
||||
staticText = "Put a token into play as a copy of a random creature card with converted mana cost X";
|
||||
}
|
||||
|
||||
|
@ -162,9 +145,11 @@ class MomirEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int value = source.getManaCostsToPay().getX();
|
||||
List<Card> options = available.get(value);
|
||||
// should this be random across card names, or card printings?
|
||||
CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).convertedManaCost(value);
|
||||
List<CardInfo> options = CardRepository.instance.findCards(criteria);
|
||||
if (options != null && !options.isEmpty()) {
|
||||
Card card = options.get(rnd.nextInt(options.size()));
|
||||
Card card = options.get(rnd.nextInt(options.size())).getCard();
|
||||
EmptyToken token = new EmptyToken();
|
||||
CardUtil.copyTo(token).from(card);
|
||||
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId(), false, false);
|
||||
|
|
|
@ -59,6 +59,7 @@ public class CardCriteria {
|
|||
private boolean red;
|
||||
private boolean white;
|
||||
private boolean colorless;
|
||||
private Integer convertedManaCost;
|
||||
private String sortBy;
|
||||
private Long start;
|
||||
private Long count;
|
||||
|
@ -173,6 +174,11 @@ public class CardCriteria {
|
|||
return this;
|
||||
}
|
||||
|
||||
public CardCriteria convertedManaCost(Integer convertedManaCost) {
|
||||
this.convertedManaCost = convertedManaCost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CardCriteria maxCardNumber(int maxCardNumber) {
|
||||
this.maxCardNumber = maxCardNumber;
|
||||
return this;
|
||||
|
@ -248,6 +254,11 @@ public class CardCriteria {
|
|||
clausesCount++;
|
||||
}
|
||||
|
||||
if (convertedManaCost != null) {
|
||||
where.eq("convertedManaCost", convertedManaCost);
|
||||
clausesCount++;
|
||||
}
|
||||
|
||||
if (!black || !blue || !green || !red || !white || !colorless) {
|
||||
int colorClauses = 0;
|
||||
if (black) {
|
||||
|
|
Loading…
Reference in a new issue