From 1c19280693458a4e84091c617723b2c20254fda8 Mon Sep 17 00:00:00 2001 From: xenohedron Date: Thu, 19 Oct 2023 22:51:50 -0400 Subject: [PATCH] rework Banewasp Affliction --- .../src/mage/cards/b/BanewaspAffliction.java | 49 +++-------------- .../AttachedPermanentToughnessCount.java | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessCount.java diff --git a/Mage.Sets/src/mage/cards/b/BanewaspAffliction.java b/Mage.Sets/src/mage/cards/b/BanewaspAffliction.java index ee188447274..14811f1de62 100644 --- a/Mage.Sets/src/mage/cards/b/BanewaspAffliction.java +++ b/Mage.Sets/src/mage/cards/b/BanewaspAffliction.java @@ -1,24 +1,21 @@ - package mage.cards.b; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.Mode; import mage.abilities.common.DiesAttachedTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.AttachedPermanentToughnessCount; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; import mage.abilities.keyword.EnchantAbility; 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.game.permanent.Permanent; -import mage.players.Player; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** * * @author Plopman @@ -29,7 +26,6 @@ public final class BanewaspAffliction extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{B}"); this.subtype.add(SubType.AURA); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); @@ -38,7 +34,10 @@ public final class BanewaspAffliction extends CardImpl { this.addAbility(ability); // When enchanted creature dies, that creature's controller loses life equal to its toughness. - this.addAbility( new DiesAttachedTriggeredAbility(new BanewaspAfflictionLoseLifeEffect(), "enchanted creature")); + this.addAbility( new DiesAttachedTriggeredAbility( + new LoseLifeControllerAttachedEffect(AttachedPermanentToughnessCount.instance) + .setText("that creature's controller loses life equal to its toughness"), + "enchanted creature")); } private BanewaspAffliction(final BanewaspAffliction card) { @@ -50,35 +49,3 @@ public final class BanewaspAffliction extends CardImpl { return new BanewaspAffliction(this); } } - - -class BanewaspAfflictionLoseLifeEffect extends OneShotEffect { - - public BanewaspAfflictionLoseLifeEffect() { - super(Outcome.LoseLife); - this.staticText = "that creature's controller loses life equal to its toughness"; - } - - private BanewaspAfflictionLoseLifeEffect(final BanewaspAfflictionLoseLifeEffect copy) { - super(copy); - } - - - @Override - public BanewaspAfflictionLoseLifeEffect copy() { - return new BanewaspAfflictionLoseLifeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent creature = (Permanent) getValue("attachedTo"); - if(creature != null){ - Player player = game.getPlayer(creature.getOwnerId()); - if (player != null) { - player.loseLife(creature.getToughness().getValue(), game, source, false); - return true; - } - } - return false; - } -} diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessCount.java new file mode 100644 index 00000000000..35543b26778 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentToughnessCount.java @@ -0,0 +1,52 @@ +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 xenohedron + */ +public enum AttachedPermanentToughnessCount implements DynamicValue { + instance; + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + Permanent attachmentPermanent = game.getPermanent(sourceAbility.getSourceId()); + if (attachmentPermanent == null) { + attachmentPermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD, sourceAbility.getSourceObjectZoneChangeCounter()); + } + if (attachmentPermanent == null || attachmentPermanent.getAttachedTo() == null) { + return 0; + } + Permanent attached; + if (effect.getValue("attachedTo") instanceof Permanent) { + // This way is needed to obtain correct LKI (e.g. Persist) + attached = (Permanent) effect.getValue("attachedTo"); + } else { + attached = game.getPermanentOrLKIBattlefield(attachmentPermanent.getAttachedTo()); + } + if (attached != null && attached.getToughness().getValue() >= 0) { + return attached.getToughness().getValue(); + } + return 0; + } + + @Override + public AttachedPermanentToughnessCount copy() { + return instance; + } + + @Override + public String toString() { + return "X"; + } + + @Override + public String getMessage() { + return "its toughness"; + } +}