Momir: lookup token at activation

loading all the cards at game start is quite slow
This commit is contained in:
Neil Gentleman 2015-11-11 12:55:49 -08:00
parent cda5a06a6c
commit c5ecb26289
2 changed files with 19 additions and 23 deletions

View file

@ -74,25 +74,11 @@ public class MomirDuel extends GameImpl {
@Override @Override
protected void init(UUID choosingPlayerId) { 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")); Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Vanguard effects"));
for (UUID playerId : state.getPlayerList(startingPlayerId)) { for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId); Player player = getPlayer(playerId);
if (player != null) { if (player != null) {
addEmblem(new MomirEmblem(available), ability, playerId); addEmblem(new MomirEmblem(), ability, playerId);
} }
} }
getState().addAbility(ability, null); 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 // faking Vanguard as an Emblem; need to come back to this and add a new type of CommandObject
class MomirEmblem extends Emblem { class MomirEmblem extends Emblem {
public MomirEmblem(Map<Integer, List<Card>> available) { public MomirEmblem() {
setName("Momir Vig, Simic Visionary"); 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. // {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.addCost(new DiscardCardCost());
ability.setTiming(TimingRule.SORCERY); ability.setTiming(TimingRule.SORCERY);
this.getAbilities().add(ability); this.getAbilities().add(ability);
@ -141,16 +127,13 @@ class MomirEmblem extends Emblem {
class MomirEffect extends OneShotEffect { class MomirEffect extends OneShotEffect {
private static final Random rnd = new Random(); 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); super(Outcome.PutCreatureInPlay);
this.available = available;
} }
public MomirEffect(MomirEffect effect) { public MomirEffect(MomirEffect effect) {
super(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"; 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 @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
int value = source.getManaCostsToPay().getX(); 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()) { 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(); EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card); CardUtil.copyTo(token).from(card);
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId(), false, false); token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId(), false, false);

View file

@ -59,6 +59,7 @@ public class CardCriteria {
private boolean red; private boolean red;
private boolean white; private boolean white;
private boolean colorless; private boolean colorless;
private Integer convertedManaCost;
private String sortBy; private String sortBy;
private Long start; private Long start;
private Long count; private Long count;
@ -173,6 +174,11 @@ public class CardCriteria {
return this; return this;
} }
public CardCriteria convertedManaCost(Integer convertedManaCost) {
this.convertedManaCost = convertedManaCost;
return this;
}
public CardCriteria maxCardNumber(int maxCardNumber) { public CardCriteria maxCardNumber(int maxCardNumber) {
this.maxCardNumber = maxCardNumber; this.maxCardNumber = maxCardNumber;
return this; return this;
@ -248,6 +254,11 @@ public class CardCriteria {
clausesCount++; clausesCount++;
} }
if (convertedManaCost != null) {
where.eq("convertedManaCost", convertedManaCost);
clausesCount++;
}
if (!black || !blue || !green || !red || !white || !colorless) { if (!black || !blue || !green || !red || !white || !colorless) {
int colorClauses = 0; int colorClauses = 0;
if (black) { if (black) {