Added lockedIn parameter to BoostEffects.

This commit is contained in:
North 2012-05-24 22:45:41 +03:00
parent 98606e16b7
commit 8618b45bc8
3 changed files with 153 additions and 138 deletions

View file

@ -48,10 +48,9 @@ public class BoostControlledEffect extends ContinuousEffectImpl<BoostControlledE
private DynamicValue power; private DynamicValue power;
private DynamicValue toughness; private DynamicValue toughness;
protected boolean excludeSource;
protected FilterCreaturePermanent filter; protected FilterCreaturePermanent filter;
// if true, all dynamic values should be calculated once protected boolean excludeSource;
protected boolean isLockedIn = false; protected boolean lockedIn = false;
public BoostControlledEffect(int power, int toughness, Duration duration) { public BoostControlledEffect(int power, int toughness, Duration duration) {
this(power, toughness, duration, new FilterCreaturePermanent(), false); this(power, toughness, duration, new FilterCreaturePermanent(), false);
@ -74,11 +73,19 @@ public class BoostControlledEffect extends ContinuousEffectImpl<BoostControlledE
} }
public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) { public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) {
this(power, toughness, duration, filter, excludeSource, false);
}
/**
* @param lockedIn if true, power and toughness will be calculated only once, when the ability resolves
*/
public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource, boolean lockedIn) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.power = power; this.power = power;
this.toughness = toughness; this.toughness = toughness;
this.filter = filter; this.filter = filter;
this.excludeSource = excludeSource; this.excludeSource = excludeSource;
this.lockedIn = lockedIn;
setText(); setText();
} }
@ -88,7 +95,7 @@ public class BoostControlledEffect extends ContinuousEffectImpl<BoostControlledE
this.toughness = effect.toughness; this.toughness = effect.toughness;
this.filter = effect.filter.copy(); this.filter = effect.filter.copy();
this.excludeSource = effect.excludeSource; this.excludeSource = effect.excludeSource;
this.isLockedIn = effect.isLockedIn; this.lockedIn = effect.lockedIn;
} }
@Override @Override
@ -106,7 +113,7 @@ public class BoostControlledEffect extends ContinuousEffectImpl<BoostControlledE
} }
} }
} }
if (this.isLockedIn) { if (this.lockedIn) {
power = new StaticValue(power.calculate(game, source)); power = new StaticValue(power.calculate(game, source));
toughness = new StaticValue(toughness.calculate(game, source)); toughness = new StaticValue(toughness.calculate(game, source));
} }
@ -155,8 +162,7 @@ public class BoostControlledEffect extends ContinuousEffectImpl<BoostControlledE
staticText = rule; staticText = rule;
} }
public void setLockedIn(boolean isLockedIn) { public void setLockedIn(boolean lockedIn) {
this.isLockedIn =isLockedIn; this.lockedIn = lockedIn;
} }
} }

View file

@ -46,15 +46,24 @@ import mage.game.permanent.Permanent;
public class BoostSourceEffect extends ContinuousEffectImpl<BoostSourceEffect> { public class BoostSourceEffect extends ContinuousEffectImpl<BoostSourceEffect> {
private DynamicValue power; private DynamicValue power;
private DynamicValue toughness; private DynamicValue toughness;
private boolean lockedIn;
public BoostSourceEffect(int power, int toughness, Duration duration) { public BoostSourceEffect(int power, int toughness, Duration duration) {
this(new StaticValue(power), new StaticValue(toughness), duration); this(new StaticValue(power), new StaticValue(toughness), duration, false);
} }
public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration) { public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration) {
this(power, toughness, duration, false);
}
/**
* @param lockedIn if true, power and toughness will be calculated only once, when the ability resolves
*/
public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, boolean lockedIn) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.power = power; this.power = power;
this.toughness = toughness; this.toughness = toughness;
this.lockedIn = lockedIn;
setText(); setText();
} }
@ -62,6 +71,7 @@ public class BoostSourceEffect extends ContinuousEffectImpl<BoostSourceEffect> {
super(effect); super(effect);
this.power = effect.power.clone(); this.power = effect.power.clone();
this.toughness = effect.toughness.clone(); this.toughness = effect.toughness.clone();
this.lockedIn = effect.lockedIn;
} }
@Override @Override
@ -69,6 +79,15 @@ public class BoostSourceEffect extends ContinuousEffectImpl<BoostSourceEffect> {
return new BoostSourceEffect(this); return new BoostSourceEffect(this);
} }
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (lockedIn) {
power = new StaticValue(power.calculate(game, source));
toughness = new StaticValue(toughness.calculate(game, source));
}
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent target = game.getPermanent(source.getSourceId()); Permanent target = game.getPermanent(source.getSourceId());

View file

@ -49,37 +49,31 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
private DynamicValue power; private DynamicValue power;
private DynamicValue toughness; private DynamicValue toughness;
// if true, all dynamic values should be calculated once private boolean lockedIn;
protected boolean isLockedIn = false;
public BoostTargetEffect(int power, int toughness, Duration duration) { public BoostTargetEffect(int power, int toughness, Duration duration) {
this(new StaticValue(power), new StaticValue(toughness), duration); this(new StaticValue(power), new StaticValue(toughness), duration, false);
} }
public BoostTargetEffect(DynamicValue power, DynamicValue toughness, Duration duration) { public BoostTargetEffect(DynamicValue power, DynamicValue toughness, Duration duration) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); this(power, toughness, duration, false);
this.power = power;
this.toughness = toughness;
} }
/** /**
* @param power power value to boost * @param lockedIn if true, power and toughness will be calculated only once, when the ability resolves
* @param toughness toughness value to boost
* @param duration how long does the effecct apply
* @param continuousCalculation true = power and toughness will be calculated continuously
* false = power and toughness will be calculated once during resolution
*/ */
public BoostTargetEffect(DynamicValue power, DynamicValue toughness, Duration duration, boolean isLockedIn) { public BoostTargetEffect(DynamicValue power, DynamicValue toughness, Duration duration, boolean lockedIn) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.power = power; this.power = power;
this.toughness = toughness; this.toughness = toughness;
this.isLockedIn = isLockedIn; this.lockedIn = lockedIn;
} }
public BoostTargetEffect(final BoostTargetEffect effect) { public BoostTargetEffect(final BoostTargetEffect effect) {
super(effect); super(effect);
this.power = effect.power.clone(); this.power = effect.power.clone();
this.toughness = effect.toughness.clone(); this.toughness = effect.toughness.clone();
this.isLockedIn = effect.isLockedIn; this.lockedIn = effect.lockedIn;
} }
@Override @Override
@ -90,7 +84,7 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
@Override @Override
public void init(Ability source, Game game) { public void init(Ability source, Game game) {
super.init(source, game); super.init(source, game);
if (isLockedIn) { if (lockedIn) {
power = new StaticValue(power.calculate(game, source)); power = new StaticValue(power.calculate(game, source));
toughness = new StaticValue(toughness.calculate(game, source)); toughness = new StaticValue(toughness.calculate(game, source));
} }
@ -140,8 +134,4 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
sb.append(message); sb.append(message);
return sb.toString(); return sb.toString();
} }
public void setLockedIn(boolean isLockedIn) {
this.isLockedIn =isLockedIn;
}
} }