Merge pull request #11031 from xenohedron/cleanup-7a-7b

More SetBasePowerToughnessSourceEffect cleanup
This commit is contained in:
xenohedron 2023-08-31 00:29:59 -04:00 committed by GitHub
commit d6c690601d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 657 additions and 256 deletions

View file

@ -1,36 +1,34 @@
package mage.abilities.effects.common.continuous;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
/**
* @author LevelX2
* @author xenohedron
*/
public class SetBasePowerSourceEffect extends ContinuousEffectImpl {
private final DynamicValue amount;
public class SetBasePowerSourceEffect extends SetBasePowerToughnessSourceEffect {
/**
* @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;
super(amount, null, Duration.EndOfGame, SubLayer.CharacteristicDefining_7a);
staticText = "{this}'s power is equal to the number of " + amount.getMessage();
}
/**
* @param amount Power to set in layer 7b
* @param duration Duration for the effect
*/
public SetBasePowerSourceEffect(int amount, Duration duration) {
super(StaticValue.get(amount), null, duration, SubLayer.SetPT_7b);
staticText = "{this} has base power " + amount + ' ' + duration.toString();
}
protected SetBasePowerSourceEffect(final SetBasePowerSourceEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
@ -38,15 +36,4 @@ public class SetBasePowerSourceEffect extends ContinuousEffectImpl {
return new SetBasePowerSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
MageObject mageObject = game.getObject(source);
if (mageObject == null) {
return false;
}
int value = amount.calculate(game, source, this);
mageObject.getPower().setModifiedBaseValue(value);
return true;
}
}

View file

@ -0,0 +1,30 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.IntPlusDynamicValue;
import mage.constants.Duration;
import mage.constants.SubLayer;
/**
* @author xenohedron
*/
public class SetBasePowerToughnessPlusOneSourceEffect extends SetBasePowerToughnessSourceEffect {
/**
* @param amount Power to set as a characteristic-defining ability; toughness is that value plus 1
*/
public SetBasePowerToughnessPlusOneSourceEffect(DynamicValue amount) {
super(amount, new IntPlusDynamicValue(1, amount), Duration.EndOfGame, SubLayer.CharacteristicDefining_7a);
this.staticText = "{this}'s power is equal to the number of " + amount.getMessage() + " and its toughness is equal to that number plus 1";
}
protected SetBasePowerToughnessPlusOneSourceEffect(final SetBasePowerToughnessPlusOneSourceEffect effect) {
super(effect);
}
@Override
public SetBasePowerToughnessPlusOneSourceEffect copy() {
return new SetBasePowerToughnessPlusOneSourceEffect(this);
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common.continuous;
import mage.MageObject;
@ -13,8 +12,6 @@ import mage.constants.SubLayer;
import mage.game.Game;
/**
* RENAME
*
* @author BetaSteward_at_googlemail.com, North, Alex-Vasile, xenohedron
*/
public class SetBasePowerToughnessSourceEffect extends ContinuousEffectImpl {
@ -23,11 +20,11 @@ public class SetBasePowerToughnessSourceEffect extends ContinuousEffectImpl {
private final DynamicValue toughness;
/**
* Note: Need to set text manually if calling this constructor directly.
* <p>
* It is possible to have power or toughness to null, in which case only the other is modified.
* This constructor is called by the other more specific constructors which set text for appropriate usages.
* @param power can be null, if only toughness is to be modified
* @param toughness can be null, if only power is to be modified
*/
public SetBasePowerToughnessSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, SubLayer subLayer) {
protected 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;
@ -42,8 +39,37 @@ public class SetBasePowerToughnessSourceEffect extends ContinuousEffectImpl {
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(StaticValue.get(power), StaticValue.get(toughness), duration, subLayer);
/**
* @param amount Power and toughness to set in layer 7b
* @param duration Duration for the effect
*/
public SetBasePowerToughnessSourceEffect(DynamicValue amount, Duration duration) {
this(amount, amount, duration, SubLayer.SetPT_7b);
if (duration.toString().isEmpty()) {
staticText = "{this}'s power and toughness are each equal to the number of " + amount.getMessage();
} else {
staticText = "{this} has base power and toughness each equal to the number of " + amount.getMessage() + " " + duration;
}
}
/**
* @param power set in layer 7b
* @param toughness set in layer 7b
* @param duration Duration for the effect
* @param text Text to set as staticText
*/
public SetBasePowerToughnessSourceEffect(DynamicValue power, DynamicValue toughness, Duration duration, String text) {
this(power, toughness, duration, SubLayer.SetPT_7b);
this.staticText = text;
}
/**
* @param power set in layer 7b
* @param toughness set in layer 7b
* @param duration Duration for the effect
*/
public SetBasePowerToughnessSourceEffect(int power, int toughness, Duration duration) {
this(StaticValue.get(power), StaticValue.get(toughness), duration, SubLayer.SetPT_7b);
this.staticText = "{this} has base power and toughness " + power + '/' + toughness + ' ' + duration.toString();
}
@ -62,25 +88,22 @@ public class SetBasePowerToughnessSourceEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
if (duration == Duration.Custom || isTemporary()) {
mageObject = game.getPermanent(source.getSourceId());
} else {
if (this.characterDefining || this.duration == Duration.WhileOnBattlefield) {
// Duration is a workaround for Primal Clay and similar which are incorrectly implemented
mageObject = game.getObject(source);
} else {
mageObject = source.getSourcePermanentIfItStillExists(game);
}
}
if (mageObject == null || (power == null && toughness == null)) {
if (mageObject == null) {
discard();
return false;
}
if (this.power != null) {
int power = this.power.calculate(game, source, this);
mageObject.getPower().setModifiedBaseValue(power);
mageObject.getPower().setModifiedBaseValue(this.power.calculate(game, source, this));
}
if (this.toughness != null) {
int toughness = this.toughness.calculate(game, source, this);
mageObject.getToughness().setModifiedBaseValue(toughness);
mageObject.getToughness().setModifiedBaseValue(this.toughness.calculate(game, source, this));
}
return true;
}

View file

@ -1,38 +1,34 @@
package mage.abilities.effects.common.continuous;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
/**
* RENAME
*
* @author Backfir3, noxx
* @author xenohedron
*/
public class SetBaseToughnessSourceEffect extends ContinuousEffectImpl {
private final DynamicValue amount;
public class SetBaseToughnessSourceEffect extends SetBasePowerToughnessSourceEffect {
/**
* @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;
super(null, amount, Duration.EndOfGame, SubLayer.CharacteristicDefining_7a);
staticText = "{this}'s toughness is equal to the number of " + amount.getMessage();
}
/**
* @param amount Toughness to set in layer 7b
* @param duration Duration for the effect
*/
public SetBaseToughnessSourceEffect(int amount, Duration duration) {
super(null, StaticValue.get(amount), duration, SubLayer.SetPT_7b);
staticText = "{this} has base toughness " + amount + ' ' + duration.toString();
}
protected SetBaseToughnessSourceEffect(final SetBaseToughnessSourceEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
@ -40,15 +36,4 @@ public class SetBaseToughnessSourceEffect extends ContinuousEffectImpl {
return new SetBaseToughnessSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
MageObject mageObject = game.getObject(source);
if (mageObject != null) {
int value = amount.calculate(game, source, this);
mageObject.getToughness().setModifiedBaseValue(value);
return true;
}
return false;
}
}

View file

@ -11,7 +11,6 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.Duration;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.counters.CounterType;
@ -55,7 +54,7 @@ public class LevelerCardBuilder {
staticAbility.setRuleVisible(false);
constructed.add(staticAbility);
}
ContinuousEffect effect = new SetBasePowerToughnessSourceEffect(power, toughness, Duration.WhileOnBattlefield, SubLayer.SetPT_7b);
ContinuousEffect effect = new SetBasePowerToughnessSourceEffect(power, toughness, Duration.WhileOnBattlefield);
ConditionalContinuousEffect ptEffect = new ConditionalContinuousEffect(effect, condition, rule);
constructed.add(new SimpleStaticAbility(Zone.BATTLEFIELD, ptEffect));

View file

@ -2,12 +2,12 @@ package mage.game.permanent.token;
import mage.MageInt;
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.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.*;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessPlusOneSourceEffect;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Zone;
/**
* @author ciaccona007
@ -15,7 +15,6 @@ import mage.constants.*;
public final class ConsumingBlobOozeToken extends TokenImpl {
private static final DynamicValue powerValue = CardTypesInGraveyardCount.YOU;
private static final DynamicValue toughnessValue = new AdditiveDynamicValue(powerValue, StaticValue.get(1));
public ConsumingBlobOozeToken() {
super("Ooze Token", "green Ooze creature token with \"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.\"");
@ -27,11 +26,7 @@ public final class ConsumingBlobOozeToken extends TokenImpl {
toughness = new MageInt(1);
// 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)
.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")
));
this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetBasePowerToughnessPlusOneSourceEffect(powerValue)));
}
private ConsumingBlobOozeToken(final ConsumingBlobOozeToken token) {