diff --git a/res/cardsfolder/m/momir_vig_simic_visionary_avatar.txt b/res/cardsfolder/m/momir_vig_simic_visionary_avatar.txt index 106cd1c3da3..f049a781f9c 100644 --- a/res/cardsfolder/m/momir_vig_simic_visionary_avatar.txt +++ b/res/cardsfolder/m/momir_vig_simic_visionary_avatar.txt @@ -2,8 +2,8 @@ Name:Momir Vig, Simic Visionary Avatar ManaCost:no cost Types:Vanguard HandLifeModifier:+0/+4 -A:AB$ ChooseCard | Cost$ X Discard<1/Card> | ActivationZone$ Command | AtRandom$ True | Choices$ Creature.cmcEQX | References$ X | Amount$ 1 | SubAbility$ DBToken | SorcerySpeed$ True | ActivationLimit$ 1 | SpellDescription$ Put a token onto the battlefield that's a copy of a creature card with converted mana cost X chosen at random. Activate this ability only any time you could cast a sorcery and only once each turn. -SVar:DBToken:DB$ CopyPermanent | Defined$ ChosenCard | NumCopies$ 1 +A:AB$ NameCard | Cost$ X Discard<1/Card> | ActivationZone$ Command | AtRandom$ True | ValidCards$ Creature | ValidAttribute$ cmcEQX | References$ X | Amount$ 1 | SubAbility$ DBToken | SorcerySpeed$ True | ActivationLimit$ 1 | AILogic$ MomirAvatar | SpellDescription$ Put a token onto the battlefield that's a copy of a creature card with converted mana cost X chosen at random. Activate this ability only any time you could cast a sorcery and only once each turn. | StackDescription$ SpellDescription +SVar:DBToken:DB$ CopyPermanent | ValidSupportedCopy$ Card | DefinedName$ NamedCard | NumCopies$ 1 | StackDescription$ SVar:X:Count$xPaid SVar:Picture:http://www.cardforge.org/fpics/vgd-lq/momir_vig_simic_visionary_avatar.jpg Oracle:Hand +0, life +4\n{X}, Discard a card: Put a token onto the battlefield that's a copy of a creature card with converted mana cost X chosen at random. Activate this ability only any time you could cast a sorcery and only once each turn. diff --git a/src/main/java/forge/card/ability/effects/ChooseCardNameEffect.java b/src/main/java/forge/card/ability/effects/ChooseCardNameEffect.java index 29801bbdb61..24f1aec717d 100644 --- a/src/main/java/forge/card/ability/effects/ChooseCardNameEffect.java +++ b/src/main/java/forge/card/ability/effects/ChooseCardNameEffect.java @@ -13,7 +13,9 @@ import com.google.common.collect.Lists; import forge.Card; import forge.CardLists; import forge.CardPredicates.Presets; +import forge.card.CardRules; import forge.card.CardRulesPredicates; +import forge.card.ability.AbilityUtils; import forge.card.ability.SpellAbilityEffect; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; @@ -23,6 +25,8 @@ import forge.game.zone.ZoneType; import forge.gui.GuiChoose; import forge.item.CardDb; import forge.item.CardPrinted; +import forge.util.Aggregates; +import forge.util.ComparableOp; public class ChooseCardNameEffect extends SpellAbilityEffect { @@ -56,8 +60,23 @@ public class ChooseCardNameEffect extends SpellAbilityEffect { if ((tgt == null) || p.canBeTargetedBy(sa)) { boolean ok = false; while (!ok) { - if (p.isHuman()) { - + if (sa.hasParam("AtRandom")) { + // Currently only used for Momir Avatar, if something else gets added here, make it more generic + Predicate baseRule = CardRulesPredicates.Presets.IS_CREATURE; + + String numericAmount = "X"; + final int validAmount = StringUtils.isNumeric(numericAmount) ? Integer.parseInt(numericAmount) : + AbilityUtils.calculateAmount(host, numericAmount, sa); + + Predicate additionalRule = CardRulesPredicates.cmc(ComparableOp.EQUALS, validAmount); + + List cards = Lists.newArrayList(CardDb.instance().getUniqueCards()); + Predicate cpp = Predicates.and(Predicates.compose(baseRule, CardPrinted.FN_GET_RULES), + Predicates.compose(additionalRule, CardPrinted.FN_GET_RULES)); + cards = Lists.newArrayList(Iterables.filter(cards, cpp)); + host.setNamedCard(Aggregates.random(cards).getName()); + ok = true; + } else if (p.isHuman()) { final String message = validDesc.equals("card") ? "Name a card" : "Name a " + validDesc + " card."; List cards = Lists.newArrayList(CardDb.instance().getUniqueCards()); diff --git a/src/main/java/forge/card/ability/effects/CopyPermanentEffect.java b/src/main/java/forge/card/ability/effects/CopyPermanentEffect.java index f3fd3a6f139..41e6b8734e5 100644 --- a/src/main/java/forge/card/ability/effects/CopyPermanentEffect.java +++ b/src/main/java/forge/card/ability/effects/CopyPermanentEffect.java @@ -96,12 +96,21 @@ public class CopyPermanentEffect extends SpellAbilityEffect { } tgtCards = choice; } else if (sa.hasParam("DefinedName")) { - final String name = sa.getParam("DefinedName"); + String name = sa.getParam("DefinedName"); + if (name.equals("NamedCard")) { + if (!hostCard.getNamedCard().isEmpty()) { + name = hostCard.getNamedCard(); + } + } + Predicate cpp = Predicates.compose(CardRulesPredicates.name(StringOp.EQUALS, name), CardPrinted.FN_GET_RULES); cards = Lists.newArrayList(Iterables.filter(cards, cpp)); - Card c = cards.get(0).getMatchingForgeCard(); + tgtCards.clear(); - tgtCards.add(c); + if (!cards.isEmpty()) { + Card c = cards.get(0).getMatchingForgeCard(); + tgtCards.add(c); + } } }