From 708a486eb65213d5f851bf3aa49222edd19a86e4 Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Thu, 14 Jan 2021 10:50:30 -0600 Subject: [PATCH] - [KHM] Added Withercrown --- Mage.Sets/src/mage/cards/w/Withercrown.java | 72 +++++++++++ Mage.Sets/src/mage/sets/Kaldheim.java | 1 + .../DoUnlessAttachedControllerPaysEffect.java | 112 ++++++++++++++++++ .../continuous/SetPowerEnchantedEffect.java | 50 ++++++++ 4 files changed, 235 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/w/Withercrown.java create mode 100644 Mage/src/main/java/mage/abilities/effects/common/DoUnlessAttachedControllerPaysEffect.java create mode 100644 Mage/src/main/java/mage/abilities/effects/common/continuous/SetPowerEnchantedEffect.java diff --git a/Mage.Sets/src/mage/cards/w/Withercrown.java b/Mage.Sets/src/mage/cards/w/Withercrown.java new file mode 100644 index 00000000000..e0ebd014594 --- /dev/null +++ b/Mage.Sets/src/mage/cards/w/Withercrown.java @@ -0,0 +1,72 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.cards.w; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.common.SacrificeSourceCost; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.DoUnlessControllerPaysEffect; +import mage.abilities.effects.common.LoseLifeSourceControllerEffect; +import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; +import mage.abilities.effects.common.continuous.SetPowerEnchantedEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.AttachmentType; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.target.TargetPermanent; +import mage.target.common.TargetCreaturePermanent; + +/** + * + * @author jeffwadsworth + */ +public final class Withercrown extends CardImpl { + + public Withercrown(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}{W}"); + + this.subtype.add(SubType.AURA); + + final String rule = "Do you want to sacrifice the enchanted creature? If not, you lose 1 life."; + + // 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); + + // Enchanted creature has base power 0 and has “At the beginning of your upkeep, you lose 1 life unless you sacrifice this creature." + Ability abilityTest = new SimpleStaticAbility(new SetPowerEnchantedEffect(0)); + Effect effect2 = new DoUnlessControllerPaysEffect(new LoseLifeSourceControllerEffect(1), + new SacrificeSourceCost(), rule); + effect2.setText("you lose 1 life unless you sacrifice this creature."); + Effect effect3 = new GainAbilityAttachedEffect(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, + effect2, TargetController.YOU, false, false, null), AttachmentType.AURA); + effect3.setText("and has “At the beginning of your upkeep, you lose 1 life unless you sacrifice this creature."); + abilityTest.addEffect(effect3); + this.addAbility(abilityTest); + + } + + private Withercrown(final Withercrown card) { + super(card); + } + + @Override + public Withercrown copy() { + return new Withercrown(this); + } +} diff --git a/Mage.Sets/src/mage/sets/Kaldheim.java b/Mage.Sets/src/mage/sets/Kaldheim.java index 6bd2cf6a7ad..15edd34dea6 100644 --- a/Mage.Sets/src/mage/sets/Kaldheim.java +++ b/Mage.Sets/src/mage/sets/Kaldheim.java @@ -200,6 +200,7 @@ public final class Kaldheim extends ExpansionSet { cards.add(new SetCardInfo("Waking the Trolls", 234, Rarity.RARE, mage.cards.w.WakingTheTrolls.class)); cards.add(new SetCardInfo("Warchanter Skald", 381, Rarity.UNCOMMON, mage.cards.w.WarchanterSkald.class)); cards.add(new SetCardInfo("Weathered Runestone", 247, Rarity.UNCOMMON, mage.cards.w.WeatheredRunestone.class)); + cards.add(new SetCardInfo("Withercrown", 119, Rarity.COMMON, mage.cards.w.Withercrown.class)); cards.add(new SetCardInfo("Woodland Chasm", 274, Rarity.COMMON, mage.cards.w.WoodlandChasm.class)); cards.add(new SetCardInfo("Youthful Valkyrie", 382, Rarity.UNCOMMON, mage.cards.y.YouthfulValkyrie.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/DoUnlessAttachedControllerPaysEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DoUnlessAttachedControllerPaysEffect.java new file mode 100644 index 00000000000..0ba9b4f2730 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/DoUnlessAttachedControllerPaysEffect.java @@ -0,0 +1,112 @@ +package mage.abilities.effects.common; + +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.costs.Cost; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.Effects; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.util.CardUtil; + +/** + * + * @author jeffwadsworth + */ +public class DoUnlessAttachedControllerPaysEffect extends OneShotEffect { + + protected Effects executingEffects = new Effects(); + private final Cost cost; + private String chooseUseText; + + public DoUnlessAttachedControllerPaysEffect(Effect effect, Cost cost) { + this(effect, cost, null); + } + + public DoUnlessAttachedControllerPaysEffect(Effect effect, Cost cost, String chooseUseText) { + super(Outcome.Neutral); + this.executingEffects.add(effect); + this.cost = cost; + this.chooseUseText = chooseUseText; + } + + public DoUnlessAttachedControllerPaysEffect(final DoUnlessAttachedControllerPaysEffect effect) { + super(effect); + this.executingEffects = effect.executingEffects.copy(); + this.cost = effect.cost.copy(); + this.chooseUseText = effect.chooseUseText; + } + + public void addEffect(Effect effect) { + executingEffects.add(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent aura = game.getPermanentOrLKIBattlefield(source.getSourceId()); + if (aura == null) { + return false; + } + Permanent attachedTo = game.getPermanentOrLKIBattlefield(aura.getAttachedTo()); + if (attachedTo == null) { + return false; + } + Player controllerOfAttachedTo = game.getPlayer(attachedTo.getControllerId()); + if (controllerOfAttachedTo != null) { + String message; + if (chooseUseText == null) { + String effectText = executingEffects.getText(source.getModes().getMode()); + message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() - 1) + ")?"; + } else { + message = chooseUseText; + } + message = CardUtil.replaceSourceName(message, aura.getName()); + boolean result = true; + boolean doEffect = true; + + // check if controller is willing to pay + if (cost.canPay(source, source, controllerOfAttachedTo.getId(), game) + && controllerOfAttachedTo.chooseUse(Outcome.Neutral, message, source, game)) { + cost.clearPaid(); + if (cost.pay(source, game, source, controllerOfAttachedTo.getId(), false, null)) { + if (!game.isSimulation()) { + game.informPlayers(controllerOfAttachedTo.getLogName() + " pays the cost to prevent the effect"); + } + doEffect = false; + } + } + + // do the effects if not paid + if (doEffect) { + for (Effect effect : executingEffects) { + effect.setTargetPointer(this.targetPointer); + if (effect instanceof OneShotEffect) { + result &= effect.apply(game, source); + } else { + game.addEffect((ContinuousEffect) effect, source); + } + } + } + return result; + } + return false; + } + + @Override + public String getText(Mode mode) { + if (!staticText.isEmpty()) { + return staticText; + } + String effectsText = executingEffects.getText(mode); + return effectsText.substring(0, effectsText.length() - 1) + " unless controller pays " + cost.getText(); + } + + @Override + public DoUnlessAttachedControllerPaysEffect copy() { + return new DoUnlessAttachedControllerPaysEffect(this); + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/SetPowerEnchantedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/SetPowerEnchantedEffect.java new file mode 100644 index 00000000000..d1534d51882 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/SetPowerEnchantedEffect.java @@ -0,0 +1,50 @@ +package mage.abilities.effects.common.continuous; + +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.SubLayer; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author jeffwadsworth + */ +public class SetPowerEnchantedEffect extends ContinuousEffectImpl { + + private final int power; + + public SetPowerEnchantedEffect(int power) { + super(Duration.WhileOnBattlefield, Layer.PTChangingEffects_7, SubLayer.SetPT_7b, Outcome.Neutral); + staticText = "Enchanted creature has base power " + power; + this.power = power; + } + + public SetPowerEnchantedEffect(final SetPowerEnchantedEffect effect) { + super(effect); + this.power = effect.power; + } + + @Override + public SetPowerEnchantedEffect copy() { + return new SetPowerEnchantedEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent enchantment = game.getPermanent(source.getSourceId()); + if (enchantment != null + && enchantment.getAttachedTo() != null) { + Permanent enchanted = game.getPermanent(enchantment.getAttachedTo()); + if (enchanted != null) { + enchanted.getPower().setValue(power); + } + return true; + } + return false; + } + +}