From 55bf5714a0c0043a946a7df29f3c6e09f712c2a0 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 9 May 2012 10:04:11 +0400 Subject: [PATCH] [AVR] Harvester Of Souls + test. --- .../sets/avacynrestored/HarvesterOfSouls.java | 68 ++++++++++++++ .../triggers/dies/HarvesterOfSoulsTest.java | 43 +++++++++ .../DiesAnotherCreatureTriggeredAbility.java | 89 +++++++++++++++++++ ...herCreatureYouControlTriggeredAbility.java | 50 +++++++++++ ...ThisOrAnotherCreatureTriggeredAbility.java | 40 +++++++++ 5 files changed, 290 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/HarvesterOfSouls.java create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/HarvesterOfSoulsTest.java create mode 100644 Mage/src/mage/abilities/common/DiesAnotherCreatureTriggeredAbility.java diff --git a/Mage.Sets/src/mage/sets/avacynrestored/HarvesterOfSouls.java b/Mage.Sets/src/mage/sets/avacynrestored/HarvesterOfSouls.java new file mode 100644 index 0000000000..87567e8eda --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/HarvesterOfSouls.java @@ -0,0 +1,68 @@ +/* + * 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.MageInt; +import mage.abilities.common.DiesAnotherCreatureTriggeredAbility; +import mage.abilities.effects.common.DrawCardControllerEffect; +import mage.abilities.keyword.DeathtouchAbility; +import mage.cards.CardImpl; + +import java.util.UUID; + +/** + * @author noxx + */ +public class HarvesterOfSouls extends CardImpl { + + public HarvesterOfSouls(UUID ownerId) { + super(ownerId, 107, "Harvester of Souls", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{4}{B}{B}"); + this.expansionSetCode = "AVR"; + this.subtype.add("Demon"); + + this.color.setBlack(true); + this.power = new MageInt(5); + this.toughness = new MageInt(5); + + this.addAbility(DeathtouchAbility.getInstance()); + + // Whenever another nontoken creature dies, you may draw a card. + this.addAbility(new DiesAnotherCreatureTriggeredAbility(new DrawCardControllerEffect(1), true, true)); + } + + public HarvesterOfSouls(final HarvesterOfSouls card) { + super(card); + } + + @Override + public HarvesterOfSouls copy() { + return new HarvesterOfSouls(this); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/HarvesterOfSoulsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/HarvesterOfSoulsTest.java new file mode 100644 index 0000000000..39f81d31d6 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/HarvesterOfSoulsTest.java @@ -0,0 +1,43 @@ +package org.mage.test.cards.triggers.dies; + +import mage.Constants; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author noxx + * + * Whenever another nontoken creature dies, you may draw a card. + */ +public class HarvesterOfSoulsTest extends CardTestPlayerBase { + + /** + * Tests creature on any side would trigger effect + * Also tests that tokens don't cause trigger to happen + */ + @Test + public void testDisabledEffectOnChangeZone() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 4); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 3); + addCard(Constants.Zone.HAND, playerA, "Day of Judgment", 1); + addCard(Constants.Zone.HAND, playerA, "Thatcher Revolt", 1); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Harvester of Souls", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Craw Wurm", 1); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Arrogant Bloodlord", 1); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Thatcher Revolt"); + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Day of Judgment"); + + setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertHandCount(playerA, 2); + assertHandCount(playerB, 0); + } + +} diff --git a/Mage/src/mage/abilities/common/DiesAnotherCreatureTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesAnotherCreatureTriggeredAbility.java new file mode 100644 index 0000000000..ba8796f5a0 --- /dev/null +++ b/Mage/src/mage/abilities/common/DiesAnotherCreatureTriggeredAbility.java @@ -0,0 +1,89 @@ +package mage.abilities.common; + +import mage.Constants; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; +import mage.game.permanent.PermanentToken; + +import java.util.UUID; + +/** + * noxx + */ +public class DiesAnotherCreatureTriggeredAbility extends TriggeredAbilityImpl { + + protected FilterCreaturePermanent filter; + protected boolean nontoken; + + public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional) { + this(effect, optional, new FilterCreaturePermanent()); + } + + public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional, boolean nontoken) { + this(effect, optional, new FilterCreaturePermanent(), nontoken); + } + + public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter) { + this(effect, optional, filter, false); + } + + public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, boolean nontoken) { + super(Constants.Zone.BATTLEFIELD, effect, optional); + this.filter = filter; + this.nontoken = nontoken; + } + + public DiesAnotherCreatureTriggeredAbility(DiesAnotherCreatureTriggeredAbility ability) { + super(ability); + this.filter = ability.filter; + this.nontoken = ability.nontoken; + } + + @Override + public DiesAnotherCreatureTriggeredAbility copy() { + return new DiesAnotherCreatureTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + + UUID sourceId = getSourceId(); + if (game.getPermanent(sourceId) == null) { + if (game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD) == null) { + return false; + } + } + + if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && zEvent.getToZone() == Constants.Zone.GRAVEYARD) { + Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); + if (permanent != null) { + if (permanent.getId().equals(this.getSourceId())) { + return false; + } + if (nontoken && permanent instanceof PermanentToken) { + return false; + } + if (filter.match(permanent)) { + return true; + } + } + } + } + return false; + } + + @Override + public String getRule() { + if (nontoken) { + return "Whenever another nontoken creature dies, " + super.getRule(); + } + return "Whenever another creature dies, " + super.getRule(); + } +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/common/DiesAnotherCreatureYouControlTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesAnotherCreatureYouControlTriggeredAbility.java index 95ef1f2aa1..90e098893c 100644 --- a/Mage/src/mage/abilities/common/DiesAnotherCreatureYouControlTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DiesAnotherCreatureYouControlTriggeredAbility.java @@ -1,3 +1,30 @@ +/* + * 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; @@ -8,24 +35,40 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; +import mage.game.permanent.PermanentToken; import java.util.UUID; +/** + * @author noxx + */ public class DiesAnotherCreatureYouControlTriggeredAbility extends TriggeredAbilityImpl { + protected FilterCreaturePermanent filter; + protected boolean nontoken; public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional) { this(effect, optional, new FilterCreaturePermanent()); } + + public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional, boolean nontoken) { + this(effect, optional, new FilterCreaturePermanent(), nontoken); + } public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter) { + this(effect, optional, filter, false); + } + + public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, boolean nontoken) { super(Constants.Zone.BATTLEFIELD, effect, optional); this.filter = filter; + this.nontoken = nontoken; } public DiesAnotherCreatureYouControlTriggeredAbility(DiesAnotherCreatureYouControlTriggeredAbility ability) { super(ability); this.filter = ability.filter; + this.nontoken = ability.nontoken; } @Override @@ -47,6 +90,10 @@ public class DiesAnotherCreatureYouControlTriggeredAbility extends TriggeredAbil ZoneChangeEvent zEvent = (ZoneChangeEvent) event; Permanent permanent = zEvent.getTarget(); + if (nontoken && permanent instanceof PermanentToken) { + return false; + } + if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE) && zEvent.isDiesEvent() && permanent.getControllerId().equals(this.getControllerId()) && filter != null && @@ -59,6 +106,9 @@ public class DiesAnotherCreatureYouControlTriggeredAbility extends TriggeredAbil @Override public String getRule() { + if (nontoken) { + return "Whenever another nontoken creature you control dies, " + super.getRule(); + } return "Whenever another creature you control dies, " + super.getRule(); } } \ No newline at end of file diff --git a/Mage/src/mage/abilities/common/DiesThisOrAnotherCreatureTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesThisOrAnotherCreatureTriggeredAbility.java index b79ae404ae..182b4eb0a1 100644 --- a/Mage/src/mage/abilities/common/DiesThisOrAnotherCreatureTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DiesThisOrAnotherCreatureTriggeredAbility.java @@ -1,3 +1,30 @@ +/* + * 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; @@ -9,6 +36,11 @@ import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; +import java.util.UUID; + +/** + * @author noxx + */ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityImpl { protected FilterCreaturePermanent filter; @@ -36,6 +68,14 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + + UUID sourceId = getSourceId(); + if (game.getPermanent(sourceId) == null) { + if (game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD) == null) { + return false; + } + } + if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && zEvent.getToZone() == Constants.Zone.GRAVEYARD) { Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); if (permanent != null) {