From 39d78aff2f0603f4bc8cc197dcbc0d88bd8da9c6 Mon Sep 17 00:00:00 2001 From: theelk801 Date: Wed, 3 May 2023 17:05:59 -0400 Subject: [PATCH] [MAT] Implement Tyvar, the Bellicose --- .../src/mage/cards/t/TyvarTheBellicose.java | 110 ++++++++++++++++++ .../sets/MarchOfTheMachineTheAftermath.java | 1 + .../AttacksWithCreaturesTriggeredAbility.java | 26 ++++- .../main/java/mage/game/events/ManaEvent.java | 2 +- 4 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/t/TyvarTheBellicose.java diff --git a/Mage.Sets/src/mage/cards/t/TyvarTheBellicose.java b/Mage.Sets/src/mage/cards/t/TyvarTheBellicose.java new file mode 100644 index 00000000000..0396738e936 --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TyvarTheBellicose.java @@ -0,0 +1,110 @@ +package mage.cards.t; + +import mage.MageInt; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.AttacksWithCreaturesTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; +import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.abilities.keyword.DeathtouchAbility; +import mage.abilities.mana.ManaAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; +import mage.game.events.GameEvent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class TyvarTheBellicose extends CardImpl { + + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(SubType.ELF, ""); + + static { + filter.add(TargetController.YOU.getControllerPredicate()); + } + + public TyvarTheBellicose(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}{G}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.ELF); + this.subtype.add(SubType.WARRIOR); + this.power = new MageInt(5); + this.toughness = new MageInt(4); + + // Whenever one or more Elves you control attack, they gain deathtouch until end of turn. + this.addAbility(new AttacksWithCreaturesTriggeredAbility( + Zone.BATTLEFIELD, new GainAbilityTargetEffect(DeathtouchAbility.getInstance()) + .setText("they gain deathtouch until end of turn"), 1, filter, true + ).setTriggerPhrase("Whenever one or more Elves you control attack, ")); + + // Each creature you control has "Whenever a mana ability of this creature resolves, put a number of +1/+1 counters on it equal to the amount of mana this creature produced. This ability triggers only once each turn." + this.addAbility(new SimpleStaticAbility(new GainAbilityControlledEffect( + new TyvarTheBellicoseTriggeredAbility(), + Duration.WhileOnBattlefield, + StaticFilters.FILTER_PERMANENT_CREATURE + ))); + } + + private TyvarTheBellicose(final TyvarTheBellicose card) { + super(card); + } + + @Override + public TyvarTheBellicose copy() { + return new TyvarTheBellicose(this); + } +} + +class TyvarTheBellicoseTriggeredAbility extends TriggeredAbilityImpl { + + TyvarTheBellicoseTriggeredAbility() { + super(Zone.BATTLEFIELD, new AddCountersSourceEffect( + CounterType.P1P1.createInstance(0), SavedDamageValue.MANY, false + )); + this.setTriggersOnce(true); + } + + private TyvarTheBellicoseTriggeredAbility(final TyvarTheBellicoseTriggeredAbility ability) { + super(ability); + } + + @Override + public TyvarTheBellicoseTriggeredAbility copy() { + return new TyvarTheBellicoseTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.MANA_ADDED; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (isControlledBy(event.getPlayerId()) + && event.getSourceId().equals(getSourceId()) + && game + .getAbility(event.getTargetId(), event.getSourceId()) + .map(ManaAbility.class::isInstance) + .orElse(false)) { + this.getEffects().setValue("damage", event.getAmount()); + return true; + } + return false; + } + + @Override + public String getRule() { + return "Whenever a mana ability of this creature resolves, put a number of +1/+1 counters on it " + + "equal to the amount of mana this creature produced. This ability triggers only once each turn."; + } +} diff --git a/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java b/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java index 1cd613d3ed9..42ca048d2d5 100644 --- a/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java +++ b/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java @@ -46,6 +46,7 @@ public final class MarchOfTheMachineTheAftermath extends ExpansionSet { cards.add(new SetCardInfo("Spark Rupture", 5, Rarity.RARE, mage.cards.s.SparkRupture.class)); cards.add(new SetCardInfo("The Kenriths' Royal Funeral", 34, Rarity.RARE, mage.cards.t.TheKenrithsRoyalFuneral.class)); cards.add(new SetCardInfo("Training Grounds", 9, Rarity.RARE, mage.cards.t.TrainingGrounds.class)); + cards.add(new SetCardInfo("Tyvar the Bellicose", 48, Rarity.MYTHIC, mage.cards.t.TyvarTheBellicose.class)); cards.add(new SetCardInfo("Undercity Upheaval", 25, Rarity.UNCOMMON, mage.cards.u.UndercityUpheaval.class)); } } diff --git a/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java index cedd901d4e4..ac5ca2e90a2 100644 --- a/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java @@ -7,8 +7,14 @@ import mage.filter.StaticFilters; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTargets; import mage.util.CardUtil; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + /** * @author Styxo */ @@ -16,6 +22,7 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl { private final FilterCreaturePermanent filter; private final int minAttackers; + private final boolean setTargetPointer; public AttacksWithCreaturesTriggeredAbility(Effect effect, int minAttackers) { this(effect, minAttackers, StaticFilters.FILTER_PERMANENT_CREATURES); @@ -26,9 +33,14 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl { } public AttacksWithCreaturesTriggeredAbility(Zone zone, Effect effect, int minAttackers, FilterCreaturePermanent filter) { + this(zone, effect, minAttackers, filter, false); + } + + public AttacksWithCreaturesTriggeredAbility(Zone zone, Effect effect, int minAttackers, FilterCreaturePermanent filter, boolean setTargetPointer) { super(zone, effect); this.filter = filter; this.minAttackers = minAttackers; + this.setTargetPointer = setTargetPointer; if (minAttackers == 1) { setTriggerPhrase("Whenever you attack, "); } else { @@ -45,6 +57,7 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl { super(ability); this.filter = ability.filter; this.minAttackers = ability.minAttackers; + this.setTargetPointer = ability.setTargetPointer; } @Override @@ -62,18 +75,21 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl { if (!isControlledBy(game.getCombat().getAttackingPlayerId())) { return false; } - int attackers = game + List attackers = game .getCombat() .getAttackers() .stream() .map(game::getPermanent) + .filter(Objects::nonNull) .filter(permanent -> filter.match(permanent, controllerId, this, game)) - .mapToInt(x -> 1) - .sum(); - if (attackers < minAttackers) { + .collect(Collectors.toList()); + if (attackers.size() < minAttackers) { return false; } - getEffects().setValue("attackers", attackers); + getEffects().setValue("attackers", attackers.size()); + if (setTargetPointer) { + getEffects().setTargetPointer(new FixedTargets(attackers, game)); + } return true; } } diff --git a/Mage/src/main/java/mage/game/events/ManaEvent.java b/Mage/src/main/java/mage/game/events/ManaEvent.java index dfcb10e1f11..108f5d1997b 100644 --- a/Mage/src/main/java/mage/game/events/ManaEvent.java +++ b/Mage/src/main/java/mage/game/events/ManaEvent.java @@ -13,7 +13,7 @@ public class ManaEvent extends GameEvent { protected Mana mana; public ManaEvent(EventType type, UUID targetId, Ability source, UUID playerId, Mana mana) { - super(type, targetId, source, playerId); + super(type, targetId, source, playerId, mana.count(), false); this.mana = mana; }