From d42e27247da34b4581e2300a78d9f843ebef4c8d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 9 Oct 2012 16:22:30 +0200 Subject: [PATCH] Added a list for appliedEffects (ReplacementEffects) to GameEvent that can be used to comply with rule 614.5. --- Mage/src/mage/game/events/GameEvent.java | 29 +++++++++++++++++-- Mage/src/mage/game/permanent/Permanent.java | 3 ++ .../mage/game/permanent/PermanentImpl.java | 19 +++++++----- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index 374956794a..5d8e9bc42e 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -28,9 +28,9 @@ package mage.game.events; -import mage.Constants.Zone; - +import java.util.ArrayList; import java.util.UUID; +import mage.Constants.Zone; /** * @@ -46,6 +46,7 @@ public class GameEvent { protected boolean flag; protected String data; protected Zone zone; + protected ArrayList appliedEffects = new ArrayList();; public enum EventType { @@ -208,4 +209,28 @@ public class GameEvent { public void setZone(Zone zone) { this.zone = zone; } + /** + * used to store which replacement effects were already applied to an event + * or or any modified events that may replace it + * + * 614.5. A replacement effect doesn't invoke itself repeatedly; it gets only one + * opportunity to affect an event or any modified events that may replace it. + * Example: A player controls two permanents, each with an ability that reads + * "If a creature you control would deal damage to a creature or player, it + * deals double that damage to that creature or player instead." A creature + * that normally deals 2 damage will deal 8 damage--not just 4, and not an + * infinite amount. + * + * @return + */ + public ArrayList getAppliedEffects() { + return appliedEffects; + } + + public void setAppliedEffects(ArrayList appliedEffects) { + if (appliedEffects == null) { + appliedEffects = new ArrayList(); + } + this.appliedEffects = appliedEffects; + } } diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index b7ade78a0f..ba440b6446 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -28,6 +28,7 @@ package mage.game.permanent; +import java.util.ArrayList; import mage.MageObject; import mage.abilities.Ability; import mage.cards.Card; @@ -85,6 +86,8 @@ public interface Permanent extends Card, Controllable { public int getDamage(); public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat); + public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, ArrayList appliedEffects); + /** * used in combat only to deal damage at the same time * diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index 7f2781128b..160b2c64c0 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -559,9 +559,12 @@ public abstract class PermanentImpl> extends CardImpl @Override public int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat) { - return damage(damageAmount, sourceId, game, preventable, combat, false); + return damage(damageAmount, sourceId, game, preventable, combat, false, null); } + public int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat, ArrayList appliedEffects) { + return damage(damageAmount, sourceId, game, preventable, combat, false, appliedEffects); + } /** * @param damageAmount * @param sourceId @@ -571,13 +574,13 @@ public abstract class PermanentImpl> extends CardImpl * @param markDamage If true, damage will be dealt later in applyDamage method * @return */ - private int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage) { + private int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage, ArrayList appliedEffects) { int damageDone = 0; if (damageAmount > 0 && canDamage(game.getObject(sourceId), game)) { if (cardType.contains(CardType.PLANESWALKER)) { - damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable, combat, markDamage); + damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable, combat, markDamage, appliedEffects); } else { - damageDone = damageCreature(damageAmount, sourceId, game, preventable, combat, markDamage); + damageDone = damageCreature(damageAmount, sourceId, game, preventable, combat, markDamage, appliedEffects); } if (damageDone > 0) { Permanent source = game.getPermanent(sourceId); @@ -599,7 +602,7 @@ public abstract class PermanentImpl> extends CardImpl @Override public int markDamage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat) { - return damage(damageAmount, sourceId, game, preventable, combat, true); + return damage(damageAmount, sourceId, game, preventable, combat, true, null); } @Override @@ -621,8 +624,9 @@ public abstract class PermanentImpl> extends CardImpl deathtouched = false; } - protected int damagePlaneswalker(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage) { + protected int damagePlaneswalker(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage, ArrayList appliedEffects) { GameEvent event = new DamagePlaneswalkerEvent(objectId, sourceId, controllerId, damage, preventable, combat); + event.setAppliedEffects(appliedEffects); if (!game.replaceEvent(event)) { int actualDamage = event.getAmount(); if (actualDamage > 0) { @@ -638,8 +642,9 @@ public abstract class PermanentImpl> extends CardImpl return 0; } - protected int damageCreature(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage) { + protected int damageCreature(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage, ArrayList appliedEffects) { GameEvent event = new DamageCreatureEvent(objectId, sourceId, controllerId, damage, preventable, combat); + event.setAppliedEffects(appliedEffects); if (!game.replaceEvent(event)) { int actualDamage = checkProtectionAbilities(event, sourceId, game); if (actualDamage > 0) {