From 41ca5f198f6b0a06befa5ebf1330b63df8fe9439 Mon Sep 17 00:00:00 2001 From: LoneFox Date: Sat, 12 Sep 2015 12:31:08 +0300 Subject: [PATCH] Add LoseLifeControllerAttachedEffect. Kill some custom abilities and effects. Implement card: Pooling Venom --- .../src/mage/sets/conflux/CorruptedRoots.java | 63 ++---------- .../sets/dragonsmaze/SinisterPossession.java | 64 +----------- .../mage/sets/futuresight/PoolingVenom.java | 78 +++++++++++++++ .../mage/sets/limitedalpha/PsychicVenom.java | 53 +--------- .../sets/ninthedition/ContaminatedBond.java | 54 +--------- .../riseoftheeldrazi/ContaminatedGround.java | 55 +---------- .../LoseLifeControllerAttachedEffect.java | 98 +++++++++++++++++++ 7 files changed, 193 insertions(+), 272 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/futuresight/PoolingVenom.java create mode 100644 Mage/src/mage/abilities/effects/common/LoseLifeControllerAttachedEffect.java diff --git a/Mage.Sets/src/mage/sets/conflux/CorruptedRoots.java b/Mage.Sets/src/mage/sets/conflux/CorruptedRoots.java index 71acd4c156a..cec2b4e7def 100644 --- a/Mage.Sets/src/mage/sets/conflux/CorruptedRoots.java +++ b/Mage.Sets/src/mage/sets/conflux/CorruptedRoots.java @@ -29,26 +29,18 @@ package mage.sets.conflux; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.Effect; +import mage.abilities.common.BecomesTappedAttachedTriggeredAbility; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.LoseLifeTargetEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; -import mage.constants.Zone; -import mage.filter.common.FilterLandPermanent; +import mage.filter.FilterPermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.SubtypePredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.target.common.TargetLandPermanent; -import mage.target.targetpointer.FixedTarget; /** * @@ -56,7 +48,7 @@ import mage.target.targetpointer.FixedTarget; */ public class CorruptedRoots extends CardImpl { - private static final FilterLandPermanent filter = new FilterLandPermanent("Forest or Plains"); + private static final FilterPermanent filter = new FilterPermanent("Forest or Plains"); static { filter.add(Predicates.or( @@ -69,17 +61,15 @@ public class CorruptedRoots extends CardImpl { this.expansionSetCode = "CON"; this.subtype.add("Aura"); - // Enchant Forest or Plains - TargetPermanent auraTarget = new TargetLandPermanent(filter); + TargetPermanent auraTarget = new TargetPermanent(filter); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); // Whenever enchanted land becomes tapped, its controller loses 2 life. - this.addAbility(new CorruptedRootsTriggeredAbility()); - + this.addAbility(new BecomesTappedAttachedTriggeredAbility(new LoseLifeControllerAttachedEffect(2), "enchanted land")); } public CorruptedRoots(final CorruptedRoots card) { @@ -91,44 +81,3 @@ public class CorruptedRoots extends CardImpl { return new CorruptedRoots(this); } } - -class CorruptedRootsTriggeredAbility extends TriggeredAbilityImpl { - - CorruptedRootsTriggeredAbility() { - super(Zone.BATTLEFIELD, new LoseLifeTargetEffect(2)); - } - - CorruptedRootsTriggeredAbility(final CorruptedRootsTriggeredAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.TAPPED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Permanent enchantment = game.getPermanent(this.sourceId); - if (enchantment != null && enchantment.getAttachedTo().equals(event.getTargetId())) { - Permanent attached = game.getPermanent(enchantment.getAttachedTo()); - if (attached != null) { - for (Effect effect : getEffects()) { - effect.setTargetPointer(new FixedTarget(attached.getControllerId())); - } - return true; - } - } - return false; - } - - @Override - public CorruptedRootsTriggeredAbility copy() { - return new CorruptedRootsTriggeredAbility(this); - } - - @Override - public String getRule() { - return "Whenever enchanted land becomes tapped, its controller loses 2 life."; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/dragonsmaze/SinisterPossession.java b/Mage.Sets/src/mage/sets/dragonsmaze/SinisterPossession.java index a06d7f1042b..961d95af885 100644 --- a/Mage.Sets/src/mage/sets/dragonsmaze/SinisterPossession.java +++ b/Mage.Sets/src/mage/sets/dragonsmaze/SinisterPossession.java @@ -29,19 +29,15 @@ package mage.sets.dragonsmaze; import mage.abilities.Ability; import mage.abilities.common.AttacksOrBlocksEnchantedTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -81,61 +77,3 @@ public class SinisterPossession extends CardImpl { return new SinisterPossession(this); } } - -class LoseLifeControllerAttachedEffect extends OneShotEffect { - - protected DynamicValue amount; - - public LoseLifeControllerAttachedEffect(int amount) { - this(new StaticValue(amount)); - } - - public LoseLifeControllerAttachedEffect(DynamicValue amount) { - super(Outcome.Damage); - this.amount = amount; - setText(); - } - - public LoseLifeControllerAttachedEffect(final LoseLifeControllerAttachedEffect effect) { - super(effect); - this.amount = effect.amount.copy(); - } - - @Override - public LoseLifeControllerAttachedEffect copy() { - return new LoseLifeControllerAttachedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment == null) { - enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature == null) { - creature = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (creature != null) { - Player player = game.getPlayer(creature.getControllerId()); - if (player != null) { - player.loseLife(amount.calculate(game, source, this), game); - return true; - } - } - } - return false; - } - - private void setText() { - StringBuilder sb = new StringBuilder(); - sb.append("it's controller loses ").append(amount.toString()).append(" life"); - String message = amount.getMessage(); - if (message.length() > 0) { - sb.append(" for each "); - sb.append(message); - } - staticText = sb.toString(); - } -} diff --git a/Mage.Sets/src/mage/sets/futuresight/PoolingVenom.java b/Mage.Sets/src/mage/sets/futuresight/PoolingVenom.java new file mode 100644 index 00000000000..d383a8aefea --- /dev/null +++ b/Mage.Sets/src/mage/sets/futuresight/PoolingVenom.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.sets.futuresight; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.BecomesTappedAttachedTriggeredAbility; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.DestroyAttachedEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; +import mage.target.TargetPermanent; +import mage.target.common.TargetLandPermanent; + +/** + * + * @author LoneFox + */ +public class PoolingVenom extends CardImpl { + + public PoolingVenom(UUID ownerId) { + super(ownerId, 74, "Pooling Venom", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{1}{B}"); + this.expansionSetCode = "FUT"; + this.subtype.add("Aura"); + + // Enchant land + TargetPermanent auraTarget = new TargetLandPermanent(); + this.getSpellAbility().addTarget(auraTarget); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); + Ability ability = new EnchantAbility(auraTarget.getTargetName()); + this.addAbility(ability); + // Whenever enchanted land becomes tapped, its controller loses 2 life. + this.addAbility(new BecomesTappedAttachedTriggeredAbility(new LoseLifeControllerAttachedEffect(2), "enchanted land")); + // {3}{B}: Destroy enchanted land. + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyAttachedEffect("enchanted land"), new ManaCostsImpl("{3}{B}"))); + } + + public PoolingVenom(final PoolingVenom card) { + super(card); + } + + @Override + public PoolingVenom copy() { + return new PoolingVenom(this); + } +} diff --git a/Mage.Sets/src/mage/sets/limitedalpha/PsychicVenom.java b/Mage.Sets/src/mage/sets/limitedalpha/PsychicVenom.java index 20f2a5d9b91..d0322dc1c74 100644 --- a/Mage.Sets/src/mage/sets/limitedalpha/PsychicVenom.java +++ b/Mage.Sets/src/mage/sets/limitedalpha/PsychicVenom.java @@ -30,22 +30,17 @@ package mage.sets.limitedalpha; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.BecomesTappedAttachedTriggeredAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DamageAttachedControllerEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetLandPermanent; -import mage.target.targetpointer.FixedTarget; /** * @@ -67,7 +62,9 @@ public class PsychicVenom extends CardImpl { Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); // Whenever enchanted land becomes tapped, Psychic Venom deals 2 damage to that land's controller. - this.addAbility(new PsychicVenomAbility()); + Effect effect = new DamageAttachedControllerEffect(2); + effect.setText("{this} deals 2 damage to that land's controller"); + this.addAbility(new BecomesTappedAttachedTriggeredAbility(effect, "enchanted land")); } public PsychicVenom(final PsychicVenom card) { @@ -79,43 +76,3 @@ public class PsychicVenom extends CardImpl { return new PsychicVenom(this); } } - -class PsychicVenomAbility extends TriggeredAbilityImpl { - PsychicVenomAbility() { - super(Zone.BATTLEFIELD, new DamageTargetEffect(2, true, "that land's controller")); - } - - PsychicVenomAbility(final PsychicVenomAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.TAPPED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Permanent source = game.getPermanent(this.sourceId); - if (source != null && source.getAttachedTo().equals(event.getTargetId())) { - Permanent attached = game.getPermanent(source.getAttachedTo()); - if (attached != null) { - for (Effect e : getEffects()) { - e.setTargetPointer(new FixedTarget(attached.getControllerId())); - } - return true; - } - } - return false; - } - - @Override - public PsychicVenomAbility copy() { - return new PsychicVenomAbility(this); - } - - @Override - public String getRule() { - return "Whenever enchanted land becomes tapped, " + super.getRule(); - } -} diff --git a/Mage.Sets/src/mage/sets/ninthedition/ContaminatedBond.java b/Mage.Sets/src/mage/sets/ninthedition/ContaminatedBond.java index c2ec93bd388..7f03c8fb9e3 100644 --- a/Mage.Sets/src/mage/sets/ninthedition/ContaminatedBond.java +++ b/Mage.Sets/src/mage/sets/ninthedition/ContaminatedBond.java @@ -30,19 +30,14 @@ package mage.sets.ninthedition; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.AttacksOrBlocksEnchantedTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.StaticValue; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -77,50 +72,3 @@ public class ContaminatedBond extends CardImpl { return new ContaminatedBond(this); } } - -class LoseLifeControllerAttachedEffect extends OneShotEffect { - - protected DynamicValue amount; - - public LoseLifeControllerAttachedEffect(int amount) { - this(new StaticValue(amount)); - } - - public LoseLifeControllerAttachedEffect(DynamicValue amount) { - super(Outcome.Damage); - this.amount = amount; - staticText = "its controller loses " + amount.toString() +" life"; - } - - public LoseLifeControllerAttachedEffect(final LoseLifeControllerAttachedEffect effect) { - super(effect); - this.amount = effect.amount.copy(); - } - - @Override - public LoseLifeControllerAttachedEffect copy() { - return new LoseLifeControllerAttachedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment == null) { - enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature == null) { - creature = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (creature != null) { - Player player = game.getPlayer(creature.getControllerId()); - if (player != null) { - player.loseLife(amount.calculate(game, source, this), game); - return true; - } - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/ContaminatedGround.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/ContaminatedGround.java index 98dbcb72f86..d7b41894cb8 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/ContaminatedGround.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/ContaminatedGround.java @@ -29,11 +29,10 @@ package mage.sets.riseoftheeldrazi; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.BecomesTappedAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.LoseLifeTargetEffect; +import mage.abilities.effects.common.LoseLifeControllerAttachedEffect; import mage.abilities.effects.common.continuous.BecomesBasicLandEnchantedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; @@ -41,13 +40,8 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetLandPermanent; -import mage.target.targetpointer.FixedTarget; /** * @author Loki @@ -69,9 +63,9 @@ public class ContaminatedGround extends CardImpl { // Enchanted land is a Swamp. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BecomesBasicLandEnchantedEffect("Swamp"))); - + // Whenever enchanted land becomes tapped, its controller loses 2 life. - this.addAbility(new ContaminatedGroundAbility()); + this.addAbility(new BecomesTappedAttachedTriggeredAbility(new LoseLifeControllerAttachedEffect(2), "enchanted land")); } public ContaminatedGround(final ContaminatedGround card) { @@ -83,44 +77,3 @@ public class ContaminatedGround extends CardImpl { return new ContaminatedGround(this); } } - -class ContaminatedGroundAbility extends TriggeredAbilityImpl { - ContaminatedGroundAbility() { - super(Zone.BATTLEFIELD, new LoseLifeTargetEffect(2)); - } - - ContaminatedGroundAbility(final ContaminatedGroundAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.TAPPED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Permanent source = game.getPermanent(this.sourceId); - if (source != null && source.getAttachedTo().equals(event.getTargetId())) { - Permanent attached = game.getPermanent(source.getAttachedTo()); - if (attached != null) { - - for (Effect e : getEffects()) { - e.setTargetPointer(new FixedTarget(attached.getControllerId())); - } - return true; - } - } - return false; - } - - @Override - public ContaminatedGroundAbility copy() { - return new ContaminatedGroundAbility(this); - } - - @Override - public String getRule() { - return "Whenever enchanted land becomes tapped, its controller loses 2 life."; - } -} diff --git a/Mage/src/mage/abilities/effects/common/LoseLifeControllerAttachedEffect.java b/Mage/src/mage/abilities/effects/common/LoseLifeControllerAttachedEffect.java new file mode 100644 index 00000000000..fb0f482d2e6 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/LoseLifeControllerAttachedEffect.java @@ -0,0 +1,98 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.effects.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + + +public class LoseLifeControllerAttachedEffect extends OneShotEffect { + + protected DynamicValue amount; + + public LoseLifeControllerAttachedEffect(int amount) { + this(new StaticValue(amount)); + } + + public LoseLifeControllerAttachedEffect(DynamicValue amount) { + super(Outcome.LoseLife); + this.amount = amount; + setText(); + } + + public LoseLifeControllerAttachedEffect(final LoseLifeControllerAttachedEffect effect) { + super(effect); + this.amount = effect.amount.copy(); + } + + @Override + public LoseLifeControllerAttachedEffect copy() { + return new LoseLifeControllerAttachedEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent enchantment = game.getPermanent(source.getSourceId()); + if (enchantment == null) { + enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); + } + if (enchantment != null && enchantment.getAttachedTo() != null) { + Permanent creature = game.getPermanent(enchantment.getAttachedTo()); + if (creature == null) { + creature = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); + } + if (creature != null) { + Player player = game.getPlayer(creature.getControllerId()); + if (player != null) { + player.loseLife(amount.calculate(game, source, this), game); + return true; + } + } + } + return false; + } + + private void setText() { + StringBuilder sb = new StringBuilder(); + sb.append("it's controller loses ").append(amount.toString()).append(" life"); + String message = amount.getMessage(); + if (message.length() > 0) { + sb.append(" for each "); + sb.append(message); + } + staticText = sb.toString(); + } +}