Refactored ConditionalContinousEffect to support otherwiseEffect

This commit is contained in:
North 2012-03-30 21:18:42 +03:00
parent c893fd891e
commit bc1dcff4fe
2 changed files with 31 additions and 66 deletions

View file

@ -30,18 +30,11 @@ package mage.sets.darkascension;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Layer;
import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.Constants.SubLayer;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.MorbidCondition;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.decorator.ConditionalContinousEffect;
import mage.abilities.effects.common.continious.BoostTargetEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.target.common.TargetCreaturePermanent;
/**
@ -58,7 +51,11 @@ public class TragicSlip extends CardImpl<TragicSlip> {
// Target creature gets -1/-1 until end of turn.
// Morbid - That creature gets -13/-13 until end of turn instead if a creature died this turn.
this.getSpellAbility().addEffect(new TragicSlipEffect());
this.getSpellAbility().addEffect(new ConditionalContinousEffect(
new BoostTargetEffect(-13, -13, Duration.EndOfTurn),
new BoostTargetEffect(-1, -1, Duration.EndOfTurn),
MorbidCondition.getInstance(),
"Target creature gets -1/-1 until end of turn. Morbid - That creature gets -13/-13 until end of turn instead if a creature died this turn"));
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
}
@ -71,53 +68,3 @@ public class TragicSlip extends CardImpl<TragicSlip> {
return new TragicSlip(this);
}
}
class TragicSlipEffect extends ContinuousEffectImpl<TragicSlipEffect> {
private ContinuousEffect effect;
private ContinuousEffect otherwiseEffect;
private Condition condition;
public TragicSlipEffect() {
super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.effect = new BoostTargetEffect(-13, -13, Duration.EndOfTurn);
this.otherwiseEffect = new BoostTargetEffect(-1, -1, Duration.EndOfTurn);
this.condition = MorbidCondition.getInstance();
this.staticText = "Target creature gets -1/-1 until end of turn. Morbid - That creature gets -13/-13 until end of turn instead if a creature died this turn.";
}
public TragicSlipEffect(final TragicSlipEffect effect) {
super(effect);
this.effect = effect.effect;
this.otherwiseEffect = effect.otherwiseEffect;
this.condition = effect.condition;
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
if (condition.apply(game, source)) {
return effect.apply(layer, sublayer, source, game);
} else {
return otherwiseEffect.apply(layer, sublayer, source, game);
}
}
@Override
public boolean apply(Game game, Ability source) {
if (condition.apply(game, source)) {
return effect.apply(game, source);
} else {
return otherwiseEffect.apply(game, source);
}
}
@Override
public boolean hasLayer(Layer layer) {
return effect.hasLayer(layer);
}
@Override
public TragicSlipEffect copy() {
return new TragicSlipEffect(this);
}
}

View file

@ -15,25 +15,42 @@ import mage.game.Game;
public class ConditionalContinousEffect extends ContinuousEffectImpl<ConditionalContinousEffect> {
protected ContinuousEffect effect;
protected ContinuousEffect otherwiseEffect;
protected Condition condition;
public ConditionalContinousEffect(ContinuousEffect effect, Condition condition, String text) {
this(effect, null, condition, text);
}
/**
* Only use this if both effects have the same layers
*
* @param effect
* @param otherwiseEffect
* @param condition
* @param text
*/
public ConditionalContinousEffect(ContinuousEffect effect, ContinuousEffect otherwiseEffect, Condition condition, String text) {
super(effect.getDuration(), effect.getLayer(), effect.getSublayer(), effect.getOutcome());
this.effect = effect;
this.otherwiseEffect = otherwiseEffect;
this.condition = condition;
this.staticText = text;
}
public ConditionalContinousEffect(final ConditionalContinousEffect effect) {
super(effect);
this.effect = effect.effect;
this.condition = effect.condition;
}
public ConditionalContinousEffect(final ConditionalContinousEffect effect) {
super(effect);
this.effect = effect.effect;
this.otherwiseEffect = effect.otherwiseEffect;
this.condition = effect.condition;
}
@Override
public boolean apply(Constants.Layer layer, Constants.SubLayer sublayer, Ability source, Game game) {
if (condition.apply(game, source)) {
return effect.apply(layer, sublayer, source, game);
} else if (otherwiseEffect != null) {
return otherwiseEffect.apply(layer, sublayer, source, game);
}
return false;
}
@ -42,6 +59,8 @@ public class ConditionalContinousEffect extends ContinuousEffectImpl<Conditional
public boolean apply(Game game, Ability source) {
if (condition.apply(game, source)) {
return effect.apply(game, source);
} else if (otherwiseEffect != null) {
return otherwiseEffect.apply(game, source);
}
return false;
}
@ -55,5 +74,4 @@ public class ConditionalContinousEffect extends ContinuousEffectImpl<Conditional
public ConditionalContinousEffect copy() {
return new ConditionalContinousEffect(this);
}
}