diff --git a/Mage.Sets/src/mage/cards/b/BoardedWindow.java b/Mage.Sets/src/mage/cards/b/BoardedWindow.java new file mode 100644 index 00000000000..a762fc91c62 --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BoardedWindow.java @@ -0,0 +1,102 @@ +package mage.cards.b; + +import java.util.UUID; + +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.condition.Condition; +import mage.abilities.effects.common.ExileSourceEffect; +import mage.abilities.effects.common.continuous.BoostAllEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.filter.common.FilterAttackingCreature; +import mage.game.Game; +import mage.game.combat.CombatGroup; +import mage.game.permanent.Permanent; +import mage.watchers.common.DamageDoneWatcher; + +/** + * + * @author weirddan455 + */ +public final class BoardedWindow extends CardImpl { + + private static final BoardedWindowFilter filter = new BoardedWindowFilter(); + + public BoardedWindow(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); + + // Creatures attacking you get -1/-0. + this.addAbility(new SimpleStaticAbility(new BoostAllEffect(-1, 0, Duration.WhileOnBattlefield, filter, false))); + + // At the beginning of each end step, if you were dealt 4 or more damage this turn, exile Boarded Window. + this.addAbility(new BeginningOfEndStepTriggeredAbility( + Zone.BATTLEFIELD, new ExileSourceEffect(), TargetController.ANY, BoardedWindowCondition.instance, false + ), new DamageDoneWatcher()); + } + + private BoardedWindow(final BoardedWindow card) { + super(card); + } + + @Override + public BoardedWindow copy() { + return new BoardedWindow(this); + } +} + +class BoardedWindowFilter extends FilterAttackingCreature { + + public BoardedWindowFilter() { + super("creatures attacking you"); + } + + private BoardedWindowFilter(final BoardedWindowFilter filter) { + super(filter); + } + + @Override + public BoardedWindowFilter copy() { + return new BoardedWindowFilter(this); + } + + @Override + public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) { + if (!super.match(permanent, sourceId, playerId, game)) { + return false; + } + + for (CombatGroup group : game.getCombat().getGroups()) { + for (UUID attacker : group.getAttackers()) { + if (attacker.equals(permanent.getId())) { + UUID defenderId = group.getDefenderId(); + if (defenderId.equals(playerId)) { + return true; + } + } + } + } + + return false; + } +} + +enum BoardedWindowCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + DamageDoneWatcher watcher = game.getState().getWatcher(DamageDoneWatcher.class); + return watcher != null && watcher.damageDoneTo(source.getControllerId(), 0, game) >= 4; + } + + @Override + public String toString() { + return "you were dealt 4 or more damage this turn"; + } +} diff --git a/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java b/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java index 9b84cff0d21..426ea5dd499 100644 --- a/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java +++ b/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java @@ -57,6 +57,7 @@ public final class InnistradCrimsonVow extends ExpansionSet { cards.add(new SetCardInfo("Bloodvial Purveyor", 98, Rarity.RARE, mage.cards.b.BloodvialPurveyor.class)); cards.add(new SetCardInfo("Bloody Betrayal", 147, Rarity.COMMON, mage.cards.b.BloodyBetrayal.class)); cards.add(new SetCardInfo("Blossom-Clad Werewolf", 226, Rarity.COMMON, mage.cards.b.BlossomCladWerewolf.class)); + cards.add(new SetCardInfo("Boarded Window", 253, Rarity.UNCOMMON, mage.cards.b.BoardedWindow.class)); cards.add(new SetCardInfo("Bramble Armor", 188, Rarity.COMMON, mage.cards.b.BrambleArmor.class)); cards.add(new SetCardInfo("Bramble Wurm", 189, Rarity.UNCOMMON, mage.cards.b.BrambleWurm.class)); cards.add(new SetCardInfo("Bride's Gown", 4, Rarity.UNCOMMON, mage.cards.b.BridesGown.class));