From 445efc8c1890373cf73628536b49288be3641e4a Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sun, 20 May 2012 10:51:34 +0400 Subject: [PATCH] [AVR] 5 cards with tests --- .../sets/avacynrestored/BowerPassage.java | 97 +++++++++++++++ .../avacynrestored/ChampionOfLambholt.java | 110 ++++++++++++++++++ .../sets/avacynrestored/DruidsRepository.java | 72 ++++++++++++ .../avacynrestored/GoldnightCommander.java | 50 +------- .../mage/sets/avacynrestored/Grounded.java | 76 ++++++++++++ .../avacynrestored/VesselOfEndlessRest.java | 67 +++++++++++ .../mage/sets/darksteel/MirrodinsCore.java | 5 +- .../sets/zendikar/BeastmasterAscension.java | 43 +------ .../cards/abilities/lose/LoseAbilityTest.java | 99 ++++++++++++++++ .../cards/asthough/AlchemistsRefugeTest.java | 23 ++++ .../combat/AttackBlockRestrictionsTest.java | 110 ++++++++++++++++++ ...ksCreatureYourControlTriggeredAbility.java | 77 ++++++++++++ ...erCreatureYourControlTriggeredAbility.java | 76 ++++++++++++ .../continious/LoseAbilityAttachedEffect.java | 93 +++++++++++++++ 14 files changed, 910 insertions(+), 88 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/BowerPassage.java create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/ChampionOfLambholt.java create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/DruidsRepository.java create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/Grounded.java create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/VesselOfEndlessRest.java create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/lose/LoseAbilityTest.java create mode 100644 Mage/src/mage/abilities/common/AttacksCreatureYourControlTriggeredAbility.java create mode 100644 Mage/src/mage/abilities/common/EntersAnotherCreatureYourControlTriggeredAbility.java create mode 100644 Mage/src/mage/abilities/effects/common/continious/LoseAbilityAttachedEffect.java diff --git a/Mage.Sets/src/mage/sets/avacynrestored/BowerPassage.java b/Mage.Sets/src/mage/sets/avacynrestored/BowerPassage.java new file mode 100644 index 0000000000..f2bfce75fb --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/BowerPassage.java @@ -0,0 +1,97 @@ +/* + * 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.avacynrestored; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.RestrictionEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; + +/** + * @author noxx + */ +public class BowerPassage extends CardImpl { + + public BowerPassage(UUID ownerId) { + super(ownerId, 170, "Bower Passage", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}"); + this.expansionSetCode = "AVR"; + + this.color.setGreen(true); + + // Creatures with flying can't block creatures you control. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new BowerPassageEffect())); + } + + public BowerPassage(final BowerPassage card) { + super(card); + } + + @Override + public BowerPassage copy() { + return new BowerPassage(this); + } +} + +class BowerPassageEffect extends RestrictionEffect { + + BowerPassageEffect() { + super(Constants.Duration.WhileOnBattlefield); + staticText = "Creatures with flying can't block creatures you control"; + } + + BowerPassageEffect(final BowerPassageEffect effect) { + super(effect); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return true; + } + + @Override + public BowerPassageEffect copy() { + return new BowerPassageEffect(this); + } + + @Override + public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { + if (attacker.getControllerId().equals(source.getControllerId()) && blocker.getAbilities().contains(FlyingAbility.getInstance())) { + return false; + } + return true; + } + +} diff --git a/Mage.Sets/src/mage/sets/avacynrestored/ChampionOfLambholt.java b/Mage.Sets/src/mage/sets/avacynrestored/ChampionOfLambholt.java new file mode 100644 index 0000000000..6562142339 --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/ChampionOfLambholt.java @@ -0,0 +1,110 @@ +/* + * 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.avacynrestored; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersAnotherCreatureYourControlTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.RestrictionEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.cards.CardImpl; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; + +/** + * @author noxx + */ +public class ChampionOfLambholt extends CardImpl { + + public ChampionOfLambholt(UUID ownerId) { + super(ownerId, 171, "Champion of Lambholt", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{G}{G}"); + this.expansionSetCode = "AVR"; + this.subtype.add("Human"); + this.subtype.add("Warrior"); + + this.color.setGreen(true); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // Creatures with power less than Champion of Lambholt's power can't block creatures you control. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ChampionOfLambholtEffect())); + + // Whenever another creature enters the battlefield under your control, put a +1/+1 counter on Champion of Lambholt. + this.addAbility(new EntersAnotherCreatureYourControlTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()))); + } + + public ChampionOfLambholt(final ChampionOfLambholt card) { + super(card); + } + + @Override + public ChampionOfLambholt copy() { + return new ChampionOfLambholt(this); + } +} + +class ChampionOfLambholtEffect extends RestrictionEffect { + + ChampionOfLambholtEffect() { + super(Constants.Duration.WhileOnBattlefield); + staticText = "Creatures with power less than {this}'s power can't block creatures you control"; + } + + ChampionOfLambholtEffect(final ChampionOfLambholtEffect effect) { + super(effect); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + if (sourcePermanent != null) { + if (permanent.getPower().getValue() < sourcePermanent.getPower().getValue()) { + return true; + } + } + return false; + } + + @Override + public ChampionOfLambholtEffect copy() { + return new ChampionOfLambholtEffect(this); + } + + @Override + public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { + return false; + } + +} diff --git a/Mage.Sets/src/mage/sets/avacynrestored/DruidsRepository.java b/Mage.Sets/src/mage/sets/avacynrestored/DruidsRepository.java new file mode 100644 index 0000000000..48aa27b3b6 --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/DruidsRepository.java @@ -0,0 +1,72 @@ +/* + * 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.avacynrestored; + +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.common.AttacksCreatureYourControlTriggeredAbility; +import mage.abilities.costs.common.RemoveCountersSourceCost; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.abilities.mana.AnyColorManaAbility; +import mage.cards.CardImpl; +import mage.counters.CounterType; + +import java.util.UUID; + +/** + * + * @author noxx + + */ +public class DruidsRepository extends CardImpl { + + public DruidsRepository(UUID ownerId) { + super(ownerId, 176, "Druids' Repository", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}{G}"); + this.expansionSetCode = "AVR"; + + this.color.setGreen(true); + + // Whenever a creature you control attacks, put a charge counter on Druids' Repository. + this.addAbility(new AttacksCreatureYourControlTriggeredAbility(new AddCountersSourceEffect(CounterType.CHARGE.createInstance()))); + + // Remove a charge counter from Druids' Repository: Add one mana of any color to your mana pool. + Ability ability = new AnyColorManaAbility(); + ability.addCost(new RemoveCountersSourceCost(CounterType.CHARGE.createInstance())); + this.addAbility(ability); + } + + public DruidsRepository(final DruidsRepository card) { + super(card); + } + + @Override + public DruidsRepository copy() { + return new DruidsRepository(this); + } +} diff --git a/Mage.Sets/src/mage/sets/avacynrestored/GoldnightCommander.java b/Mage.Sets/src/mage/sets/avacynrestored/GoldnightCommander.java index f6137c13d8..5fb447ef0c 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/GoldnightCommander.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/GoldnightCommander.java @@ -27,23 +27,17 @@ */ package mage.sets.avacynrestored; -import java.util.UUID; - import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.MageInt; -import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.common.DrawCardControllerEffect; +import mage.abilities.common.EntersAnotherCreatureYourControlTriggeredAbility; import mage.abilities.effects.common.continious.BoostControlledEffect; import mage.cards.CardImpl; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.ZoneChangeEvent; -import mage.game.permanent.Permanent; + +import java.util.UUID; /** - * * @author Loki */ public class GoldnightCommander extends CardImpl { @@ -60,7 +54,7 @@ public class GoldnightCommander extends CardImpl { this.toughness = new MageInt(2); // Whenever another creature enters the battlefield under your control, creatures you control get +1/+1 until end of turn. - this.addAbility(new GoldnightCommanderAbility()); + this.addAbility(new EntersAnotherCreatureYourControlTriggeredAbility(new BoostControlledEffect(1, 1, Constants.Duration.EndOfTurn))); } public GoldnightCommander(final GoldnightCommander card) { @@ -71,40 +65,4 @@ public class GoldnightCommander extends CardImpl { public GoldnightCommander copy() { return new GoldnightCommander(this); } -} - -class GoldnightCommanderAbility extends TriggeredAbilityImpl { - - public GoldnightCommanderAbility() { - super(Constants.Zone.BATTLEFIELD, new BoostControlledEffect(1, 1, Constants.Duration.EndOfTurn), true); - } - - public GoldnightCommanderAbility(final GoldnightCommanderAbility ability) { - super(ability); - } - - @Override - public GoldnightCommanderAbility copy() { - return new GoldnightCommanderAbility(this); - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.ZONE_CHANGE && !event.getTargetId().equals(this.getSourceId())) { - ZoneChangeEvent zEvent = (ZoneChangeEvent)event; - if (zEvent.getToZone() == Constants.Zone.BATTLEFIELD) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getCardType().contains(CardType.CREATURE) && permanent.getControllerId().equals(this.getControllerId())) { - return true; - } - } - } - return false; - } - - @Override - public String getRule() { - return "Whenever another creature enters the battlefield under your control, creatures you control get +1/+1 until end of turn."; - } - } \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/avacynrestored/Grounded.java b/Mage.Sets/src/mage/sets/avacynrestored/Grounded.java new file mode 100644 index 0000000000..5c522a00a1 --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/Grounded.java @@ -0,0 +1,76 @@ +/* + * 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.avacynrestored; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.continious.LoseAbilityAttachedEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.target.TargetPermanent; +import mage.target.common.TargetCreaturePermanent; + +import java.util.UUID; + +/** + * @author noxx + */ +public class Grounded extends CardImpl { + + public Grounded(UUID ownerId) { + super(ownerId, 181, "Grounded", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}"); + this.expansionSetCode = "AVR"; + this.subtype.add("Aura"); + + this.color.setGreen(true); + + // Enchant creature + TargetPermanent auraTarget = new TargetCreaturePermanent(); + this.getSpellAbility().addTarget(auraTarget); + this.getSpellAbility().addEffect(new AttachEffect(Constants.Outcome.LoseAbility)); + Ability ability = new EnchantAbility(auraTarget.getTargetName()); + this.addAbility(ability); + + // Enchanted creature loses flying. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new LoseAbilityAttachedEffect(FlyingAbility.getInstance(), Constants.AttachmentType.AURA))); + } + + public Grounded(final Grounded card) { + super(card); + } + + @Override + public Grounded copy() { + return new Grounded(this); + } +} diff --git a/Mage.Sets/src/mage/sets/avacynrestored/VesselOfEndlessRest.java b/Mage.Sets/src/mage/sets/avacynrestored/VesselOfEndlessRest.java new file mode 100644 index 0000000000..9fef192564 --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/VesselOfEndlessRest.java @@ -0,0 +1,67 @@ +/* + * 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.avacynrestored; + +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.common.PutOnLibraryTargetEffect; +import mage.abilities.mana.AnyColorManaAbility; +import mage.cards.CardImpl; +import mage.target.common.TargetCardInGraveyard; + +import java.util.UUID; + +/** + * @author noxx + */ +public class VesselOfEndlessRest extends CardImpl { + + public VesselOfEndlessRest(UUID ownerId) { + super(ownerId, 224, "Vessel of Endless Rest", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{3}"); + this.expansionSetCode = "AVR"; + + // When Vessel of Endless Rest enters the battlefield, put target card from a graveyard on the bottom of its owner's library. + Ability ability = new EntersBattlefieldTriggeredAbility(new PutOnLibraryTargetEffect(false), false); + ability.addTarget(new TargetCardInGraveyard()); + this.addAbility(ability); + + // {tap}: Add one mana of any color to your mana pool. + this.addAbility(new AnyColorManaAbility()); + } + + public VesselOfEndlessRest(final VesselOfEndlessRest card) { + super(card); + } + + @Override + public VesselOfEndlessRest copy() { + return new VesselOfEndlessRest(this); + } +} diff --git a/Mage.Sets/src/mage/sets/darksteel/MirrodinsCore.java b/Mage.Sets/src/mage/sets/darksteel/MirrodinsCore.java index 7df4f76865..664636a279 100644 --- a/Mage.Sets/src/mage/sets/darksteel/MirrodinsCore.java +++ b/Mage.Sets/src/mage/sets/darksteel/MirrodinsCore.java @@ -28,8 +28,6 @@ package mage.sets.darksteel; -import java.util.UUID; - import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; @@ -43,6 +41,8 @@ import mage.abilities.mana.ColorlessManaAbility; import mage.cards.CardImpl; import mage.counters.CounterType; +import java.util.UUID; + /** * * @author Loki @@ -57,7 +57,6 @@ public class MirrodinsCore extends CardImpl { Ability ability = new AnyColorManaAbility(); ability.addCost(new RemoveCountersSourceCost(CounterType.CHARGE.createInstance())); this.addAbility(ability); - } public MirrodinsCore (final MirrodinsCore card) { diff --git a/Mage.Sets/src/mage/sets/zendikar/BeastmasterAscension.java b/Mage.Sets/src/mage/sets/zendikar/BeastmasterAscension.java index fe0f7577fc..fc89c71247 100644 --- a/Mage.Sets/src/mage/sets/zendikar/BeastmasterAscension.java +++ b/Mage.Sets/src/mage/sets/zendikar/BeastmasterAscension.java @@ -28,24 +28,22 @@ package mage.sets.zendikar; -import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Duration; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.AttacksCreatureYourControlTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.continious.BoostControlledEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.counters.CounterType; -import mage.counters.common.QuestCounter; import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; +import java.util.UUID; + /** * * @author BetaSteward_at_googlemail.com @@ -57,7 +55,7 @@ public class BeastmasterAscension extends CardImpl { this.expansionSetCode = "ZEN"; this.color.setGreen(true); - this.addAbility(new BeastmasterAscensionAbility()); + this.addAbility(new AttacksCreatureYourControlTriggeredAbility(new AddCountersSourceEffect(CounterType.QUEST.createInstance()), true)); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BeastmasterAscensionEffect())); } @@ -72,39 +70,6 @@ public class BeastmasterAscension extends CardImpl { } -class BeastmasterAscensionAbility extends TriggeredAbilityImpl { - - public BeastmasterAscensionAbility() { - super(Zone.BATTLEFIELD, new AddCountersSourceEffect(new QuestCounter()), true); - } - - public BeastmasterAscensionAbility(final BeastmasterAscensionAbility ability) { - super(ability); - } - - @Override - public BeastmasterAscensionAbility copy() { - return new BeastmasterAscensionAbility(this); - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == EventType.ATTACKER_DECLARED) { - Permanent source = game.getPermanent(event.getSourceId()); - if (source != null && source.getControllerId().equals(controllerId)) { - return true; - } - } - return false; - } - - @Override - public String getRule() { - return "Whenever a creature you control attacks, you may put a quest counter on {this}."; - } - -} - class BeastmasterAscensionEffect extends BoostControlledEffect { public BeastmasterAscensionEffect() { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/lose/LoseAbilityTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/lose/LoseAbilityTest.java new file mode 100644 index 0000000000..942eed0e79 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/lose/LoseAbilityTest.java @@ -0,0 +1,99 @@ +package org.mage.test.cards.abilities.lose; + +import mage.Constants; +import mage.abilities.keyword.FlyingAbility; +import mage.game.permanent.Permanent; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author noxx + */ +public class LoseAbilityTest extends CardTestPlayerBase { + + @Test + public void testLoseFlyingByEnchantCreature() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 4); + addCard(Constants.Zone.HAND, playerA, "Grounded", 2); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Air Elemental"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Grounded", "Elite Vanguard"); + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Grounded", "Air Elemental"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + Permanent eliteVanguard = getPermanent("Elite Vanguard", playerA.getId()); + Assert.assertNotNull(eliteVanguard); + Assert.assertFalse(eliteVanguard.getAbilities().contains(FlyingAbility.getInstance())); + + Permanent airElemental = getPermanent("Air Elemental", playerA.getId()); + Assert.assertNotNull(airElemental); + // should NOT have flying + Assert.assertFalse(airElemental.getAbilities().contains(FlyingAbility.getInstance())); + } + + /** + * Tests that first losing ability and then gaining it will results in Flying existence + */ + @Test + public void testLoseVsGainAbility() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Air Elemental"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Constants.Zone.HAND, playerA, "Grounded"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 6); + addCard(Constants.Zone.HAND, playerA, "Drake Umbra"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Grounded", "Air Elemental"); + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Drake Umbra", "Air Elemental"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + Permanent airElemental = getPermanent("Air Elemental", playerA.getId()); + Assert.assertNotNull(airElemental); + + Assert.assertTrue(airElemental.getAttachments().size() == 2); + // should have flying + Assert.assertTrue(airElemental.getAbilities().contains(FlyingAbility.getInstance())); + } + + /** + * Tests that first gaining multiple copies of ability and then losing it will results in Flying not existence + */ + @Test + public void testMultiGainVsLoseAbility() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Air Elemental"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 5); + addCard(Constants.Zone.HAND, playerA, "Grounded"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 10); + addCard(Constants.Zone.HAND, playerA, "Drake Umbra", 2); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Drake Umbra", "Air Elemental"); + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Drake Umbra", "Air Elemental"); + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Grounded", "Air Elemental"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + Permanent airElemental = getPermanent("Air Elemental", playerA.getId()); + Assert.assertNotNull(airElemental); + + Assert.assertTrue(airElemental.getAttachments().size() == 3); + // should NOT have flying + Assert.assertFalse(airElemental.getAbilities().contains(FlyingAbility.getInstance())); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/asthough/AlchemistsRefugeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/asthough/AlchemistsRefugeTest.java index 13ca98b647..bd6e8498b2 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/asthough/AlchemistsRefugeTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/asthough/AlchemistsRefugeTest.java @@ -54,4 +54,27 @@ public class AlchemistsRefugeTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Elite Vanguard", 0); } + /** + * Tests that effect will be removed at the end of the turn + */ + @Test + public void testEffectOnlyForOneTurn() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Alchemist's Refuge"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains"); + addCard(Constants.Zone.HAND, playerA, "Elite Vanguard"); + + activateAbility(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{G}{U}, {tap}:"); + castSpell(4, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Elite Vanguard"); + + setStopAt(4, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Elite Vanguard", 0); + } + } diff --git a/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java b/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java index 0bae98c71c..ef9091d39b 100644 --- a/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java @@ -93,4 +93,114 @@ public class AttackBlockRestrictionsTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Hunted Ghoul", 0); } + + /** + * Tests "Creatures with flying can't block creatures you control" + */ + @Test + public void testBowerPassage() { + addCard(Constants.Zone.BATTLEFIELD, playerB, "Bower Passage"); + + addCard(Constants.Zone.BATTLEFIELD, playerB, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Arbor Elf"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Assault Griffin"); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Angelic Wall"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Air Elemental"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Llanowar Elves"); + + // non flying vs. flying + attack(2, playerB, "Elite Vanguard"); + block(2, playerA, "Angelic Wall", "Elite Vanguard"); + // non flying vs. non flying + attack(2, playerB, "Arbor Elf"); + block(2, playerA, "Llanowar Elves", "Arbor Elf"); + // flying vs. flying + attack(2, playerB, "Assault Griffin"); + block(2, playerA, "Air Elemental", "Assault Griffin"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 15); + assertLife(playerB, 20); + } + + /** + * Tests restriction effect going away after card is destroyed + */ + @Test + public void testBowerPassageDestroyed() { + addCard(Constants.Zone.BATTLEFIELD, playerB, "Bower Passage"); + + addCard(Constants.Zone.BATTLEFIELD, playerB, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Arbor Elf"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Assault Griffin"); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Angelic Wall"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Air Elemental"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Llanowar Elves"); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Constants.Zone.HAND, playerA, "Naturalize"); + + // non flying vs. flying + attack(2, playerB, "Elite Vanguard"); + block(2, playerA, "Angelic Wall", "Elite Vanguard"); + // non flying vs. non flying + attack(2, playerB, "Arbor Elf"); + block(2, playerA, "Llanowar Elves", "Arbor Elf"); + // flying vs. flying + attack(2, playerB, "Assault Griffin"); + block(2, playerA, "Air Elemental", "Assault Griffin"); + + castSpell(2, Constants.PhaseStep.DECLARE_ATTACKERS, playerA, "Naturalize", "Bower Passage"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerB, "Bower Passage", 0); + + assertLife(playerA, 20); + assertLife(playerB, 20); + } + + /** + * Tests "Creatures with flying can't block creatures you control" + */ + @Test + public void testChampionOfLambholt() { + addCard(Constants.Zone.BATTLEFIELD, playerB, "Champion of Lambholt"); + + addCard(Constants.Zone.BATTLEFIELD, playerB, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Arbor Elf"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Assault Griffin"); + + addCard(Constants.Zone.BATTLEFIELD, playerB, "Plains", 5); + addCard(Constants.Zone.HAND, playerB, "Baneslayer Angel"); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Angelic Wall"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Air Elemental"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Llanowar Elves"); + + castSpell(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Baneslayer Angel"); + + // non flying vs. flying + attack(2, playerB, "Elite Vanguard"); + block(2, playerA, "Angelic Wall", "Elite Vanguard"); + // non flying vs. non flying + attack(2, playerB, "Arbor Elf"); + block(2, playerA, "Llanowar Elves", "Arbor Elf"); + // flying vs. flying + attack(2, playerB, "Assault Griffin"); + block(2, playerA, "Air Elemental", "Assault Griffin"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertPowerToughness(playerB, "Champion of Lambholt", 2, 2); + + assertLife(playerA, 17); + assertLife(playerB, 20); + } } diff --git a/Mage/src/mage/abilities/common/AttacksCreatureYourControlTriggeredAbility.java b/Mage/src/mage/abilities/common/AttacksCreatureYourControlTriggeredAbility.java new file mode 100644 index 0000000000..8985cc5d3d --- /dev/null +++ b/Mage/src/mage/abilities/common/AttacksCreatureYourControlTriggeredAbility.java @@ -0,0 +1,77 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; + +/** + * + * @author noxx + */ +public class AttacksCreatureYourControlTriggeredAbility extends TriggeredAbilityImpl { + + public AttacksCreatureYourControlTriggeredAbility(Effect effect) { + this(effect, false); + } + + public AttacksCreatureYourControlTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + public AttacksCreatureYourControlTriggeredAbility(AttacksCreatureYourControlTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) { + Permanent source = game.getPermanent(event.getSourceId()); + if (source != null && source.getControllerId().equals(controllerId)) { + return true; + } + } + return false; + } + + @Override + public AttacksCreatureYourControlTriggeredAbility copy() { + return new AttacksCreatureYourControlTriggeredAbility(this); + } + + @Override + public String getRule() { + return "Whenever a creature you control attacks, " + super.getRule(); + } + +} diff --git a/Mage/src/mage/abilities/common/EntersAnotherCreatureYourControlTriggeredAbility.java b/Mage/src/mage/abilities/common/EntersAnotherCreatureYourControlTriggeredAbility.java new file mode 100644 index 0000000000..f2b5b56855 --- /dev/null +++ b/Mage/src/mage/abilities/common/EntersAnotherCreatureYourControlTriggeredAbility.java @@ -0,0 +1,76 @@ +/* +* 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.common; + +import mage.Constants; +import mage.Constants.Zone; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; + +/** + * + * @author noxx + */ +public class EntersAnotherCreatureYourControlTriggeredAbility extends ZoneChangeTriggeredAbility { + + public EntersAnotherCreatureYourControlTriggeredAbility(Effect effect) { + this(effect, false); + } + + public EntersAnotherCreatureYourControlTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, "Whenever another creature enters the battlefield under your control, ", optional); + } + + public EntersAnotherCreatureYourControlTriggeredAbility(EntersAnotherCreatureYourControlTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE && !event.getTargetId().equals(this.getSourceId())) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getToZone() == Constants.Zone.BATTLEFIELD) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE) && permanent.getControllerId().equals(this.getControllerId())) { + return true; + } + } + } + return false; + } + + @Override + public EntersAnotherCreatureYourControlTriggeredAbility copy() { + return new EntersAnotherCreatureYourControlTriggeredAbility(this); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/continious/LoseAbilityAttachedEffect.java b/Mage/src/mage/abilities/effects/common/continious/LoseAbilityAttachedEffect.java new file mode 100644 index 0000000000..98caf7cdd9 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/continious/LoseAbilityAttachedEffect.java @@ -0,0 +1,93 @@ +/* + * 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.continious; + +import mage.Constants.*; +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class LoseAbilityAttachedEffect extends ContinuousEffectImpl { + + protected Ability ability; + protected AttachmentType attachmentType; + + public LoseAbilityAttachedEffect(Ability ability, AttachmentType attachmentType) { + super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.LoseAbility); + this.ability = ability; + this.attachmentType = attachmentType; + setText(); + } + + public LoseAbilityAttachedEffect(final LoseAbilityAttachedEffect effect) { + super(effect); + this.ability = effect.ability.copy(); + this.attachmentType = effect.attachmentType; + } + + @Override + public LoseAbilityAttachedEffect copy() { + return new LoseAbilityAttachedEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent equipment = game.getPermanent(source.getSourceId()); + if (equipment != null && equipment.getAttachedTo() != null) { + Permanent creature = game.getPermanent(equipment.getAttachedTo()); + if (creature != null) { + creature.getAbilities().remove(ability); + } + } + return true; + } + + private void setText() { + StringBuilder sb = new StringBuilder(); + if (attachmentType == AttachmentType.AURA) { + sb.append("Enchanted"); + } else if (attachmentType == AttachmentType.EQUIPMENT) { + sb.append("Equipped"); + } + sb.append(" creature "); + if (duration == Duration.WhileOnBattlefield) { + sb.append("loses "); + } else { + sb.append("loses "); + } + sb.append(ability.getRule()); + staticText = sb.toString(); + } + +}