Refactor to clean up base P/T setting and fix text generation (#10264)

* Adjust constructors to simplify

* Refactor to remove duration parameter for CDA (always end of game)

* Fix warnings

* Druid Class not CDA

* Entropic Specter fixup

* Further constructor simplification

* Analogous simplification for setting power only

* Analogous simplification for setting toughness only

* Remove superfluous parameter

* Set fields final
This commit is contained in:
xenohedron 2023-04-24 09:43:18 -04:00 committed by GitHub
parent 96cf6dc019
commit 1780972f71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
226 changed files with 269 additions and 464 deletions

View file

@ -19,13 +19,13 @@ public class SetBasePowerSourceEffect extends ContinuousEffectImpl {
private final DynamicValue amount;
public SetBasePowerSourceEffect(DynamicValue amount, Duration duration) {
this(amount, duration, SubLayer.CharacteristicDefining_7a);
}
public SetBasePowerSourceEffect(DynamicValue amount, Duration duration, SubLayer subLayer) {
super(duration, Layer.PTChangingEffects_7, subLayer, Outcome.BoostCreature);
setCharacterDefining(subLayer == SubLayer.CharacteristicDefining_7a);
/**
*
* @param amount Power to set as a characteristic-defining ability
*/
public SetBasePowerSourceEffect(DynamicValue amount) {
super(Duration.EndOfGame, Layer.PTChangingEffects_7, SubLayer.CharacteristicDefining_7a, Outcome.BoostCreature);
setCharacterDefining(true);
this.amount = amount;
staticText = "{this}'s power is equal to the number of " + amount.getMessage();
}

View file

@ -14,57 +14,34 @@ import mage.game.Game;
/**
* RENAME
* @author BetaSteward_at_googlemail.com, North, Alex-Vasile
* @author BetaSteward_at_googlemail.com, North, Alex-Vasile, xenohedron
*/
public class SetBasePowerToughnessSourceEffect extends ContinuousEffectImpl {
private DynamicValue power;
private DynamicValue toughness;
private final DynamicValue power;
private final DynamicValue toughness;
/**
*
* @param power
* @param toughness
* @param duration
* @param subLayer
* @param baseInText Whether or not the rules text should refer to "base power and toughness" or "power and toughness"
* Either way, it is always the based power and toughness that are set.
* Note: Need to set text manually if calling this constructor directly
*/
public SetBasePowerToughnessSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, SubLayer subLayer, boolean baseInText) {
public SetBasePowerToughnessSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, SubLayer subLayer) {
super(duration, Layer.PTChangingEffects_7, subLayer, Outcome.BoostCreature);
setCharacterDefining(subLayer == SubLayer.CharacteristicDefining_7a);
this.power = power;
this.toughness = toughness;
if (power == toughness) { // When power and toughness are equal, a previous constructor passes the same object for both power nad toughness, so use == instead of .equals
this.staticText = "{this}'s " + (baseInText ? "base " : "") + "power and toughness are each equal to the number of " + power.getMessage();
} else { // The only other constructor creates the power and toughenss dynamic values as static values from passed-in ints.
String value = (power != null ? power.toString() : toughness.toString());
this.staticText = "{this}'s " + (baseInText ? "base " : "") + "power and toughness is " + value + '/' + toughness + ' ' + duration.toString();
}
}
public SetBasePowerToughnessSourceEffect(DynamicValue amount, Duration duration) {
this(amount, duration, SubLayer.CharacteristicDefining_7a, false);
}
public SetBasePowerToughnessSourceEffect(DynamicValue amount, Duration duration, SubLayer subLayer) {
this(amount, duration, subLayer, true);
}
public SetBasePowerToughnessSourceEffect(DynamicValue amount, Duration duration, SubLayer subLayer, boolean changeBaseValue) {
this(amount, amount, duration, subLayer, changeBaseValue);
}
public SetBasePowerToughnessSourceEffect(int power, int toughness, Duration duration, boolean changeBaseValue) {
this(power, toughness, duration, SubLayer.CharacteristicDefining_7a, changeBaseValue);
/**
* @param amount Power and toughness to set as a characteristic-defining ability
*/
public SetBasePowerToughnessSourceEffect(DynamicValue amount) {
this(amount, amount, Duration.EndOfGame, SubLayer.CharacteristicDefining_7a);
this.staticText = "{this}'s power and toughness are each equal to the number of " + amount.getMessage();
}
public SetBasePowerToughnessSourceEffect(int power, int toughness, Duration duration, SubLayer subLayer) {
this(power, toughness, duration, subLayer, false);
}
public SetBasePowerToughnessSourceEffect(int power, int toughness, Duration duration, SubLayer subLayer, boolean changeBaseValue) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, subLayer, changeBaseValue);
this(StaticValue.get(power), StaticValue.get(toughness), duration, subLayer);
this.staticText = "{this} has base power and toughness " + power + '/' + toughness + ' ' + duration.toString();
}
public SetBasePowerToughnessSourceEffect(final SetBasePowerToughnessSourceEffect effect) {

View file

@ -19,12 +19,13 @@ public class SetBaseToughnessSourceEffect extends ContinuousEffectImpl {
private final DynamicValue amount;
public SetBaseToughnessSourceEffect(DynamicValue amount, Duration duration) {
this(amount, duration, SubLayer.CharacteristicDefining_7a);
}
public SetBaseToughnessSourceEffect(DynamicValue amount, Duration duration, SubLayer subLayer) {
super(duration, Layer.PTChangingEffects_7, subLayer, Outcome.BoostCreature);
/**
*
* @param amount Toughness to set as a characteristic-defining ability
*/
public SetBaseToughnessSourceEffect(DynamicValue amount) {
super(Duration.EndOfGame, Layer.PTChangingEffects_7, SubLayer.CharacteristicDefining_7a, Outcome.BoostCreature);
setCharacterDefining(true);
this.amount = amount;
staticText = "{this}'s toughness is equal to the number of " + amount.getMessage();
}
@ -46,10 +47,6 @@ public class SetBaseToughnessSourceEffect extends ContinuousEffectImpl {
int value = amount.calculate(game, source, this);
mageObject.getToughness().setModifiedBaseValue(value);
return true;
} else {
if (duration == Duration.Custom) {
discard();
}
}
return false;
}

View file

@ -55,7 +55,7 @@ public class LevelerCardBuilder {
staticAbility.setRuleVisible(false);
constructed.add(staticAbility);
}
ContinuousEffect effect = new SetBasePowerToughnessSourceEffect(power, toughness, Duration.WhileOnBattlefield, SubLayer.SetPT_7b, true);
ContinuousEffect effect = new SetBasePowerToughnessSourceEffect(power, toughness, Duration.WhileOnBattlefield, SubLayer.SetPT_7b);
ConditionalContinuousEffect ptEffect = new ConditionalContinuousEffect(effect, condition, rule);
constructed.add(new SimpleStaticAbility(Zone.BATTLEFIELD, ptEffect));

View file

@ -4,8 +4,6 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.ControllerLifeCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubLayer;
import mage.constants.SubType;
import java.util.Arrays;
@ -21,8 +19,7 @@ public final class AvatarToken extends TokenImpl {
subtype.add(SubType.AVATAR);
color.setWhite(true);
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(
ControllerLifeCount.instance, Duration.WhileOnBattlefield,
SubLayer.CharacteristicDefining_7a
ControllerLifeCount.instance
).setText("this creature's power and toughness are each equal to your life total")));
availableImageSetCodes = Arrays.asList("LRW", "M10", "M11");

View file

@ -1,19 +1,13 @@
package mage.game.permanent.token;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.AdditiveDynamicValue;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.CardTypesInGraveyardCount;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.abilities.hint.common.CardTypesInGraveyardHint;
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game;
import java.util.Arrays;
@ -37,7 +31,7 @@ public final class ConsumingBlobOozeToken extends TokenImpl {
// This creature's power is equal to the number of card types among cards in your graveyard and its toughness is equal to that number plus 1.
this.addAbility(new SimpleStaticAbility(
Zone.ALL,
new SetBasePowerToughnessSourceEffect(powerValue, toughnessValue, Duration.EndOfGame, SubLayer.CharacteristicDefining_7a, false)
new SetBasePowerToughnessSourceEffect(powerValue, toughnessValue, Duration.EndOfGame, SubLayer.CharacteristicDefining_7a)
.setText("{this}'s power is equal to the number of creature cards in all graveyards and its toughness is equal to that number plus 1")
));

View file

@ -7,7 +7,6 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
@ -32,7 +31,7 @@ public final class DogIllusionToken extends TokenImpl {
// This creature's power and toughness are each equal to twice the number of cards in your hand.
this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetBasePowerToughnessSourceEffect(
DogIllusionValue.instance, Duration.EndOfGame)
DogIllusionValue.instance)
.setText("this creature's power and toughness are each equal to twice the number of cards in your hand")
));

View file

@ -6,7 +6,6 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.common.FilterCreaturePermanent;
@ -36,7 +35,7 @@ public final class DoomedArtisanToken extends TokenImpl {
toughness = new MageInt(0);
// This creature's power and toughness are each equal to the number of Sculpturess you control.
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(xValue, Duration.EndOfGame)));
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(xValue)));
}
private DoomedArtisanToken(final DoomedArtisanToken token) {

View file

@ -7,7 +7,6 @@ import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard;
@ -28,7 +27,7 @@ public final class ElephantResurgenceToken extends TokenImpl {
this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new SetBasePowerToughnessSourceEffect(new CardsInControllerGraveyardCount(new FilterCreatureCard()), Duration.EndOfGame)
new SetBasePowerToughnessSourceEffect(new CardsInControllerGraveyardCount(new FilterCreatureCard()))
.setText("This creature's power and toughness are each equal to the number of creature cards in its controller's graveyard.")
));
}

View file

@ -10,7 +10,6 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
@ -35,7 +34,7 @@ public final class GutterGrimeToken extends TokenImpl {
color.setGreen(true);
power = new MageInt(0);
toughness = new MageInt(0);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(new GutterGrimeCounters(sourceId), Duration.WhileOnBattlefield)));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(new GutterGrimeCounters(sourceId))));
}
public GutterGrimeToken(final GutterGrimeToken token) {

View file

@ -6,7 +6,6 @@ import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
@ -33,7 +32,7 @@ public final class KalonianTwingroveTreefolkWarriorToken extends TokenImpl {
power = new MageInt(0);
toughness = new MageInt(0);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(new PermanentsOnBattlefieldCount(filterLands), Duration.WhileOnBattlefield)));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(new PermanentsOnBattlefieldCount(filterLands))));
}
public KalonianTwingroveTreefolkWarriorToken(final KalonianTwingroveTreefolkWarriorToken token) {

View file

@ -10,7 +10,6 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
@ -33,7 +32,7 @@ public final class SaprolingBurstToken extends TokenImpl {
this.color.setGreen(true);
this.subtype.add(SubType.SAPROLING);
this.cardType.add(CardType.CREATURE);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(new SaprolingBurstTokenDynamicValue(saprolingBurstMOR), Duration.WhileOnBattlefield)));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(new SaprolingBurstTokenDynamicValue(saprolingBurstMOR))));
}
public SaprolingBurstToken(final SaprolingBurstToken token) {

View file

@ -9,7 +9,6 @@ import mage.abilities.hint.Hint;
import mage.abilities.hint.StaticHint;
import mage.abilities.keyword.TrampleAbility;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import java.util.Arrays;
@ -34,7 +33,7 @@ public final class SeizeTheStormElementalToken extends TokenImpl {
toughness = new MageInt(0);
this.addAbility(TrampleAbility.getInstance());
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(
xValue, Duration.WhileOnBattlefield
xValue
).setText("this creature's power and toughness are each equal to the number of " +
"instant and sorcery cards in your graveyard, plus the number of cards with flashback you own in exile")
).addHint(hint));

View file

@ -7,7 +7,6 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -31,7 +30,7 @@ public class SpiritClericToken extends TokenImpl {
toughness = new MageInt(0);
// This creatures power and toughness are each equal to the number of Spirits you control.
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(SpiritClericTokenValue.instance, Duration.EndOfGame)));
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(SpiritClericTokenValue.instance)));
availableImageSetCodes = Arrays.asList("VOW");
}

View file

@ -5,7 +5,6 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.CreaturesYouControlCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone;
@ -29,7 +28,7 @@ public final class VoiceOfResurgenceToken extends TokenImpl {
// This creature's power and toughness are each equal to the number of creatures you control.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetBasePowerToughnessSourceEffect(
CreaturesYouControlCount.instance, Duration.EndOfGame)));
CreaturesYouControlCount.instance)));
availableImageSetCodes = Arrays.asList("DGM", "MM3", "2XM");
}

View file

@ -6,7 +6,6 @@ import mage.abilities.dynamicvalue.common.LandsYouControlCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.abilities.keyword.ReachAbility;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone;
@ -26,7 +25,7 @@ public final class WrennAndSevenTreefolkToken extends TokenImpl {
toughness = new MageInt(0);
this.addAbility(ReachAbility.getInstance());
this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetBasePowerToughnessSourceEffect(
LandsYouControlCount.instance, Duration.EndOfGame
LandsYouControlCount.instance
).setText("this creature's power and toughness are each equal to the number of lands you control")));
availableImageSetCodes.addAll(Arrays.asList("MID"));