From c5ecb26289b31f9e10f5860af0677f7b1cec049b Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Wed, 11 Nov 2015 12:55:49 -0800 Subject: [PATCH] Momir: lookup token at activation loading all the cards at game start is quite slow --- .../src/mage/game/MomirDuel.java | 31 +++++-------------- .../mage/cards/repository/CardCriteria.java | 11 +++++++ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java b/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java index 65290a0b72..e34dd81d2a 100644 --- a/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java +++ b/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java @@ -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> available = new HashMap<>(); - CardCriteria criteria = new CardCriteria().types(CardType.CREATURE); - List cards = CardRepository.instance.findCards(criteria); - - for (CardInfo card : cards) { - List 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> 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> available; - public MomirEffect(Map> 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 options = available.get(value); + // should this be random across card names, or card printings? + CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).convertedManaCost(value); + List 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); diff --git a/Mage/src/mage/cards/repository/CardCriteria.java b/Mage/src/mage/cards/repository/CardCriteria.java index 3f33e19da6..38e25425db 100644 --- a/Mage/src/mage/cards/repository/CardCriteria.java +++ b/Mage/src/mage/cards/repository/CardCriteria.java @@ -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) {