From b93ff11aeb8fad81b8a144e4c772770437fc4949 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 17 Jul 2013 11:45:22 +0200 Subject: [PATCH] Added possibility to set a flag for effects that causes to call game.applyEffects() after the effect is resolved. --- Mage/src/mage/abilities/AbilityImpl.java | 4 ++++ Mage/src/mage/abilities/effects/Effect.java | 2 ++ Mage/src/mage/abilities/effects/EffectImpl.java | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 6cfe632855..86763c0270 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -156,6 +156,10 @@ public abstract class AbilityImpl> implements Ability { else { game.addEffect((ContinuousEffect) effect, this); } + // some effects must be applied before next effect is resolved, because effect is dependend. + if (effect.applyEffectsAfter()) { + game.applyEffects(); + } } } return result; diff --git a/Mage/src/mage/abilities/effects/Effect.java b/Mage/src/mage/abilities/effects/Effect.java index bd227555f5..6f49cae408 100644 --- a/Mage/src/mage/abilities/effects/Effect.java +++ b/Mage/src/mage/abilities/effects/Effect.java @@ -54,6 +54,8 @@ public interface Effect> extends Serializable { TargetPointer getTargetPointer(); void setValue(String key, Object value); Object getValue(String key); + void setApplyEffectsAfter(); + boolean applyEffectsAfter(); T copy(); diff --git a/Mage/src/mage/abilities/effects/EffectImpl.java b/Mage/src/mage/abilities/effects/EffectImpl.java index 328999fa8b..a5fa63225f 100644 --- a/Mage/src/mage/abilities/effects/EffectImpl.java +++ b/Mage/src/mage/abilities/effects/EffectImpl.java @@ -51,6 +51,7 @@ public abstract class EffectImpl> implements Effect { protected TargetPointer targetPointer = FirstTargetPointer.getInstance(); protected String staticText = ""; protected Map values; + protected boolean applyEffectsAfter = false; public EffectImpl(Outcome outcome) { this.id = UUID.randomUUID(); @@ -70,6 +71,7 @@ public abstract class EffectImpl> implements Effect { values.put(entry.getKey(), entry.getValue()); } } + this.applyEffectsAfter = effect.applyEffectsAfter; } @Override @@ -133,4 +135,18 @@ public abstract class EffectImpl> implements Effect { } return values.get(key); } + + /** + * If set, the game.applyEffects() method will be called to apply the effects before the + * next effect (of the same ability) will resolve. + */ + @Override + public void setApplyEffectsAfter() { + applyEffectsAfter = true; + } + + @Override + public boolean applyEffectsAfter() { + return applyEffectsAfter; + } }