diff --git a/Mage.Sets/src/mage/cards/g/GiftOfDoom.java b/Mage.Sets/src/mage/cards/g/GiftOfDoom.java index 5b5e37858e..1a0c125d63 100644 --- a/Mage.Sets/src/mage/cards/g/GiftOfDoom.java +++ b/Mage.Sets/src/mage/cards/g/GiftOfDoom.java @@ -5,7 +5,6 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.effects.AsTurnedFaceUpEffect; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.keyword.DeathtouchAbility; import mage.abilities.keyword.EnchantAbility; @@ -17,23 +16,33 @@ import mage.constants.AttachmentType; 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; import mage.target.TargetPermanent; import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetCreaturePermanent; - import java.util.UUID; - +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.AttachEffect; import static mage.constants.Outcome.Benefit; +import mage.constants.Zone; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.AnotherPredicate; +import mage.target.targetadjustment.TargetAdjuster; /** * @author TheElk801 */ public final class GiftOfDoom extends CardImpl { + private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); + + static { + filter.add(AnotherPredicate.instance); + } + public GiftOfDoom(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{4}{B}"); @@ -42,26 +51,30 @@ public final class GiftOfDoom extends CardImpl { // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); - this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.AddAbility)); + this.getSpellAbility().setTargetAdjuster(GiftOfDoomAdjuster.instance); // to remove the target set if Morph casting cost is paid Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); // Enchanted creature has deathtouch and indestructible. - ability = new SimpleStaticAbility(new GainAbilityAttachedEffect( + Ability ability2 = new SimpleStaticAbility(new GainAbilityAttachedEffect( DeathtouchAbility.getInstance(), AttachmentType.AURA )); - ability.addEffect(new GainAbilityAttachedEffect( + ability2.addEffect(new GainAbilityAttachedEffect( IndestructibleAbility.getInstance(), AttachmentType.AURA )); - this.addAbility(ability); + this.addAbility(ability2); // Morph—Sacrifice another creature. this.addAbility(new MorphAbility(this, new SacrificeTargetCost( - new TargetControlledPermanent(StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE) + new TargetControlledPermanent(filter) ))); // As Gift of Doom is turned face up, you may attach it to a creature. - this.addAbility(new SimpleStaticAbility(new AsTurnedFaceUpEffect(new GiftOfDoomEffect(), true))); + Effect effect = new AsTurnedFaceUpEffect(new GiftOfDoomEffect(), true); + Ability ability3 = new SimpleStaticAbility(effect); + ability3.setWorksFaceDown(true); + this.addAbility(ability3); } private GiftOfDoom(final GiftOfDoom card) { @@ -74,8 +87,26 @@ public final class GiftOfDoom extends CardImpl { } } +enum GiftOfDoomAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + // if the Morph casting cost is paid, clear the target of Enchant Creature + if (game.getState().getValue("MorphAbility" + ability.getSourceId()) == "activated") { + ability.getTargets().clear(); + } + } +} + class GiftOfDoomEffect extends OneShotEffect { + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); + + static { + filter.add(AnotherPredicate.instance); + } + GiftOfDoomEffect() { super(Benefit); staticText = "attach it to a creature"; @@ -93,16 +124,20 @@ class GiftOfDoomEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - Permanent permanent = game.getPermanent(source.getSourceId()); - if (player == null || permanent == null) { + Permanent giftOfDoom = game.getPermanent(source.getSourceId()); + if (player == null || giftOfDoom == null) { return false; } - TargetCreaturePermanent target = new TargetCreaturePermanent(0, 1); + TargetCreaturePermanent target = new TargetCreaturePermanent(filter); target.setNotTarget(true); - if (!player.choose(outcome, target, source.getSourceId(), game)) { - return false; + if (player.choose(outcome, target, source.getSourceId(), game) + && game.getPermanent(target.getFirstTarget()) != null + && !game.getPermanent(target.getFirstTarget()).cantBeAttachedBy(giftOfDoom, game)) { + game.getState().setValue("attachTo:" + giftOfDoom.getId(), target.getFirstTarget()); + game.getPermanent(target.getFirstTarget()).addAttachment(giftOfDoom.getId(), game); + return true; } - permanent.attachTo(target.getFirstTarget(), game); - return true; + player.moveCardToGraveyardWithInfo(giftOfDoom, source.getId(), game, Zone.BATTLEFIELD); //no legal target + return false; } -} \ No newline at end of file +} diff --git a/Mage/src/main/java/mage/abilities/keyword/MorphAbility.java b/Mage/src/main/java/mage/abilities/keyword/MorphAbility.java index 66ba57de9e..e6482cc92e 100644 --- a/Mage/src/main/java/mage/abilities/keyword/MorphAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/MorphAbility.java @@ -186,6 +186,7 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost spell.setFaceDown(true, game); // so only the back is visible if (alternateCosts.canPay(ability, sourceId, controllerId, game)) { if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 face-down creature for " + getCosts().getText() + " ?", ability, game)) { + game.getState().setValue("MorphAbility" + ability.getSourceId(), "activated"); // Gift of Doom activateMorph(game); // change mana costs ability.getManaCostsToPay().clear();