From ca05fb9253be0cecf8047ba665cf7005c0655fa2 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Fri, 22 Jan 2021 12:52:54 -0500 Subject: [PATCH] [KHM] Implemented Codespell Cleric --- .../src/mage/cards/c/CodespellCleric.java | 68 +++++++++++++++++++ Mage.Sets/src/mage/sets/Kaldheim.java | 1 + .../EntersBattlefieldTriggeredAbility.java | 8 ++- .../common/CastSpellLastTurnWatcher.java | 15 ++++ 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/c/CodespellCleric.java diff --git a/Mage.Sets/src/mage/cards/c/CodespellCleric.java b/Mage.Sets/src/mage/cards/c/CodespellCleric.java new file mode 100644 index 0000000000..3f7421ac5a --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/CodespellCleric.java @@ -0,0 +1,68 @@ +package mage.cards.c; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.condition.Condition; +import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; +import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.abilities.keyword.VigilanceAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.common.TargetCreaturePermanent; +import mage.watchers.common.CastSpellLastTurnWatcher; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class CodespellCleric extends CardImpl { + + public CodespellCleric(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{W}"); + + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.CLERIC); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // Vigilance + this.addAbility(VigilanceAbility.getInstance()); + + // When Codespell Cleric enters the battlefield, if it was the second spell you cast this turn, put a +1/+1 counter on target creature. + Ability ability = new ConditionalInterveningIfTriggeredAbility( + new EntersBattlefieldTriggeredAbility(new AddCountersTargetEffect(CounterType.P1P1.createInstance())), + CodespellClericCondition.instance, "When {this} enters the battlefield, " + + "if it was the second spell you cast this turn, put a +1/+1 counter on target creature." + ); + ability.addTarget(new TargetCreaturePermanent()); + this.addAbility(ability); + } + + private CodespellCleric(final CodespellCleric card) { + super(card); + } + + @Override + public CodespellCleric copy() { + return new CodespellCleric(this); + } +} + +enum CodespellClericCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); + return watcher != null && watcher.getPermanentSpellOrder( + (Permanent) source.getEffects().get(0).getValue("permanentEnteredBattlefield"), game + ) == 2; + } +} diff --git a/Mage.Sets/src/mage/sets/Kaldheim.java b/Mage.Sets/src/mage/sets/Kaldheim.java index 307251f6c3..ca1a67fc2c 100644 --- a/Mage.Sets/src/mage/sets/Kaldheim.java +++ b/Mage.Sets/src/mage/sets/Kaldheim.java @@ -119,6 +119,7 @@ public final class Kaldheim extends ExpansionSet { cards.add(new SetCardInfo("Cinderheart Giant", 126, Rarity.COMMON, mage.cards.c.CinderheartGiant.class)); cards.add(new SetCardInfo("Clarion Spirit", 6, Rarity.UNCOMMON, mage.cards.c.ClarionSpirit.class)); cards.add(new SetCardInfo("Cleaving Reaper", 376, Rarity.RARE, mage.cards.c.CleavingReaper.class)); + cards.add(new SetCardInfo("Codespell Cleric", 7, Rarity.COMMON, mage.cards.c.CodespellCleric.class)); cards.add(new SetCardInfo("Colossal Plow", 236, Rarity.UNCOMMON, mage.cards.c.ColossalPlow.class)); cards.add(new SetCardInfo("Cosmos Elixir", 237, Rarity.RARE, mage.cards.c.CosmosElixir.class)); cards.add(new SetCardInfo("Craven Hulk", 127, Rarity.COMMON, mage.cards.c.CravenHulk.class)); diff --git a/Mage/src/main/java/mage/abilities/common/EntersBattlefieldTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/EntersBattlefieldTriggeredAbility.java index bec1ddd16f..653216c558 100644 --- a/Mage/src/main/java/mage/abilities/common/EntersBattlefieldTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/EntersBattlefieldTriggeredAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.common; import mage.abilities.TriggeredAbilityImpl; @@ -8,7 +7,6 @@ import mage.game.Game; import mage.game.events.GameEvent; /** - * * @author BetaSteward_at_googlemail.com */ public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl { @@ -47,7 +45,11 @@ public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - return event.getTargetId().equals(getSourceId()); + if (event.getTargetId().equals(getSourceId())) { + this.getEffects().setValue("permanentEnteredBattlefield", game.getPermanent(event.getTargetId())); + return true; + } + return false; } @Override diff --git a/Mage/src/main/java/mage/watchers/common/CastSpellLastTurnWatcher.java b/Mage/src/main/java/mage/watchers/common/CastSpellLastTurnWatcher.java index c2fe4644a8..5fe0c10784 100644 --- a/Mage/src/main/java/mage/watchers/common/CastSpellLastTurnWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CastSpellLastTurnWatcher.java @@ -4,6 +4,7 @@ import mage.MageObjectReference; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; import mage.watchers.Watcher; import java.util.*; @@ -69,4 +70,18 @@ public class CastSpellLastTurnWatcher extends Watcher { } return 0; } + + public int getPermanentSpellOrder(Permanent permanent, Game game) { + if (permanent == null) { + return -1; + } + int index = 0; + for (MageObjectReference mor : spellsCastThisTurnInOrder) { + index++; + if (mor.getSourceId() == permanent.getId() && mor.getZoneChangeCounter() + 1 == permanent.getZoneChangeCounter(game)) { + return index; + } + } + return -1; + } }