From fac51c9e7577119df1f7fbae3c3da8a8a4d904e1 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 2 Dec 2013 23:32:49 +0100 Subject: [PATCH] Added DrawCardOpponentTriggeredAbility. --- .../mage/sets/alarareborn/LorescaleCoatl.java | 4 +- .../sets/guildpact/NivMizzetTheFiremind.java | 4 +- .../mage/sets/lorwyn/HoofprintsOfTheStag.java | 4 +- .../mage/sets/magic2010/UnderworldDreams.java | 39 ++------- .../src/mage/sets/magic2011/JacesErasure.java | 4 +- .../src/mage/sets/mirrodin/MindsEye.java | 41 +--------- .../mirrodinbesieged/PsychosisCrawler.java | 4 +- .../mage/sets/morningtide/DivinersWand.java | 4 +- .../src/mage/sets/theros/HorizonChimera.java | 4 +- ...> DrawCardControllerTriggeredAbility.java} | 10 +-- .../DrawCardOpponentTriggeredAbility.java | 79 +++++++++++++++++++ 11 files changed, 107 insertions(+), 90 deletions(-) rename Mage/src/mage/abilities/common/{DrawCardTriggeredAbility.java => DrawCardControllerTriggeredAbility.java} (85%) create mode 100644 Mage/src/mage/abilities/common/DrawCardOpponentTriggeredAbility.java diff --git a/Mage.Sets/src/mage/sets/alarareborn/LorescaleCoatl.java b/Mage.Sets/src/mage/sets/alarareborn/LorescaleCoatl.java index f30bc13b60..5204f9c7bd 100644 --- a/Mage.Sets/src/mage/sets/alarareborn/LorescaleCoatl.java +++ b/Mage.Sets/src/mage/sets/alarareborn/LorescaleCoatl.java @@ -32,7 +32,7 @@ import java.util.UUID; import mage.constants.CardType; import mage.constants.Rarity; import mage.MageInt; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.counters.CounterType; @@ -53,7 +53,7 @@ public class LorescaleCoatl extends CardImpl { this.power = new MageInt(2); this.toughness = new MageInt(2); - this.addAbility(new DrawCardTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true)); + this.addAbility(new DrawCardControllerTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true)); } public LorescaleCoatl (final LorescaleCoatl card) { diff --git a/Mage.Sets/src/mage/sets/guildpact/NivMizzetTheFiremind.java b/Mage.Sets/src/mage/sets/guildpact/NivMizzetTheFiremind.java index 9e127bb3e3..2164a44e72 100644 --- a/Mage.Sets/src/mage/sets/guildpact/NivMizzetTheFiremind.java +++ b/Mage.Sets/src/mage/sets/guildpact/NivMizzetTheFiremind.java @@ -33,7 +33,7 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.DamageTargetEffect; @@ -60,7 +60,7 @@ public class NivMizzetTheFiremind extends CardImpl { this.power = new MageInt(4); this.toughness = new MageInt(4); this.addAbility(FlyingAbility.getInstance()); - Ability ability = new DrawCardTriggeredAbility(new DamageTargetEffect(1), false); + Ability ability = new DrawCardControllerTriggeredAbility(new DamageTargetEffect(1), false); ability.addTarget(new TargetCreatureOrPlayer()); this.addAbility(ability); this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new DrawCardControllerEffect(1), new TapSourceCost())); diff --git a/Mage.Sets/src/mage/sets/lorwyn/HoofprintsOfTheStag.java b/Mage.Sets/src/mage/sets/lorwyn/HoofprintsOfTheStag.java index 6ef2ef9708..46522f44b6 100644 --- a/Mage.Sets/src/mage/sets/lorwyn/HoofprintsOfTheStag.java +++ b/Mage.Sets/src/mage/sets/lorwyn/HoofprintsOfTheStag.java @@ -31,7 +31,7 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.costs.common.RemoveCountersSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.common.CreateTokenEffect; @@ -58,7 +58,7 @@ public class HoofprintsOfTheStag extends CardImpl { this.supertype.add("Tribal"); this.subtype.add("Elemental"); this.color.setWhite(true); - this.addAbility(new DrawCardTriggeredAbility(new AddCountersSourceEffect(CounterType.HOOFPRINT.createInstance(1)), true)); + this.addAbility(new DrawCardControllerTriggeredAbility(new AddCountersSourceEffect(CounterType.HOOFPRINT.createInstance(1)), true)); Ability ability = new ActivateIfConditionActivatedAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new WhiteElementalToken(), 1), new ManaCostsImpl("{2}{W}"), MyTurnCondition.getInstance()); ability.addCost(new RemoveCountersSourceCost(CounterType.HOOFPRINT.createInstance(4))); this.addAbility(ability); diff --git a/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java b/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java index 13c6c39305..a1048ecff8 100644 --- a/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java +++ b/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java @@ -28,12 +28,13 @@ package mage.sets.magic2010; import java.util.UUID; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.DrawCardOpponentTriggeredAbility; +import mage.abilities.effects.common.DamageTargetEffect; +import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; import mage.constants.Zone; -import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.common.DamageTargetEffect; -import mage.cards.CardImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.target.targetpointer.FixedTarget; @@ -51,7 +52,7 @@ public class UnderworldDreams extends CardImpl { this.color.setBlack(true); // Whenever an opponent draws a card, Underworld Dreams deals 1 damage to him or her. - this.addAbility(new UnderworldDreamsTriggeredAbility()); + this.addAbility(new DrawCardOpponentTriggeredAbility(new DamageTargetEffect(1, true, "him or her"), false, true)); } public UnderworldDreams(final UnderworldDreams card) { @@ -63,33 +64,3 @@ public class UnderworldDreams extends CardImpl { return new UnderworldDreams(this); } } - -class UnderworldDreamsTriggeredAbility extends TriggeredAbilityImpl { - - UnderworldDreamsTriggeredAbility() { - super(Zone.BATTLEFIELD, new DamageTargetEffect(1), false); - } - - UnderworldDreamsTriggeredAbility(final UnderworldDreamsTriggeredAbility ability) { - super(ability); - } - - @Override - public UnderworldDreamsTriggeredAbility copy() { - return new UnderworldDreamsTriggeredAbility(this); - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.DREW_CARD && game.getOpponents(this.getControllerId()).contains(event.getPlayerId())) { - getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId())); - return true; - } - return false; - } - - @Override - public String getRule() { - return "Whenever an opponent draws a card, {this} deals 1 damage to him or her"; - } -} diff --git a/Mage.Sets/src/mage/sets/magic2011/JacesErasure.java b/Mage.Sets/src/mage/sets/magic2011/JacesErasure.java index 8b82f8a740..e47c40671c 100644 --- a/Mage.Sets/src/mage/sets/magic2011/JacesErasure.java +++ b/Mage.Sets/src/mage/sets/magic2011/JacesErasure.java @@ -31,7 +31,7 @@ package mage.sets.magic2011; import java.util.UUID; import mage.constants.CardType; import mage.constants.Rarity; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.effects.common.PutLibraryIntoGraveTargetEffect; import mage.cards.CardImpl; import mage.target.TargetPlayer; @@ -47,7 +47,7 @@ public class JacesErasure extends CardImpl { this.expansionSetCode = "M11"; this.color.setBlue(true); - DrawCardTriggeredAbility ability = new DrawCardTriggeredAbility(new PutLibraryIntoGraveTargetEffect(1), true); + DrawCardControllerTriggeredAbility ability = new DrawCardControllerTriggeredAbility(new PutLibraryIntoGraveTargetEffect(1), true); ability.addTarget(new TargetPlayer()); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/sets/mirrodin/MindsEye.java b/Mage.Sets/src/mage/sets/mirrodin/MindsEye.java index a47a0ec763..182da49255 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/MindsEye.java +++ b/Mage.Sets/src/mage/sets/mirrodin/MindsEye.java @@ -28,17 +28,13 @@ package mage.sets.mirrodin; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.DrawCardOpponentTriggeredAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.DoIfCostPaid; import mage.abilities.effects.common.DrawCardControllerEffect; import mage.cards.CardImpl; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; +import mage.constants.CardType; +import mage.constants.Rarity; /** * @@ -51,7 +47,7 @@ public class MindsEye extends CardImpl { this.expansionSetCode = "MRD"; // Whenever an opponent draws a card, you may pay {1}. If you do, draw a card. - this.addAbility(new MindsEyeTriggeredAbility()); + this.addAbility(new DrawCardOpponentTriggeredAbility(new DoIfCostPaid(new DrawCardControllerEffect(1), new GenericManaCost(1)), false, false)); } public MindsEye(final MindsEye card) { @@ -63,32 +59,3 @@ public class MindsEye extends CardImpl { return new MindsEye(this); } } - -class MindsEyeTriggeredAbility extends TriggeredAbilityImpl { - - MindsEyeTriggeredAbility() { - super(Zone.BATTLEFIELD, new DoIfCostPaid(new DrawCardControllerEffect(1), new GenericManaCost(1)), false); - } - - MindsEyeTriggeredAbility(final MindsEyeTriggeredAbility ability) { - super(ability); - } - - @Override - public MindsEyeTriggeredAbility copy() { - return new MindsEyeTriggeredAbility(this); - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.DREW_CARD && game.getOpponents(this.getControllerId()).contains(event.getPlayerId())) { - return true; - } - return false; - } - - @Override - public String getRule() { - return "Whenever an opponent draws a card, you may pay {1}. If you do, draw a card."; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/PsychosisCrawler.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/PsychosisCrawler.java index 896179394a..3acbabab63 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/PsychosisCrawler.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/PsychosisCrawler.java @@ -36,7 +36,7 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.dynamicvalue.common.CardsInControllerHandCount; import mage.abilities.effects.OneShotEffect; @@ -61,7 +61,7 @@ public class PsychosisCrawler extends CardImpl { this.toughness = new MageInt(0); this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetPowerToughnessSourceEffect(new CardsInControllerHandCount(), Duration.EndOfGame))); - this.addAbility(new DrawCardTriggeredAbility(new LoseLifeOpponentsEffect(), false)); + this.addAbility(new DrawCardControllerTriggeredAbility(new LoseLifeOpponentsEffect(), false)); } public PsychosisCrawler(final PsychosisCrawler card) { diff --git a/Mage.Sets/src/mage/sets/morningtide/DivinersWand.java b/Mage.Sets/src/mage/sets/morningtide/DivinersWand.java index 2792fd2355..8d44ea0049 100644 --- a/Mage.Sets/src/mage/sets/morningtide/DivinersWand.java +++ b/Mage.Sets/src/mage/sets/morningtide/DivinersWand.java @@ -35,7 +35,7 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.abilities.Ability; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.common.EntersBattlefieldAllTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleStaticAbility; @@ -72,7 +72,7 @@ public class DivinersWand extends CardImpl { this.subtype.add("Equipment"); // Equipped creature has "Whenever you draw a card, this creature gets +1/+1 and gains flying until end of turn" and "{4}: Draw a card." - Ability gainedAbility = new DrawCardTriggeredAbility(new BoostSourceEffect(1,1, Duration.EndOfTurn), false); + Ability gainedAbility = new DrawCardControllerTriggeredAbility(new BoostSourceEffect(1,1, Duration.EndOfTurn), false); gainedAbility.addEffect(new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.EndOfTurn)); Effect effect = new GainAbilityAttachedEffect(gainedAbility, AttachmentType.EQUIPMENT); effect.setText("Equipped creature has \"Whenever you draw a card, this creature gets +1/+1 and gains flying until end of turn\""); diff --git a/Mage.Sets/src/mage/sets/theros/HorizonChimera.java b/Mage.Sets/src/mage/sets/theros/HorizonChimera.java index 5ee43d9693..8e1894b66f 100644 --- a/Mage.Sets/src/mage/sets/theros/HorizonChimera.java +++ b/Mage.Sets/src/mage/sets/theros/HorizonChimera.java @@ -29,7 +29,7 @@ package mage.sets.theros; import java.util.UUID; import mage.MageInt; -import mage.abilities.common.DrawCardTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.keyword.FlashAbility; import mage.abilities.keyword.FlyingAbility; @@ -61,7 +61,7 @@ public class HorizonChimera extends CardImpl { // Trample this.addAbility(TrampleAbility.getInstance()); // Whenever you draw a card, you gain 1 life. - this.addAbility(new DrawCardTriggeredAbility(new GainLifeEffect(1), false)); + this.addAbility(new DrawCardControllerTriggeredAbility(new GainLifeEffect(1), false)); } public HorizonChimera(final HorizonChimera card) { diff --git a/Mage/src/mage/abilities/common/DrawCardTriggeredAbility.java b/Mage/src/mage/abilities/common/DrawCardControllerTriggeredAbility.java similarity index 85% rename from Mage/src/mage/abilities/common/DrawCardTriggeredAbility.java rename to Mage/src/mage/abilities/common/DrawCardControllerTriggeredAbility.java index cd846efddf..f421807ad1 100644 --- a/Mage/src/mage/abilities/common/DrawCardTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DrawCardControllerTriggeredAbility.java @@ -37,13 +37,13 @@ import mage.game.events.GameEvent; * * @author North */ -public class DrawCardTriggeredAbility extends TriggeredAbilityImpl { +public class DrawCardControllerTriggeredAbility extends TriggeredAbilityImpl { - public DrawCardTriggeredAbility(Effect effect, boolean optional) { + public DrawCardControllerTriggeredAbility(Effect effect, boolean optional) { super(Zone.BATTLEFIELD, effect, optional); } - public DrawCardTriggeredAbility(final DrawCardTriggeredAbility ability) { + public DrawCardControllerTriggeredAbility(final DrawCardControllerTriggeredAbility ability) { super(ability); } @@ -61,7 +61,7 @@ public class DrawCardTriggeredAbility extends TriggeredAbilityImpl { + + boolean setTargetPointer; + + public DrawCardOpponentTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) { + super(Zone.BATTLEFIELD, effect, optional); + this.setTargetPointer = setTargetPointer; + } + + public DrawCardOpponentTriggeredAbility(final DrawCardOpponentTriggeredAbility ability) { + super(ability); + this.setTargetPointer = ability.setTargetPointer; + } + + @Override + public DrawCardOpponentTriggeredAbility copy() { + return new DrawCardOpponentTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.DREW_CARD && game.getOpponents(this.getControllerId()).contains(event.getPlayerId())) { + if (setTargetPointer) { + for (Effect effect:this.getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getPlayerId())); + } + } + return true; + } + return false; + } + + @Override + public String getRule() { + return new StringBuilder("Whenever an opponent draws a card, ").append(super.getRule()).toString(); + } +}