From 120d7612f625662796f75c1647193709041549b2 Mon Sep 17 00:00:00 2001 From: emerald000 Date: Mon, 19 Sep 2016 09:22:21 -0400 Subject: [PATCH] Fixed Panharmonicon triggering for opponents abilities. Added tests. --- .../src/mage/sets/kaladesh/Panharmonicon.java | 16 ++- .../cards/replacement/PanharmoniconTest.java | 105 ++++++++++++++++++ .../mage/abilities/TriggeredAbilities.java | 8 +- .../events/EntersTheBattlefieldEvent.java | 6 +- .../main/java/mage/game/events/GameEvent.java | 1 + .../game/events/NumberOfTriggersEvent.java | 50 +++++++++ .../mage/game/permanent/PermanentImpl.java | 7 +- 7 files changed, 178 insertions(+), 15 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/replacement/PanharmoniconTest.java create mode 100644 Mage/src/main/java/mage/game/events/NumberOfTriggersEvent.java diff --git a/Mage.Sets/src/mage/sets/kaladesh/Panharmonicon.java b/Mage.Sets/src/mage/sets/kaladesh/Panharmonicon.java index f335d301cab..187da675f2a 100644 --- a/Mage.Sets/src/mage/sets/kaladesh/Panharmonicon.java +++ b/Mage.Sets/src/mage/sets/kaladesh/Panharmonicon.java @@ -41,7 +41,7 @@ import mage.game.Game; import mage.game.events.EntersTheBattlefieldEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; +import mage.game.events.NumberOfTriggersEvent; /** * @@ -85,15 +85,19 @@ class PanharmoniconEffect extends ReplacementEffectImpl { @Override public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; + return event.getType() == EventType.NUMBER_OF_TRIGGERS; } @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event instanceof EntersTheBattlefieldEvent) { - Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget(); - if (permanent != null) { - return permanent.getCardType().contains(CardType.ARTIFACT) || permanent.getCardType().contains(CardType.CREATURE); + if (event instanceof NumberOfTriggersEvent) { + NumberOfTriggersEvent numberOfTriggersEvent = (NumberOfTriggersEvent) event; + if (source.getControllerId().equals(event.getPlayerId())) { + GameEvent sourceEvent = numberOfTriggersEvent.getSourceEvent(); + if (sourceEvent.getType() == EventType.ENTERS_THE_BATTLEFIELD && sourceEvent instanceof EntersTheBattlefieldEvent) { + EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) sourceEvent; + return entersTheBattlefieldEvent.getTarget().getCardType().contains(CardType.ARTIFACT) || entersTheBattlefieldEvent.getTarget().getCardType().contains(CardType.CREATURE); + } } } return false; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/PanharmoniconTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/PanharmoniconTest.java new file mode 100644 index 00000000000..d3286978fd1 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/PanharmoniconTest.java @@ -0,0 +1,105 @@ +/* + * 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 org.mage.test.cards.replacement; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class PanharmoniconTest extends CardTestPlayerBase { + + /** + * Check that Panharmonicon adds EtB triggers correctly. + * + */ + @Test + public void testAddsTrigger() { + // If an artifact or creature entering the battlefield causes a triggered ability of a permanent you control to trigger, that ability triggers an additional time. + addCard(Zone.BATTLEFIELD, playerA, "Panharmonicon"); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + // Whenever another creature enters the battlefield, you gain 1 life. + addCard(Zone.HAND, playerA, "Soul Warden"); + // When Devout Monk enters the battlefield, you gain 1 life. + addCard(Zone.HAND, playerA, "Devout Monk"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Soul Warden"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Devout Monk"); // Life: 20 + 2*1 + 2*1 = 24 + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertLife(playerA, 24); + } + + /** + * Check that Panharmonicon doesn't add to opponents' triggers. + * + */ + @Test + public void testDoesntAddOpponentsTriggers() { + // If an artifact or creature entering the battlefield causes a triggered ability of a permanent you control to trigger, that ability triggers an additional time. + addCard(Zone.BATTLEFIELD, playerA, "Panharmonicon"); + addCard(Zone.BATTLEFIELD, playerB, "Plains", 2); + // Whenever another creature enters the battlefield, you gain 1 life. + addCard(Zone.HAND, playerB, "Soul Warden"); + // When Devout Monk enters the battlefield, you gain 1 life. + addCard(Zone.HAND, playerB, "Devout Monk"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Soul Warden"); + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Devout Monk"); // Life: 20 + 1 + 1 = 22 + + setStopAt(2, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertLife(playerB, 22); + } + + /** + * Check that Panharmonicon doesn't add to lands triggers. + * + */ + @Test + public void testDoesntAddLandsTriggers() { + // If an artifact or creature entering the battlefield causes a triggered ability of a permanent you control to trigger, that ability triggers an additional time. + addCard(Zone.BATTLEFIELD, playerA, "Panharmonicon"); + // When Radiant Fountain enters the battlefield, you gain 2 life. + addCard(Zone.HAND, playerA, "Radiant Fountain"); + + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Radiant Fountain"); // Life: 20 + 2 = 22 + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertLife(playerA, 22); + } +} diff --git a/Mage/src/main/java/mage/abilities/TriggeredAbilities.java b/Mage/src/main/java/mage/abilities/TriggeredAbilities.java index c066f8ef090..e5fd438390d 100644 --- a/Mage/src/main/java/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/main/java/mage/abilities/TriggeredAbilities.java @@ -41,6 +41,7 @@ import mage.cards.Card; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.NumberOfTriggersEvent; import mage.game.permanent.Permanent; import mage.game.stack.Spell; @@ -124,7 +125,12 @@ public class TriggeredAbilities extends ConcurrentHashMap appliedEffects) { super(EventType.ENTERS_THE_BATTLEFIELD, target.getId(), sourceId, playerId); this.fromZone = fromZone; - this.target = target; if (appliedEffects != null) { this.appliedEffects = appliedEffects; } - this.amount = 1; // Number of times to trigger (Panharmonicon can change that value) } public Zone getFromZone() { diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index a984f80cbad..9e2626b6015 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -266,6 +266,7 @@ public class GameEvent implements Serializable { REGENERATE, REGENERATED, CHANGE_COLOR, COLOR_CHANGED, + NUMBER_OF_TRIGGERS, //combat events COMBAT_DAMAGE_APPLIED, SELECTED_ATTACKER, SELECTED_BLOCKER; diff --git a/Mage/src/main/java/mage/game/events/NumberOfTriggersEvent.java b/Mage/src/main/java/mage/game/events/NumberOfTriggersEvent.java new file mode 100644 index 00000000000..881baac488f --- /dev/null +++ b/Mage/src/main/java/mage/game/events/NumberOfTriggersEvent.java @@ -0,0 +1,50 @@ +/* +* 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.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class NumberOfTriggersEvent extends GameEvent { + + private final GameEvent sourceEvent; + + public NumberOfTriggersEvent(UUID controllerOfAbilityId, GameEvent sourceEvent) { + super(EventType.NUMBER_OF_TRIGGERS, null, null, controllerOfAbilityId); + this.sourceEvent = sourceEvent; + this.amount = 1; // Number of times to trigger. Panharmonicon can change this. + } + + public GameEvent getSourceEvent() { + return sourceEvent; + } +} diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index cb4d9d8a211..fa4319cbecc 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -881,12 +881,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { EntersTheBattlefieldEvent event = new EntersTheBattlefieldEvent(this, sourceId, getControllerId(), fromZone); if (!game.replaceEvent(event)) { if (fireEvent) { - // Trigger multiple times with Panharmonicon. - for (int i = 0; i < event.getAmount(); i++) { - game.addSimultaneousEvent(event); - } + game.addSimultaneousEvent(event); + return true; } - return true; } return false; }