refactor: remove unnecessary "lockedIn" parameter (#11244)

* remove lockedIn from logic: BoostControlledEffect

* remove lockedIn field: BoostControlledEffect

* remove constructor parameter: BoostControlledEffect

* simplify BoostEnchantedEffect

* apply fix to BoostSourceEffect

* remove unused param

* refactor SetBasePowerToughnessAllEffect

* additional cleanup
This commit is contained in:
xenohedron 2023-10-01 22:50:44 -04:00 committed by GitHub
parent 2d24f067f3
commit 4273d3b5ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
119 changed files with 174 additions and 216 deletions

View file

@ -30,13 +30,13 @@ public class ConditionalRequirementEffect extends RequirementEffect {
}
public ConditionalRequirementEffect(RequirementEffect effect, Condition condition, String text) {
this(effect.getDuration(), effect, condition, null, false);
this(effect.getDuration(), effect, condition, null);
if (text != null) {
setText(text);
}
}
public ConditionalRequirementEffect(Duration duration, RequirementEffect effect, Condition condition, RequirementEffect otherwiseEffect, boolean lockedInCondition) {
public ConditionalRequirementEffect(Duration duration, RequirementEffect effect, Condition condition, RequirementEffect otherwiseEffect) {
super(duration);
this.effectType = EffectType.REQUIREMENT;
this.effect = effect;

View file

@ -27,7 +27,6 @@ public class BoostControlledEffect extends ContinuousEffectImpl {
private DynamicValue toughness;
protected FilterCreaturePermanent filter;
protected boolean excludeSource;
protected boolean lockedIn = false;
public BoostControlledEffect(int power, int toughness, Duration duration) {
this(power, toughness, duration, StaticFilters.FILTER_PERMANENT_CREATURES, false);
@ -46,30 +45,18 @@ public class BoostControlledEffect extends ContinuousEffectImpl {
}
public BoostControlledEffect(int power, int toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, filter, excludeSource, true);
}
public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) {
this(power, toughness, duration, filter, excludeSource, false);
this(StaticValue.get(power), StaticValue.get(toughness), duration, filter, excludeSource);
}
/**
* @param power
* @param toughness
* @param duration
* @param filter AnotherPredicate is not working, you need to use the
* excludeSource option
* @param lockedIn if true, power and toughness will be calculated only
* once, when the ability resolves
* @param excludeSource
* Note: use excludeSource rather than AnotherPredicate
*/
public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource, boolean lockedIn) {
public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.power = power;
this.toughness = toughness;
this.filter = (filter == null ? StaticFilters.FILTER_PERMANENT_CREATURES : filter);
this.excludeSource = excludeSource;
this.lockedIn = lockedIn;
setText();
}
@ -79,7 +66,6 @@ public class BoostControlledEffect extends ContinuousEffectImpl {
this.toughness = effect.toughness;
this.filter = effect.filter.copy();
this.excludeSource = effect.excludeSource;
this.lockedIn = effect.lockedIn;
}
@Override
@ -97,8 +83,6 @@ public class BoostControlledEffect extends ContinuousEffectImpl {
affectedObjectList.add(new MageObjectReference(perm, game));
}
}
}
if (this.lockedIn) {
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}
@ -141,11 +125,4 @@ public class BoostControlledEffect extends ContinuousEffectImpl {
staticText = sb.toString();
}
public void setRule(String rule) {
staticText = rule;
}
public void setLockedIn(boolean lockedIn) {
this.lockedIn = lockedIn;
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
@ -7,7 +6,6 @@ import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -21,7 +19,6 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl {
private DynamicValue power;
private DynamicValue toughness;
private boolean lockedIn = false;
public BoostEnchantedEffect(int power, int toughness) {
this(power, toughness, Duration.WhileOnBattlefield);
@ -46,7 +43,6 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl {
super(effect);
this.power = effect.power.copy();
this.toughness = effect.toughness.copy();
this.lockedIn = effect.lockedIn;
}
@Override
@ -57,10 +53,6 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl {
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (lockedIn) {
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}
if (affectedObjectsSet) {
// Added boosts of activated or triggered abilities exist independent from the source they are created by
// so a continuous effect for the permanent itself with the attachment is created
@ -68,6 +60,8 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl {
if (equipment != null && equipment.getAttachedTo() != null) {
this.setTargetPointer(new FixedTarget(equipment.getAttachedTo(), game.getState().getZoneChangeCounter(equipment.getAttachedTo())));
}
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}
}
@ -93,7 +87,4 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl {
return true;
}
public void setLockedIn(boolean lockedIn) {
this.lockedIn = lockedIn;
}
}

View file

@ -20,36 +20,23 @@ import org.apache.log4j.Logger;
public class BoostSourceEffect extends ContinuousEffectImpl {
private DynamicValue power;
private DynamicValue toughness;
private final boolean lockedIn;
public BoostSourceEffect(int power, int toughness, Duration duration) {
this(power, toughness, duration, "{this}");
}
public BoostSourceEffect(int power, int toughness, Duration duration, String description) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, false, description);
this(StaticValue.get(power), StaticValue.get(toughness), duration, description);
}
public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration) {
this(power, toughness, duration, false);
this(power, toughness, duration, "{this}");
}
public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, boolean lockedIn) {
this(power, toughness, duration, lockedIn, "{this}");
}
/**
* @param power
* @param toughness
* @param duration
* @param lockedIn if true, power and toughness will be calculated only once, when the ability resolves
* @param description
*/
public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, boolean lockedIn, String description) {
public BoostSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, String description) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.power = power;
this.toughness = toughness;
this.lockedIn = lockedIn;
this.staticText = description + " gets " + CardUtil.getBoostText(power, toughness, duration);
}
@ -57,7 +44,6 @@ public class BoostSourceEffect extends ContinuousEffectImpl {
super(effect);
this.power = effect.power.copy();
this.toughness = effect.toughness.copy();
this.lockedIn = effect.lockedIn;
}
@Override
@ -74,8 +60,6 @@ public class BoostSourceEffect extends ContinuousEffectImpl {
} catch (IllegalArgumentException ex) {
Logger.getLogger(BoostSourceEffect.class).error("Could not get sourceId reference: " + source.getRule());
}
}
if (lockedIn) {
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}

View file

@ -2,7 +2,6 @@ package mage.abilities.effects.common.continuous;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.ContinuousEffectImpl;
@ -11,7 +10,7 @@ import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -26,22 +25,24 @@ public class SetBasePowerToughnessAllEffect extends ContinuousEffectImpl {
private final FilterPermanent filter;
private DynamicValue power;
private DynamicValue toughness;
private final boolean lockedInPT;
public SetBasePowerToughnessAllEffect(int power, int toughness, Duration duration) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, new FilterCreaturePermanent("Creatures"), true);
this(power, toughness, duration, StaticFilters.FILTER_PERMANENT_CREATURES);
}
public SetBasePowerToughnessAllEffect(int power, int toughness, Duration duration, FilterPermanent filter, boolean lockedInPT) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, filter, lockedInPT);
public SetBasePowerToughnessAllEffect(int power, int toughness, Duration duration, FilterPermanent filter) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, filter);
}
public SetBasePowerToughnessAllEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterPermanent filter, boolean lockedInPT) {
public SetBasePowerToughnessAllEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterPermanent filter) {
super(duration, Layer.PTChangingEffects_7, SubLayer.SetPT_7b, Outcome.BoostCreature);
this.power = power;
this.toughness = toughness;
this.filter = filter;
this.lockedInPT = lockedInPT;
this.staticText = filter.getMessage()
+ (filter.getMessage().toLowerCase(Locale.ENGLISH).startsWith("each ") ? " has " : " have ")
+ "base power and toughness " + power + '/' + toughness
+ (duration.toString().isEmpty() ? "" : ' ' + duration.toString());
}
protected SetBasePowerToughnessAllEffect(final SetBasePowerToughnessAllEffect effect) {
@ -49,7 +50,6 @@ public class SetBasePowerToughnessAllEffect extends ContinuousEffectImpl {
this.power = effect.power;
this.toughness = effect.toughness;
this.filter = effect.filter;
this.lockedInPT = effect.lockedInPT;
}
@Override
@ -64,8 +64,6 @@ public class SetBasePowerToughnessAllEffect extends ContinuousEffectImpl {
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
affectedObjectList.add(new MageObjectReference(perm, game));
}
}
if (lockedInPT) {
power = StaticValue.get(power.calculate(game, source, this));
toughness = StaticValue.get(toughness.calculate(game, source, this));
}
@ -94,23 +92,4 @@ public class SetBasePowerToughnessAllEffect extends ContinuousEffectImpl {
return true;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append(filter.getMessage());
if (filter.getMessage().toLowerCase(Locale.ENGLISH).startsWith("each ")) {
sb.append(" has base power and toughness ");
} else {
sb.append(" have base power and toughness ");
}
sb.append(power).append('/').append(toughness);
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}
return sb.toString();
}
}

View file

@ -7,7 +7,6 @@ import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.game.Game;
/**
@ -23,7 +22,7 @@ public class BushidoAbility extends BlocksOrBlockedSourceTriggeredAbility {
}
public BushidoAbility(DynamicValue value) {
super(new BoostSourceEffect(value, value, Duration.EndOfTurn, true));
super(new BoostSourceEffect(value, value, Duration.EndOfTurn));
this.value = value;
rule = (
value instanceof StaticValue ?

View file

@ -19,7 +19,7 @@ import java.util.*;
public class MeleeAbility extends AttacksTriggeredAbility {
public MeleeAbility() {
super(new BoostSourceEffect(MeleeDynamicValue.instance, MeleeDynamicValue.instance, Duration.EndOfTurn, true), false);
super(new BoostSourceEffect(MeleeDynamicValue.instance, MeleeDynamicValue.instance, Duration.EndOfTurn), false);
this.addWatcher(new MeleeWatcher());
}

View file

@ -1,6 +1,5 @@
package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedSourceTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.MultipliedValue;
@ -26,7 +25,7 @@ public class RampageAbility extends BecomesBlockedSourceTriggeredAbility {
: " <i>(Whenever this creature becomes blocked, it gets +"
+ amount + "/+" + amount + " until end of turn for each creature blocking it beyond the first.)</i>");
DynamicValue rv = (amount == 1 ? BlockingCreatureCount.BEYOND_FIRST : new MultipliedValue(BlockingCreatureCount.BEYOND_FIRST, amount));
this.addEffect(new BoostSourceEffect(rv, rv, Duration.EndOfTurn, true));
this.addEffect(new BoostSourceEffect(rv, rv, Duration.EndOfTurn));
}
protected RampageAbility(final RampageAbility ability) {