simplify SetBaseToughnessSourceEffect

fix Duration.WhileOnBattlefield -> Duration.Custom in some effects
This commit is contained in:
xenohedron 2023-08-26 01:06:56 -04:00
parent 33a859cb68
commit ab0abcfd22
5 changed files with 23 additions and 49 deletions

View file

@ -4,9 +4,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.abilities.effects.common.continuous.SetBaseToughnessSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
@ -77,7 +76,7 @@ class SentinelEffect extends OneShotEffect {
Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && targetPermanent != null) {
int newToughness = CardUtil.overflowInc(targetPermanent.getPower().getValue(), 1);
game.addEffect(new SetBasePowerToughnessSourceEffect(null, StaticValue.get(newToughness), Duration.WhileOnBattlefield, SubLayer.SetPT_7b), source);
game.addEffect(new SetBaseToughnessSourceEffect(newToughness, Duration.WhileOnBattlefield), source);
return true;
}
return false;

View file

@ -1,16 +1,11 @@
package mage.cards.t;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessTargetEffect;
import mage.abilities.effects.common.continuous.SetBaseToughnessSourceEffect;
import mage.abilities.keyword.DefenderAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -19,7 +14,8 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetOpponent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
@ -88,9 +84,7 @@ class TreeOfPerditionEffect extends OneShotEffect {
// For example, say Tree of Perdition is equipped with Cultists Staff (which makes it 2/15) and the players life total is 7.
// After the exchange, Tree of Perdition would be a 2/9 creature (its toughness became 7, which was then modified by Cultists Staff) and the players life total would be 15.
// (2016-07-13)
ContinuousEffect powerToughnessEffect = new SetBasePowerToughnessTargetEffect(null, StaticValue.get(life), Duration.Custom);
powerToughnessEffect.setTargetPointer(new FixedTarget(perm.getId()));
game.addEffect(powerToughnessEffect, source);
game.addEffect(new SetBaseToughnessSourceEffect(life, Duration.Custom), source);
return true;
}

View file

@ -1,13 +1,11 @@
package mage.cards.t;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.abilities.effects.common.continuous.SetBaseToughnessSourceEffect;
import mage.abilities.keyword.DefenderAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -65,7 +63,6 @@ class TreeOfRedemptionEffect extends OneShotEffect {
return false;
}
int amount = perm.getToughness().getValue();
int life = player.getLife();
if (life == amount) {
@ -78,7 +75,7 @@ class TreeOfRedemptionEffect extends OneShotEffect {
return false;
}
player.setLife(amount, game, source);
game.addEffect(new SetBasePowerToughnessSourceEffect(null, StaticValue.get(life), Duration.WhileOnBattlefield, SubLayer.SetPT_7b), source);
game.addEffect(new SetBaseToughnessSourceEffect(life, Duration.Custom), source);
return true;
}

View file

@ -4,9 +4,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.abilities.effects.common.continuous.SetBaseToughnessSourceEffect;
import mage.abilities.keyword.DefenderAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -65,7 +64,7 @@ class WallOfTombstonesEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
int newToughness = CardUtil.overflowInc(1, new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this));
game.addEffect(new SetBasePowerToughnessSourceEffect(null, StaticValue.get(newToughness), Duration.WhileOnBattlefield, SubLayer.SetPT_7b), source);
game.addEffect(new SetBaseToughnessSourceEffect(newToughness, Duration.WhileOnBattlefield), source);
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;
}
}