From 367cf9169c31294b00fdea144a1caab3d1e739c6 Mon Sep 17 00:00:00 2001 From: xenohedron Date: Thu, 27 Jul 2023 23:42:45 -0400 Subject: [PATCH] Implement [LTC] Lothlorien Blade --- .../src/mage/cards/b/BloodfireInfusion.java | 45 ++-------- .../src/mage/cards/l/LothlorienBlade.java | 83 +++++++++++++++++++ .../src/mage/cards/m/MurderInvestigation.java | 49 ++--------- .../sets/TalesOfMiddleEarthCommander.java | 1 + .../common/AttachedPermanentPowerCount.java | 43 ++++++++++ 5 files changed, 138 insertions(+), 83 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/l/LothlorienBlade.java create mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentPowerCount.java diff --git a/Mage.Sets/src/mage/cards/b/BloodfireInfusion.java b/Mage.Sets/src/mage/cards/b/BloodfireInfusion.java index 2d5a0f5a475..9aa0548ec0a 100644 --- a/Mage.Sets/src/mage/cards/b/BloodfireInfusion.java +++ b/Mage.Sets/src/mage/cards/b/BloodfireInfusion.java @@ -1,12 +1,10 @@ - package mage.cards.b; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeAttachedCost; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.AttachedPermanentPowerCount; import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.DamageAllEffect; @@ -14,15 +12,15 @@ import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Outcome; +import mage.constants.SubType; import mage.constants.Zone; -import mage.target.TargetPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.filter.common.FilterCreaturePermanent; +import mage.target.TargetPermanent; import mage.target.common.TargetControlledCreaturePermanent; +import java.util.UUID; + /** * * @author L_J @@ -41,7 +39,7 @@ public final class BloodfireInfusion extends CardImpl { this.addAbility(ability); // {R}, Sacrifice enchanted creature: Bloodfire Infusion deals damage equal to the sacrificed creature's power to each creature. - Effect effect = new DamageAllEffect(new AttachedPermanentPowerCount(), new FilterCreaturePermanent()); + Effect effect = new DamageAllEffect(AttachedPermanentPowerCount.instance, new FilterCreaturePermanent()); effect.setText("{this} deals damage equal to the sacrificed creature's power to each creature"); Ability ability2 = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl<>("{R}")); ability2.addCost(new SacrificeAttachedCost()); @@ -58,34 +56,3 @@ public final class BloodfireInfusion extends CardImpl { return new BloodfireInfusion(this); } } - -class AttachedPermanentPowerCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Permanent attachment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId()); - if (attachment == null) { - return 0; - } - Permanent permanent = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo()); - if (permanent != null && (permanent.getPower().getValue() >= 0)) { - return permanent.getPower().getValue(); - } - return 0; - } - - @Override - public AttachedPermanentPowerCount copy() { - return new AttachedPermanentPowerCount(); - } - - @Override - public String toString() { - return "X"; - } - - @Override - public String getMessage() { - return "enchanted creature's power"; - } -} diff --git a/Mage.Sets/src/mage/cards/l/LothlorienBlade.java b/Mage.Sets/src/mage/cards/l/LothlorienBlade.java new file mode 100644 index 00000000000..53fac8be30c --- /dev/null +++ b/Mage.Sets/src/mage/cards/l/LothlorienBlade.java @@ -0,0 +1,83 @@ +package mage.cards.l; + +import mage.abilities.Ability; +import mage.abilities.common.AttacksAttachedTriggeredAbility; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.dynamicvalue.common.AttachedPermanentPowerCount; +import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.common.TargetCreaturePermanent; + +import java.util.Optional; +import java.util.UUID; + +/** + * @author xenohedron + */ +public final class LothlorienBlade extends CardImpl { + + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls"); + private static final FilterControlledCreaturePermanent filterElf = new FilterControlledCreaturePermanent(SubType.ELF, "Elf"); + + static { + filter.add(LothlorienBladePredicate.instance); + } + + public LothlorienBlade(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); + + this.subtype.add(SubType.EQUIPMENT); + + // Whenever equipped creature attacks, it deals damage equal to its power to target creature defending player controls. + Ability ability = new AttacksAttachedTriggeredAbility(new DamageTargetEffect(AttachedPermanentPowerCount.instance) + .setText("it deals damage equal to its power to target creature defending player controls")); + ability.addTarget(new TargetCreaturePermanent(filter)); + this.addAbility(ability); + + // Equip Elf {2} + this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2), new TargetControlledCreaturePermanent(filterElf), false)); + + // Equip {5} + this.addAbility(new EquipAbility(5, false)); + + } + + private LothlorienBlade(final LothlorienBlade card) { + super(card); + } + + @Override + public LothlorienBlade copy() { + return new LothlorienBlade(this); + } +} + +enum LothlorienBladePredicate implements ObjectSourcePlayerPredicate { + instance; + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + return Optional.ofNullable(input.getSource().getSourcePermanentOrLKI(game)) + .map(Permanent::getAttachedTo) + .map(uuid -> game.getCombat().getDefendingPlayerId(uuid, game)) + .map(input.getObject()::isControlledBy) + .orElse(false); + } + + @Override + public String toString() { + return ""; + } +} diff --git a/Mage.Sets/src/mage/cards/m/MurderInvestigation.java b/Mage.Sets/src/mage/cards/m/MurderInvestigation.java index eb4838b2c66..4f16b29b2a6 100644 --- a/Mage.Sets/src/mage/cards/m/MurderInvestigation.java +++ b/Mage.Sets/src/mage/cards/m/MurderInvestigation.java @@ -1,26 +1,22 @@ - package mage.cards.m; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.DiesAttachedTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.AttachedPermanentPowerCount; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.keyword.EnchantAbility; 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.permanent.Permanent; +import mage.constants.SubType; import mage.game.permanent.token.SoldierToken; import mage.target.TargetPermanent; import mage.target.common.TargetControlledCreaturePermanent; +import java.util.UUID; + /** * * @author LevelX2 @@ -39,7 +35,7 @@ public final class MurderInvestigation extends CardImpl { this.addAbility(ability); // When enchanted creature dies, create X 1/1 white Soldier creature tokens, where X is its power. - this.addAbility(new DiesAttachedTriggeredAbility(new CreateTokenEffect(new SoldierToken(), new AttachedPermanentPowerCount()), "enchanted creature")); + this.addAbility(new DiesAttachedTriggeredAbility(new CreateTokenEffect(new SoldierToken(), AttachedPermanentPowerCount.instance), "enchanted creature")); } private MurderInvestigation(final MurderInvestigation card) { @@ -51,38 +47,3 @@ public final class MurderInvestigation extends CardImpl { return new MurderInvestigation(this); } } - -class AttachedPermanentPowerCount implements DynamicValue { - - @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) { - if (effect.getValue("attachedTo") != null) { - Permanent attached = (Permanent)effect.getValue("attachedTo"); - if (attached != null) { - return attached.getPower().getValue(); - } - } - } - return 0; - } - - @Override - public AttachedPermanentPowerCount copy() { - return new AttachedPermanentPowerCount(); - } - - @Override - public String toString() { - return "X"; - } - - @Override - public String getMessage() { - return "its power"; - } -} diff --git a/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java b/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java index c37b4677087..f34fff94d15 100644 --- a/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java +++ b/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java @@ -157,6 +157,7 @@ public final class TalesOfMiddleEarthCommander extends ExpansionSet { cards.add(new SetCardInfo("Lord of the Nazgul", 60, Rarity.RARE, mage.cards.l.LordOfTheNazgul.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Lord of the Nazgul", 142, Rarity.RARE, mage.cards.l.LordOfTheNazgul.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Lossarnach Captain", 16, Rarity.RARE, mage.cards.l.LossarnachCaptain.class)); + cards.add(new SetCardInfo("Lothlorien Blade", 77, Rarity.RARE, mage.cards.l.LothlorienBlade.class)); cards.add(new SetCardInfo("Marshal's Anthem", 172, Rarity.RARE, mage.cards.m.MarshalsAnthem.class)); cards.add(new SetCardInfo("Mentor of the Meek", 173, Rarity.RARE, mage.cards.m.MentorOfTheMeek.class)); cards.add(new SetCardInfo("Merciless Executioner", 204, Rarity.UNCOMMON, mage.cards.m.MercilessExecutioner.class)); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentPowerCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentPowerCount.java new file mode 100644 index 00000000000..ef748c9d56f --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/AttachedPermanentPowerCount.java @@ -0,0 +1,43 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * @author xenohedron + */ +public enum AttachedPermanentPowerCount implements DynamicValue { + instance; + + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + Permanent attachment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId()); + if (attachment == null) { + return 0; + } + Permanent permanent = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo()); + if (permanent != null && (permanent.getPower().getValue() >= 0)) { + return permanent.getPower().getValue(); + } + return 0; + } + + @Override + public AttachedPermanentPowerCount copy() { + return instance; + } + + @Override + public String toString() { + return "X"; + } + + @Override + public String getMessage() { + return "its power"; + } +}