From 8684eb2b3ce3db90c5a3d55f9df0c9e36e02d752 Mon Sep 17 00:00:00 2001 From: Noah Gleason Date: Sun, 1 Jul 2018 22:05:43 -0400 Subject: [PATCH] Implement Cover of Winter --- Mage.Sets/src/mage/cards/c/CoverOfWinter.java | 102 ++++++++++++++++++ Mage.Sets/src/mage/sets/Coldsnap.java | 1 + 2 files changed, 103 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/c/CoverOfWinter.java diff --git a/Mage.Sets/src/mage/cards/c/CoverOfWinter.java b/Mage.Sets/src/mage/cards/c/CoverOfWinter.java new file mode 100644 index 0000000000..5497f041bb --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/CoverOfWinter.java @@ -0,0 +1,102 @@ +package mage.cards.c; + +import java.util.UUID; + +import mage.abilities.Ability; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.PreventionEffectData; +import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.constants.Duration; +import mage.constants.SuperType; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.keyword.CumulativeUpkeepAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; + +/** + * + * @author noahg + */ +public final class CoverOfWinter extends CardImpl { + + public CoverOfWinter(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); + + this.addSuperType(SuperType.SNOW); + + // Cumulative upkeep {S} + this.addAbility(new CumulativeUpkeepAbility(new ManaCostsImpl("{S}"))); + + // If a creature would deal combat damage to you and/or one or more creatures you control, prevent X of that damage, where X is the number of age counters on Cover of Winter. + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CoverOfWinterEffect())); + + // {S}: Put an age counter on Cover of Winter. + this.addAbility(new SimpleActivatedAbility(new AddCountersSourceEffect(CounterType.AGE.createInstance()), new ManaCostsImpl("{S}"))); + } + + public CoverOfWinter(final CoverOfWinter card) { + super(card); + } + + @Override + public CoverOfWinter copy() { + return new CoverOfWinter(this); + } +} + +class CoverOfWinterEffect extends PreventionEffectImpl { + + public CoverOfWinterEffect() { + super(Duration.WhileOnBattlefield, -1, true); + this.staticText = "If a creature would deal combat damage to you and/or one or more creatures you control, prevent X of that damage, where X is the number of age counters on {this}"; + } + + public CoverOfWinterEffect(CoverOfWinterEffect effect) { + super(effect); + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_PLAYER || event.getType() == GameEvent.EventType.DAMAGE_CREATURE; + } + + @Override + protected PreventionEffectData preventDamageAction(GameEvent event, Ability source, Game game) { + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + if (sourcePermanent != null) { + return game.preventDamage(event, source, game, sourcePermanent.getCounters(game).getCount(CounterType.AGE)); + } else { + this.discard(); + return game.preventDamage(event, source, game, 0); + } + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER + && event.getTargetId().equals(source.getControllerId())) { + return super.applies(event, source, game); + } + + if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.getControllerId().equals(source.getControllerId())) { + return super.applies(event, source, game); + } + } + return false; + } + + @Override + public CoverOfWinterEffect copy() { + return new CoverOfWinterEffect(this); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/Coldsnap.java b/Mage.Sets/src/mage/sets/Coldsnap.java index 6fbb6b7f9d..a0f628dcc9 100644 --- a/Mage.Sets/src/mage/sets/Coldsnap.java +++ b/Mage.Sets/src/mage/sets/Coldsnap.java @@ -52,6 +52,7 @@ public final class Coldsnap extends ExpansionSet { cards.add(new SetCardInfo("Commandeer", 29, Rarity.RARE, mage.cards.c.Commandeer.class)); cards.add(new SetCardInfo("Controvert", 30, Rarity.UNCOMMON, mage.cards.c.Controvert.class)); cards.add(new SetCardInfo("Counterbalance", 31, Rarity.UNCOMMON, mage.cards.c.Counterbalance.class)); + cards.add(new SetCardInfo("Cover of Winter", 3, Rarity.RARE, mage.cards.c.CoverOfWinter.class)); cards.add(new SetCardInfo("Cryoclasm", 79, Rarity.UNCOMMON, mage.cards.c.Cryoclasm.class)); cards.add(new SetCardInfo("Darien, King of Kjeldor", 4, Rarity.RARE, mage.cards.d.DarienKingOfKjeldor.class)); cards.add(new SetCardInfo("Dark Depths", 145, Rarity.RARE, mage.cards.d.DarkDepths.class));