From 234bba64a31e22da133513fcd2e8fec7acd56081 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 26 May 2015 17:43:39 +0200 Subject: [PATCH] Cleaned up some replacment effects. --- .../mage/sets/arabiannights/AliFromCairo.java | 41 ++++---- .../sets/avacynrestored/GloomSurgeon.java | 34 +++---- .../avacynrestored/InfiniteReflection.java | 22 ++--- .../mage/sets/avacynrestored/Malignus.java | 31 +++--- .../sets/avacynrestored/PillarOfFlame.java | 17 +++- .../avacynrestored/SigardaHostOfHerons.java | 16 ++-- .../betrayersofkamigawa/KumanosBlessing.java | 23 ++--- .../OpalEyeKondasYojimbo.java | 95 ++++++------------- .../sets/betrayersofkamigawa/OrbOfDreams.java | 16 ++-- .../betrayersofkamigawa/ToshiroUmezawa.java | 25 ++--- .../championsofkamigawa/AkkiLavarunner.java | 21 ++-- .../mage/sets/championsofkamigawa/Hinder.java | 13 ++- .../SamuraiOfThePaleCurtain.java | 19 ++-- .../championsofkamigawa/YamabushisStorm.java | 70 +++++++------- .../src/mage/sets/commander/SpellCrumple.java | 13 ++- .../sets/commander2013/NayaSoulbeast.java | 21 ++-- .../mage/sets/commander2013/OpalPalace.java | 18 ++-- .../mage/sets/commander2013/WarCadence.java | 12 +-- .../mage/sets/darkascension/Immerwolf.java | 43 ++++----- .../src/mage/sets/darksteel/SerumPowder.java | 21 ++-- .../src/mage/sets/dissension/RainOfGore.java | 23 ++--- .../sets/dragonsmaze/MasterOfCruelties.java | 25 +++-- Mage.Sets/src/mage/sets/exodus/KorChant.java | 8 +- .../mage/sets/fifthdawn/GoblinBrawler.java | 16 ++-- .../src/mage/sets/fifthedition/Kismet.java | 15 +-- .../mage/sets/futuresight/AvenMindcensor.java | 17 ++-- .../mage/sets/gatecrash/BlindObedience.java | 14 +-- .../mage/sets/gatecrash/MasterBiomancer.java | 25 ++--- .../src/mage/sets/gatecrash/Skullcrack.java | 16 ++-- .../mage/sets/iceage/KjeldoranRoyalGuard.java | 15 ++- .../mage/sets/innistrad/DearlyDeparted.java | 25 +++-- .../mage/sets/innistrad/EssenceOfTheWild.java | 23 ++--- .../src/mage/sets/invasion/TsabosWeb.java | 17 ++-- .../mage/sets/invasion/YawgmothsAgenda.java | 13 ++- .../sets/khansoftarkir/DeflectingPalm.java | 7 +- .../mage/sets/khansoftarkir/UginsNexus.java | 14 +-- .../mage/sets/limitedalpha/JadeMonolith.java | 29 +++--- Mage.Sets/src/mage/sets/lorwyn/Vigor.java | 15 ++- .../src/mage/sets/magic2010/HarmsWay.java | 26 +++-- .../sets/magic2011/LeylineOfPunishment.java | 18 +--- .../mage/sets/magic2011/LeylineOfTheVoid.java | 14 +-- .../mage/sets/magic2011/ObstinateBaloth.java | 16 ++-- .../mage/sets/magic2013/ElderscaleWurm.java | 35 +++---- .../sets/magic2014/ImposingSovereign.java | 12 +-- .../sets/magic2014/PyromancersGauntlet.java | 34 ++++--- .../mage/sets/magic2014/SavageSummoning.java | 30 ++---- .../src/mage/sets/mirage/ForbiddenCrypt.java | 12 +-- .../src/mage/sets/mirage/GravebaneZombie.java | 17 ++-- .../src/mage/sets/mirrodin/DampingMatrix.java | 24 +++-- .../sets/mirrodinbesieged/MelirasKeepers.java | 23 ++--- .../sets/morningtide/BramblewoodParagon.java | 27 +++--- .../sets/morningtide/OonasBlackguard.java | 21 ++-- .../mage/sets/morningtide/SageOfFables.java | 22 ++--- .../mage/sets/nemesis/OraclesAttendants.java | 19 ++-- .../src/mage/sets/newphyrexia/DueRespect.java | 16 ++-- .../sets/newphyrexia/MeliraSylvokOutcast.java | 32 +++---- .../sets/newphyrexia/PhyrexianUnlife.java | 14 +-- .../sets/newphyrexia/UrabraskTheHidden.java | 17 ++-- .../src/mage/sets/odyssey/AegisOfHonor.java | 32 +++---- .../src/mage/sets/odyssey/DelayingShield.java | 10 +- .../mage/sets/planarchaos/FrozenAEther.java | 13 +-- .../src/mage/sets/prophecy/ShieldDancer.java | 8 +- .../mage/sets/ravnica/LoxodonGatekeeper.java | 15 +-- .../src/mage/sets/ravnica/Phytohydra.java | 13 ++- .../sets/returntoravnica/RestInPeace.java | 13 +-- .../riseoftheeldrazi/TajuruPreserver.java | 28 +++--- .../sets/scarsofmirrodin/HeavyArbalest.java | 13 ++- .../mage/sets/shadowmoor/MossbridgeTroll.java | 19 ++-- .../sets/shadowmoor/WheelOfSunAndMoon.java | 29 +++--- .../sets/shardsofalara/EmpyrialArchangel.java | 12 +-- .../src/mage/sets/stronghold/ShamanEnKor.java | 10 +- .../src/mage/sets/tempest/FurnaceOfRath.java | 23 +---- Mage.Sets/src/mage/sets/tempest/RootMaze.java | 22 ++--- .../mage/sets/timespiral/DralnuLichLord.java | 10 +- .../mage/sets/timespiral/FortuneThief.java | 39 ++++---- .../mage/sets/unlimitededition/TimeVault.java | 14 +-- Mage.Sets/src/mage/sets/urzassaga/Pariah.java | 25 ++--- .../src/mage/sets/urzassaga/Worship.java | 32 +++---- .../mage/sets/urzassaga/YawgmothsWill.java | 15 ++- .../src/mage/sets/visions/ElephantGrass.java | 36 ++++--- .../sets/worldwake/WrexialTheRisenDeep.java | 34 +++---- .../src/mage/sets/zendikar/NissasChosen.java | 36 ++++--- .../mage/sets/zendikar/UnstableFooting.java | 23 ++--- .../PlaneswalkerRedirectionEffect.java | 42 ++++---- .../effects/ReplacementEffectImpl.java | 5 - .../common/AddContinuousEffectToGame.java | 3 +- 86 files changed, 844 insertions(+), 1047 deletions(-) diff --git a/Mage.Sets/src/mage/sets/arabiannights/AliFromCairo.java b/Mage.Sets/src/mage/sets/arabiannights/AliFromCairo.java index 5979cec8a0..076d03c794 100644 --- a/Mage.Sets/src/mage/sets/arabiannights/AliFromCairo.java +++ b/Mage.Sets/src/mage/sets/arabiannights/AliFromCairo.java @@ -83,35 +83,36 @@ class AliFromCairoReplacementEffect extends ReplacementEffectImpl { return new AliFromCairoReplacementEffect(this); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS)) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null - && (controller.getLife() > 0) &&(controller.getLife() - event.getAmount()) < 1 - && event.getPlayerId().equals(controller.getId()) - ) { - event.setAmount(controller.getLife() - 1); - //unsure how to make this comply with - // 10/1/2008: The ability doesn't change how much damage is dealt; - // it just changes how much life that damage makes you lose. - // An effect such as Spirit Link will see the full amount of damage being dealt. - } + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null + && (controller.getLife() > 0) &&(controller.getLife() - event.getAmount()) < 1 + && event.getPlayerId().equals(controller.getId()) + ) { + return true; + //unsure how to make this comply with + // 10/1/2008: The ability doesn't change how much damage is dealt; + // it just changes how much life that damage makes you lose. + // An effect such as Spirit Link will see the full amount of damage being dealt. } } - - return false; - } - - @Override - public boolean apply(Game game, Ability source) { return false; } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + event.setAmount(controller.getLife() - 1); + } return false; } diff --git a/Mage.Sets/src/mage/sets/avacynrestored/GloomSurgeon.java b/Mage.Sets/src/mage/sets/avacynrestored/GloomSurgeon.java index 6398ed2a5f..1e1c67ad31 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/GloomSurgeon.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/GloomSurgeon.java @@ -84,31 +84,24 @@ class GloomSurgeonEffect extends ReplacementEffectImpl { GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); if (!game.replaceEvent(preventEvent)) { int preventedDamage = event.getAmount(); - event.setAmount(0); - - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - int cardsCount = Math.min(preventedDamage, player.getLibrary().size()); - for (int i = 0; i < cardsCount; i++) { - Card card = player.getLibrary().removeFromTop(game); - if (card != null) { - player.moveCardToExileWithInfo(card, null, null, source.getSourceId(), game, Zone.LIBRARY, true); - } else { - break; - } - } - } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), preventedDamage)); + Player player = game.getPlayer(source.getControllerId()); + if (player != null) { + player.moveCards(player.getLibrary().getTopCards(game, preventedDamage), Zone.LIBRARY, Zone.EXILED, source, game); + } return true; } - return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE && event.getTargetId().equals(source.getSourceId())) { + if (event.getTargetId().equals(source.getSourceId())) { DamageCreatureEvent damageEvent = (DamageCreatureEvent) event; if (damageEvent.isCombatDamage()) { return true; @@ -117,11 +110,6 @@ class GloomSurgeonEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public GloomSurgeonEffect copy() { return new GloomSurgeonEffect(this); diff --git a/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java b/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java index 5add19975f..3f79caf503 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java @@ -131,23 +131,19 @@ class InfiniteReflectionEntersBattlefieldEffect extends ReplacementEffectImpl { super(effect); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getControllerId().equals(source.getControllerId()) - && permanent.getCardType().contains(CardType.CREATURE) - && !(permanent instanceof PermanentToken)) { - return true; - } - } - return false; + Permanent permanent = game.getPermanent(event.getTargetId()); + return permanent != null && permanent.getControllerId().equals(source.getControllerId()) + && permanent.getCardType().contains(CardType.CREATURE) + && !(permanent instanceof PermanentToken); } - @Override - public boolean apply(Game game, Ability source) { - return false; - } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { diff --git a/Mage.Sets/src/mage/sets/avacynrestored/Malignus.java b/Mage.Sets/src/mage/sets/avacynrestored/Malignus.java index ec21e7895b..401e828148 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/Malignus.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/Malignus.java @@ -27,22 +27,25 @@ */ package mage.sets.avacynrestored; +import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.CardsInControllerHandCount; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.Effect; -import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect; import mage.cards.CardImpl; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; -import java.util.UUID; - /** * @author noxx */ @@ -111,7 +114,7 @@ class HighestLifeTotalAmongOpponentsCount implements DynamicValue { } } -class MalignusEffect extends ReplacementEffectImpl { +class MalignusEffect extends ContinuousRuleModifyingEffectImpl { public MalignusEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit); @@ -126,23 +129,15 @@ class MalignusEffect extends ReplacementEffectImpl { public MalignusEffect copy() { return new MalignusEffect(this); } - + @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.PREVENT_DAMAGE; } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.PREVENT_DAMAGE && event.getSourceId().equals(source.getSourceId())) { - return true; - } - return false; + return event.getSourceId().equals(source.getSourceId()); } } diff --git a/Mage.Sets/src/mage/sets/avacynrestored/PillarOfFlame.java b/Mage.Sets/src/mage/sets/avacynrestored/PillarOfFlame.java index a4fc0537d1..014284bd8e 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/PillarOfFlame.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/PillarOfFlame.java @@ -37,11 +37,13 @@ import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies; import mage.cards.CardImpl; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetCreatureOrPlayer; import mage.watchers.common.DamagedByWatcher; @@ -55,7 +57,6 @@ public class PillarOfFlame extends CardImpl { super(ownerId, 149, "Pillar of Flame", Rarity.COMMON, new CardType[]{CardType.SORCERY}, "{R}"); this.expansionSetCode = "AVR"; - // Pillar of Flame deals 2 damage to target creature or player. this.getSpellAbility().addEffect(new DamageTargetEffect(2)); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); @@ -97,19 +98,25 @@ class PillarOfFlameEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = ((ZoneChangeEvent) event).getTarget(); - if (permanent != null) { - return permanent.moveToExile(null, "", source.getSourceId(), game); + if (controller != null && permanent != null) { + return controller.moveCards(permanent, Zone.BATTLEFIELD, Zone.EXILED, source, game); } return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) { + if (((ZoneChangeEvent) event).isDiesEvent()) { DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); if (watcher != null) { - return watcher.damagedCreatures.contains(event.getTargetId()); + return watcher.wasDamaged(event.getTargetId(), game); } } return false; diff --git a/Mage.Sets/src/mage/sets/avacynrestored/SigardaHostOfHerons.java b/Mage.Sets/src/mage/sets/avacynrestored/SigardaHostOfHerons.java index f1946da244..6807769fbe 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/SigardaHostOfHerons.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/SigardaHostOfHerons.java @@ -34,6 +34,7 @@ import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.HexproofAbility; @@ -75,7 +76,7 @@ public class SigardaHostOfHerons extends CardImpl { } } -class SigardaHostOfHeronsEffect extends ReplacementEffectImpl { +class SigardaHostOfHeronsEffect extends ContinuousRuleModifyingEffectImpl { public SigardaHostOfHeronsEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit); @@ -92,18 +93,13 @@ class SigardaHostOfHeronsEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.SACRIFICE_PERMANENT; } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.SACRIFICE_PERMANENT && event.getPlayerId().equals(source.getControllerId())) { + if (event.getPlayerId().equals(source.getControllerId())) { MageObject object = game.getObject(event.getSourceId()); if (object instanceof PermanentCard) { if (game.getOpponents(source.getControllerId()).contains(((PermanentCard)object).getControllerId())) { diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/KumanosBlessing.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/KumanosBlessing.java index f5bf7ddc56..6f181f5b10 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/KumanosBlessing.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/KumanosBlessing.java @@ -65,7 +65,6 @@ public class KumanosBlessing extends CardImpl { this.expansionSetCode = "BOK"; this.subtype.add("Aura"); - // Flash this.addAbility(FlashAbility.getInstance()); // Enchant creature @@ -106,11 +105,6 @@ class KumanosBlessingEffect extends ReplacementEffectImpl { return new KumanosBlessingEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent permanent = ((ZoneChangeEvent)event).getTarget(); @@ -121,15 +115,18 @@ class KumanosBlessingEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE) { - ZoneChangeEvent zce = (ZoneChangeEvent) event; - if (zce.isDiesEvent()) { - DamagedByEnchantedWatcher watcher = (DamagedByEnchantedWatcher) game.getState().getWatchers().get("DamagedByEnchantedWatcher", source.getSourceId()); - if (watcher != null) { - return watcher.wasDamaged(zce.getTarget(), game); - } + ZoneChangeEvent zce = (ZoneChangeEvent) event; + if (zce.isDiesEvent()) { + DamagedByEnchantedWatcher watcher = (DamagedByEnchantedWatcher) game.getState().getWatchers().get("DamagedByEnchantedWatcher", source.getSourceId()); + if (watcher != null) { + return watcher.wasDamaged(zce.getTarget(), game); } } return false; diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/OpalEyeKondasYojimbo.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/OpalEyeKondasYojimbo.java index 6c4f04570e..d76893538a 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/OpalEyeKondasYojimbo.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/OpalEyeKondasYojimbo.java @@ -41,6 +41,7 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.PreventDamageToSourceEffect; import mage.abilities.keyword.BushidoAbility; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; @@ -78,8 +79,8 @@ public class OpalEyeKondasYojimbo extends CardImpl { ability.addTarget(new TargetSource()); this.addAbility(ability); - // {1}{W}: Prevent the next 1 damage that would be dealt to Opal-Eye this turn. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new OpalEyeKondasYojimboPreventEffect(), new ManaCostsImpl("{1}{W}"))); + // {1}{W}: Prevent the next 1 damage that would be dealt to Opal-Eye this turn. + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToSourceEffect(Duration.EndOfTurn, 1), new ManaCostsImpl("{1}{W}"))); } @@ -94,32 +95,43 @@ public class OpalEyeKondasYojimbo extends CardImpl { } class OpalEyeKondasYojimboRedirectionEffect extends ReplacementEffectImpl { - + + private final TargetSource target; + OpalEyeKondasYojimboRedirectionEffect() { super(Duration.EndOfTurn, Outcome.RedirectDamage); staticText = "The next time a source of your choice would deal damage this turn, that damage is dealt to {this} instead"; + this.target = new TargetSource(); } OpalEyeKondasYojimboRedirectionEffect(final OpalEyeKondasYojimboRedirectionEffect effect) { super(effect); + this.target = effect.target.copy(); + } + + @Override + public void init(Ability source, Game game) { + this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); + super.init(source, game); } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE ) || + public boolean checksEventType(GameEvent event, Game game) { + return event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE ) || event.getType().equals(GameEvent.EventType.DAMAGE_PLANESWALKER ) || - event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER ) ) { - if (event.getSourceId().equals(targetPointer.getFirst(game, source))) { - // check source - MageObject object = game.getObject(event.getSourceId()); - if (object == null) { - game.informPlayers("Couldn't find source of damage"); - return false; - } - return true; - } + event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER ); + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getSourceId().equals(target.getFirstTarget())) { + // check source + MageObject object = game.getObject(event.getSourceId()); + if (object == null) { + game.informPlayers("Couldn't find source of damage"); + return false; } + return true; } return false; } @@ -148,64 +160,15 @@ class OpalEyeKondasYojimboRedirectionEffect extends ReplacementEffectImpl { } game.informPlayers(message.toString()); // redirect damage - this.used = true; + discard(); sourcePermanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); return true; } return false; } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public OpalEyeKondasYojimboRedirectionEffect copy() { return new OpalEyeKondasYojimboRedirectionEffect(this); } } - -class OpalEyeKondasYojimboPreventEffect extends PreventionEffectImpl { - - public OpalEyeKondasYojimboPreventEffect() { - super(Duration.EndOfTurn); - staticText = "Prevent the next 1 damage that would be dealt to {this} this turn"; - } - - public OpalEyeKondasYojimboPreventEffect(final OpalEyeKondasYojimboPreventEffect effect) { - super(effect); - } - - @Override - public OpalEyeKondasYojimboPreventEffect copy() { - return new OpalEyeKondasYojimboPreventEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - if (event.getAmount() >= 1) { - int damage = 1; - event.setAmount(event.getAmount() - 1); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), damage)); - } - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/OrbOfDreams.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/OrbOfDreams.java index 6dfdc70dce..b896f12a2c 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/OrbOfDreams.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/OrbOfDreams.java @@ -85,19 +85,17 @@ public class OrbOfDreams extends CardImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - return true; - } - return false; + return true; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } } } diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/ToshiroUmezawa.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/ToshiroUmezawa.java index 9e176256d2..f7b16531b1 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/ToshiroUmezawa.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/ToshiroUmezawa.java @@ -130,7 +130,7 @@ class ToshiroUmezawaEffect extends OneShotEffect { class ToshiroUmezawaReplacementEffect extends ReplacementEffectImpl { - private UUID cardId; + private final UUID cardId; public ToshiroUmezawaReplacementEffect(UUID cardId) { super(Duration.EndOfTurn, Outcome.Exile); @@ -147,11 +147,6 @@ class ToshiroUmezawaReplacementEffect extends ReplacementEffectImpl { return new ToshiroUmezawaReplacementEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { UUID eventObject = ((ZoneChangeEvent) event).getTargetId(); @@ -167,16 +162,16 @@ class ToshiroUmezawaReplacementEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE) { - ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - if (zEvent.getToZone() == Zone.GRAVEYARD - && ((ZoneChangeEvent) event).getTargetId().equals(cardId)) { - return true; - } - } - return false; + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + return zEvent.getToZone() == Zone.GRAVEYARD + && ((ZoneChangeEvent) event).getTargetId().equals(cardId); } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/AkkiLavarunner.java b/Mage.Sets/src/mage/sets/championsofkamigawa/AkkiLavarunner.java index de318507a6..c30235ab5f 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/AkkiLavarunner.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/AkkiLavarunner.java @@ -118,25 +118,24 @@ class TokTokVolcanoBornEffect extends ReplacementEffectImpl { super(effect); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_PLAYER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER) { - Card card = game.getCard(event.getSourceId()); - if (card != null && card.getColor().isRed()) { - event.setAmount(event.getAmount() + 1); - } + Card card = game.getCard(event.getSourceId()); + if (card != null && card.getColor().isRed()) { + return true; } return false; } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return apply(game, source); + event.setAmount(event.getAmount() + 1); + return false; } @Override diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/Hinder.java b/Mage.Sets/src/mage/sets/championsofkamigawa/Hinder.java index 963f1cd450..afdac715e2 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/Hinder.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/Hinder.java @@ -60,7 +60,6 @@ public class Hinder extends CardImpl { super(ownerId, 65, "Hinder", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{1}{U}{U}"); this.expansionSetCode = "CHK"; - // Counter target spell. If that spell is countered this way, put that card on the top or bottom of its owner's library instead of into that player's graveyard. this.getSpellAbility().addEffect(new HinderEffect()); this.getSpellAbility().addTarget(new TargetSpell()); @@ -143,11 +142,6 @@ class HinderReplacementEffect extends ReplacementEffectImpl { return new HinderReplacementEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public boolean isInactive(Ability source, Game game) { if (!game.getPhase().getStep().getType().equals(phaseStep)) { @@ -179,9 +173,14 @@ class HinderReplacementEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone().equals(Zone.GRAVEYARD)) { + if (((ZoneChangeEvent)event).getToZone().equals(Zone.GRAVEYARD)) { MageObject mageObject = game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.STACK); if (mageObject instanceof Spell) { return ((Spell)mageObject).getSourceId().equals(event.getTargetId()); diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/SamuraiOfThePaleCurtain.java b/Mage.Sets/src/mage/sets/championsofkamigawa/SamuraiOfThePaleCurtain.java index 5a340f6d80..8d5a6b433a 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/SamuraiOfThePaleCurtain.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/SamuraiOfThePaleCurtain.java @@ -96,11 +96,6 @@ class SamuraiOfThePaleCurtainEffect extends ReplacementEffectImpl { return new SamuraiOfThePaleCurtainEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent permanent = ((ZoneChangeEvent)event).getTarget(); @@ -110,15 +105,15 @@ class SamuraiOfThePaleCurtainEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE ) { - ZoneChangeEvent zEvent = (ZoneChangeEvent)event; - if (zEvent.getToZone() == Zone.GRAVEYARD) { - return true; - } - } - return false; + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + return zEvent.getToZone() == Zone.GRAVEYARD; } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/YamabushisStorm.java b/Mage.Sets/src/mage/sets/championsofkamigawa/YamabushisStorm.java index 4219511373..9ec4a27bcc 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/YamabushisStorm.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/YamabushisStorm.java @@ -39,28 +39,29 @@ import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.DamageAllEffect; import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies; import mage.cards.CardImpl; +import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.watchers.common.DamagedByWatcher; /** * * @author LevelX */ - public class YamabushisStorm extends CardImpl { public YamabushisStorm(UUID ownerId) { super(ownerId, 199, "Yamabushi's Storm", Rarity.COMMON, new CardType[]{CardType.SORCERY}, "{1}{R}"); this.expansionSetCode = "CHK"; - // Yamabushi's Storm deals 1 damage to each creature. this.getSpellAbility().addEffect(new DamageAllEffect(1, new FilterCreaturePermanent())); + // If a creature dealt damage this way would die this turn, exile it instead. this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn)); this.getSpellAbility().addWatcher(new DamagedByWatcher()); @@ -79,43 +80,42 @@ public class YamabushisStorm extends CardImpl { class YamabushisStormEffect extends ReplacementEffectImpl { - public YamabushisStormEffect() { - super(Duration.EndOfTurn, Outcome.Exile); - staticText = "If a creature dealt damage this way would die this turn, exile it instead"; - } + public YamabushisStormEffect() { + super(Duration.EndOfTurn, Outcome.Exile); + staticText = "If a creature dealt damage this way would die this turn, exile it instead"; + } - public YamabushisStormEffect(final YamabushisStormEffect effect) { - super(effect); - } + public YamabushisStormEffect(final YamabushisStormEffect effect) { + super(effect); + } - @Override - public YamabushisStormEffect copy() { - return new YamabushisStormEffect(this); - } + @Override + public YamabushisStormEffect copy() { + return new YamabushisStormEffect(this); + } - @Override - public boolean apply(Game game, Ability source) { - return true; + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + Permanent permanent = ((ZoneChangeEvent) event).getTarget(); + if (controller != null && permanent != null) { + return controller.moveCardToExileWithInfo(permanent, null, "", source.getSourceId(), game, Zone.BATTLEFIELD, true); } + return false; + } - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Permanent permanent = ((ZoneChangeEvent)event).getTarget(); - if (permanent != null) { - return permanent.moveToExile(null, "", source.getSourceId(), game); - } - return false; + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (((ZoneChangeEvent) event).isDiesEvent()) { + DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); + return watcher != null && watcher.wasDamaged(event.getTargetId(), game); } + return false; + } - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) { - DamagedByWatcher watcher = - (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); - if (watcher != null) - return watcher.damagedCreatures.contains(event.getTargetId()); - } - return false; - } - -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/commander/SpellCrumple.java b/Mage.Sets/src/mage/sets/commander/SpellCrumple.java index c545647b17..08c38924c8 100644 --- a/Mage.Sets/src/mage/sets/commander/SpellCrumple.java +++ b/Mage.Sets/src/mage/sets/commander/SpellCrumple.java @@ -61,7 +61,6 @@ public class SpellCrumple extends CardImpl { super(ownerId, 63, "Spell Crumple", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{1}{U}{U}"); this.expansionSetCode = "CMD"; - // Counter target spell. If that spell is countered this way, put it on the bottom of its owner's library instead of into that player's graveyard. Put Spell Crumple on the bottom of its owner's library. this.getSpellAbility().addTarget(new TargetSpell()); this.getSpellAbility().addEffect(new SpellCrumpleCounterEffect()); @@ -145,11 +144,6 @@ class SpellCrumpleReplacementEffect extends ReplacementEffectImpl { return new SpellCrumpleReplacementEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public boolean isInactive(Ability source, Game game) { if (!game.getPhase().getStep().getType().equals(phaseStep)) { @@ -180,9 +174,14 @@ class SpellCrumpleReplacementEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone().equals(Zone.GRAVEYARD)) { + if (((ZoneChangeEvent)event).getToZone().equals(Zone.GRAVEYARD)) { MageObject mageObject = game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.STACK); if (mageObject instanceof Spell) { return ((Spell)mageObject).getSourceId().equals(event.getTargetId()); diff --git a/Mage.Sets/src/mage/sets/commander2013/NayaSoulbeast.java b/Mage.Sets/src/mage/sets/commander2013/NayaSoulbeast.java index f7474d20df..a858e59187 100644 --- a/Mage.Sets/src/mage/sets/commander2013/NayaSoulbeast.java +++ b/Mage.Sets/src/mage/sets/commander2013/NayaSoulbeast.java @@ -137,27 +137,22 @@ class NayaSoulbeastReplacementEffect extends ReplacementEffectImpl { public NayaSoulbeastReplacementEffect(final NayaSoulbeastReplacementEffect effect) { super(effect); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) { - if (event.getTargetId().equals(source.getSourceId())) { - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; + return event.getTargetId().equals(source.getSourceId()); } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Object object = this.getValue("NayaSoulbeastCounters"); if (object instanceof Integer) { - int amount = ((Integer)object).intValue(); + int amount = ((Integer)object); new AddCountersSourceEffect(CounterType.P1P1.createInstance(amount)).apply(game, source); } return false; diff --git a/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java b/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java index 609212f2df..33704e9e31 100644 --- a/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java +++ b/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java @@ -146,19 +146,15 @@ class OpalPalaceEntersBattlefieldEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) { - OpalPalaceWatcher watcher = (OpalPalaceWatcher) game.getState().getWatchers().get("ManaPaidFromOpalPalaceWatcher", source.getSourceId()); - if (watcher != null) { - return watcher.commanderId.contains(event.getTargetId()); - } - } - return false; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; } - + @Override - public boolean apply(Game game, Ability source) { - return false; + public boolean applies(GameEvent event, Ability source, Game game) { + OpalPalaceWatcher watcher = (OpalPalaceWatcher) game.getState().getWatchers().get("ManaPaidFromOpalPalaceWatcher", source.getSourceId()); + return watcher != null && + watcher.commanderId.contains(event.getTargetId()); } @Override diff --git a/Mage.Sets/src/mage/sets/commander2013/WarCadence.java b/Mage.Sets/src/mage/sets/commander2013/WarCadence.java index 5663e853d6..d34d2bd6ab 100644 --- a/Mage.Sets/src/mage/sets/commander2013/WarCadence.java +++ b/Mage.Sets/src/mage/sets/commander2013/WarCadence.java @@ -83,11 +83,6 @@ class WarCadenceReplacementEffect extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player player = game.getPlayer(event.getPlayerId()); @@ -108,9 +103,14 @@ class WarCadenceReplacementEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DECLARE_BLOCKER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType().equals(GameEvent.EventType.DECLARE_BLOCKER); + return true; } @Override diff --git a/Mage.Sets/src/mage/sets/darkascension/Immerwolf.java b/Mage.Sets/src/mage/sets/darkascension/Immerwolf.java index 35ed6b36b9..b209e272a5 100644 --- a/Mage.Sets/src/mage/sets/darkascension/Immerwolf.java +++ b/Mage.Sets/src/mage/sets/darkascension/Immerwolf.java @@ -27,23 +27,27 @@ */ package mage.sets.darkascension; -import mage.constants.*; +import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.common.continuous.BoostControlledEffect; import mage.abilities.keyword.IntimidateAbility; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; -import java.util.UUID; - /** * * @author BetaSteward @@ -84,14 +88,13 @@ public class Immerwolf extends CardImpl { } } -class ImmerwolfEffect extends ReplacementEffectImpl { +class ImmerwolfEffect extends ContinuousRuleModifyingEffectImpl { - private static final FilterCreaturePermanent filterWerewolf = new FilterCreaturePermanent("Werewolf creature"); - private static final FilterCreaturePermanent filterNonhuman = new FilterCreaturePermanent("Non-human creature"); + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); static { - filterWerewolf.add(new SubtypePredicate("Werewolf")); - filterNonhuman.add(Predicates.not(new SubtypePredicate("Human"))); + filter.add(new SubtypePredicate("Werewolf")); + filter.add(Predicates.not(new SubtypePredicate("Human"))); } public ImmerwolfEffect() { @@ -109,23 +112,15 @@ class ImmerwolfEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.TRANSFORM; } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.TRANSFORM) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getControllerId().equals(source.getControllerId()) && filterWerewolf.match(permanent, game) && filterNonhuman.match(permanent, game)) { - return true; - } - } - return false; + Permanent permanent = game.getPermanent(event.getTargetId()); + return permanent != null && + permanent.getControllerId().equals(source.getControllerId()) && + filter.match(permanent, game) ; } } diff --git a/Mage.Sets/src/mage/sets/darksteel/SerumPowder.java b/Mage.Sets/src/mage/sets/darksteel/SerumPowder.java index 9df0425724..3b07147d6d 100644 --- a/Mage.Sets/src/mage/sets/darksteel/SerumPowder.java +++ b/Mage.Sets/src/mage/sets/darksteel/SerumPowder.java @@ -87,6 +87,9 @@ class SerumPowderReplaceEffect extends ReplacementEffectImpl { Player controller = game.getPlayer(source.getControllerId()); Card sourceCard = game.getCard(source.getSourceId()); if (controller != null && sourceCard != null) { + if (!controller.chooseUse(outcome, "Exile all cards from hand and draw that many cards?", game)) { + return false; + } int cardsHand = controller.getHand().size(); if (cardsHand > 0){ Cards cards = new CardsImpl(); @@ -98,26 +101,20 @@ class SerumPowderReplaceEffect extends ReplacementEffectImpl { } controller.drawCards(cardsHand, game); } - game.informPlayers(new StringBuilder(sourceCard.getName()).append(": ").append(controller.getLogName()).append(" exiles hand and draws ").append(cardsHand).append(" card(s)").toString()); + game.informPlayers(sourceCard.getLogName() +": " + controller.getLogName() + " exiles hand and draws " + cardsHand + " card(s)"); return true; } return false; } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.CAN_TAKE_MULLIGAN && source.getControllerId().equals(event.getPlayerId())) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - return controller.chooseUse(outcome, "Exile all cards from hand and draw that many cards?", game); - } - } - return false; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.CAN_TAKE_MULLIGAN; } - + @Override - public boolean apply(Game game, Ability source) { - return false; + public boolean applies(GameEvent event, Ability source, Game game) { + return source.getControllerId().equals(event.getPlayerId()); } @Override diff --git a/Mage.Sets/src/mage/sets/dissension/RainOfGore.java b/Mage.Sets/src/mage/sets/dissension/RainOfGore.java index fe97130d4c..02db58c59e 100644 --- a/Mage.Sets/src/mage/sets/dissension/RainOfGore.java +++ b/Mage.Sets/src/mage/sets/dissension/RainOfGore.java @@ -86,11 +86,6 @@ class RainOfGoreEffect extends ReplacementEffectImpl { return new RainOfGoreEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player player = game.getPlayer(event.getPlayerId()); @@ -100,16 +95,18 @@ class RainOfGoreEffect extends ReplacementEffectImpl { return true; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.GAIN_LIFE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - switch (event.getType()) { - case GAIN_LIFE: - if (!game.getStack().isEmpty()) { - StackObject stackObject = game.getStack().getFirst(); - if (stackObject != null) { - return stackObject.getControllerId().equals(event.getPlayerId()); - } - } + if (!game.getStack().isEmpty()) { + StackObject stackObject = game.getStack().getFirst(); + if (stackObject != null) { + return stackObject.getControllerId().equals(event.getPlayerId()); + } } return false; } diff --git a/Mage.Sets/src/mage/sets/dragonsmaze/MasterOfCruelties.java b/Mage.Sets/src/mage/sets/dragonsmaze/MasterOfCruelties.java index 138f8dd8fe..ff74e7bdac 100644 --- a/Mage.Sets/src/mage/sets/dragonsmaze/MasterOfCruelties.java +++ b/Mage.Sets/src/mage/sets/dragonsmaze/MasterOfCruelties.java @@ -36,6 +36,7 @@ import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.keyword.CanAttackOnlyAloneAbility; @@ -153,7 +154,7 @@ class MasterOfCrueltiesEffect extends OneShotEffect { } } -class MasterOfCrueltiesNoDamageEffect extends ReplacementEffectImpl { +class MasterOfCrueltiesNoDamageEffect extends ContinuousRuleModifyingEffectImpl { public MasterOfCrueltiesNoDamageEffect() { super(Duration.EndOfCombat, Outcome.PreventDamage); @@ -170,25 +171,21 @@ class MasterOfCrueltiesNoDamageEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { + public boolean checksEventType(GameEvent event, Game game) { switch (event.getType()) { case DAMAGE_CREATURE: case DAMAGE_PLAYER: case DAMAGE_PLANESWALKER: - DamageEvent damageEvent = (DamageEvent) event; - return event.getSourceId().equals(source.getSourceId()) && damageEvent.isCombatDamage(); + return true; default: return false; } } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + DamageEvent damageEvent = (DamageEvent) event; + return event.getSourceId().equals(source.getSourceId()) && damageEvent.isCombatDamage(); + + } } diff --git a/Mage.Sets/src/mage/sets/exodus/KorChant.java b/Mage.Sets/src/mage/sets/exodus/KorChant.java index 33d0c0d38c..0269d443ed 100644 --- a/Mage.Sets/src/mage/sets/exodus/KorChant.java +++ b/Mage.Sets/src/mage/sets/exodus/KorChant.java @@ -117,10 +117,14 @@ class KorChantEffect extends RedirectionEffect { this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE - && event.getTargetId().equals(this.getTargetPointer().getFirst(game, source)) + if (event.getTargetId().equals(this.getTargetPointer().getFirst(game, source)) && event.getSourceId().equals(this.target.getFirstTarget())) { this.redirectTarget = source.getTargets().get(1); return true; diff --git a/Mage.Sets/src/mage/sets/fifthdawn/GoblinBrawler.java b/Mage.Sets/src/mage/sets/fifthdawn/GoblinBrawler.java index 3dffc7e3c9..13b1344e3d 100644 --- a/Mage.Sets/src/mage/sets/fifthdawn/GoblinBrawler.java +++ b/Mage.Sets/src/mage/sets/fifthdawn/GoblinBrawler.java @@ -32,6 +32,7 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.keyword.FirstStrikeAbility; import mage.cards.CardImpl; @@ -75,7 +76,7 @@ public class GoblinBrawler extends CardImpl { } } -class CantBeEquippedSourceEffect extends ReplacementEffectImpl { +class CantBeEquippedSourceEffect extends ContinuousRuleModifyingEffectImpl { public CantBeEquippedSourceEffect(CantBeEquippedSourceEffect effect) { super(effect); @@ -92,18 +93,13 @@ class CantBeEquippedSourceEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ATTACH; } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ATTACH && event.getTargetId().equals(source.getSourceId())) { + if (event.getTargetId().equals(source.getSourceId())) { Permanent permanent = game.getPermanent(event.getSourceId()); if(permanent != null && permanent.getSubtype().contains("Equipment")){ return true; diff --git a/Mage.Sets/src/mage/sets/fifthedition/Kismet.java b/Mage.Sets/src/mage/sets/fifthedition/Kismet.java index 3dfb9ed242..9e327b2277 100644 --- a/Mage.Sets/src/mage/sets/fifthedition/Kismet.java +++ b/Mage.Sets/src/mage/sets/fifthedition/Kismet.java @@ -39,6 +39,7 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; /** @@ -51,7 +52,6 @@ public class Kismet extends CardImpl { super(ownerId, 319, "Kismet", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}"); this.expansionSetCode = "5ED"; - // Artifacts, creatures, and lands played by your opponents enter the battlefield tapped. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new KismetEffect())); } @@ -86,9 +86,15 @@ class KismetEffect extends ReplacementEffectImpl { return false; } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { + if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && (permanent.getCardType().contains(CardType.ARTIFACT) || permanent.getCardType().contains(CardType.CREATURE) || @@ -99,11 +105,6 @@ class KismetEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public KismetEffect copy() { return new KismetEffect(this); diff --git a/Mage.Sets/src/mage/sets/futuresight/AvenMindcensor.java b/Mage.Sets/src/mage/sets/futuresight/AvenMindcensor.java index d9e317a705..bd96759553 100644 --- a/Mage.Sets/src/mage/sets/futuresight/AvenMindcensor.java +++ b/Mage.Sets/src/mage/sets/futuresight/AvenMindcensor.java @@ -95,19 +95,14 @@ class AvenMindcensorEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.SEARCH_LIBRARY) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null && game.isOpponent(controller, event.getPlayerId())) { - return true; - } - } - return false; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.SEARCH_LIBRARY; } - + @Override - public boolean apply(Game game, Ability source) { - return false; + public boolean applies(GameEvent event, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + return controller != null && game.isOpponent(controller, event.getPlayerId()); } @Override diff --git a/Mage.Sets/src/mage/sets/gatecrash/BlindObedience.java b/Mage.Sets/src/mage/sets/gatecrash/BlindObedience.java index 9051f4bc47..3bc36d4526 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/BlindObedience.java +++ b/Mage.Sets/src/mage/sets/gatecrash/BlindObedience.java @@ -89,10 +89,15 @@ class BlindObedienceTapEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { + if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && (permanent.getCardType().contains(CardType.CREATURE) || permanent.getCardType().contains(CardType.ARTIFACT))) { return true; @@ -101,11 +106,6 @@ class BlindObedienceTapEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public BlindObedienceTapEffect copy() { return new BlindObedienceTapEffect(this); diff --git a/Mage.Sets/src/mage/sets/gatecrash/MasterBiomancer.java b/Mage.Sets/src/mage/sets/gatecrash/MasterBiomancer.java index 5d967f7609..eeb0b6346d 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/MasterBiomancer.java +++ b/Mage.Sets/src/mage/sets/gatecrash/MasterBiomancer.java @@ -86,23 +86,18 @@ class MasterBiomancerEntersBattlefieldEffect extends ReplacementEffectImpl { public MasterBiomancerEntersBattlefieldEffect(MasterBiomancerEntersBattlefieldEffect effect) { super(effect); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) { - Permanent creature = game.getPermanent(event.getTargetId()); - if (creature != null && creature.getControllerId().equals(source.getControllerId()) - && creature.getCardType().contains(CardType.CREATURE) - && !event.getTargetId().equals(source.getSourceId())) { - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; + Permanent creature = game.getPermanent(event.getTargetId()); + return creature != null && creature.getControllerId().equals(source.getControllerId()) + && creature.getCardType().contains(CardType.CREATURE) + && !event.getTargetId().equals(source.getSourceId()); } @Override diff --git a/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java b/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java index d7303a90eb..f541d99037 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java +++ b/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java @@ -33,6 +33,7 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.abilities.Ability; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.continuous.CantGainLifeAllEffect; @@ -71,7 +72,7 @@ public class Skullcrack extends CardImpl { } } -class DamageCantBePreventedEffect extends ReplacementEffectImpl { +class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectImpl { public DamageCantBePreventedEffect() { super(Duration.EndOfTurn, Outcome.Benefit); @@ -91,17 +92,14 @@ class DamageCantBePreventedEffect extends ReplacementEffectImpl { public boolean apply(Game game, Ability source) { return true; } - + @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.PREVENT_DAMAGE; } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE)) { - return true; - } - return false; + return true; } } diff --git a/Mage.Sets/src/mage/sets/iceage/KjeldoranRoyalGuard.java b/Mage.Sets/src/mage/sets/iceage/KjeldoranRoyalGuard.java index 3ef0d4d97d..ee7134946b 100644 --- a/Mage.Sets/src/mage/sets/iceage/KjeldoranRoyalGuard.java +++ b/Mage.Sets/src/mage/sets/iceage/KjeldoranRoyalGuard.java @@ -103,11 +103,15 @@ class KjeldoranRoyalGuardEffect extends ReplacementEffectImpl { } return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_PLAYER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER - && event.getPlayerId().equals(source.getControllerId()) + if (event.getPlayerId().equals(source.getControllerId()) && ((DamageEvent)event).isCombatDamage()) { Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { @@ -121,11 +125,6 @@ class KjeldoranRoyalGuardEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public KjeldoranRoyalGuardEffect copy() { return new KjeldoranRoyalGuardEffect(this); diff --git a/Mage.Sets/src/mage/sets/innistrad/DearlyDeparted.java b/Mage.Sets/src/mage/sets/innistrad/DearlyDeparted.java index 4a3a953c42..4a1345a52c 100644 --- a/Mage.Sets/src/mage/sets/innistrad/DearlyDeparted.java +++ b/Mage.Sets/src/mage/sets/innistrad/DearlyDeparted.java @@ -51,13 +51,14 @@ import mage.game.stack.Spell; import mage.target.targetpointer.FixedTarget; import java.util.UUID; +import mage.game.events.GameEvent.EventType; /** * @author nantuko */ public class DearlyDeparted extends CardImpl { - private static final String ruleText = "As long as Dearly Departed is in your graveyard, each Human creature you control enters the battlefield with an additional +1/+1 counter on it"; + private static final String ruleText = "As long as {this} is in your graveyard, each Human creature you control enters the battlefield with an additional +1/+1 counter on it"; public DearlyDeparted(UUID ownerId) { super(ownerId, 9, "Dearly Departed", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{4}{W}{W}"); @@ -110,24 +111,22 @@ class EntersBattlefieldEffect extends ReplacementEffectImpl { public void addEffect(Effect effect) { baseEffects.add(effect); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getControllerId().equals(source.getControllerId()) && permanent.hasSubtype("Human")) { - setValue("target", permanent); - return true; - } + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.getControllerId().equals(source.getControllerId()) && permanent.hasSubtype("Human")) { + setValue("target", permanent); + return true; } return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Spell spell = game.getStack().getSpell(event.getSourceId()); diff --git a/Mage.Sets/src/mage/sets/innistrad/EssenceOfTheWild.java b/Mage.Sets/src/mage/sets/innistrad/EssenceOfTheWild.java index 8633a1bab2..9084404897 100644 --- a/Mage.Sets/src/mage/sets/innistrad/EssenceOfTheWild.java +++ b/Mage.Sets/src/mage/sets/innistrad/EssenceOfTheWild.java @@ -86,21 +86,16 @@ class EssenceOfTheWildEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) { - Permanent perm = game.getPermanent(event.getTargetId()); - if (perm != null && perm.getCardType().contains(CardType.CREATURE) && perm.getControllerId().equals(source.getControllerId())) { - return true; - } - } - return false; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; } - + @Override - public boolean apply(Game game, Ability source) { - return false; + public boolean applies(GameEvent event, Ability source, Game game) { + Permanent perm = game.getPermanent(event.getTargetId()); + return perm != null && perm.getCardType().contains(CardType.CREATURE) && perm.getControllerId().equals(source.getControllerId()); } - + @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent perm = game.getPermanent(source.getSourceId()); @@ -122,8 +117,8 @@ class EssenceOfTheWildEffect extends ReplacementEffectImpl { class EssenceOfTheWildCopyEffect extends ContinuousEffectImpl { - private Permanent essence; - private UUID targetId; + private final Permanent essence; + private final UUID targetId; public EssenceOfTheWildCopyEffect(Permanent essence, UUID targetId) { super(Duration.EndOfGame, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature); diff --git a/Mage.Sets/src/mage/sets/invasion/TsabosWeb.java b/Mage.Sets/src/mage/sets/invasion/TsabosWeb.java index d83a3216f9..6c97c4cfc6 100644 --- a/Mage.Sets/src/mage/sets/invasion/TsabosWeb.java +++ b/Mage.Sets/src/mage/sets/invasion/TsabosWeb.java @@ -33,6 +33,7 @@ import mage.abilities.ActivatedAbility; import mage.abilities.PlayLandAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.mana.ManaAbility; @@ -61,7 +62,6 @@ public class TsabosWeb extends CardImpl { this.addAbility(new EntersBattlefieldTriggeredAbility(new DrawCardSourceControllerEffect(1), false)); // Each land with an activated ability that isn't a mana ability doesn't untap during its controller's untap step. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TsabosWebPreventUntapEffect())); - } public TsabosWeb(final TsabosWeb card) { @@ -74,7 +74,7 @@ public class TsabosWeb extends CardImpl { } } -class TsabosWebPreventUntapEffect extends ReplacementEffectImpl { +class TsabosWebPreventUntapEffect extends ContinuousRuleModifyingEffectImpl { public TsabosWebPreventUntapEffect() { super(Duration.WhileOnBattlefield, Outcome.Detriment); @@ -85,24 +85,19 @@ class TsabosWebPreventUntapEffect extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public TsabosWebPreventUntapEffect copy() { return new TsabosWebPreventUntapEffect(this); } @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.UNTAP; } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP) { + if (game.getTurn().getStepType() == PhaseStep.UNTAP) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && permanent.getCardType().contains(CardType.LAND)) { for (Ability ability :permanent.getAbilities()) { diff --git a/Mage.Sets/src/mage/sets/invasion/YawgmothsAgenda.java b/Mage.Sets/src/mage/sets/invasion/YawgmothsAgenda.java index cc6b266c70..94605a4347 100644 --- a/Mage.Sets/src/mage/sets/invasion/YawgmothsAgenda.java +++ b/Mage.Sets/src/mage/sets/invasion/YawgmothsAgenda.java @@ -61,7 +61,6 @@ public class YawgmothsAgenda extends CardImpl { super(ownerId, 135, "Yawgmoth's Agenda", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}{B}"); this.expansionSetCode = "INV"; - // You can't cast more than one spell each turn. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantCastMoreThanOneSpellEffect(TargetController.YOU))); // You may play cards from your graveyard. @@ -134,11 +133,6 @@ class YawgmothsAgendaReplacementEffect extends ReplacementEffectImpl { return new YawgmothsAgendaReplacementEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); @@ -159,9 +153,14 @@ class YawgmothsAgendaReplacementEffect extends ReplacementEffectImpl { return true; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD) { + if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD) { Card card = game.getCard(event.getTargetId()); if (card != null && card.getOwnerId().equals(source.getControllerId())) { Permanent permanent = ((ZoneChangeEvent) event).getTarget(); diff --git a/Mage.Sets/src/mage/sets/khansoftarkir/DeflectingPalm.java b/Mage.Sets/src/mage/sets/khansoftarkir/DeflectingPalm.java index a3a5590866..85b05826db 100644 --- a/Mage.Sets/src/mage/sets/khansoftarkir/DeflectingPalm.java +++ b/Mage.Sets/src/mage/sets/khansoftarkir/DeflectingPalm.java @@ -54,7 +54,6 @@ public class DeflectingPalm extends CardImpl { super(ownerId, 173, "Deflecting Palm", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{R}{W}"); this.expansionSetCode = "KTK"; - // The next time a source of your choice would deal damage to you this turn, prevent that damage. If damage is prevented this way, Deflecting Palm deals that much damage to that source's controller. this.getSpellAbility().addEffect(new DeflectingPalmEffect()); } @@ -89,14 +88,10 @@ class DeflectingPalmEffect extends PreventionEffectImpl { return new DeflectingPalmEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public void init(Ability source, Game game) { this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); + super.init(source, game); } @Override diff --git a/Mage.Sets/src/mage/sets/khansoftarkir/UginsNexus.java b/Mage.Sets/src/mage/sets/khansoftarkir/UginsNexus.java index a066b66d67..02059b65d7 100644 --- a/Mage.Sets/src/mage/sets/khansoftarkir/UginsNexus.java +++ b/Mage.Sets/src/mage/sets/khansoftarkir/UginsNexus.java @@ -90,11 +90,6 @@ class UginsNexusSkipExtraTurnsEffect extends ReplacementEffectImpl { return new UginsNexusSkipExtraTurnsEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player player = game.getPlayer(event.getPlayerId()); @@ -104,10 +99,15 @@ class UginsNexusSkipExtraTurnsEffect extends ReplacementEffectImpl { } return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.EXTRA_TURN; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType() == EventType.EXTRA_TURN; + return true; } } diff --git a/Mage.Sets/src/mage/sets/limitedalpha/JadeMonolith.java b/Mage.Sets/src/mage/sets/limitedalpha/JadeMonolith.java index 7ab124a2d6..a90fb2a9ca 100644 --- a/Mage.Sets/src/mage/sets/limitedalpha/JadeMonolith.java +++ b/Mage.Sets/src/mage/sets/limitedalpha/JadeMonolith.java @@ -39,6 +39,7 @@ import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; +import mage.filter.FilterObject; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; @@ -79,9 +80,9 @@ class JadeMonolithRedirectionEffect extends ReplacementEffectImpl { private final TargetSource targetSource; public JadeMonolithRedirectionEffect() { - super(Duration.EndOfTurn, Outcome.RedirectDamage); + super(Duration.OneUse, Outcome.RedirectDamage); this.staticText = "The next time a source of your choice would deal damage to target creature this turn, that source deals that damage to you instead"; - this.targetSource = new TargetSource(); + this.targetSource = new TargetSource(new FilterObject("source of your choice")); } public JadeMonolithRedirectionEffect(final JadeMonolithRedirectionEffect effect) { @@ -98,11 +99,6 @@ class JadeMonolithRedirectionEffect extends ReplacementEffectImpl { public void init(Ability source, Game game) { this.targetSource.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { @@ -111,27 +107,26 @@ class JadeMonolithRedirectionEffect extends ReplacementEffectImpl { MageObject sourceObject = game.getObject(source.getSourceId()); DamageEvent damageEvent = (DamageEvent) event; if (controller != null && targetCreature != null) { - this.used = true; - controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects()); - + controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects()); StringBuilder sb = new StringBuilder(sourceObject != null ? sourceObject.getLogName() : ""); sb.append(": ").append(damageEvent.getAmount()).append(" damage redirected from ").append(targetCreature.getLogName()); sb.append(" to ").append(controller.getLogName()); game.informPlayers(sb.toString()); - + discard(); // only one use return true; } return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used) { - if (event.getType().equals(EventType.DAMAGE_CREATURE)) { - if (event.getSourceId().equals(targetSource.getFirstTarget()) && event.getTargetId().equals(source.getFirstTarget())) { - return true; - } - } + if (event.getSourceId().equals(targetSource.getFirstTarget()) && event.getTargetId().equals(source.getFirstTarget())) { + return true; } return false; } diff --git a/Mage.Sets/src/mage/sets/lorwyn/Vigor.java b/Mage.Sets/src/mage/sets/lorwyn/Vigor.java index af064b8651..be79e7b13e 100644 --- a/Mage.Sets/src/mage/sets/lorwyn/Vigor.java +++ b/Mage.Sets/src/mage/sets/lorwyn/Vigor.java @@ -107,19 +107,18 @@ class VigorReplacementEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType() == GameEvent.EventType.DAMAGE_CREATURE - && event.getPlayerId().equals(source.getControllerId()) + return event.getPlayerId().equals(source.getControllerId()) && !event.getTargetId().equals(source.getSourceId()); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public VigorReplacementEffect copy() { return new VigorReplacementEffect(this); diff --git a/Mage.Sets/src/mage/sets/magic2010/HarmsWay.java b/Mage.Sets/src/mage/sets/magic2010/HarmsWay.java index bfdce00dd2..12a58405a4 100644 --- a/Mage.Sets/src/mage/sets/magic2010/HarmsWay.java +++ b/Mage.Sets/src/mage/sets/magic2010/HarmsWay.java @@ -35,6 +35,7 @@ import mage.abilities.effects.PreventionEffectImpl; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.Rarity; import mage.game.Game; import mage.game.events.GameEvent; @@ -53,10 +54,8 @@ public class HarmsWay extends CardImpl { super(ownerId, 14, "Harm's Way", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{W}"); this.expansionSetCode = "M10"; - // The next 2 damage that a source of your choice would deal to you and/or permanents you control this turn is dealt to target creature or player instead. this.getSpellAbility().addEffect(new HarmsWayPreventDamageTargetEffect()); - this.getSpellAbility().addTarget(new TargetSource()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); } @@ -71,24 +70,29 @@ public class HarmsWay extends CardImpl { } class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl { - + + private final TargetSource target; + public HarmsWayPreventDamageTargetEffect() { super(Duration.EndOfTurn, 2, false, true); staticText = "The next 2 damage that a source of your choice would deal to you and/or permanents you control this turn is dealt to target creature or player instead"; + this.target = new TargetSource(); } public HarmsWayPreventDamageTargetEffect(final HarmsWayPreventDamageTargetEffect effect) { super(effect); + this.target = effect.target.copy(); } @Override public HarmsWayPreventDamageTargetEffect copy() { return new HarmsWayPreventDamageTargetEffect(this); } - + @Override - public boolean apply(Game game, Ability source) { - return true; + public void init(Ability source, Game game) { + this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); + super.init(source, game); } @Override @@ -96,18 +100,20 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl { PreventionEffectData preventionData = preventDamageAction(event, source, game); // deal damage now if (preventionData.getPreventedDamage() > 0) { - UUID redirectTo = source.getTargets().get(1).getFirstTarget(); + UUID redirectTo = source.getFirstTarget(); Permanent permanent = game.getPermanent(redirectTo); if (permanent != null) { game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + permanent.getLogName() + " instead"); // keep the original source id as it is redirecting permanent.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true); + discard(); } Player player = game.getPlayer(redirectTo); if (player != null) { game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + player.getLogName() + " instead"); // keep the original source id as it is redirecting player.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true); + discard(); } } return false; @@ -115,7 +121,7 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { + if (super.applies(event, source, game)) { // check source MageObject object = game.getObject(event.getSourceId()); if (object == null) { @@ -123,8 +129,8 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl { return false; } - if (!object.getId().equals(source.getFirstTarget()) - && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(source.getFirstTarget()))) { + if (!object.getId().equals(target.getFirstTarget()) + && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(target.getFirstTarget()))) { return false; } diff --git a/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java b/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java index 31e242ba38..8c6ecef50a 100644 --- a/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java +++ b/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java @@ -39,6 +39,7 @@ import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.continuous.CantGainLifeAllEffect; import mage.abilities.keyword.LeylineAbility; @@ -58,7 +59,6 @@ public class LeylineOfPunishment extends CardImpl { super(ownerId, 148, "Leyline of Punishment", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{2}{R}{R}"); this.expansionSetCode = "M11"; - // If Leyline of Punishment is in your opening hand, you may begin the game with it on the battlefield. this.addAbility(LeylineAbility.getInstance()); // Players can't gain life. @@ -78,7 +78,7 @@ public class LeylineOfPunishment extends CardImpl { } -class LeylineOfPunishmentEffect2 extends ReplacementEffectImpl { +class LeylineOfPunishmentEffect2 extends ContinuousRuleModifyingEffectImpl { public LeylineOfPunishmentEffect2() { super(Duration.WhileOnBattlefield, Outcome.Benefit); @@ -95,21 +95,13 @@ class LeylineOfPunishmentEffect2 extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.PREVENT_DAMAGE; } @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.PREVENT_DAMAGE) { - return true; - } - return false; + return true; } } diff --git a/Mage.Sets/src/mage/sets/magic2011/LeylineOfTheVoid.java b/Mage.Sets/src/mage/sets/magic2011/LeylineOfTheVoid.java index a082fad325..522a640e33 100644 --- a/Mage.Sets/src/mage/sets/magic2011/LeylineOfTheVoid.java +++ b/Mage.Sets/src/mage/sets/magic2011/LeylineOfTheVoid.java @@ -90,11 +90,6 @@ class LeylineOfTheVoidEffect extends ReplacementEffectImpl { return new LeylineOfTheVoidEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); @@ -114,10 +109,15 @@ class LeylineOfTheVoidEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD) { + if (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD) { Card card = game.getCard(event.getTargetId()); if (card != null && game.getOpponents(source.getControllerId()).contains(card.getOwnerId())) { return true; diff --git a/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java b/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java index d2adbc1706..f4675b3bc4 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java +++ b/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java @@ -96,10 +96,15 @@ class ObstinateBalothEffect extends ReplacementEffectImpl { public ObstinateBalothEffect copy() { return new ObstinateBalothEffect(this); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(source.getSourceId())) { + if (event.getTargetId().equals(source.getSourceId())) { ZoneChangeEvent zcEvent = (ZoneChangeEvent) event; if (zcEvent.getFromZone() == Zone.HAND && zcEvent.getToZone() == Zone.GRAVEYARD) { StackObject spell = game.getStack().getStackObject(event.getSourceId()); @@ -112,7 +117,7 @@ class ObstinateBalothEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { + public boolean replaceEvent(GameEvent event, Ability source, Game game) { Card card = game.getCard(source.getSourceId()); if (card != null) { Player owner = game.getPlayer(card.getOwnerId()); @@ -125,9 +130,4 @@ class ObstinateBalothEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return apply(game, source); - } - } \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/magic2013/ElderscaleWurm.java b/Mage.Sets/src/mage/sets/magic2013/ElderscaleWurm.java index ae076d44e6..b2e9325a77 100644 --- a/Mage.Sets/src/mage/sets/magic2013/ElderscaleWurm.java +++ b/Mage.Sets/src/mage/sets/magic2013/ElderscaleWurm.java @@ -38,7 +38,6 @@ import mage.abilities.keyword.TrampleAbility; import mage.cards.CardImpl; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; import mage.players.Player; import java.util.UUID; @@ -120,34 +119,30 @@ class ElderscaleWurmReplacementEffect extends ReplacementEffectImpl { public ElderscaleWurmReplacementEffect copy() { return new ElderscaleWurmReplacementEffect(this); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS)) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent == null) { - permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (permanent != null) { - Player controller = game.getPlayer(permanent.getControllerId()); - if (controller != null && controller.getLife() >= 7 - && (controller.getLife() - event.getAmount()) < 7 - && event.getPlayerId().equals(controller.getId())) { - event.setAmount(controller.getLife() - 7); - } + if (event.getPlayerId().equals(source.getControllerId())) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null && controller.getLife() >= 7 + && (controller.getLife() - event.getAmount()) < 7) { + return true; } } - - return false; - } - - @Override - public boolean apply(Game game, Ability source) { return false; } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + event.setAmount(controller.getLife() - 7); + } return false; } diff --git a/Mage.Sets/src/mage/sets/magic2014/ImposingSovereign.java b/Mage.Sets/src/mage/sets/magic2014/ImposingSovereign.java index c9f35721b6..0a7c07a129 100644 --- a/Mage.Sets/src/mage/sets/magic2014/ImposingSovereign.java +++ b/Mage.Sets/src/mage/sets/magic2014/ImposingSovereign.java @@ -91,9 +91,14 @@ class ImposingSovereignEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { + if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { return true; @@ -102,11 +107,6 @@ class ImposingSovereignEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public ImposingSovereignEffect copy() { return new ImposingSovereignEffect(this); diff --git a/Mage.Sets/src/mage/sets/magic2014/PyromancersGauntlet.java b/Mage.Sets/src/mage/sets/magic2014/PyromancersGauntlet.java index 0547801c6d..574a2d664f 100644 --- a/Mage.Sets/src/mage/sets/magic2014/PyromancersGauntlet.java +++ b/Mage.Sets/src/mage/sets/magic2014/PyromancersGauntlet.java @@ -79,31 +79,29 @@ class PyromancersGauntletReplacementEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER) + public boolean checksEventType(GameEvent event, Game game) { + return event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER) || event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) - || event.getType().equals(GameEvent.EventType.DAMAGE_PLANESWALKER)) { - MageObject object = game.getObject(event.getSourceId()); - if (object != null && object instanceof Spell) { - if (((Spell) object).getControllerId().equals(source.getControllerId()) - && (object.getCardType().contains(CardType.INSTANT) - || object.getCardType().contains(CardType.SORCERY))){ - return true; - } - } - Permanent permanent = game.getBattlefield().getPermanent(event.getSourceId()); - if(permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER)){ + || event.getType().equals(GameEvent.EventType.DAMAGE_PLANESWALKER); + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + MageObject object = game.getObject(event.getSourceId()); + if (object != null && object instanceof Spell) { + if (((Spell) object).getControllerId().equals(source.getControllerId()) + && (object.getCardType().contains(CardType.INSTANT) + || object.getCardType().contains(CardType.SORCERY))){ return true; } } + Permanent permanent = game.getBattlefield().getPermanent(event.getSourceId()); + if(permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER)){ + return true; + } return false; } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { event.setAmount(event.getAmount() + 2); diff --git a/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java b/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java index c323b750f9..6e1407ba2d 100644 --- a/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java +++ b/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java @@ -50,6 +50,7 @@ import mage.constants.WatcherScope; import mage.counters.CounterType; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.watchers.Watcher; @@ -193,10 +194,7 @@ class SavageSummoningWatcher extends Watcher { public boolean isSpellCastWithThisSavageSummoning(UUID spellId, UUID cardId, int zoneChangeCounter) { String cardKey = new StringBuilder(cardId.toString()).append("_").append(zoneChangeCounter).toString(); HashSet savageSpells = (HashSet) spellsCastWithSavageSummoning.get(spellId); - if (savageSpells != null && savageSpells.contains(cardKey)) { - return true; - } - return false; + return savageSpells != null && savageSpells.contains(cardKey); } public boolean isCardCastWithThisSavageSummoning(Card card, UUID cardId, int zoneChangeCounter, Game game) { @@ -204,10 +202,7 @@ class SavageSummoningWatcher extends Watcher { // add one because card is now gone to battlefield as creature String cardKey = new StringBuilder(cardId.toString()).append("_").append(zoneChangeCounter).toString(); HashSet savageSpells = (HashSet) cardsCastWithSavageSummoning.get(creatureCardKey); - if (savageSpells != null && savageSpells.contains(cardKey)) { - return true; - } - return false; + return savageSpells != null && savageSpells.contains(cardKey); } @Override @@ -307,11 +302,6 @@ class SavageSummoningEntersBattlefieldEffect extends ReplacementEffectImpl { return new SavageSummoningEntersBattlefieldEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent creature = game.getPermanent(event.getTargetId()); @@ -322,15 +312,15 @@ class SavageSummoningEntersBattlefieldEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if ((event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD)) { - Card card = game.getCard(event.getTargetId()); - if (card != null && watcher.isCardCastWithThisSavageSummoning(card, source.getSourceId(), zoneChangeCounter, game)) { - return true; - } - } - return false; + Card card = game.getCard(event.getTargetId()); + return card != null && watcher.isCardCastWithThisSavageSummoning(card, source.getSourceId(), zoneChangeCounter, game); } } diff --git a/Mage.Sets/src/mage/sets/mirage/ForbiddenCrypt.java b/Mage.Sets/src/mage/sets/mirage/ForbiddenCrypt.java index 321f592e93..e886dc432b 100644 --- a/Mage.Sets/src/mage/sets/mirage/ForbiddenCrypt.java +++ b/Mage.Sets/src/mage/sets/mirage/ForbiddenCrypt.java @@ -89,11 +89,6 @@ class ForbiddenCryptDrawCardReplacementEffect extends ReplacementEffectImpl { public ForbiddenCryptDrawCardReplacementEffect copy() { return new ForbiddenCryptDrawCardReplacementEffect(this); } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { @@ -119,9 +114,14 @@ class ForbiddenCryptDrawCardReplacementEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DRAW_CARD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType() == EventType.DRAW_CARD && event.getPlayerId().equals(source.getControllerId()); + return event.getPlayerId().equals(source.getControllerId()); } } diff --git a/Mage.Sets/src/mage/sets/mirage/GravebaneZombie.java b/Mage.Sets/src/mage/sets/mirage/GravebaneZombie.java index 210d3155ff..e64a6e958c 100644 --- a/Mage.Sets/src/mage/sets/mirage/GravebaneZombie.java +++ b/Mage.Sets/src/mage/sets/mirage/GravebaneZombie.java @@ -94,18 +94,15 @@ class GravebaneZombieEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(source.getSourceId())) { - return ((ZoneChangeEvent) event).isDiesEvent(); - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return true; + return event.getTargetId().equals(source.getSourceId()) && ((ZoneChangeEvent) event).isDiesEvent(); } @Override diff --git a/Mage.Sets/src/mage/sets/mirrodin/DampingMatrix.java b/Mage.Sets/src/mage/sets/mirrodin/DampingMatrix.java index ca28187abe..491766f4fd 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/DampingMatrix.java +++ b/Mage.Sets/src/mage/sets/mirrodin/DampingMatrix.java @@ -89,11 +89,6 @@ class DampingMatrixEffect extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public DampingMatrixEffect copy() { return new DampingMatrixEffect(this); @@ -103,16 +98,19 @@ class DampingMatrixEffect extends ReplacementEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ACTIVATE_ABILITY; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ACTIVATE_ABILITY) { - MageObject object = game.getObject(event.getSourceId()); - if (object instanceof Permanent && filter.match((Permanent)object, game)) { - Ability ability = object.getAbilities().get(event.getTargetId()); - if (ability != null && !(ability instanceof ManaAbility)) { - return true; - } + MageObject object = game.getObject(event.getSourceId()); + if (object instanceof Permanent && filter.match((Permanent)object, game)) { + Ability ability = object.getAbilities().get(event.getTargetId()); + if (ability != null && !(ability instanceof ManaAbility)) { + return true; } } return false; diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/MelirasKeepers.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/MelirasKeepers.java index 81f77ae8f9..899228b0ee 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/MelirasKeepers.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/MelirasKeepers.java @@ -36,7 +36,7 @@ import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.cards.CardImpl; import mage.game.Game; import mage.game.events.GameEvent; @@ -57,6 +57,7 @@ public class MelirasKeepers extends CardImpl { this.power = new MageInt(4); this.toughness = new MageInt(4); + // Melira's Keepers can't have counters placed on it this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MelirasKeepersEffect())); } @@ -71,7 +72,7 @@ public class MelirasKeepers extends CardImpl { } -class MelirasKeepersEffect extends ReplacementEffectImpl { +class MelirasKeepersEffect extends ContinuousRuleModifyingEffectImpl { public MelirasKeepersEffect() { super(Duration.WhileOnBattlefield, Outcome.PreventDamage); @@ -82,27 +83,19 @@ class MelirasKeepersEffect extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public MelirasKeepersEffect copy() { return new MelirasKeepersEffect(this); } - + @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ADD_COUNTER; } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ADD_COUNTER && event.getTargetId().equals(source.getSourceId())) { - return true; - } - return false; + return event.getTargetId().equals(source.getSourceId()); } } diff --git a/Mage.Sets/src/mage/sets/morningtide/BramblewoodParagon.java b/Mage.Sets/src/mage/sets/morningtide/BramblewoodParagon.java index ba50f12ecf..51657bef40 100644 --- a/Mage.Sets/src/mage/sets/morningtide/BramblewoodParagon.java +++ b/Mage.Sets/src/mage/sets/morningtide/BramblewoodParagon.java @@ -99,24 +99,19 @@ class BramblewoodParagonReplacementEffect extends ReplacementEffectImpl { BramblewoodParagonReplacementEffect(BramblewoodParagonReplacementEffect effect) { super(effect); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - Permanent creature = game.getPermanent(event.getTargetId()); - if (creature != null && creature.getControllerId().equals(source.getControllerId()) - && creature.getCardType().contains(CardType.CREATURE) - && creature.hasSubtype("Warrior") - && !event.getTargetId().equals(source.getSourceId())) { - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; + Permanent creature = game.getPermanent(event.getTargetId()); + return creature != null && creature.getControllerId().equals(source.getControllerId()) + && creature.getCardType().contains(CardType.CREATURE) + && creature.hasSubtype("Warrior") + && !event.getTargetId().equals(source.getSourceId()); } @Override diff --git a/Mage.Sets/src/mage/sets/morningtide/OonasBlackguard.java b/Mage.Sets/src/mage/sets/morningtide/OonasBlackguard.java index 9e5d846240..69d1fd40a3 100644 --- a/Mage.Sets/src/mage/sets/morningtide/OonasBlackguard.java +++ b/Mage.Sets/src/mage/sets/morningtide/OonasBlackguard.java @@ -31,7 +31,6 @@ import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.ReplacementEffectImpl; @@ -47,6 +46,7 @@ import mage.counters.CounterType; import mage.game.Game; import mage.game.events.DamagedPlayerEvent; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; @@ -95,16 +95,19 @@ class OonasBlackguardReplacementEffect extends ReplacementEffectImpl { super(effect); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - Permanent creature = game.getPermanent(event.getTargetId()); - if (creature != null && creature.getControllerId().equals(source.getControllerId()) - && creature.getCardType().contains(CardType.CREATURE) - && creature.getSubtype().contains("Rogue") - && !event.getTargetId().equals(source.getSourceId())) { - return true; - } + Permanent creature = game.getPermanent(event.getTargetId()); + if (creature != null && creature.getControllerId().equals(source.getControllerId()) + && creature.getCardType().contains(CardType.CREATURE) + && creature.getSubtype().contains("Rogue") + && !event.getTargetId().equals(source.getSourceId())) { + return true; } return false; } diff --git a/Mage.Sets/src/mage/sets/morningtide/SageOfFables.java b/Mage.Sets/src/mage/sets/morningtide/SageOfFables.java index 813fcd3af3..c7a423909b 100644 --- a/Mage.Sets/src/mage/sets/morningtide/SageOfFables.java +++ b/Mage.Sets/src/mage/sets/morningtide/SageOfFables.java @@ -91,19 +91,19 @@ class SageOfFablesReplacementEffect extends ReplacementEffectImpl { SageOfFablesReplacementEffect(SageOfFablesReplacementEffect effect) { super(effect); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - Permanent creature = game.getPermanent(event.getTargetId()); - if (creature != null && creature.getControllerId().equals(source.getControllerId()) - && creature.getCardType().contains(CardType.CREATURE) - && creature.getSubtype().contains("Wizard") - && !event.getTargetId().equals(source.getSourceId())) { - return true; - } - } - return false; + Permanent creature = game.getPermanent(event.getTargetId()); + return creature != null && creature.getControllerId().equals(source.getControllerId()) + && creature.getCardType().contains(CardType.CREATURE) + && creature.getSubtype().contains("Wizard") + && !event.getTargetId().equals(source.getSourceId()); } @Override diff --git a/Mage.Sets/src/mage/sets/nemesis/OraclesAttendants.java b/Mage.Sets/src/mage/sets/nemesis/OraclesAttendants.java index a7f5e850f6..d87c60cee9 100644 --- a/Mage.Sets/src/mage/sets/nemesis/OraclesAttendants.java +++ b/Mage.Sets/src/mage/sets/nemesis/OraclesAttendants.java @@ -42,6 +42,7 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamageCreatureEvent; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.target.TargetSource; import mage.target.common.TargetCreaturePermanent; @@ -101,11 +102,6 @@ class OraclesAttendantsReplacementEffect extends ReplacementEffectImpl { public void init(Ability source, Game game) { this.targetSource.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { @@ -118,14 +114,15 @@ class OraclesAttendantsReplacementEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE - && event.getTargetId().equals(source.getFirstTarget()) - && event.getSourceId().equals(targetSource.getFirstTarget())) { - return true; - } - return false; + return event.getTargetId().equals(source.getFirstTarget()) + && event.getSourceId().equals(targetSource.getFirstTarget()); } } diff --git a/Mage.Sets/src/mage/sets/newphyrexia/DueRespect.java b/Mage.Sets/src/mage/sets/newphyrexia/DueRespect.java index b39778b606..2fef2672aa 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/DueRespect.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/DueRespect.java @@ -91,17 +91,15 @@ class DueRespectEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - return true; - } - return false; + return true; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } } diff --git a/Mage.Sets/src/mage/sets/newphyrexia/MeliraSylvokOutcast.java b/Mage.Sets/src/mage/sets/newphyrexia/MeliraSylvokOutcast.java index 7a363fa84e..b43ddb4547 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/MeliraSylvokOutcast.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/MeliraSylvokOutcast.java @@ -99,11 +99,6 @@ class MeliraSylvokOutcastEffect extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public MeliraSylvokOutcastEffect copy() { return new MeliraSylvokOutcastEffect(this); @@ -114,12 +109,14 @@ class MeliraSylvokOutcastEffect extends ReplacementEffectImpl { return true; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ADD_COUNTER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ADD_COUNTER && event.getData().equals(CounterType.POISON.getName()) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; + return event.getData().equals(CounterType.POISON.getName()) && event.getTargetId().equals(source.getControllerId()); } } @@ -135,11 +132,6 @@ class MeliraSylvokOutcastEffect2 extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public MeliraSylvokOutcastEffect2 copy() { return new MeliraSylvokOutcastEffect2(this); @@ -149,13 +141,19 @@ class MeliraSylvokOutcastEffect2 extends ReplacementEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ADD_COUNTER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ADD_COUNTER && event.getData().equals(CounterType.M1M1.getName())) { + if (event.getData().equals(CounterType.M1M1.getName())) { Permanent perm = game.getPermanent(event.getTargetId()); - if (perm != null && perm.getCardType().contains(CardType.CREATURE) && perm.getControllerId().equals(source.getControllerId())) + if (perm != null && perm.getCardType().contains(CardType.CREATURE) && perm.getControllerId().equals(source.getControllerId())) { return true; + } } return false; } diff --git a/Mage.Sets/src/mage/sets/newphyrexia/PhyrexianUnlife.java b/Mage.Sets/src/mage/sets/newphyrexia/PhyrexianUnlife.java index eedd8bc52e..2928637381 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/PhyrexianUnlife.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/PhyrexianUnlife.java @@ -98,11 +98,6 @@ class PhyrexianUnlifeEffect2 extends ReplacementEffectImpl { return new PhyrexianUnlifeEffect2(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { DamagePlayerEvent damageEvent = (DamagePlayerEvent) event; @@ -119,10 +114,15 @@ class PhyrexianUnlifeEffect2 extends ReplacementEffectImpl { } return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_PLAYER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.DAMAGE_PLAYER && event.getPlayerId().equals(source.getControllerId())) { + if (event.getPlayerId().equals(source.getControllerId())) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { // The decision if the player has more than 0 life has to be checked only at start of a combat damage step diff --git a/Mage.Sets/src/mage/sets/newphyrexia/UrabraskTheHidden.java b/Mage.Sets/src/mage/sets/newphyrexia/UrabraskTheHidden.java index 31fbda858a..45d7993164 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/UrabraskTheHidden.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/UrabraskTheHidden.java @@ -41,6 +41,7 @@ import mage.cards.CardImpl; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; /** @@ -91,20 +92,22 @@ class UrabraskTheHiddenEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { - Card c = game.getCard(event.getTargetId()); - if (c != null && c.getCardType().contains(CardType.CREATURE)) + if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { + Card card = game.getCard(event.getTargetId()); + if (card != null && card.getCardType().contains(CardType.CREATURE)) { return true; + } } return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } @Override public UrabraskTheHiddenEffect copy() { diff --git a/Mage.Sets/src/mage/sets/odyssey/AegisOfHonor.java b/Mage.Sets/src/mage/sets/odyssey/AegisOfHonor.java index becd3df993..3e13811199 100644 --- a/Mage.Sets/src/mage/sets/odyssey/AegisOfHonor.java +++ b/Mage.Sets/src/mage/sets/odyssey/AegisOfHonor.java @@ -31,7 +31,6 @@ package mage.sets.odyssey; import java.util.UUID; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; @@ -46,26 +45,24 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.stack.Spell; import mage.game.stack.StackObject; -import mage.target.TargetPermanent; +import mage.target.TargetPlayer; /** * @author cbt33 / LevelX2 */ +public class AegisOfHonor extends CardImpl { -public class AegisOfHonor extends CardImpl{ - - public AegisOfHonor(UUID ownerId){ - super(ownerId, 1, "Aegis of Honor", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{W}"); - this.expansionSetCode = "ODY"; - + public AegisOfHonor(UUID ownerId) { + super(ownerId, 1, "Aegis of Honor", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{W}"); + this.expansionSetCode = "ODY"; // {1}: The next time an instant or sorcery spell would deal damage to you this - //turn, that spell deals that damage to its controller instead. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new AegisOfHonorEffect(), new ManaCostsImpl("{1}"))); + //turn, that spell deals that damage to its controller instead. + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new AegisOfHonorEffect(), new ManaCostsImpl("{1}"))); + } - } - public AegisOfHonor(final AegisOfHonor card) { + public AegisOfHonor(final AegisOfHonor card) { super(card); } @@ -97,11 +94,14 @@ class AegisOfHonorEffect extends RedirectionEffect { return true; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_PLAYER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER) //Checks for player damage - && event.getTargetId().equals(source.getControllerId())) //Checks to see the damage is to Aegis of Honor's controller - { + if (event.getTargetId().equals(source.getControllerId())) { //Checks to see the damage is to Aegis of Honor's controller Spell spell = null; StackObject stackObject = game.getStack().getStackObject(event.getSourceId()); if (stackObject == null) { @@ -112,7 +112,7 @@ class AegisOfHonorEffect extends RedirectionEffect { } //Checks if damage is from a sorcery or instants if (spell != null && instantOrSorceryfilter.match(spell.getCard(), game)) { - TargetPermanent target = new TargetPermanent(); + TargetPlayer target = new TargetPlayer(); target.add(spell.getControllerId(), game); redirectTarget = target; return true; diff --git a/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java b/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java index 132e60bac0..8d62548220 100644 --- a/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java +++ b/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java @@ -99,13 +99,13 @@ class DelayingShieldReplacementEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType() == EventType.DAMAGE_PLAYER && event.getTargetId().equals(source.getControllerId()); + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_PLAYER; } - + @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean applies(GameEvent event, Ability source, Game game) { + return event.getTargetId().equals(source.getControllerId()); } @Override diff --git a/Mage.Sets/src/mage/sets/planarchaos/FrozenAEther.java b/Mage.Sets/src/mage/sets/planarchaos/FrozenAEther.java index 38c4e082ea..39c827a0a1 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/FrozenAEther.java +++ b/Mage.Sets/src/mage/sets/planarchaos/FrozenAEther.java @@ -39,6 +39,7 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; /** @@ -84,9 +85,14 @@ class FrozenAEtherTapEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { + if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && (permanent.getCardType().contains(CardType.CREATURE) || @@ -98,11 +104,6 @@ class FrozenAEtherTapEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public FrozenAEtherTapEffect copy() { return new FrozenAEtherTapEffect(this); diff --git a/Mage.Sets/src/mage/sets/prophecy/ShieldDancer.java b/Mage.Sets/src/mage/sets/prophecy/ShieldDancer.java index c21941250c..8176e79671 100644 --- a/Mage.Sets/src/mage/sets/prophecy/ShieldDancer.java +++ b/Mage.Sets/src/mage/sets/prophecy/ShieldDancer.java @@ -92,10 +92,14 @@ class ShieldDancerRedirectionEffect extends RedirectionEffect { return new ShieldDancerRedirectionEffect(this); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.DAMAGE_CREATURE - && event.getTargetId().equals(source.getSourceId()) + if (event.getTargetId().equals(source.getSourceId()) && event.getSourceId().equals(source.getTargets().get(0).getFirstTarget())) { DamageEvent damageEvent = (DamageEvent) event; if (damageEvent.isCombatDamage()) { diff --git a/Mage.Sets/src/mage/sets/ravnica/LoxodonGatekeeper.java b/Mage.Sets/src/mage/sets/ravnica/LoxodonGatekeeper.java index 89e4454946..5b4297fba7 100644 --- a/Mage.Sets/src/mage/sets/ravnica/LoxodonGatekeeper.java +++ b/Mage.Sets/src/mage/sets/ravnica/LoxodonGatekeeper.java @@ -40,6 +40,7 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; @@ -91,10 +92,15 @@ class LoxodonGatekeeperTapEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { + if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && (permanent.getCardType().contains(CardType.CREATURE) || @@ -106,11 +112,6 @@ class LoxodonGatekeeperTapEffect extends ReplacementEffectImpl { return false; } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public LoxodonGatekeeperTapEffect copy() { return new LoxodonGatekeeperTapEffect(this); diff --git a/Mage.Sets/src/mage/sets/ravnica/Phytohydra.java b/Mage.Sets/src/mage/sets/ravnica/Phytohydra.java index 8e13c6aa98..13de6e22ca 100644 --- a/Mage.Sets/src/mage/sets/ravnica/Phytohydra.java +++ b/Mage.Sets/src/mage/sets/ravnica/Phytohydra.java @@ -39,6 +39,7 @@ import mage.counters.CounterType; import mage.game.Game; import mage.game.events.DamageCreatureEvent; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; /** @@ -89,13 +90,15 @@ class PhytohydraEffect extends ReplacementEffectImpl { } return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE && event.getTargetId().equals(source.getSourceId())) { - return true; - } - return false; + return event.getTargetId().equals(source.getSourceId()); } @Override diff --git a/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java b/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java index d4c29e9ca9..0462939b00 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java @@ -42,6 +42,7 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; import mage.players.Player; @@ -142,11 +143,6 @@ class RestInPeaceReplacementEffect extends ReplacementEffectImpl { return new RestInPeaceReplacementEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); @@ -167,10 +163,15 @@ class RestInPeaceReplacementEffect extends ReplacementEffectImpl { } return false; } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD; + return ((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD; } } diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/TajuruPreserver.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/TajuruPreserver.java index 9a22c9cdf4..f242ffd914 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/TajuruPreserver.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/TajuruPreserver.java @@ -85,29 +85,27 @@ class TajuruPreserverEffect extends ReplacementEffectImpl { return new TajuruPreserverEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { return true; } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.SACRIFICE_PERMANENT; + } @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.SACRIFICE_PERMANENT) { - MageObject object = game.getObject(event.getSourceId()); - if (object instanceof PermanentCard) { - if (game.getOpponents(source.getControllerId()).contains(((PermanentCard)object).getControllerId())) { - return true; - } + MageObject object = game.getObject(event.getSourceId()); + if (object instanceof PermanentCard) { + if (game.getOpponents(source.getControllerId()).contains(((PermanentCard)object).getControllerId())) { + return true; } - if (object instanceof Spell) { - if (game.getOpponents(source.getControllerId()).contains(((Spell)object).getControllerId())) { - return true; - } + } + if (object instanceof Spell) { + if (game.getOpponents(source.getControllerId()).contains(((Spell)object).getControllerId())) { + return true; } } return false; diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/HeavyArbalest.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/HeavyArbalest.java index 814dd794d2..4ec89a1a62 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/HeavyArbalest.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/HeavyArbalest.java @@ -100,20 +100,19 @@ class HeavyArbalestEffect extends ReplacementEffectImpl { return new HeavyArbalestEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return false; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { return true; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.UNTAP; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (game.getTurn().getStepType() == PhaseStep.UNTAP - && event.getType() == EventType.UNTAP ) { + if (game.getTurn().getStepType() == PhaseStep.UNTAP) { Permanent equipment = game.getPermanent(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { Permanent equipped = game.getPermanent(equipment.getAttachedTo()); diff --git a/Mage.Sets/src/mage/sets/shadowmoor/MossbridgeTroll.java b/Mage.Sets/src/mage/sets/shadowmoor/MossbridgeTroll.java index d72317de5d..9fa0b2ed6c 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/MossbridgeTroll.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/MossbridgeTroll.java @@ -78,8 +78,7 @@ public class MossbridgeTroll extends CardImpl { Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(20, 20, Duration.EndOfTurn), new MossbridgeTrollCost()); ability.setAdditionalCostsRuleVisible(false); this.addAbility(ability); - - + } public MossbridgeTroll(final MossbridgeTroll card) { @@ -103,11 +102,6 @@ class MossbridgeTrollReplacementEffect extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent mossbridgeTroll = game.getPermanent(event.getTargetId()); @@ -117,13 +111,14 @@ class MossbridgeTrollReplacementEffect extends ReplacementEffectImpl { return false; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DESTROY_PERMANENT; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DESTROY_PERMANENT - && event.getTargetId() == source.getSourceId()) { - return true; - } - return false; + return event.getTargetId() == source.getSourceId(); } @Override diff --git a/Mage.Sets/src/mage/sets/shadowmoor/WheelOfSunAndMoon.java b/Mage.Sets/src/mage/sets/shadowmoor/WheelOfSunAndMoon.java index db1f8e3602..d028787067 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/WheelOfSunAndMoon.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/WheelOfSunAndMoon.java @@ -62,7 +62,6 @@ public class WheelOfSunAndMoon extends CardImpl { this.expansionSetCode = "SHM"; this.subtype.add("Aura"); - // Enchant player TargetPlayer auraTarget = new TargetPlayer(); this.getSpellAbility().addTarget(auraTarget); @@ -99,29 +98,27 @@ class WheelOfSunAndMoonEffect extends ReplacementEffectImpl { return new WheelOfSunAndMoonEffect(this); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (EventType.ZONE_CHANGE.equals(event.getType())) { - ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - if (zEvent.getToZone().equals(Zone.GRAVEYARD)) { - Card card = game.getCard(event.getTargetId()); - if (card != null) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null && - card.getOwnerId().equals(enchantment.getAttachedTo())) { - return true; - } + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getToZone().equals(Zone.GRAVEYARD)) { + Card card = game.getCard(event.getTargetId()); + if (card != null) { + Permanent enchantment = game.getPermanent(source.getSourceId()); + if (enchantment != null && enchantment.getAttachedTo() != null && + card.getOwnerId().equals(enchantment.getAttachedTo())) { + return true; } } } return false; } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); diff --git a/Mage.Sets/src/mage/sets/shardsofalara/EmpyrialArchangel.java b/Mage.Sets/src/mage/sets/shardsofalara/EmpyrialArchangel.java index 3ddeb53edc..4dfdca070c 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/EmpyrialArchangel.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/EmpyrialArchangel.java @@ -94,15 +94,13 @@ class EmpyrialArchangelEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER && event.getPlayerId().equals(source.getControllerId())) - return true; - return false; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_PLAYER; } - + @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean applies(GameEvent event, Ability source, Game game) { + return event.getPlayerId().equals(source.getControllerId()); } @Override diff --git a/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java b/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java index 3285803e74..97c5d5349e 100644 --- a/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java +++ b/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java @@ -46,6 +46,7 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetSource; @@ -155,10 +156,15 @@ class ShamanEnKorReplacementEffect extends ReplacementEffectImpl { } } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_CREATURE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { if (!this.used) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) && targetSource != null) { + if (targetSource != null) { if (event.getSourceId().equals(targetSource.getFirstTarget())) { // check source MageObject object = game.getObject(event.getSourceId()); @@ -220,4 +226,4 @@ class ShamanEnKorReplacementEffect extends ReplacementEffectImpl { public ShamanEnKorReplacementEffect copy() { return new ShamanEnKorReplacementEffect(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/tempest/FurnaceOfRath.java b/Mage.Sets/src/mage/sets/tempest/FurnaceOfRath.java index cfbf7d803c..7e03c9d1f3 100644 --- a/Mage.Sets/src/mage/sets/tempest/FurnaceOfRath.java +++ b/Mage.Sets/src/mage/sets/tempest/FurnaceOfRath.java @@ -84,7 +84,7 @@ class FurnaceOfRathEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { + public boolean checksEventType(GameEvent event, Game game) { switch (event.getType()) { case DAMAGE_PLAYER: return true; @@ -92,29 +92,16 @@ class FurnaceOfRathEffect extends ReplacementEffectImpl { return true; } return false; - } - + } + @Override - public boolean apply(Game game, Ability source) { + public boolean applies(GameEvent event, Ability source, Game game) { return true; } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - DamageEvent damageEvent = (DamageEvent)event; - if (damageEvent.getType() == EventType.DAMAGE_PLAYER) { - Player targetPlayer = game.getPlayer(event.getTargetId()); - if (targetPlayer != null) { - targetPlayer.damage(damageEvent.getAmount()*2, damageEvent.getSourceId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage(), event.getAppliedEffects()); - return true; - } - } else { - Permanent targetPermanent = game.getPermanent(event.getTargetId()); - if (targetPermanent != null) { - targetPermanent.damage(damageEvent.getAmount()*2, damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); - return true; - } - } + event.setAmount(2 * event.getAmount()); return false; } } diff --git a/Mage.Sets/src/mage/sets/tempest/RootMaze.java b/Mage.Sets/src/mage/sets/tempest/RootMaze.java index e79acbf420..36109448c2 100644 --- a/Mage.Sets/src/mage/sets/tempest/RootMaze.java +++ b/Mage.Sets/src/mage/sets/tempest/RootMaze.java @@ -52,7 +52,6 @@ public class RootMaze extends CardImpl { super(ownerId, 144, "Root Maze", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{G}"); this.expansionSetCode = "TMP"; - // Artifacts and lands enter the battlefield tapped. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new RootMazeEffect())); } @@ -85,21 +84,16 @@ class RootMazeEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && (permanent.getCardType().contains(CardType.LAND) || permanent.getCardType().contains(CardType.ARTIFACT))) { - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; + Permanent permanent = game.getPermanent(event.getTargetId()); + return permanent != null && (permanent.getCardType().contains(CardType.LAND) || permanent.getCardType().contains(CardType.ARTIFACT)); } @Override diff --git a/Mage.Sets/src/mage/sets/timespiral/DralnuLichLord.java b/Mage.Sets/src/mage/sets/timespiral/DralnuLichLord.java index abcb883f06..104eb94b3f 100644 --- a/Mage.Sets/src/mage/sets/timespiral/DralnuLichLord.java +++ b/Mage.Sets/src/mage/sets/timespiral/DralnuLichLord.java @@ -116,13 +116,13 @@ class DralnuLichLordReplacementEffect extends ReplacementEffectImpl { } @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return event.getType() == GameEvent.EventType.DAMAGE_CREATURE && event.getTargetId().equals(source.getSourceId()); + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CREATURE; } - + @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean applies(GameEvent event, Ability source, Game game) { + return event.getTargetId().equals(source.getSourceId()); } @Override diff --git a/Mage.Sets/src/mage/sets/timespiral/FortuneThief.java b/Mage.Sets/src/mage/sets/timespiral/FortuneThief.java index c819fd4230..e928af4fd7 100644 --- a/Mage.Sets/src/mage/sets/timespiral/FortuneThief.java +++ b/Mage.Sets/src/mage/sets/timespiral/FortuneThief.java @@ -91,31 +91,28 @@ class FortuneThiefReplacementEffect extends ReplacementEffectImpl { public FortuneThiefReplacementEffect copy() { return new FortuneThiefReplacementEffect(this); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS)) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null - && (controller.getLife() > 0) &&(controller.getLife() - event.getAmount()) < 1 - && event.getPlayerId().equals(controller.getId()) - ) { - event.setAmount(controller.getLife() - 1); - //unsure how to make this comply with - // 10/1/2008: The ability doesn't change how much damage is dealt; - // it just changes how much life that damage makes you lose. - // An effect such as Spirit Link will see the full amount of damage being dealt. - } + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null + && (controller.getLife() > 0) &&(controller.getLife() - event.getAmount()) < 1 + && event.getPlayerId().equals(controller.getId()) + ) { + event.setAmount(controller.getLife() - 1); + //unsure how to make this comply with + // 10/1/2008: The ability doesn't change how much damage is dealt; + // it just changes how much life that damage makes you lose. + // An effect such as Spirit Link will see the full amount of damage being dealt. } } - - return false; - } - - @Override - public boolean apply(Game game, Ability source) { return false; } diff --git a/Mage.Sets/src/mage/sets/unlimitededition/TimeVault.java b/Mage.Sets/src/mage/sets/unlimitededition/TimeVault.java index e5525fea2b..f81de7e109 100644 --- a/Mage.Sets/src/mage/sets/unlimitededition/TimeVault.java +++ b/Mage.Sets/src/mage/sets/unlimitededition/TimeVault.java @@ -98,9 +98,14 @@ class TimeVaultReplacementEffect extends ReplacementEffectImpl { return new TimeVaultReplacementEffect(this); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.PLAY_TURN; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.PLAY_TURN && source.getControllerId().equals(event.getPlayerId())) { + if (source.getControllerId().equals(event.getPlayerId())) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null && permanent.isTapped()) { return true; @@ -108,12 +113,7 @@ class TimeVaultReplacementEffect extends ReplacementEffectImpl { } return false; } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - + @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player player = game.getPlayer(source.getControllerId()); diff --git a/Mage.Sets/src/mage/sets/urzassaga/Pariah.java b/Mage.Sets/src/mage/sets/urzassaga/Pariah.java index a2967c460b..e5502f2785 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/Pariah.java +++ b/Mage.Sets/src/mage/sets/urzassaga/Pariah.java @@ -57,12 +57,12 @@ public class Pariah extends CardImpl { this.expansionSetCode = "USG"; this.subtype.add("Aura"); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + // All damage that would be dealt to you is dealt to enchanted creature instead. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PariahEffect())); } @@ -90,22 +90,25 @@ class PariahEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { DamagePlayerEvent damageEvent = (DamagePlayerEvent) event; - Permanent equipment = game.getPermanent(source.getSourceId()); - if(equipment != null){ + Permanent equipment = game.getPermanent(source.getSourceId()); + if (equipment != null) { Permanent p = game.getPermanent(equipment.getAttachedTo()); - if (p != null) { - p.damage(damageEvent.getAmount(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable()); - return true; - } - } + if (p != null) { + p.damage(damageEvent.getAmount(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable()); + return true; + } + } return true; } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_PLAYER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER && event.getPlayerId().equals(source.getControllerId())) - return true; - return false; + return event.getPlayerId().equals(source.getControllerId()); } @Override diff --git a/Mage.Sets/src/mage/sets/urzassaga/Worship.java b/Mage.Sets/src/mage/sets/urzassaga/Worship.java index 0053b2fcbe..8b3743841f 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/Worship.java +++ b/Mage.Sets/src/mage/sets/urzassaga/Worship.java @@ -35,7 +35,6 @@ import mage.cards.CardImpl; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; import mage.players.Player; import java.util.UUID; @@ -49,7 +48,6 @@ public class Worship extends CardImpl { super(ownerId, 57, "Worship", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}"); this.expansionSetCode = "USG"; - // If you control a creature, damage that would reduce your life total to less than 1 reduces it to 1 instead. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new WorshipReplacementEffect())); } @@ -79,26 +77,23 @@ class WorshipReplacementEffect extends ReplacementEffectImpl { public WorshipReplacementEffect copy() { return new WorshipReplacementEffect(this); } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS)) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent == null) { - permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (permanent != null) { - Player controller = game.getPlayer(permanent.getControllerId()); - if (controller != null - && (controller.getLife() - event.getAmount()) < 1 - && event.getPlayerId().equals(controller.getId()) - && game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getSourceId(), event.getPlayerId(), game) > 0 - ) { - event.setAmount(controller.getLife() - 1); - } + if (source.getControllerId().equals(event.getPlayerId())) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null + && (controller.getLife() - event.getAmount()) < 1 + && game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getSourceId(), event.getPlayerId(), game) > 0 + ) { + event.setAmount(controller.getLife() - 1); } } - return false; } @@ -111,5 +106,4 @@ class WorshipReplacementEffect extends ReplacementEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { return false; } - } diff --git a/Mage.Sets/src/mage/sets/urzassaga/YawgmothsWill.java b/Mage.Sets/src/mage/sets/urzassaga/YawgmothsWill.java index 5f20f765e6..caa8114d83 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/YawgmothsWill.java +++ b/Mage.Sets/src/mage/sets/urzassaga/YawgmothsWill.java @@ -58,7 +58,6 @@ public class YawgmothsWill extends CardImpl { super(ownerId, 171, "Yawgmoth's Will", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{2}{B}"); this.expansionSetCode = "USG"; - // Until end of turn, you may play cards from your graveyard. this.getSpellAbility().addEffect(new CanPlayCardsFromGraveyardEffect()); @@ -130,11 +129,6 @@ class YawgmothsWillReplacementEffect extends ReplacementEffectImpl { return new YawgmothsWillReplacementEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); @@ -154,10 +148,15 @@ class YawgmothsWillReplacementEffect extends ReplacementEffectImpl { } return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD) { + if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD) { Card card = game.getCard(event.getTargetId()); if (card != null && card.getOwnerId().equals(source.getControllerId())) { Permanent permanent = ((ZoneChangeEvent) event).getTarget(); diff --git a/Mage.Sets/src/mage/sets/visions/ElephantGrass.java b/Mage.Sets/src/mage/sets/visions/ElephantGrass.java index c54819decd..11f14fe5eb 100644 --- a/Mage.Sets/src/mage/sets/visions/ElephantGrass.java +++ b/Mage.Sets/src/mage/sets/visions/ElephantGrass.java @@ -71,7 +71,6 @@ public class ElephantGrass extends CardImpl { class ElephantGrassReplacementEffect extends ReplacementEffectImpl { - ElephantGrassReplacementEffect ( ) { super(Duration.WhileOnBattlefield, Outcome.Neutral); @@ -101,8 +100,7 @@ class ElephantGrassReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { return true; - } - + } @Override public ElephantGrassReplacementEffect copy() { @@ -122,32 +120,30 @@ class ElephantGrassReplacementEffect2 extends ReplacementEffectImpl { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if ( event.getType() == GameEvent.EventType.DECLARE_ATTACKER) { - Player player = game.getPlayer(event.getPlayerId()); - if ( player != null && event.getTargetId().equals(source.getControllerId())) { - ManaCostsImpl attackCost = new ManaCostsImpl("{2}"); - if ( attackCost.canPay(source, source.getSourceId(), event.getPlayerId(), game) && - player.chooseUse(Outcome.Benefit, "Pay {2} to attack player?", game) ) { - if (attackCost.payOrRollback(source, game, this.getId(), event.getPlayerId())) { - return false; - } + Player player = game.getPlayer(event.getPlayerId()); + if ( player != null && event.getTargetId().equals(source.getControllerId())) { + ManaCostsImpl attackCost = new ManaCostsImpl("{2}"); + if ( attackCost.canPay(source, source.getSourceId(), event.getPlayerId(), game) && + player.chooseUse(Outcome.Benefit, "Pay {2} to attack player?", game) ) { + if (attackCost.payOrRollback(source, game, this.getId(), event.getPlayerId())) { + return false; } - return true; } + return true; } return false; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DECLARE_ATTACKER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if ( event.getType() == GameEvent.EventType.DECLARE_ATTACKER && event.getTargetId().equals(source.getControllerId()) ) { + if (event.getTargetId().equals(source.getControllerId()) ) { Permanent creature = game.getPermanent(event.getSourceId()); if (creature != null && !creature.getColor().isBlack()) { Player attackedPlayer = game.getPlayer(event.getTargetId()); diff --git a/Mage.Sets/src/mage/sets/worldwake/WrexialTheRisenDeep.java b/Mage.Sets/src/mage/sets/worldwake/WrexialTheRisenDeep.java index 873b913bb6..c0c7699178 100644 --- a/Mage.Sets/src/mage/sets/worldwake/WrexialTheRisenDeep.java +++ b/Mage.Sets/src/mage/sets/worldwake/WrexialTheRisenDeep.java @@ -153,35 +153,35 @@ class WrexialReplacementEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return true; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; } - + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getToZone() == Zone.GRAVEYARD + && ((ZoneChangeEvent) event).getTargetId() == cardid) { + return true; + } + return false; + } + @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { UUID eventObject = ((ZoneChangeEvent) event).getTargetId(); StackObject card = game.getStack().getStackObject(eventObject); - if (card != null) { + Player controller = game.getPlayer(source.getControllerId()); + if (card != null && controller != null) { if (card instanceof Spell) { game.rememberLKI(card.getId(), Zone.STACK, (Spell) card); } - if (card instanceof Card && eventObject == cardid) { - ((Card) card).moveToExile(source.getSourceId(), "Wrexial, The Risen Deep", source.getSourceId(), game); + if (card instanceof Card) { + controller.moveCardToExileWithInfo((Card)card, null, "", source.getSourceId(), game, game.getState().getZone(event.getTargetId()), true); return true; } } return false; } - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.ZONE_CHANGE) { - ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - if (zEvent.getToZone() == Zone.GRAVEYARD - && ((ZoneChangeEvent) event).getTargetId() == cardid) { - return true; - } - } - return false; - } } diff --git a/Mage.Sets/src/mage/sets/zendikar/NissasChosen.java b/Mage.Sets/src/mage/sets/zendikar/NissasChosen.java index 3b4b5e1bda..008deec3f2 100644 --- a/Mage.Sets/src/mage/sets/zendikar/NissasChosen.java +++ b/Mage.Sets/src/mage/sets/zendikar/NissasChosen.java @@ -43,6 +43,7 @@ import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; +import mage.players.Player; /** * @@ -59,6 +60,7 @@ public class NissasChosen extends CardImpl { this.power = new MageInt(2); this.toughness = new MageInt(3); + // If Nissa's Chosen would be put into a graveyard from the battlefield, put it on the bottom of its owner's library instead this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new NissasChosenEffect())); } @@ -89,27 +91,13 @@ class NissasChosenEffect extends ReplacementEffectImpl { } @Override - public boolean apply(Game game, Ability source) { - return false; + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Permanent permanent = ((ZoneChangeEvent) event).getTarget(); - if (permanent != null) { - if(permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false)) { - game.informPlayers(new StringBuilder(permanent.getName()).append(" was put on the bottom of its owner's library").toString()); - return true; - } - - } - return false; - } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if ( event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(source.getSourceId()) ) - { + if (event.getTargetId().equals(source.getSourceId())) { ZoneChangeEvent zEvent = (ZoneChangeEvent)event; if ( zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD ) { return true; @@ -117,5 +105,15 @@ class NissasChosenEffect extends ReplacementEffectImpl { } return false; } - + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Permanent permanent = ((ZoneChangeEvent) event).getTarget(); + Player controller = game.getPlayer(source.getControllerId()); + if (permanent != null && controller != null) { + controller.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, Zone.BATTLEFIELD, false, true); + return true; + } + return false; + } } diff --git a/Mage.Sets/src/mage/sets/zendikar/UnstableFooting.java b/Mage.Sets/src/mage/sets/zendikar/UnstableFooting.java index 913efaeefa..51de9cffdc 100644 --- a/Mage.Sets/src/mage/sets/zendikar/UnstableFooting.java +++ b/Mage.Sets/src/mage/sets/zendikar/UnstableFooting.java @@ -43,6 +43,7 @@ import mage.cards.CardImpl; import mage.constants.Duration; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.target.TargetPlayer; /** @@ -55,7 +56,6 @@ public class UnstableFooting extends CardImpl { super(ownerId, 153, "Unstable Footing", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{R}"); this.expansionSetCode = "ZEN"; - // Kicker {3}{R} (You may pay an additional {3}{R} as you cast this spell.) this.addAbility(new KickerAbility("{3}{R}")); @@ -64,9 +64,7 @@ public class UnstableFooting extends CardImpl { this.getSpellAbility().addEffect(new ConditionalOneShotEffect( new DamageTargetEffect(5), KickedCondition.getInstance(), - "If Unstable Footing was kicked, it deals 5 damage to target player")); - - + "If {this} was kicked, it deals 5 damage to target player")); } @@ -106,22 +104,19 @@ class UnstableFootingEffect extends ReplacementEffectImpl { return new UnstableFootingEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { return true; } - + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.PREVENT_DAMAGE; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.PREVENT_DAMAGE) { - return true; - } - return false; + return true; } } \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java b/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java index 8a1ec5aa8a..3e4aad2d6e 100644 --- a/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java +++ b/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java @@ -64,31 +64,35 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect { return new PlaneswalkerRedirectionEffect(this); } + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGE_PLAYER; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == EventType.DAMAGE_PLAYER) { - DamageEvent damageEvent = (DamageEvent)event; - UUID playerId = getSourceControllerId(event.getSourceId(), game); - if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) { - Player target = game.getPlayer(event.getTargetId()); - Player player = game.getPlayer(playerId); - if (target != null && player != null) { - int numPlaneswalkers = game.getBattlefield().countAll(filter, target.getId(), game); - if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) { - redirectTarget = new TargetPermanent(filter); - if (numPlaneswalkers == 1) { - redirectTarget.add(game.getBattlefield().getAllActivePermanents(filter, target.getId(), game).get(0).getId(), game); - } - else { - player.choose(Outcome.Damage, redirectTarget, null, game); - } - if (!game.isSimulation()) - game.informPlayers(new StringBuilder(player.getLogName()).append(" redirects ") + DamageEvent damageEvent = (DamageEvent)event; + UUID playerId = getSourceControllerId(event.getSourceId(), game); + if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) { + Player target = game.getPlayer(event.getTargetId()); + Player player = game.getPlayer(playerId); + if (target != null && player != null) { + int numPlaneswalkers = game.getBattlefield().countAll(filter, target.getId(), game); + if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) { + redirectTarget = new TargetPermanent(filter); + if (numPlaneswalkers == 1) { + redirectTarget.add(game.getBattlefield().getAllActivePermanents(filter, target.getId(), game).get(0).getId(), game); + } + else { + player.choose(Outcome.Damage, redirectTarget, null, game); + } + if (!game.isSimulation()) { + game.informPlayers(new StringBuilder(player.getLogName()).append(" redirects ") .append(event.getAmount()) .append(" damage to ") .append(game.getPermanent(redirectTarget.getFirstTarget()).getLogName()).toString()); - return true; } + return true; } } } diff --git a/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java b/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java index 1243f4a3f3..48b96a68be 100644 --- a/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java +++ b/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java @@ -79,9 +79,4 @@ public abstract class ReplacementEffectImpl extends ContinuousEffectImpl impleme throw new UnsupportedOperationException("Not used for replacemnt effect."); } - @Override - public boolean checksEventType(GameEvent event, Game game) { - return true; - } - } diff --git a/Mage/src/mage/abilities/effects/common/AddContinuousEffectToGame.java b/Mage/src/mage/abilities/effects/common/AddContinuousEffectToGame.java index 1cfcdae0e2..a209a9a65b 100644 --- a/Mage/src/mage/abilities/effects/common/AddContinuousEffectToGame.java +++ b/Mage/src/mage/abilities/effects/common/AddContinuousEffectToGame.java @@ -59,8 +59,7 @@ public class AddContinuousEffectToGame extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - ContinuousEffect effectToAdd = effect.copy(); - game.addEffect(effectToAdd, source); + game.addEffect(effect, source); return true; } }