From a47af7a5a9eb5468e08c03fff3ab242cfaa99419 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Fri, 16 Jul 2021 08:09:39 -0400 Subject: [PATCH] [AFR] Implemented Spare Dagger --- Mage.Sets/src/mage/cards/s/SpareDagger.java | 84 +++++++++++++++++++ .../sets/AdventuresInTheForgottenRealms.java | 1 + .../GainAbilityWithAttachmentEffect.java | 18 ++-- 3 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/s/SpareDagger.java diff --git a/Mage.Sets/src/mage/cards/s/SpareDagger.java b/Mage.Sets/src/mage/cards/s/SpareDagger.java new file mode 100644 index 00000000000..eb77c8d121f --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SpareDagger.java @@ -0,0 +1,84 @@ +package mage.cards.s; + +import mage.abilities.Ability; +import mage.abilities.common.AttacksTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.common.delayed.ReflexiveTriggeredAbility; +import mage.abilities.costs.common.SacrificeAttachmentCost; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DoWhenCostPaid; +import mage.abilities.effects.common.continuous.BoostEquippedEffect; +import mage.abilities.effects.common.continuous.GainAbilityWithAttachmentEffect; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.game.Game; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class SpareDagger extends CardImpl { + + public SpareDagger(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{1}"); + + this.subtype.add(SubType.EQUIPMENT); + + // Equipped creature gets +1/+0 and has "Whenever this creature attacks, you may sacrifice Spare Dagger. When you do, this creature deals 1 damage to any target." + Ability ability = new SimpleStaticAbility(new BoostEquippedEffect(1, 0)); + ability.addEffect(new SpareDaggerEffect()); + this.addAbility(ability); + + // Equip {1} + this.addAbility(new EquipAbility(1)); + } + + private SpareDagger(final SpareDagger card) { + super(card); + } + + @Override + public SpareDagger copy() { + return new SpareDagger(this); + } +} + +class SpareDaggerEffect extends GainAbilityWithAttachmentEffect { + + SpareDaggerEffect() { + super("and has \"Whenever this creature attacks, you may sacrifice {this}. " + + "When you do, this creature deals 1 damage to any target.\"", + (Effect) null, null, new SacrificeAttachmentCost(), null); + } + + private SpareDaggerEffect(final SpareDaggerEffect effect) { + super(effect); + } + + @Override + public SpareDaggerEffect copy() { + return new SpareDaggerEffect(this); + } + + @Override + protected Ability makeAbility(Game game, Ability source) { + if (source == null || game == null) { + return null; + } + String sourceName = source.getSourcePermanentIfItStillExists(game).getName(); + ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility( + new DamageTargetEffect(1), false, + "This creature deals 1 damage to any target" + ); + return new AttacksTriggeredAbility(new DoWhenCostPaid( + ability, useAttachedCost.copy().setMageObjectReference(source, game), + "Sacrifice " + sourceName + "?" + ), false, "Whenever this creature attacks, you may sacrifice " + + sourceName + ". When you do, this creature deals 1 damage to any target."); + } +} diff --git a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java index 76509aa6e7c..8ec70595294 100644 --- a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java +++ b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java @@ -214,6 +214,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet { cards.add(new SetCardInfo("Skeletal Swarming", 232, Rarity.RARE, mage.cards.s.SkeletalSwarming.class)); cards.add(new SetCardInfo("Skullport Merchant", 120, Rarity.UNCOMMON, mage.cards.s.SkullportMerchant.class)); cards.add(new SetCardInfo("Soulknife Spy", 75, Rarity.COMMON, mage.cards.s.SoulknifeSpy.class)); + cards.add(new SetCardInfo("Spare Dagger", 250, Rarity.COMMON, mage.cards.s.SpareDagger.class)); cards.add(new SetCardInfo("Sphere of Annihilation", 121, Rarity.RARE, mage.cards.s.SphereOfAnnihilation.class)); cards.add(new SetCardInfo("Spiked Pit Trap", 251, Rarity.COMMON, mage.cards.s.SpikedPitTrap.class)); cards.add(new SetCardInfo("Split the Party", 76, Rarity.UNCOMMON, mage.cards.s.SplitTheParty.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityWithAttachmentEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityWithAttachmentEffect.java index 6018a71566a..631195bc2cf 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityWithAttachmentEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityWithAttachmentEffect.java @@ -28,8 +28,8 @@ public class GainAbilityWithAttachmentEffect extends ContinuousEffectImpl { private final Effects effects = new Effects(); private final Targets targets = new Targets(); - private final Costs costs = new CostsImpl(); - private final UseAttachedCost useAttachedCost; + private final Costs costs = new CostsImpl<>(); + protected final UseAttachedCost useAttachedCost; public GainAbilityWithAttachmentEffect(String rule, Effect effect, Target target, UseAttachedCost attachedCost, Cost... costs) { this(rule, new Effects(effect), new Targets(target), attachedCost, costs); @@ -42,10 +42,10 @@ public class GainAbilityWithAttachmentEffect extends ContinuousEffectImpl { this.targets.addAll(targets); this.costs.addAll(Arrays.asList(costs)); this.useAttachedCost = attachedCost; - this.generateGainAbilityDependencies(makeAbility(this.effects, this.targets, this.costs), null); + this.generateGainAbilityDependencies(makeAbility(null, null), null); } - public GainAbilityWithAttachmentEffect(final GainAbilityWithAttachmentEffect effect) { + protected GainAbilityWithAttachmentEffect(final GainAbilityWithAttachmentEffect effect) { super(effect); this.effects.addAll(effect.effects); this.targets.addAll(effect.targets); @@ -87,14 +87,13 @@ public class GainAbilityWithAttachmentEffect extends ContinuousEffectImpl { if (permanent == null) { return true; } - Ability ability = makeAbility(this.effects, this.targets, this.costs); + Ability ability = makeAbility(game, source); ability.getEffects().setValue("attachedPermanent", game.getPermanent(source.getSourceId())); - ability.addCost(useAttachedCost.copy().setMageObjectReference(source, game)); permanent.addAbility(ability, source.getSourceId(), game); return true; } - private static Ability makeAbility(Effects effects, Targets targets, Cost... costs) { + protected Ability makeAbility(Game game, Ability source) { Ability ability = new SimpleActivatedAbility(null, null); for (Effect effect : effects) { if (effect == null) { @@ -108,12 +107,15 @@ public class GainAbilityWithAttachmentEffect extends ContinuousEffectImpl { } ability.addTarget(target); } - for (Cost cost : costs) { + for (Cost cost : this.costs) { if (cost == null) { continue; } ability.addCost(cost.copy()); } + if (source != null && game != null) { + ability.addCost(useAttachedCost.copy().setMageObjectReference(source, game)); + } return ability; } }