[KHM] Implemented Codespell Cleric

This commit is contained in:
Evan Kranzler 2021-01-22 12:52:54 -05:00
parent 623ff23762
commit ca05fb9253
4 changed files with 89 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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));

View file

@ -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

View file

@ -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;
}
}