Added a list for appliedEffects (ReplacementEffects) to GameEvent that can be used to comply with rule 614.5.

This commit is contained in:
LevelX2 2012-10-09 16:22:30 +02:00
parent bd784dfbb0
commit d42e27247d
3 changed files with 42 additions and 9 deletions

View file

@ -28,9 +28,9 @@
package mage.game.events; package mage.game.events;
import mage.Constants.Zone; import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
import mage.Constants.Zone;
/** /**
* *
@ -46,6 +46,7 @@ public class GameEvent {
protected boolean flag; protected boolean flag;
protected String data; protected String data;
protected Zone zone; protected Zone zone;
protected ArrayList<UUID> appliedEffects = new ArrayList<UUID>();;
public enum EventType { public enum EventType {
@ -208,4 +209,28 @@ public class GameEvent {
public void setZone(Zone zone) { public void setZone(Zone zone) {
this.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<UUID> getAppliedEffects() {
return appliedEffects;
}
public void setAppliedEffects(ArrayList<UUID> appliedEffects) {
if (appliedEffects == null) {
appliedEffects = new ArrayList<UUID>();
}
this.appliedEffects = appliedEffects;
}
} }

View file

@ -28,6 +28,7 @@
package mage.game.permanent; package mage.game.permanent;
import java.util.ArrayList;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.cards.Card; import mage.cards.Card;
@ -85,6 +86,8 @@ public interface Permanent extends Card, Controllable {
public int getDamage(); 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);
public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, ArrayList<UUID> appliedEffects);
/** /**
* used in combat only to deal damage at the same time * used in combat only to deal damage at the same time
* *

View file

@ -559,9 +559,12 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
@Override @Override
public int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat) { 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<UUID> appliedEffects) {
return damage(damageAmount, sourceId, game, preventable, combat, false, appliedEffects);
}
/** /**
* @param damageAmount * @param damageAmount
* @param sourceId * @param sourceId
@ -571,13 +574,13 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
* @param markDamage If true, damage will be dealt later in applyDamage method * @param markDamage If true, damage will be dealt later in applyDamage method
* @return * @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<UUID> appliedEffects) {
int damageDone = 0; int damageDone = 0;
if (damageAmount > 0 && canDamage(game.getObject(sourceId), game)) { if (damageAmount > 0 && canDamage(game.getObject(sourceId), game)) {
if (cardType.contains(CardType.PLANESWALKER)) { if (cardType.contains(CardType.PLANESWALKER)) {
damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable, combat, markDamage); damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable, combat, markDamage, appliedEffects);
} else { } else {
damageDone = damageCreature(damageAmount, sourceId, game, preventable, combat, markDamage); damageDone = damageCreature(damageAmount, sourceId, game, preventable, combat, markDamage, appliedEffects);
} }
if (damageDone > 0) { if (damageDone > 0) {
Permanent source = game.getPermanent(sourceId); Permanent source = game.getPermanent(sourceId);
@ -599,7 +602,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
@Override @Override
public int markDamage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat) { 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 @Override
@ -621,8 +624,9 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
deathtouched = false; 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<UUID> appliedEffects) {
GameEvent event = new DamagePlaneswalkerEvent(objectId, sourceId, controllerId, damage, preventable, combat); GameEvent event = new DamagePlaneswalkerEvent(objectId, sourceId, controllerId, damage, preventable, combat);
event.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) { if (!game.replaceEvent(event)) {
int actualDamage = event.getAmount(); int actualDamage = event.getAmount();
if (actualDamage > 0) { if (actualDamage > 0) {
@ -638,8 +642,9 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
return 0; 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<UUID> appliedEffects) {
GameEvent event = new DamageCreatureEvent(objectId, sourceId, controllerId, damage, preventable, combat); GameEvent event = new DamageCreatureEvent(objectId, sourceId, controllerId, damage, preventable, combat);
event.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) { if (!game.replaceEvent(event)) {
int actualDamage = checkProtectionAbilities(event, sourceId, game); int actualDamage = checkProtectionAbilities(event, sourceId, game);
if (actualDamage > 0) { if (actualDamage > 0) {