From 081b2f2f398f0a3dd85580d121198e2563da4973 Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Sat, 2 Apr 2022 02:11:12 -0400 Subject: [PATCH] Replace more custom effects with SavedDamageValue --- .../src/mage/cards/a/ArmadilloCloak.java | 4 +- Mage.Sets/src/mage/cards/b/Backfire.java | 9 +- .../src/mage/cards/b/BalefireDragon.java | 50 ++--------- Mage.Sets/src/mage/cards/b/BindingAgony.java | 15 ++-- .../mage/cards/b/BrigidHeroOfKinsbaile.java | 42 ++-------- .../src/mage/cards/c/ColdEyedSelkie.java | 44 ++-------- Mage.Sets/src/mage/cards/c/CreatureBond.java | 47 +++++++++-- Mage.Sets/src/mage/cards/d/DreamPillager.java | 48 ++--------- Mage.Sets/src/mage/cards/d/Dreamstealer.java | 45 ++-------- Mage.Sets/src/mage/cards/d/DruidsCall.java | 10 +-- .../src/mage/cards/e/EmpyrealVoyager.java | 41 ++------- .../src/mage/cards/f/FiredrinkerSatyr.java | 44 ++-------- Mage.Sets/src/mage/cards/f/FlayedNim.java | 47 ++--------- Mage.Sets/src/mage/cards/f/FleshReaver.java | 44 ++-------- .../src/mage/cards/g/GlintEyeNephilim.java | 43 ++-------- .../src/mage/cards/h/HuntersProwess.java | 51 ++---------- Mage.Sets/src/mage/cards/j/JackalPup.java | 38 +-------- Mage.Sets/src/mage/cards/j/JaggedPoppet.java | 83 ++----------------- Mage.Sets/src/mage/cards/l/LivingHive.java | 40 +-------- Mage.Sets/src/mage/cards/n/NeedleSpecter.java | 46 ++-------- Mage.Sets/src/mage/cards/o/OldGnawbone.java | 35 +------- .../src/mage/cards/p/PaladinOfPrahv.java | 45 ++-------- Mage.Sets/src/mage/cards/r/RaggedVeins.java | 17 ++-- .../src/mage/cards/s/ShinkaGatekeeper.java | 40 +-------- .../src/mage/cards/s/ShockmawDragon.java | 48 ++--------- Mage.Sets/src/mage/cards/s/SoulLink.java | 12 ++- Mage.Sets/src/mage/cards/s/SpiritLink.java | 8 +- Mage.Sets/src/mage/cards/s/SpiritLoop.java | 16 ++-- Mage.Sets/src/mage/cards/s/Spiritualize.java | 38 +-------- .../src/mage/cards/s/SpitefulSliver.java | 38 ++------- Mage.Sets/src/mage/cards/t/Tamanoa.java | 5 +- .../src/mage/cards/t/TanaTheBloodsower.java | 41 +-------- Mage.Sets/src/mage/cards/v/VampiricLink.java | 10 +-- Mage.Sets/src/mage/cards/w/WallOfSouls.java | 37 ++------- Mage.Sets/src/mage/cards/w/WandOfOrcus.java | 40 ++------- ...lueTest.java => SavedDamageValueTest.java} | 8 +- ...sDamageGainLifeSourceTriggeredAbility.java | 41 +-------- .../AttachedPermanentToughnessValue.java | 45 ---------- .../dynamicvalue/common/SavedDamageValue.java | 4 +- .../DamageAllControlledTargetEffect.java | 60 +++++++++++--- .../DamageAttachedControllerEffect.java | 15 +--- .../effects/common/DamageAttachedEffect.java | 36 ++------ .../common/DamageControllerEffect.java | 52 +++++------- .../effects/common/GainLifeEffect.java | 6 +- .../LoseLifeTargetControllerEffect.java | 29 ++++--- .../discard/DiscardControllerEffect.java | 14 +--- .../main/java/mage/filter/StaticFilters.java | 6 ++ .../TargetAttackingOrBlockingCreature.java | 7 +- 48 files changed, 318 insertions(+), 1226 deletions(-) rename Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/{NumericSetToEffectValueTest.java => SavedDamageValueTest.java} (94%) delete mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessValue.java diff --git a/Mage.Sets/src/mage/cards/a/ArmadilloCloak.java b/Mage.Sets/src/mage/cards/a/ArmadilloCloak.java index c3b369eba50..90fdb9290ac 100644 --- a/Mage.Sets/src/mage/cards/a/ArmadilloCloak.java +++ b/Mage.Sets/src/mage/cards/a/ArmadilloCloak.java @@ -5,7 +5,7 @@ import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.DealsDamageAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.GainLifeEffect; @@ -44,7 +44,7 @@ public final class ArmadilloCloak extends CardImpl { this.addAbility(ability); // Whenever enchanted creature deals damage, you gain that much life. - this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false)); + this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false)); } diff --git a/Mage.Sets/src/mage/cards/b/Backfire.java b/Mage.Sets/src/mage/cards/b/Backfire.java index e9948284cbc..57e3fdf6cf7 100644 --- a/Mage.Sets/src/mage/cards/b/Backfire.java +++ b/Mage.Sets/src/mage/cards/b/Backfire.java @@ -1,10 +1,8 @@ - package mage.cards.b; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.DealsDamageToAPlayerAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.DamageAttachedControllerEffect; import mage.abilities.keyword.EnchantAbility; @@ -32,11 +30,10 @@ public final class Backfire extends CardImpl { TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.UnboostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Whenever enchanted creature deals damage to you, Backfire deals that much damage to that creature's controller. - this.addAbility(new DealsDamageToAPlayerAttachedTriggeredAbility(new DamageAttachedControllerEffect(new NumericSetToEffectValues("that much", "damage")), "enchanted creature", false, true, false, TargetController.YOU)); + this.addAbility(new DealsDamageToAPlayerAttachedTriggeredAbility(new DamageAttachedControllerEffect(SavedDamageValue.MUCH), "enchanted creature", false, true, false, TargetController.YOU)); } private Backfire(final Backfire card) { diff --git a/Mage.Sets/src/mage/cards/b/BalefireDragon.java b/Mage.Sets/src/mage/cards/b/BalefireDragon.java index 827778e328a..61468c3d7dd 100644 --- a/Mage.Sets/src/mage/cards/b/BalefireDragon.java +++ b/Mage.Sets/src/mage/cards/b/BalefireDragon.java @@ -1,21 +1,15 @@ - package mage.cards.b; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DamageAllControlledTargetEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -31,9 +25,12 @@ public final class BalefireDragon extends CardImpl { this.toughness = new MageInt(6); this.addAbility(FlyingAbility.getInstance()); - // Whenever Balefire Dragon deals combat damage to a player, it deals that much damage to each creature that player controls. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new BalefireDragonEffect(), false, true)); + // Whenever Balefire Dragon deals combat damage to a player, + // it deals that much damage to each creature that player controls. + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DamageAllControlledTargetEffect(SavedDamageValue.MUCH, "it"), + false, true)); } private BalefireDragon(final BalefireDragon card) { @@ -45,36 +42,3 @@ public final class BalefireDragon extends CardImpl { return new BalefireDragon(this); } } - -class BalefireDragonEffect extends OneShotEffect { - - public BalefireDragonEffect() { - super(Outcome.Damage); - staticText = "it deals that much damage to each creature that player controls"; - } - - public BalefireDragonEffect(final BalefireDragonEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game)) { - creature.damage(amount, source.getSourceId(), source, game, false, true); - } - } - return true; - } - return false; - } - - @Override - public BalefireDragonEffect copy() { - return new BalefireDragonEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/cards/b/BindingAgony.java b/Mage.Sets/src/mage/cards/b/BindingAgony.java index 8f73dfd4190..f3332c069d1 100644 --- a/Mage.Sets/src/mage/cards/b/BindingAgony.java +++ b/Mage.Sets/src/mage/cards/b/BindingAgony.java @@ -1,13 +1,10 @@ - package mage.cards.b; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.DealtDamageAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DamageAttachedControllerEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -29,12 +26,10 @@ public final class BindingAgony extends CardImpl { TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + // Whenever enchanted creature is dealt damage, Binding Agony deals that much damage to that creature's controller. - Effect effect = new DamageTargetEffect(new NumericSetToEffectValues("that much", "damage")); - effect.setText("{this} deals that much damage to that creature's controller"); - this.addAbility(new DealtDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, effect, false, SetTargetPointer.PLAYER)); + this.addAbility(new DealtDamageAttachedTriggeredAbility(new DamageAttachedControllerEffect(SavedDamageValue.MUCH), false)); } private BindingAgony(final BindingAgony card) { diff --git a/Mage.Sets/src/mage/cards/b/BrigidHeroOfKinsbaile.java b/Mage.Sets/src/mage/cards/b/BrigidHeroOfKinsbaile.java index 4c08237e243..7191cc4db7b 100644 --- a/Mage.Sets/src/mage/cards/b/BrigidHeroOfKinsbaile.java +++ b/Mage.Sets/src/mage/cards/b/BrigidHeroOfKinsbaile.java @@ -1,4 +1,3 @@ - package mage.cards.b; import java.util.UUID; @@ -6,15 +5,12 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DamageAllControlledTargetEffect; import mage.abilities.keyword.FirstStrikeAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.filter.common.FilterAttackingOrBlockingCreature; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; +import mage.filter.StaticFilters; import mage.target.TargetPlayer; /** @@ -35,10 +31,11 @@ public final class BrigidHeroOfKinsbaile extends CardImpl { this.addAbility(FirstStrikeAbility.getInstance()); // {T}: Brigid, Hero of Kinsbaile deals 2 damage to each attacking or blocking creature target player controls. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BrigidHeroOfKinsbaileEffect(), new TapSourceCost()); + Ability ability = new SimpleActivatedAbility( + new DamageAllControlledTargetEffect(2, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE), + new TapSourceCost()); ability.addTarget(new TargetPlayer()); this.addAbility(ability); - } private BrigidHeroOfKinsbaile(final BrigidHeroOfKinsbaile card) { @@ -50,32 +47,3 @@ public final class BrigidHeroOfKinsbaile extends CardImpl { return new BrigidHeroOfKinsbaile(this); } } - -class BrigidHeroOfKinsbaileEffect extends OneShotEffect { - - public BrigidHeroOfKinsbaileEffect() { - super(Outcome.Damage); - staticText = "{this} deals 2 damage to each attacking or blocking creature target player controls"; - } - - public BrigidHeroOfKinsbaileEffect(final BrigidHeroOfKinsbaileEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source)); - if (targetPlayer != null) { - for (Permanent creature : game.getBattlefield().getAllActivePermanents(new FilterAttackingOrBlockingCreature(), targetPlayer.getId(), game)) { - creature.damage(2, source.getSourceId(), source, game, false, true); - } - return true; - } - return false; - } - - @Override - public BrigidHeroOfKinsbaileEffect copy() { - return new BrigidHeroOfKinsbaileEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/c/ColdEyedSelkie.java b/Mage.Sets/src/mage/cards/c/ColdEyedSelkie.java index 02a67433c38..58428ba40e0 100644 --- a/Mage.Sets/src/mage/cards/c/ColdEyedSelkie.java +++ b/Mage.Sets/src/mage/cards/c/ColdEyedSelkie.java @@ -1,19 +1,15 @@ - package mage.cards.c; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.keyword.IslandwalkAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.game.Game; -import mage.players.Player; /** * @@ -31,9 +27,11 @@ public final class ColdEyedSelkie extends CardImpl { // Islandwalk this.addAbility(new IslandwalkAbility()); - // Whenever Cold-Eyed Selkie deals combat damage to a player, you may draw that many cards. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new ColdEyeSelkieEffect(), true, true)); + // Whenever Cold-Eyed Selkie deals combat damage to a player, you may draw that many cards. + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DrawCardSourceControllerEffect(SavedDamageValue.MANY), + true, true)); } private ColdEyedSelkie(final ColdEyedSelkie card) { @@ -45,33 +43,3 @@ public final class ColdEyedSelkie extends CardImpl { return new ColdEyedSelkie(this); } } - -class ColdEyeSelkieEffect extends OneShotEffect { - - public ColdEyeSelkieEffect() { - super(Outcome.DrawCard); - this.staticText = "draw that many cards"; - } - - public ColdEyeSelkieEffect(final ColdEyeSelkieEffect effect) { - super(effect); - } - - @Override - public ColdEyeSelkieEffect copy() { - return new ColdEyeSelkieEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.drawCards(amount, source, game); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/c/CreatureBond.java b/Mage.Sets/src/mage/cards/c/CreatureBond.java index 9e19b52bdbb..eb28133c1a1 100644 --- a/Mage.Sets/src/mage/cards/c/CreatureBond.java +++ b/Mage.Sets/src/mage/cards/c/CreatureBond.java @@ -1,10 +1,10 @@ - package mage.cards.c; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.DiesAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.AttachedPermanentToughnessValue; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.DamageAttachedControllerEffect; import mage.abilities.keyword.EnchantAbility; @@ -13,6 +13,9 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -24,18 +27,19 @@ public final class CreatureBond extends CardImpl { public CreatureBond(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}"); - + this.subtype.add(SubType.AURA); // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); - this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // When enchanted creature dies, Creature Bond deals damage equal to that creature's toughness to the creature's controller. - this.addAbility( new DiesAttachedTriggeredAbility(new DamageAttachedControllerEffect(AttachedPermanentToughnessValue.instance), "enchanted creature")); + Effect effect = new DamageAttachedControllerEffect(CreatureBondValue.instance); + effect.setText("{this} deals damage equal to that creature's toughness to the creature's controller"); + this.addAbility(new DiesAttachedTriggeredAbility(effect, "enchanted creature")); } private CreatureBond(final CreatureBond card) { @@ -47,3 +51,32 @@ public final class CreatureBond extends CardImpl { return new CreatureBond(this); } } + +enum CreatureBondValue implements DynamicValue { + instance; + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + // In the case that the enchantment is blinked + Permanent enchantment = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); + if (enchantment == null) { + // It was not blinked, use the standard method + enchantment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId()); + } + if (enchantment == null) { + return 0; + } + Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo()); + return enchanted.getToughness().getValue(); + } + + @Override + public CreatureBondValue copy() { + return instance; + } + + @Override + public String getMessage() { + return "that creature's toughness"; + } +} diff --git a/Mage.Sets/src/mage/cards/d/DreamPillager.java b/Mage.Sets/src/mage/cards/d/DreamPillager.java index 45e5f290a3d..228c9fd15c6 100644 --- a/Mage.Sets/src/mage/cards/d/DreamPillager.java +++ b/Mage.Sets/src/mage/cards/d/DreamPillager.java @@ -5,9 +5,8 @@ import java.util.UUID; import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.effects.ContinuousEffect; -import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect; import mage.abilities.keyword.FlyingAbility; @@ -18,8 +17,6 @@ import mage.cards.Cards; import mage.cards.CardsImpl; import mage.constants.*; import mage.game.Game; -import mage.game.events.DamagedPlayerEvent; -import mage.game.events.GameEvent; import mage.players.Player; import mage.target.targetpointer.FixedTargets; @@ -38,7 +35,9 @@ public final class DreamPillager extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); // Whenever Dream Pillager deals combat damage to a player, exile that many cards from the top of your library. Until end of turn, you may cast nonland cards from among those exiled cards. - this.addAbility(new DreamPillagerTriggeredAbility()); + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DreamPillagerEffect(), + false, true)); } private DreamPillager(final DreamPillager card) { @@ -51,48 +50,11 @@ public final class DreamPillager extends CardImpl { } } -class DreamPillagerTriggeredAbility extends TriggeredAbilityImpl { - - public DreamPillagerTriggeredAbility() { - super(Zone.BATTLEFIELD, new DreamPillagerEffect(), false); - } - - public DreamPillagerTriggeredAbility(final DreamPillagerTriggeredAbility ability) { - super(ability); - } - - @Override - public DreamPillagerTriggeredAbility copy() { - return new DreamPillagerTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) { - for (Effect effect : getEffects()) { - effect.setValue("damage", event.getAmount()); - } - return true; - } - return false; - } - - @Override - public String getRule() { - return "Whenever {this} deals combat damage to a player, exile that many cards from the top of your library. Until end of turn, you may cast spells from among those exiled cards."; - } -} - class DreamPillagerEffect extends OneShotEffect { public DreamPillagerEffect() { super(Outcome.Benefit); - this.staticText = "exile that many cards from the top of your library. Until end of turn, you may cast nonland cards from among those exiled cards"; + this.staticText = "exile that many cards from the top of your library. Until end of turn, you may cast spells from among those exiled cards"; } public DreamPillagerEffect(final DreamPillagerEffect effect) { diff --git a/Mage.Sets/src/mage/cards/d/Dreamstealer.java b/Mage.Sets/src/mage/cards/d/Dreamstealer.java index 7fea7af4f36..858a16f2379 100644 --- a/Mage.Sets/src/mage/cards/d/Dreamstealer.java +++ b/Mage.Sets/src/mage/cards/d/Dreamstealer.java @@ -1,21 +1,17 @@ - package mage.cards.d; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.discard.DiscardTargetEffect; import mage.abilities.keyword.EternalizeAbility; import mage.abilities.keyword.MenaceAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.game.Game; -import mage.players.Player; /** * @@ -34,12 +30,13 @@ public final class Dreamstealer extends CardImpl { // Menace this.addAbility(new MenaceAbility(false)); - // When Dreamstealer deals combat damage to a player, that player discards that many cards. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new DreamstealerDiscardEffect(), false, true)); + // Whenever Dreamstealer deals combat damage to a player, that player discards that many cards. + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DiscardTargetEffect(SavedDamageValue.MANY), + false, true)); // Eternalize {4}{B}{B} this.addAbility(new EternalizeAbility(new ManaCostsImpl("{4}{B}{B}"), this)); - } private Dreamstealer(final Dreamstealer card) { @@ -51,33 +48,3 @@ public final class Dreamstealer extends CardImpl { return new Dreamstealer(this); } } - -class DreamstealerDiscardEffect extends OneShotEffect { - - public DreamstealerDiscardEffect() { - super(Outcome.Discard); - this.staticText = "that player discards that many cards"; - } - - public DreamstealerDiscardEffect(final DreamstealerDiscardEffect effect) { - super(effect); - } - - @Override - public DreamstealerDiscardEffect copy() { - return new DreamstealerDiscardEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); - if (targetPlayer != null) { - int damage = (Integer) getValue("damage"); - targetPlayer.discard(damage, false, false, source, game); - game.informPlayers(targetPlayer.getLogName() + "discards " + damage + " card(s)"); - return true; - } - return false; - } - -} diff --git a/Mage.Sets/src/mage/cards/d/DruidsCall.java b/Mage.Sets/src/mage/cards/d/DruidsCall.java index f067b70a1b4..77072372e04 100644 --- a/Mage.Sets/src/mage/cards/d/DruidsCall.java +++ b/Mage.Sets/src/mage/cards/d/DruidsCall.java @@ -1,10 +1,8 @@ - package mage.cards.d; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.DealtDamageAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.CreateTokenTargetEffect; @@ -30,16 +28,14 @@ public final class DruidsCall extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{G}"); this.subtype.add(SubType.AURA); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.AddAbility)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Whenever enchanted creature is dealt damage, its controller creates that many 1/1 green Squirrel creature tokens. - Effect effect = new CreateTokenTargetEffect(new SquirrelToken(), new NumericSetToEffectValues("that much", "damage")); + Effect effect = new CreateTokenTargetEffect(new SquirrelToken(), SavedDamageValue.MANY); effect.setText("its controller creates that many 1/1 green Squirrel creature tokens"); this.addAbility(new DealtDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, effect, false, SetTargetPointer.PLAYER)); } diff --git a/Mage.Sets/src/mage/cards/e/EmpyrealVoyager.java b/Mage.Sets/src/mage/cards/e/EmpyrealVoyager.java index abe68125655..cc061ad3356 100644 --- a/Mage.Sets/src/mage/cards/e/EmpyrealVoyager.java +++ b/Mage.Sets/src/mage/cards/e/EmpyrealVoyager.java @@ -1,11 +1,9 @@ - package mage.cards.e; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.TrampleAbility; @@ -13,9 +11,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.game.Game; -import mage.players.Player; /** * @@ -35,7 +30,10 @@ public final class EmpyrealVoyager extends CardImpl { // Trample this.addAbility(TrampleAbility.getInstance()); // Whenever Empyreal Voyager deals combat damage to a player you get that many {E} - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new EmpyrealVoyagerEffect(), false, true)); + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new GetEnergyCountersControllerEffect(SavedDamageValue.MANY) + .setText("you get that many {E} (energy counters)."), + false, true)); } private EmpyrealVoyager(final EmpyrealVoyager card) { @@ -47,32 +45,3 @@ public final class EmpyrealVoyager extends CardImpl { return new EmpyrealVoyager(this); } } - -class EmpyrealVoyagerEffect extends OneShotEffect { - - public EmpyrealVoyagerEffect() { - super(Outcome.Benefit); - this.staticText = "you get that many {E}"; - } - - public EmpyrealVoyagerEffect(final EmpyrealVoyagerEffect effect) { - super(effect); - } - - @Override - public EmpyrealVoyagerEffect copy() { - return new EmpyrealVoyagerEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - return new GetEnergyCountersControllerEffect(amount).apply(game, source); - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/f/FiredrinkerSatyr.java b/Mage.Sets/src/mage/cards/f/FiredrinkerSatyr.java index f5877ae4dfa..f0b29a5c965 100644 --- a/Mage.Sets/src/mage/cards/f/FiredrinkerSatyr.java +++ b/Mage.Sets/src/mage/cards/f/FiredrinkerSatyr.java @@ -5,15 +5,12 @@ import mage.abilities.Ability; import mage.abilities.common.DealtDamageToSourceTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.DamageControllerEffect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.game.Game; -import mage.players.Player; import java.util.UUID; @@ -31,12 +28,11 @@ public final class FiredrinkerSatyr extends CardImpl { this.toughness = new MageInt(1); // Whenever Firedrinker Satyr is dealt damage, it deals that much damage to you. - this.addAbility(new DealtDamageToSourceTriggeredAbility(new FiredrinkerSatyrDealDamageEffect(), false, false)); + this.addAbility(new DealtDamageToSourceTriggeredAbility( + new DamageControllerEffect(SavedDamageValue.MUCH, "it"), false)); // {1}{R}: Firedrinker Satyr gets +1/+0 until end of turn and deals 1 damage to you. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(1, 0, Duration.EndOfTurn), new ManaCostsImpl("{1}{R}")); - Effect effect = new DamageControllerEffect(1); - effect.setText("and deals 1 damage to you"); - ability.addEffect(effect); + Ability ability = new SimpleActivatedAbility(new BoostSourceEffect(1, 0, Duration.EndOfTurn), new ManaCostsImpl<>("{1}{R}")); + ability.addEffect(new DamageControllerEffect(1, "and")); this.addAbility(ability); } @@ -49,33 +45,3 @@ public final class FiredrinkerSatyr extends CardImpl { return new FiredrinkerSatyr(this); } } - -class FiredrinkerSatyrDealDamageEffect extends OneShotEffect { - - public FiredrinkerSatyrDealDamageEffect() { - super(Outcome.Damage); - this.staticText = "it deals that much damage to you"; - } - - public FiredrinkerSatyrDealDamageEffect(final FiredrinkerSatyrDealDamageEffect effect) { - super(effect); - } - - @Override - public FiredrinkerSatyrDealDamageEffect copy() { - return new FiredrinkerSatyrDealDamageEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - player.damage(amount, source.getSourceId(), source, game); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/f/FlayedNim.java b/Mage.Sets/src/mage/cards/f/FlayedNim.java index 2eb04278497..ea2df4f1ff0 100644 --- a/Mage.Sets/src/mage/cards/f/FlayedNim.java +++ b/Mage.Sets/src/mage/cards/f/FlayedNim.java @@ -5,17 +5,13 @@ import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToACreatureTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.LoseLifeTargetControllerEffect; import mage.abilities.effects.common.RegenerateSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; import java.util.UUID; @@ -32,10 +28,13 @@ public final class FlayedNim extends CardImpl { this.toughness = new MageInt(2); // Whenever Flayed Nim deals combat damage to a creature, that creature's controller loses that much life. - this.addAbility(new DealsCombatDamageToACreatureTriggeredAbility(new FlayedNimEffect(), false, true)); + this.addAbility(new DealsCombatDamageToACreatureTriggeredAbility( + new LoseLifeTargetControllerEffect(SavedDamageValue.MUCH) + .setText("that creature's controller loses that much life"), + false, true)); // {2}{B}: Regenerate Flayed Nim. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RegenerateSourceEffect(), new ManaCostsImpl("{2}{B}"))); + this.addAbility(new SimpleActivatedAbility(new RegenerateSourceEffect(), new ManaCostsImpl("{2}{B}"))); } private FlayedNim(final FlayedNim card) { @@ -47,35 +46,3 @@ public final class FlayedNim extends CardImpl { return new FlayedNim(this); } } - -class FlayedNimEffect extends OneShotEffect { - - FlayedNimEffect() { - super(Outcome.Benefit); - this.staticText = "that creature's controller loses that much life"; - } - - FlayedNimEffect(final FlayedNimEffect effect) { - super(effect); - } - - @Override - public FlayedNimEffect copy() { - return new FlayedNimEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent creature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source); - if (creature == null) { - return false; - } - Player player = game.getPlayer(creature.getControllerId()); - if (player == null) { - return false; - } - int damage = (int) this.getValue("damage"); - player.loseLife(damage, game, source, false); - return true; - } -} diff --git a/Mage.Sets/src/mage/cards/f/FleshReaver.java b/Mage.Sets/src/mage/cards/f/FleshReaver.java index df4093ebc60..472f04a6f22 100644 --- a/Mage.Sets/src/mage/cards/f/FleshReaver.java +++ b/Mage.Sets/src/mage/cards/f/FleshReaver.java @@ -1,19 +1,17 @@ package mage.cards.f; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DamageControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; -import mage.players.Player; import java.util.UUID; @@ -47,7 +45,7 @@ public final class FleshReaver extends CardImpl { class FleshReaverTriggeredAbility extends TriggeredAbilityImpl { FleshReaverTriggeredAbility() { - super(Zone.BATTLEFIELD, new FleshReaverEffect()); + super(Zone.BATTLEFIELD, new DamageControllerEffect(SavedDamageValue.MUCH)); } private FleshReaverTriggeredAbility(final FleshReaverTriggeredAbility effect) { @@ -80,39 +78,7 @@ class FleshReaverTriggeredAbility extends TriggeredAbilityImpl { } @Override - public String getRule() { - return "Whenever {this} deals damage to a creature or opponent, {this} deals that much damage to you."; - } - -} - -class FleshReaverEffect extends OneShotEffect { - - FleshReaverEffect() { - super(Outcome.Detriment); - this.staticText = "{this} deals that much damage to you."; - } - - private FleshReaverEffect(final FleshReaverEffect effect) { - super(effect); - } - - @Override - public FleshReaverEffect copy() { - return new FleshReaverEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - Permanent creature = game.getPermanentOrLKIBattlefield(source.getSourceId()); - if (creature == null || controller == null) { - return false; - } - int damageToDeal = (Integer) getValue("damage"); - if (damageToDeal > 0) { - controller.damage(damageToDeal, source.getSourceId(), source, game); - } - return true; + public String getTriggerPhrase() { + return "Whenever {this} deals damage to a creature or opponent, "; } } diff --git a/Mage.Sets/src/mage/cards/g/GlintEyeNephilim.java b/Mage.Sets/src/mage/cards/g/GlintEyeNephilim.java index 999efefb61e..c78d7e82ee4 100644 --- a/Mage.Sets/src/mage/cards/g/GlintEyeNephilim.java +++ b/Mage.Sets/src/mage/cards/g/GlintEyeNephilim.java @@ -1,4 +1,3 @@ - package mage.cards.g; import java.util.UUID; @@ -8,7 +7,8 @@ import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.DiscardCardCost; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -16,9 +16,6 @@ import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Duration; import mage.constants.Outcome; -import mage.constants.Zone; -import mage.game.Game; -import mage.players.Player; /** * @author fenhl @@ -33,10 +30,12 @@ public final class GlintEyeNephilim extends CardImpl { this.toughness = new MageInt(2); // Whenever Glint-Eye Nephilim deals combat damage to a player, draw that many cards. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new GlintEyeNephilimEffect(), false, true)); + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DrawCardSourceControllerEffect(SavedDamageValue.MANY), + false, true)); // {1}, Discard a card: Glint-Eye Nephilim gets +1/+1 until end of turn. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(1, 1, Duration.EndOfTurn), new GenericManaCost(1)); + Ability ability = new SimpleActivatedAbility(new BoostSourceEffect(1, 1, Duration.EndOfTurn), new GenericManaCost(1)); ability.addCost(new DiscardCardCost()); this.addAbility(ability); @@ -51,33 +50,3 @@ public final class GlintEyeNephilim extends CardImpl { return new GlintEyeNephilim(this); } } - -class GlintEyeNephilimEffect extends OneShotEffect { - - public GlintEyeNephilimEffect() { - super(Outcome.DrawCard); - this.staticText = "draw that many cards"; - } - - public GlintEyeNephilimEffect(final GlintEyeNephilimEffect effect) { - super(effect); - } - - @Override - public GlintEyeNephilimEffect copy() { - return new GlintEyeNephilimEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.drawCards(amount, source, game); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/h/HuntersProwess.java b/Mage.Sets/src/mage/cards/h/HuntersProwess.java index 8f9c39f9cb7..40ef45fdc4e 100644 --- a/Mage.Sets/src/mage/cards/h/HuntersProwess.java +++ b/Mage.Sets/src/mage/cards/h/HuntersProwess.java @@ -1,11 +1,11 @@ - package mage.cards.h; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; import mage.abilities.keyword.TrampleAbility; @@ -13,9 +13,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; -import mage.game.Game; -import mage.players.Player; import mage.target.common.TargetCreaturePermanent; /** @@ -27,15 +24,15 @@ public final class HuntersProwess extends CardImpl { public HuntersProwess(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{4}{G}"); - // Until end of turn, target creature gets +3/+3 and gains trample and "Whenever this creature deals combat damage to a player, draw that many cards." - Effect effect = new BoostTargetEffect(3,3, Duration.EndOfTurn); - effect.setText("Until end of turn, target creature gets +3/+3"); + Effect effect = new BoostTargetEffect(3, 3, Duration.EndOfTurn); + effect.setText("Until end of turn, target creature gets +3/+3"); this.getSpellAbility().addEffect(effect); effect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn); - effect.setText("and gains trample"); - this.getSpellAbility().addEffect(effect); - Ability grantedAbility = new DealsCombatDamageToAPlayerTriggeredAbility(new HuntersProwessDrawEffect(), false, true); + effect.setText("and gains trample"); + this.getSpellAbility().addEffect(effect); + Ability grantedAbility = new DealsCombatDamageToAPlayerTriggeredAbility( + new DrawCardSourceControllerEffect(SavedDamageValue.MANY), false, true); this.getSpellAbility().addEffect(new GainAbilityTargetEffect(grantedAbility, Duration.EndOfTurn, "and \"Whenever this creature deals combat damage to a player, draw that many cards.\"")); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); @@ -50,35 +47,3 @@ public final class HuntersProwess extends CardImpl { return new HuntersProwess(this); } } - -class HuntersProwessDrawEffect extends OneShotEffect { - - public HuntersProwessDrawEffect() { - super(Outcome.Benefit); - this.staticText = "draw that many cards"; - } - - public HuntersProwessDrawEffect(final HuntersProwessDrawEffect effect) { - super(effect); - } - - @Override - public HuntersProwessDrawEffect copy() { - return new HuntersProwessDrawEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int damage = (Integer) this.getValue("damage"); - if (damage > 0) { - controller.drawCards(damage, source, game); - } - return true; - } - - - return false; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/j/JackalPup.java b/Mage.Sets/src/mage/cards/j/JackalPup.java index 24c7fa97eec..d72970a9363 100644 --- a/Mage.Sets/src/mage/cards/j/JackalPup.java +++ b/Mage.Sets/src/mage/cards/j/JackalPup.java @@ -1,16 +1,13 @@ package mage.cards.j; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealtDamageToSourceTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DamageControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.game.Game; -import mage.players.Player; import java.util.UUID; @@ -27,8 +24,8 @@ public final class JackalPup extends CardImpl { this.toughness = new MageInt(1); // Whenever Jackal Pup is dealt damage, it deals that much damage to you. - this.addAbility(new DealtDamageToSourceTriggeredAbility(new JackalPupEffect(), false, false)); - + this.addAbility(new DealtDamageToSourceTriggeredAbility( + new DamageControllerEffect(SavedDamageValue.MUCH, "it"), false)); } private JackalPup(final JackalPup card) { @@ -40,30 +37,3 @@ public final class JackalPup extends CardImpl { return new JackalPup(this); } } - -class JackalPupEffect extends OneShotEffect { - - public JackalPupEffect() { - super(Outcome.Damage); - staticText = "it deals that much damage to you"; - } - - public JackalPupEffect(final JackalPupEffect effect) { - super(effect); - } - - @Override - public JackalPupEffect copy() { - return new JackalPupEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player you = game.getPlayer(source.getControllerId()); - if (you != null) { - you.damage((Integer) this.getValue("damage"), source.getSourceId(), source, game); - } - return true; - } - -} diff --git a/Mage.Sets/src/mage/cards/j/JaggedPoppet.java b/Mage.Sets/src/mage/cards/j/JaggedPoppet.java index 5e70143e79b..ce1ca657e24 100644 --- a/Mage.Sets/src/mage/cards/j/JaggedPoppet.java +++ b/Mage.Sets/src/mage/cards/j/JaggedPoppet.java @@ -1,4 +1,3 @@ - package mage.cards.j; import java.util.UUID; @@ -8,15 +7,14 @@ import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.DealtDamageToSourceTriggeredAbility; import mage.abilities.condition.common.HellbentCondition; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.discard.DiscardControllerEffect; +import mage.abilities.effects.common.discard.DiscardTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.AbilityWord; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.game.Game; -import mage.players.Player; /** * @@ -33,16 +31,15 @@ public final class JaggedPoppet extends CardImpl { this.toughness = new MageInt(4); // Whenever Jagged Poppet is dealt damage, discard that many cards. - this.addAbility(new DealtDamageToSourceTriggeredAbility(new JaggedPoppetDealtDamageEffect(), false, false)); + this.addAbility(new DealtDamageToSourceTriggeredAbility(new DiscardControllerEffect(SavedDamageValue.MANY), false)); // Hellbent - Whenever Jagged Poppet deals combat damage to a player, if you have no cards in hand, that player discards cards equal to the damage. Ability hellbentAbility = new ConditionalInterveningIfTriggeredAbility( - new DealsCombatDamageToAPlayerTriggeredAbility(new JaggedPoppetDealsDamageEffect(), false, true), + new DealsCombatDamageToAPlayerTriggeredAbility(new DiscardTargetEffect(SavedDamageValue.MANY), false, true), HellbentCondition.instance, "Whenever {this} deals combat damage to a player, if you have no cards in hand, that player discards cards equal to the damage."); hellbentAbility.setAbilityWord(AbilityWord.HELLBENT); this.addAbility(hellbentAbility); - } private JaggedPoppet(final JaggedPoppet card) { @@ -54,73 +51,3 @@ public final class JaggedPoppet extends CardImpl { return new JaggedPoppet(this); } } - -class JaggedPoppetDealsDamageEffect extends OneShotEffect { - - public JaggedPoppetDealsDamageEffect() { - super(Outcome.Discard); - //staticText = "it deals that much damage to each creature that player controls"; - } - - public JaggedPoppetDealsDamageEffect(final JaggedPoppetDealsDamageEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - //According to the Balefire Dragon code, This statement gets the player that was dealt the combat damage - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { - //Call the getValue method of the Effect class to retrieve the amount of damage - int amount = (Integer) getValue("damage"); - - if (amount > 0) { - //Call the player discard function discarding cards equal to damage - player.discard(amount, false, false, source, game); - } - return true; - } - return false; - } - - @Override - public JaggedPoppetDealsDamageEffect copy() { - return new JaggedPoppetDealsDamageEffect(this); - } -} - -class JaggedPoppetDealtDamageEffect extends OneShotEffect { - - public JaggedPoppetDealtDamageEffect() { - super(Outcome.Discard); - staticText = "discard that many cards"; - } - - public JaggedPoppetDealtDamageEffect(final JaggedPoppetDealtDamageEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - - //According to the Firedrinker Satyr code, This statement gets the player that controls Jagged Poppet - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - //Call the getValue method of the Effect class to retrieve the amount of damage - int amount = (Integer) getValue("damage"); - - if (amount > 0) { - //Call the player discard function discarding cards equal to damage - player.discard(amount, false, false, source, game); - } - return true; - } - return false; - - } - - @Override - public JaggedPoppetDealtDamageEffect copy() { - return new JaggedPoppetDealtDamageEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/l/LivingHive.java b/Mage.Sets/src/mage/cards/l/LivingHive.java index bcc6c973dc7..77df233c3b1 100644 --- a/Mage.Sets/src/mage/cards/l/LivingHive.java +++ b/Mage.Sets/src/mage/cards/l/LivingHive.java @@ -1,21 +1,16 @@ - package mage.cards.l; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.keyword.TrampleAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.game.Game; import mage.game.permanent.token.InsectToken; -import mage.players.Player; /** * @@ -33,7 +28,8 @@ public final class LivingHive extends CardImpl { // Trample this.addAbility(TrampleAbility.getInstance()); // Whenever Living Hive deals combat damage to a player, create that many 1/1 green Insect creature tokens. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new LivingHiveEffect(), false, true)); + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new CreateTokenEffect(new InsectToken(), SavedDamageValue.MANY), false, true)); } private LivingHive(final LivingHive card) { @@ -45,33 +41,3 @@ public final class LivingHive extends CardImpl { return new LivingHive(this); } } - -class LivingHiveEffect extends OneShotEffect { - - public LivingHiveEffect() { - super(Outcome.PutCreatureInPlay); - this.staticText = "create that many 1/1 green Insect creature tokens"; - } - - public LivingHiveEffect(final LivingHiveEffect effect) { - super(effect); - } - - @Override - public LivingHiveEffect copy() { - return new LivingHiveEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { - int amount = (Integer)getValue("damage"); - if (amount > 0) { - return new CreateTokenEffect(new InsectToken(), amount).apply(game, source); - } - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/n/NeedleSpecter.java b/Mage.Sets/src/mage/cards/n/NeedleSpecter.java index bc00276dd67..514dff2e594 100644 --- a/Mage.Sets/src/mage/cards/n/NeedleSpecter.java +++ b/Mage.Sets/src/mage/cards/n/NeedleSpecter.java @@ -1,20 +1,17 @@ - package mage.cards.n; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.discard.DiscardTargetEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.WitherAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.game.Game; -import mage.players.Player; /** * @@ -31,13 +28,14 @@ public final class NeedleSpecter extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); - + // Wither this.addAbility(WitherAbility.getInstance()); - + // Whenever Needle Specter deals combat damage to a player, that player discards that many cards. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new NeedleSpecterEffect(), false, true)); - + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DiscardTargetEffect(SavedDamageValue.MANY), + false, true)); } private NeedleSpecter(final NeedleSpecter card) { @@ -49,33 +47,3 @@ public final class NeedleSpecter extends CardImpl { return new NeedleSpecter(this); } } - -class NeedleSpecterEffect extends OneShotEffect { - - public NeedleSpecterEffect() { - super(Outcome.Discard); - this.staticText = "that player discards that many cards"; - } - - public NeedleSpecterEffect(final NeedleSpecterEffect effect) { - super(effect); - } - - @Override - public NeedleSpecterEffect copy() { - return new NeedleSpecterEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); - if (targetPlayer != null) { - int damage = (Integer)getValue("damage"); - targetPlayer.discard(damage, false, false, source, game); - game.informPlayers(targetPlayer.getLogName() + "discards " + damage + " card(s)"); - return true; - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/o/OldGnawbone.java b/Mage.Sets/src/mage/cards/o/OldGnawbone.java index 86770749d72..2b83bf460f0 100644 --- a/Mage.Sets/src/mage/cards/o/OldGnawbone.java +++ b/Mage.Sets/src/mage/cards/o/OldGnawbone.java @@ -2,10 +2,8 @@ package mage.cards.o; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsDamageToAPlayerAllTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.CreateTokenEffect; import mage.constants.SetTargetPointer; import mage.constants.SubType; @@ -15,7 +13,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.filter.StaticFilters; -import mage.game.Game; import mage.game.permanent.token.TreasureToken; /** @@ -37,7 +34,7 @@ public final class OldGnawbone extends CardImpl { // Whenever a creature you control deals combat damage to a player, create that many Treasure tokens. this.addAbility(new DealsDamageToAPlayerAllTriggeredAbility( - new CreateTokenEffect(new TreasureToken(), OldGnawboneValue.instance), + new CreateTokenEffect(new TreasureToken(), SavedDamageValue.MANY), StaticFilters.FILTER_CONTROLLED_A_CREATURE, false, SetTargetPointer.NONE, true )); @@ -52,31 +49,3 @@ public final class OldGnawbone extends CardImpl { return new OldGnawbone(this); } } - -enum OldGnawboneValue implements DynamicValue { - instance; - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Integer damage = (Integer) effect.getValue("damage"); - if (damage != null) { - return damage; - } - return 0; - } - - @Override - public String toString() { - return "that many"; - } - - @Override - public String getMessage() { - return ""; - } - - @Override - public OldGnawboneValue copy() { - return OldGnawboneValue.instance; - } -} diff --git a/Mage.Sets/src/mage/cards/p/PaladinOfPrahv.java b/Mage.Sets/src/mage/cards/p/PaladinOfPrahv.java index 83773fbae30..ff3bb29742c 100644 --- a/Mage.Sets/src/mage/cards/p/PaladinOfPrahv.java +++ b/Mage.Sets/src/mage/cards/p/PaladinOfPrahv.java @@ -7,20 +7,19 @@ import mage.abilities.Ability; import mage.abilities.DelayedTriggeredAbility; import mage.abilities.common.DealsDamageGainLifeSourceTriggeredAbility; import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.keyword.ForecastAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; -import mage.constants.Outcome; +import mage.constants.SubType; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.common.TargetCreaturePermanent; /** @@ -59,13 +58,12 @@ public final class PaladinOfPrahv extends CardImpl { class PaladinOfPrahvTriggeredAbility extends DelayedTriggeredAbility { public PaladinOfPrahvTriggeredAbility() { - super(new PaladinOfPrahvEffect(), Duration.EndOfTurn, false); + super(new GainLifeEffect(SavedDamageValue.MUCH), Duration.EndOfTurn, false); } - + public PaladinOfPrahvTriggeredAbility(final PaladinOfPrahvTriggeredAbility ability) { super(ability); } - @Override public PaladinOfPrahvTriggeredAbility copy() { @@ -93,40 +91,9 @@ class PaladinOfPrahvTriggeredAbility extends DelayedTriggeredAbility { } return false; } - + @Override public String getTriggerPhrase() { return "Whenever target creature deals damage this turn, " ; } } - -class PaladinOfPrahvEffect extends OneShotEffect { - - public PaladinOfPrahvEffect() { - super(Outcome.GainLife); - this.staticText = "you gain that much life"; - } - - public PaladinOfPrahvEffect(final PaladinOfPrahvEffect effect) { - super(effect); - } - - @Override - public PaladinOfPrahvEffect copy() { - return new PaladinOfPrahvEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - controller.gainLife(amount, game, source); - return true; - } - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/r/RaggedVeins.java b/Mage.Sets/src/mage/cards/r/RaggedVeins.java index f77066b7a4d..8af532872e7 100644 --- a/Mage.Sets/src/mage/cards/r/RaggedVeins.java +++ b/Mage.Sets/src/mage/cards/r/RaggedVeins.java @@ -1,13 +1,10 @@ - - package mage.cards.r; import java.util.UUID; import mage.abilities.common.DealtDamageAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.LoseLifeTargetEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.FlashAbility; import mage.cards.CardImpl; @@ -15,8 +12,6 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Outcome; -import mage.constants.SetTargetPointer; -import mage.constants.Zone; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -30,7 +25,6 @@ public final class RaggedVeins extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{B}"); this.subtype.add(SubType.AURA); - // Flash this.addAbility(FlashAbility.getInstance()); @@ -41,9 +35,10 @@ public final class RaggedVeins extends CardImpl { this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Whenever enchanted creature is dealt damage, its controller loses that much life. - Effect effect = new LoseLifeTargetEffect(new NumericSetToEffectValues("that much", "damage")); - effect.setText("its controller loses that much life"); - this.addAbility(new DealtDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, effect, false, SetTargetPointer.PLAYER)); + this.addAbility(new DealtDamageAttachedTriggeredAbility( + new LoseLifeControllerAttachedEffect(SavedDamageValue.MUCH), + false + )); } private RaggedVeins(final RaggedVeins card) { diff --git a/Mage.Sets/src/mage/cards/s/ShinkaGatekeeper.java b/Mage.Sets/src/mage/cards/s/ShinkaGatekeeper.java index 20f608fa9f3..6a73703d067 100644 --- a/Mage.Sets/src/mage/cards/s/ShinkaGatekeeper.java +++ b/Mage.Sets/src/mage/cards/s/ShinkaGatekeeper.java @@ -1,16 +1,13 @@ package mage.cards.s; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealtDamageToSourceTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DamageControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.game.Game; -import mage.players.Player; import java.util.UUID; @@ -28,7 +25,8 @@ public final class ShinkaGatekeeper extends CardImpl { this.toughness = new MageInt(2); // Whenever Shinka Gatekeeper is dealt damage, it deals that much damage to you. - this.addAbility(new DealtDamageToSourceTriggeredAbility(new ShinkaGatekeeperDealDamageEffect(), false, false)); + this.addAbility(new DealtDamageToSourceTriggeredAbility( + new DamageControllerEffect(SavedDamageValue.MUCH, "it"), false)); } private ShinkaGatekeeper(final ShinkaGatekeeper card) { @@ -40,33 +38,3 @@ public final class ShinkaGatekeeper extends CardImpl { return new ShinkaGatekeeper(this); } } - -class ShinkaGatekeeperDealDamageEffect extends OneShotEffect { - - public ShinkaGatekeeperDealDamageEffect() { - super(Outcome.Damage); - this.staticText = "it deals that much damage to you"; - } - - public ShinkaGatekeeperDealDamageEffect(final ShinkaGatekeeperDealDamageEffect effect) { - super(effect); - } - - @Override - public ShinkaGatekeeperDealDamageEffect copy() { - return new ShinkaGatekeeperDealDamageEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - player.damage(amount, source.getSourceId(), source, game); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/s/ShockmawDragon.java b/Mage.Sets/src/mage/cards/s/ShockmawDragon.java index ce34126d46a..54ff2020af1 100644 --- a/Mage.Sets/src/mage/cards/s/ShockmawDragon.java +++ b/Mage.Sets/src/mage/cards/s/ShockmawDragon.java @@ -2,19 +2,13 @@ package mage.cards.s; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DamageAllControlledTargetEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -31,8 +25,11 @@ public final class ShockmawDragon extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); - // Whenever Shockmaw Dragon deals combat damage to a player, it deals 1 damage to each creature that player controls. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new ShockmawDragonEffect(), false, true)); + // Whenever Shockmaw Dragon deals combat damage to a player, + // it deals 1 damage to each creature that player controls. + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new DamageAllControlledTargetEffect(1, "it"), + false, true)); } private ShockmawDragon(final ShockmawDragon card) { @@ -44,36 +41,3 @@ public final class ShockmawDragon extends CardImpl { return new ShockmawDragon(this); } } - -class ShockmawDragonEffect extends OneShotEffect { - - public ShockmawDragonEffect() { - super(Outcome.Damage); - staticText = "it deals 1 damage to each creature that player controls"; - } - - public ShockmawDragonEffect(final ShockmawDragonEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game)) { - creature.damage(1, source.getSourceId(), source, game, false, true); - } - } - return true; - } - return false; - } - - @Override - public ShockmawDragonEffect copy() { - return new ShockmawDragonEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/cards/s/SoulLink.java b/Mage.Sets/src/mage/cards/s/SoulLink.java index 3713ebe0a68..b77f6e96e09 100644 --- a/Mage.Sets/src/mage/cards/s/SoulLink.java +++ b/Mage.Sets/src/mage/cards/s/SoulLink.java @@ -1,11 +1,9 @@ - package mage.cards.s; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.DealsDamageAttachedTriggeredAbility; import mage.abilities.common.DealtDamageAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.keyword.EnchantAbility; @@ -32,13 +30,13 @@ public final class SoulLink extends CardImpl { TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + // Whenever enchanted creature deals damage, you gain that much life. this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, - new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false)); + new GainLifeEffect(SavedDamageValue.MUCH), false)); // Whenever enchanted creature is dealt damage, you gain that much life. - this.addAbility(new DealtDamageAttachedTriggeredAbility(new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false)); + this.addAbility(new DealtDamageAttachedTriggeredAbility(new GainLifeEffect(SavedDamageValue.MUCH), false)); } private SoulLink(final SoulLink card) { diff --git a/Mage.Sets/src/mage/cards/s/SpiritLink.java b/Mage.Sets/src/mage/cards/s/SpiritLink.java index 5c7ed70def0..422399d667d 100644 --- a/Mage.Sets/src/mage/cards/s/SpiritLink.java +++ b/Mage.Sets/src/mage/cards/s/SpiritLink.java @@ -1,10 +1,9 @@ - package mage.cards.s; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.DealsDamageAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.keyword.EnchantAbility; @@ -31,11 +30,10 @@ public final class SpiritLink extends CardImpl { TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Whenever enchanted creature deals damage, you gain that much life. - this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false)); + this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false)); } private SpiritLink(final SpiritLink card) { diff --git a/Mage.Sets/src/mage/cards/s/SpiritLoop.java b/Mage.Sets/src/mage/cards/s/SpiritLoop.java index b7de9aa9f3b..c629ea21665 100644 --- a/Mage.Sets/src/mage/cards/s/SpiritLoop.java +++ b/Mage.Sets/src/mage/cards/s/SpiritLoop.java @@ -1,11 +1,9 @@ - package mage.cards.s; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.DealsDamageAttachedTriggeredAbility; import mage.abilities.common.PutIntoGraveFromBattlefieldSourceTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.ReturnToHandSourceEffect; @@ -32,15 +30,13 @@ public final class SpiritLoop extends CardImpl { TargetPermanent auraTarget = new TargetControlledCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); - + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + // Whenever enchanted creature deals damage, you gain that much life. - this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false)); - + this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false)); + // When Spirit Loop is put into a graveyard from the battlefield, return Spirit Loop to its owner's hand. this.addAbility(new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new ReturnToHandSourceEffect())); - } private SpiritLoop(final SpiritLoop card) { @@ -51,4 +47,4 @@ public final class SpiritLoop extends CardImpl { public SpiritLoop copy() { return new SpiritLoop(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/cards/s/Spiritualize.java b/Mage.Sets/src/mage/cards/s/Spiritualize.java index a45d98d71a5..21cd9dcc71b 100644 --- a/Mage.Sets/src/mage/cards/s/Spiritualize.java +++ b/Mage.Sets/src/mage/cards/s/Spiritualize.java @@ -1,23 +1,21 @@ - package mage.cards.s; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.common.TargetCreaturePermanent; /** @@ -50,7 +48,7 @@ public final class Spiritualize extends CardImpl { class SpiritualizeTriggeredAbility extends DelayedTriggeredAbility { public SpiritualizeTriggeredAbility() { - super(new SpiritualizeEffect(), Duration.EndOfTurn, false); + super(new GainLifeEffect(SavedDamageValue.MUCH), Duration.EndOfTurn, false); } public SpiritualizeTriggeredAbility(final SpiritualizeTriggeredAbility ability) { @@ -85,33 +83,3 @@ class SpiritualizeTriggeredAbility extends DelayedTriggeredAbility { return "Whenever target creature deals damage, " ; } } - -class SpiritualizeEffect extends OneShotEffect { - - public SpiritualizeEffect() { - super(Outcome.GainLife); - this.staticText = "you gain that much life"; - } - - public SpiritualizeEffect(final SpiritualizeEffect effect) { - super(effect); - } - - @Override - public SpiritualizeEffect copy() { - return new SpiritualizeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.gainLife(amount, game, source); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/s/SpitefulSliver.java b/Mage.Sets/src/mage/cards/s/SpitefulSliver.java index fab6c735873..9d371990462 100644 --- a/Mage.Sets/src/mage/cards/s/SpitefulSliver.java +++ b/Mage.Sets/src/mage/cards/s/SpitefulSliver.java @@ -4,15 +4,14 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.DealtDamageToSourceTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.target.TargetPlayer; +import mage.target.common.TargetPlayerOrPlaneswalker; import java.util.UUID; @@ -29,13 +28,11 @@ public final class SpitefulSliver extends CardImpl { this.toughness = new MageInt(2); // Sliver creatures you control have "Whenever this creature is dealt damage, it deals that much damage to target player or planeswalker." - Ability ability = new DealtDamageToSourceTriggeredAbility( - new SpitefulSliverEffect(), - false, false - ); - ability.addTarget(new TargetPlayer()); + Ability ability = new DealtDamageToSourceTriggeredAbility(new DamageTargetEffect(SavedDamageValue.MUCH, "it"), false); + ability.addTarget(new TargetPlayerOrPlaneswalker()); + this.addAbility(new SimpleStaticAbility(new GainAbilityControlledEffect( - ability, Duration.WhileOnBattlefield, StaticFilters.FILTER_PERMANENT_ALL_SLIVERS + ability, Duration.WhileOnBattlefield, StaticFilters.FILTER_PERMANENT_SLIVERS ).setText("Sliver creatures you control have \"Whenever this creature is dealt damage, " + "it deals that much damage to target player or planeswalker.\"") )); @@ -50,26 +47,3 @@ public final class SpitefulSliver extends CardImpl { return new SpitefulSliver(this); } } - -class SpitefulSliverEffect extends OneShotEffect { - - SpitefulSliverEffect() { - super(Outcome.Damage); - this.staticText = "it deals that much damage to target player or planeswalker"; - } - - private SpitefulSliverEffect(final SpitefulSliverEffect effect) { - super(effect); - } - - @Override - public SpitefulSliverEffect copy() { - return new SpitefulSliverEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - return new DamageTargetEffect(amount).apply(game, source); - } -} diff --git a/Mage.Sets/src/mage/cards/t/Tamanoa.java b/Mage.Sets/src/mage/cards/t/Tamanoa.java index 03bf1e1d97b..cbd84866c28 100644 --- a/Mage.Sets/src/mage/cards/t/Tamanoa.java +++ b/Mage.Sets/src/mage/cards/t/Tamanoa.java @@ -1,4 +1,3 @@ - package mage.cards.t; import java.util.UUID; @@ -6,7 +5,7 @@ import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; import mage.abilities.effects.common.GainLifeEffect; import mage.cards.CardImpl; @@ -31,7 +30,7 @@ public final class Tamanoa extends CardImpl { this.toughness = new MageInt(4); // Whenever a noncreature source you control deals damage, you gain that much life. - Ability ability = new TamanoaDealsDamageTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false); + Ability ability = new TamanoaDealsDamageTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/t/TanaTheBloodsower.java b/Mage.Sets/src/mage/cards/t/TanaTheBloodsower.java index 4482c0080fc..f050d396019 100644 --- a/Mage.Sets/src/mage/cards/t/TanaTheBloodsower.java +++ b/Mage.Sets/src/mage/cards/t/TanaTheBloodsower.java @@ -1,11 +1,9 @@ - package mage.cards.t; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.keyword.PartnerAbility; import mage.abilities.keyword.TrampleAbility; @@ -13,11 +11,8 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; import mage.constants.SuperType; -import mage.game.Game; import mage.game.permanent.token.SaprolingToken; -import mage.players.Player; /** * @@ -36,8 +31,10 @@ public final class TanaTheBloodsower extends CardImpl { // Trample this.addAbility(TrampleAbility.getInstance()); + // Whenever Tana, the Bloodsower deals combat damage to a player, create that many 1/1 green Saproling creature tokens. - this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new TanaTheBloodsowerEffect(), false, true)); + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new CreateTokenEffect(new SaprolingToken(), SavedDamageValue.MANY), false, true)); // Partner this.addAbility(PartnerAbility.getInstance()); @@ -52,33 +49,3 @@ public final class TanaTheBloodsower extends CardImpl { return new TanaTheBloodsower(this); } } - -class TanaTheBloodsowerEffect extends OneShotEffect { - - public TanaTheBloodsowerEffect() { - super(Outcome.PutCreatureInPlay); - this.staticText = "create that many 1/1 green Saproling creature tokens"; - } - - public TanaTheBloodsowerEffect(final TanaTheBloodsowerEffect effect) { - super(effect); - } - - @Override - public TanaTheBloodsowerEffect copy() { - return new TanaTheBloodsowerEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { - int amount = (Integer)getValue("damage"); - if (amount > 0) { - return new CreateTokenEffect(new SaprolingToken(), amount).apply(game, source); - } - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/v/VampiricLink.java b/Mage.Sets/src/mage/cards/v/VampiricLink.java index f1d394c5909..0913cec0350 100644 --- a/Mage.Sets/src/mage/cards/v/VampiricLink.java +++ b/Mage.Sets/src/mage/cards/v/VampiricLink.java @@ -1,10 +1,9 @@ - package mage.cards.v; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.DealsDamageAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.common.NumericSetToEffectValues; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.keyword.EnchantAbility; @@ -30,12 +29,11 @@ public final class VampiricLink extends CardImpl { // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); - this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Whenever enchanted creature deals damage, you gain that much life. - this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false)); + this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false)); } private VampiricLink(final VampiricLink card) { diff --git a/Mage.Sets/src/mage/cards/w/WallOfSouls.java b/Mage.Sets/src/mage/cards/w/WallOfSouls.java index 4004cbc40f2..1df5ee113c9 100644 --- a/Mage.Sets/src/mage/cards/w/WallOfSouls.java +++ b/Mage.Sets/src/mage/cards/w/WallOfSouls.java @@ -1,17 +1,16 @@ - package mage.cards.w; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamagedEvent; @@ -33,7 +32,7 @@ public final class WallOfSouls extends CardImpl { // Defender this.addAbility(DefenderAbility.getInstance()); - // Whenever Wall of Souls is dealt combat damage, it deals that much damage to target opponent. + // Whenever Wall of Souls is dealt combat damage, it deals that much damage to target opponent or planeswalker. Ability ability = new WallOfSoulsTriggeredAbility(); ability.addTarget(new TargetOpponentOrPlaneswalker()); this.addAbility(ability); @@ -52,7 +51,7 @@ public final class WallOfSouls extends CardImpl { class WallOfSoulsTriggeredAbility extends TriggeredAbilityImpl { public WallOfSoulsTriggeredAbility() { - super(Zone.BATTLEFIELD, new WallOfSoulsDealDamageEffect()); + super(Zone.BATTLEFIELD, new DamageTargetEffect(SavedDamageValue.MUCH, "it")); } public WallOfSoulsTriggeredAbility(final WallOfSoulsTriggeredAbility effect) { @@ -72,7 +71,7 @@ class WallOfSoulsTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getTargetId().equals(this.sourceId) && ((DamagedEvent) event).isCombatDamage()) { - this.getEffects().get(0).setValue("damage", event.getAmount()); + this.getEffects().setValue("damage", event.getAmount()); return true; } return false; @@ -83,29 +82,3 @@ class WallOfSoulsTriggeredAbility extends TriggeredAbilityImpl { return "Whenever {this} is dealt combat damage, " ; } } - -class WallOfSoulsDealDamageEffect extends OneShotEffect { - - public WallOfSoulsDealDamageEffect() { - super(Outcome.Damage); - this.staticText = "it deals that much damage to target opponent or planeswalker"; - } - - public WallOfSoulsDealDamageEffect(final WallOfSoulsDealDamageEffect effect) { - super(effect); - } - - @Override - public WallOfSoulsDealDamageEffect copy() { - return new WallOfSoulsDealDamageEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - return game.damagePlayerOrPlaneswalker(source.getFirstTarget(), amount, source.getSourceId(), source, game, false, true) > 0; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/w/WandOfOrcus.java b/Mage.Sets/src/mage/cards/w/WandOfOrcus.java index 8aef1a42196..00a1219dd7b 100644 --- a/Mage.Sets/src/mage/cards/w/WandOfOrcus.java +++ b/Mage.Sets/src/mage/cards/w/WandOfOrcus.java @@ -3,8 +3,9 @@ package mage.cards.w; import mage.abilities.Ability; import mage.abilities.common.AttacksOrBlocksAttachedTriggeredAbility; import mage.abilities.common.DealsDamageToAPlayerAttachedTriggeredAbility; -import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.dynamicvalue.common.SavedDamageValue; +import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; import mage.abilities.keyword.DeathtouchAbility; @@ -13,7 +14,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.filter.FilterPermanent; -import mage.game.Game; import mage.game.permanent.token.ZombieToken; import java.util.UUID; @@ -44,12 +44,12 @@ public final class WandOfOrcus extends CardImpl { // Whenever equipped creature deals combat damage to a player, create that many // 2/2 black Zombie creature tokens. this.addAbility(new DealsDamageToAPlayerAttachedTriggeredAbility( - new WandOfOrcusZombieEffect(), "equipped creature", - false, true - )); + new CreateTokenEffect(new ZombieToken(), SavedDamageValue.MANY), + "equipped creature", + false)); // Equip {3} - this.addAbility(new EquipAbility(Outcome.AddAbility, new ManaCostsImpl<>("{3}"))); + this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3))); } private WandOfOrcus(final WandOfOrcus card) { @@ -61,29 +61,3 @@ public final class WandOfOrcus extends CardImpl { return new WandOfOrcus(this); } } - -class WandOfOrcusZombieEffect extends OneShotEffect { - - public WandOfOrcusZombieEffect() { - super(Outcome.Benefit); - this.staticText = "create that many 2/2 black Zombie creature tokens"; - } - - public WandOfOrcusZombieEffect(final WandOfOrcusZombieEffect effect) { - super(effect); - } - - @Override - public WandOfOrcusZombieEffect copy() { - return new WandOfOrcusZombieEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Integer damage = (Integer) this.getValue("damage"); - if (damage != null) { - return new ZombieToken().putOntoBattlefield(damage, game, source, source.getControllerId()); - } - return false; - } -} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/NumericSetToEffectValueTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/SavedDamageValueTest.java similarity index 94% rename from Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/NumericSetToEffectValueTest.java rename to Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/SavedDamageValueTest.java index 5be1d4ca712..30d0406e504 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/NumericSetToEffectValueTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/SavedDamageValueTest.java @@ -1,4 +1,3 @@ - package org.mage.test.cards.dynamicvalue; import mage.constants.PhaseStep; @@ -11,8 +10,7 @@ import org.mage.test.serverside.base.CardTestPlayerBase; * @author LevelX2 */ -public class NumericSetToEffectValueTest extends CardTestPlayerBase { - +public class SavedDamageValueTest extends CardTestPlayerBase { /** * Check that the dealt damage is added to life @@ -40,7 +38,5 @@ public class NumericSetToEffectValueTest extends CardTestPlayerBase { assertLife(playerA, 24); assertLife(playerB, 16); - } - -} \ No newline at end of file +} diff --git a/Mage/src/main/java/mage/abilities/common/DealsDamageGainLifeSourceTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DealsDamageGainLifeSourceTriggeredAbility.java index 50015cacfc3..564b3f37bf4 100644 --- a/Mage/src/main/java/mage/abilities/common/DealsDamageGainLifeSourceTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DealsDamageGainLifeSourceTriggeredAbility.java @@ -1,16 +1,12 @@ - - package mage.abilities.common; -import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.dynamicvalue.common.SavedDamageValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; -import mage.constants.Outcome; +import mage.abilities.effects.common.GainLifeEffect; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; -import mage.players.Player; /** * @@ -20,7 +16,7 @@ import mage.players.Player; public class DealsDamageGainLifeSourceTriggeredAbility extends TriggeredAbilityImpl { public DealsDamageGainLifeSourceTriggeredAbility() { - super(Zone.BATTLEFIELD, new GainThatMuchLifeEffect(), false); + super(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false); } public DealsDamageGainLifeSourceTriggeredAbility(final DealsDamageGainLifeSourceTriggeredAbility ability) { @@ -53,34 +49,3 @@ public class DealsDamageGainLifeSourceTriggeredAbility extends TriggeredAbilityI return "Whenever {this} deals damage, " ; } } - -class GainThatMuchLifeEffect extends OneShotEffect { - - public GainThatMuchLifeEffect() { - super(Outcome.GainLife); - this.staticText = "you gain that much life"; - } - - public GainThatMuchLifeEffect(final GainThatMuchLifeEffect effect) { - super(effect); - } - - @Override - public GainThatMuchLifeEffect copy() { - return new GainThatMuchLifeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int amount = (Integer) getValue("damage"); - if (amount > 0) { - controller.gainLife(amount, game, source); - - } - return true; - } - return false; - } -} diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessValue.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessValue.java deleted file mode 100644 index cfe130c50e1..00000000000 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessValue.java +++ /dev/null @@ -1,45 +0,0 @@ -package mage.abilities.dynamicvalue.common; - -import mage.abilities.Ability; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; - -/** - * @author MTGfan - */ -public enum AttachedPermanentToughnessValue implements DynamicValue { - instance; - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - // In the case that the enchantment is blinked - Permanent enchantment = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); - if (enchantment == null) { - // It was not blinked, use the standard method - enchantment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId()); - } - if (enchantment == null) { - return 0; - } - Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo()); - return enchanted.getToughness().getValue(); - } - - @Override - public AttachedPermanentToughnessValue copy() { - return AttachedPermanentToughnessValue.instance; - } - - @Override - public String toString() { - return "equal to"; - } - - @Override - public String getMessage() { - return "that creature's toughness"; - } -} diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SavedDamageValue.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SavedDamageValue.java index cf8f379dfba..ac6e0cd6b8c 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SavedDamageValue.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SavedDamageValue.java @@ -15,7 +15,7 @@ public enum SavedDamageValue implements DynamicValue { private final String message; SavedDamageValue(String message) { - this.message = message; + this.message = "that " + message; } @Override @@ -30,7 +30,7 @@ public enum SavedDamageValue implements DynamicValue { @Override public String toString() { - return "that " + message; + return message; } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/DamageAllControlledTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DamageAllControlledTargetEffect.java index da0c5dd2b3c..3b30b9e8799 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DamageAllControlledTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DamageAllControlledTargetEffect.java @@ -1,10 +1,13 @@ - package mage.abilities.effects.common; -import mage.constants.Outcome; import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; @@ -15,20 +18,43 @@ import mage.players.Player; */ public class DamageAllControlledTargetEffect extends OneShotEffect { - private FilterPermanent filter; - private int amount; + private final DynamicValue amount; + private final FilterPermanent filter; + private String sourceName = "{this}"; + + public DamageAllControlledTargetEffect(int amount) { + this(amount, StaticFilters.FILTER_PERMANENT_CREATURE); + } + + public DamageAllControlledTargetEffect(int amount, String whoDealDamageName) { + this(amount, StaticFilters.FILTER_PERMANENT_CREATURE); + this.sourceName = whoDealDamageName; + } + + public DamageAllControlledTargetEffect(DynamicValue amount) { + this(amount, StaticFilters.FILTER_PERMANENT_CREATURE); + } + + public DamageAllControlledTargetEffect(DynamicValue amount, String whoDealDamageName) { + this(amount, StaticFilters.FILTER_PERMANENT_CREATURE); + this.sourceName = whoDealDamageName; + } public DamageAllControlledTargetEffect(int amount, FilterPermanent filter) { + this(StaticValue.get(amount), filter); + } + + public DamageAllControlledTargetEffect(DynamicValue amount, FilterPermanent filter) { super(Outcome.Damage); this.amount = amount; this.filter = filter; - getText(); } public DamageAllControlledTargetEffect(final DamageAllControlledTargetEffect effect) { super(effect); - this.amount = effect.amount; + this.amount = effect.amount.copy(); this.filter = effect.filter.copy(); + this.sourceName = effect.sourceName; } @Override @@ -38,19 +64,29 @@ public class DamageAllControlledTargetEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayerOrPlaneswalkerController(source.getFirstTarget()); + Player player = game.getPlayerOrPlaneswalkerController(targetPointer.getFirst(game, source)); if (player == null) { return false; } for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) { - permanent.damage(amount, source.getSourceId(), source, game, false, true); + permanent.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true); } return true; } - private void getText() { - StringBuilder sb = new StringBuilder("{this} deals "); - sb.append(amount).append(" damage to each ").append(filter.getMessage()).append(" controlled by target player"); - staticText = sb.toString(); + @Override + public String getText(Mode mode) { + if (staticText != null && !staticText.isEmpty()) { + return staticText; + } + StringBuilder sb = new StringBuilder(sourceName); + sb.append(" deals ").append(amount).append(" damage to each ").append(filter.getMessage()); + if (mode.getTargets().isEmpty()) { + sb.append(" that player"); + } else { + sb.append(" target ").append(mode.getTargets().get(0).getTargetName()); + } + sb.append(" controls"); + return sb.toString(); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedControllerEffect.java index 7e350a8da3a..401d8e49cba 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedControllerEffect.java @@ -19,13 +19,13 @@ public class DamageAttachedControllerEffect extends OneShotEffect { protected DynamicValue amount; public DamageAttachedControllerEffect(int amount) { - super(Outcome.Damage); - this.amount = StaticValue.get(amount); + this(StaticValue.get(amount)); } public DamageAttachedControllerEffect(DynamicValue amount) { super(Outcome.Damage); this.amount = amount; + this.staticText = "{this} deals " + amount + " damage to that creature's controller"; } public DamageAttachedControllerEffect(final DamageAttachedControllerEffect effect) { @@ -60,15 +60,4 @@ public class DamageAttachedControllerEffect extends OneShotEffect { } return false; } - - @Override - public String getText(Mode mode) { - if (staticText != null && !staticText.isEmpty()) { - return staticText; - } - if ("equal to".equals(amount.toString())) { - return "{this} deals damage " + amount + " that creatures toughness to that creature's controller"; - } - return "{this} deals " + amount + " damage to that creature's controller"; - } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedEffect.java index df3089bea3e..2a858c8f419 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DamageAttachedEffect.java @@ -1,5 +1,3 @@ - - package mage.abilities.effects.common; import mage.abilities.Ability; @@ -19,27 +17,28 @@ import mage.game.permanent.Permanent; public class DamageAttachedEffect extends OneShotEffect { protected DynamicValue amount; - private String sourceName = "{this}"; public DamageAttachedEffect(int amount) { - super(Outcome.Damage); - this.amount = StaticValue.get(amount); + this(StaticValue.get(amount), "{this}"); } public DamageAttachedEffect(int amount, String whoDealDamageName) { - this(amount); - this.sourceName = whoDealDamageName; + this(StaticValue.get(amount), whoDealDamageName); } - + public DamageAttachedEffect(DynamicValue amount) { + this(amount, "{this}"); + } + + public DamageAttachedEffect(DynamicValue amount, String whoDealDamageName) { super(Outcome.Damage); this.amount = amount; + this.staticText = whoDealDamageName + " deals " + amount + " damage to enchanted creature"; } public DamageAttachedEffect(final DamageAttachedEffect effect) { super(effect); this.amount = effect.amount; - this.sourceName = effect.sourceName; } @Override @@ -65,23 +64,4 @@ public class DamageAttachedEffect extends OneShotEffect { enchanted.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true); return true; } - - @Override - public String getText(Mode mode) { - if (staticText != null && !staticText.isEmpty()) { - return staticText; - } - if ("equal to".equals(amount.toString())) { - return this.sourceName + " deals damage " + amount + " that creatures toughness to enchanted creature"; - } - return this.sourceName + " deals " + amount + " damage to enchanted creature"; - } - - public String getSourceName() { - return sourceName; - } - - public void setSourceName(String sourceName) { - this.sourceName = sourceName; - } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/DamageControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DamageControllerEffect.java index 15c41536dd9..616ea253b5d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DamageControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DamageControllerEffect.java @@ -1,5 +1,3 @@ - - package mage.abilities.effects.common; import mage.constants.Outcome; @@ -21,39 +19,35 @@ public class DamageControllerEffect extends OneShotEffect { protected boolean preventable; private String sourceName = "{this}"; - public DamageControllerEffect(int amount, String whoDealDamageName) { - this(amount, true, whoDealDamageName); - } - public DamageControllerEffect(int amount) { this(amount, true); } - public DamageControllerEffect(int amount, boolean preventable, String whoDealDamageName) { - super(Outcome.Damage); - this.amount = StaticValue.get(amount); - this.preventable = preventable; - this.sourceName = whoDealDamageName; + public DamageControllerEffect(int amount, boolean preventable) { + this(amount, preventable, "{this}"); } - public DamageControllerEffect(int amount, boolean preventable) { - super(Outcome.Damage); - this.amount = StaticValue.get(amount); - this.preventable = preventable; + public DamageControllerEffect(int amount, String whoDealDamageName) { + this(amount, true, whoDealDamageName); + } + + public DamageControllerEffect(int amount, boolean preventable, String whoDealDamageName) { + this(StaticValue.get(amount), preventable, whoDealDamageName); } public DamageControllerEffect(DynamicValue amount) { + this(amount, "{this}"); + } + + public DamageControllerEffect(DynamicValue amount, String whoDealDamageName) { + this(amount, true, whoDealDamageName); + } + + public DamageControllerEffect(DynamicValue amount, boolean preventable, String whoDealDamageName) { super(Outcome.Damage); this.amount = amount; - this.preventable = true; - } - - public int getAmount() { - if (amount instanceof StaticValue) { - return amount.calculate(null, null, this); - } else { - return 0; - } + this.preventable = preventable; + this.sourceName = whoDealDamageName; } public DamageControllerEffect(final DamageControllerEffect effect) { @@ -77,7 +71,7 @@ public class DamageControllerEffect extends OneShotEffect { } return false; } - + @Override public String getText(Mode mode) { if (staticText != null && !staticText.isEmpty()) { @@ -107,12 +101,4 @@ public class DamageControllerEffect extends OneShotEffect { } return sb.toString(); } - - public String getSourceName() { - return sourceName; - } - - public void setSourceName(String sourceName) { - this.sourceName = sourceName; - } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/GainLifeEffect.java b/Mage/src/main/java/mage/abilities/effects/common/GainLifeEffect.java index ca4dbf1f801..9ec9404ed87 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/GainLifeEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/GainLifeEffect.java @@ -60,13 +60,11 @@ public class GainLifeEffect extends OneShotEffect { StringBuilder sb = new StringBuilder(); String message = life.getMessage(); sb.append("you gain "); - if (message.startsWith("that")) { - sb.append(message).append(' '); - } else if (message.isEmpty() || !life.toString().equals("1")) { + if (message.isEmpty() || !life.toString().equals("1")) { sb.append(life).append(' '); } sb.append("life"); - if (!message.isEmpty() && !message.startsWith("that")) { + if (!message.isEmpty()) { sb.append(life.toString().equals("1") ? " equal to the number of " : " for each "); sb.append(message); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/LoseLifeTargetControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/LoseLifeTargetControllerEffect.java index 60258d8c0ab..e0d2a94c0ad 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/LoseLifeTargetControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/LoseLifeTargetControllerEffect.java @@ -1,12 +1,13 @@ - package mage.abilities.effects.common; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; +import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.stack.Spell; @@ -18,9 +19,13 @@ import mage.players.Player; */ public class LoseLifeTargetControllerEffect extends OneShotEffect { - protected int amount; + private final DynamicValue amount; public LoseLifeTargetControllerEffect(int amount) { + this(StaticValue.get(amount)); + } + + public LoseLifeTargetControllerEffect(DynamicValue amount) { super(Outcome.Damage); this.amount = amount; staticText = "Its controller loses " + amount + " life"; @@ -28,7 +33,7 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect { public LoseLifeTargetControllerEffect(final LoseLifeTargetControllerEffect effect) { super(effect); - this.amount = effect.amount; + this.amount = effect.amount.copy(); } @Override @@ -38,16 +43,11 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - MageObject targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD); + MageObject targetCard = targetPointer.getFirstTargetPermanentOrLKI(game, source); + // if target is a countered spell if ( targetCard == null ) { - MageObject obj = game.getObject(targetPointer.getFirst(game, source)); - if ( obj instanceof Card ) { - targetCard = (Card)obj; - } else { - // if target is a countered spell - targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK); - } + targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK); } if ( targetCard != null ) { @@ -65,11 +65,10 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect { } if ( controller != null ) { - controller.loseLife(amount, game, source, false); + controller.loseLife(amount.calculate(game, source, this), game, source, false); return true; } } return false; } - } diff --git a/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java index ed032cb68cb..02c7e62ad65 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java @@ -55,18 +55,10 @@ public class DiscardControllerEffect extends OneShotEffect { private void setText() { StringBuilder sb = new StringBuilder("discard "); - if (amount.toString().equals("1")) { - sb.append('a'); + if (amount.toString().equals("1") || amount.toString().equals("a")) { + sb.append("a card"); } else { - sb.append(CardUtil.numberToText(amount.toString())); - } - sb.append(" card"); - try { - if (Integer.parseInt(amount.toString()) > 1) { - sb.append('s'); - } - } catch (Exception e) { - sb.append('s'); + sb.append(CardUtil.numberToText(amount.toString())).append(" cards"); } if (randomDiscard) { sb.append(" at random"); diff --git a/Mage/src/main/java/mage/filter/StaticFilters.java b/Mage/src/main/java/mage/filter/StaticFilters.java index 175a8d82994..e89d258e60f 100644 --- a/Mage/src/main/java/mage/filter/StaticFilters.java +++ b/Mage/src/main/java/mage/filter/StaticFilters.java @@ -875,6 +875,12 @@ public final class StaticFilters { FILTER_ATTACKING_CREATURES.setLockedFilter(true); } + public static final FilterAttackingOrBlockingCreature FILTER_ATTACKING_OR_BLOCKING_CREATURE = new FilterAttackingOrBlockingCreature(); + + static { + FILTER_ATTACKING_OR_BLOCKING_CREATURE.setLockedFilter(true); + } + public static final FilterAttackingOrBlockingCreature FILTER_ATTACKING_OR_BLOCKING_CREATURES = new FilterAttackingOrBlockingCreature("attacking or blocking creatures"); static { diff --git a/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java b/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java index 8d5f87c606e..53ba1106521 100644 --- a/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java +++ b/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java @@ -1,7 +1,6 @@ - - package mage.target.common; +import mage.filter.StaticFilters; import mage.filter.common.FilterAttackingOrBlockingCreature; import mage.target.TargetPermanent; @@ -12,11 +11,11 @@ import mage.target.TargetPermanent; public class TargetAttackingOrBlockingCreature extends TargetPermanent { public TargetAttackingOrBlockingCreature() { - this(1, 1, new FilterAttackingOrBlockingCreature(), false); + this(1, 1, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE, false); } public TargetAttackingOrBlockingCreature(int numTargets) { - this(numTargets, numTargets, new FilterAttackingOrBlockingCreature(), false); + this(numTargets, numTargets, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE, false); } public TargetAttackingOrBlockingCreature(int minNumTargets, int maxNumTargets, FilterAttackingOrBlockingCreature filter, boolean notTarget) {