From ab0abcfd2258ed49a0a4f858915ace706e581dcb Mon Sep 17 00:00:00 2001 From: xenohedron Date: Sat, 26 Aug 2023 01:06:56 -0400 Subject: [PATCH] simplify SetBaseToughnessSourceEffect fix Duration.WhileOnBattlefield -> Duration.Custom in some effects --- Mage.Sets/src/mage/cards/s/Sentinel.java | 5 +-- .../src/mage/cards/t/TreeOfPerdition.java | 14 ++----- .../src/mage/cards/t/TreeOfRedemption.java | 7 +--- .../src/mage/cards/w/WallOfTombstones.java | 5 +-- .../SetBaseToughnessSourceEffect.java | 41 ++++++------------- 5 files changed, 23 insertions(+), 49 deletions(-) diff --git a/Mage.Sets/src/mage/cards/s/Sentinel.java b/Mage.Sets/src/mage/cards/s/Sentinel.java index 0a7df439e21..a76c0cdb24b 100644 --- a/Mage.Sets/src/mage/cards/s/Sentinel.java +++ b/Mage.Sets/src/mage/cards/s/Sentinel.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/t/TreeOfPerdition.java b/Mage.Sets/src/mage/cards/t/TreeOfPerdition.java index be473c5011d..b478a50c00c 100644 --- a/Mage.Sets/src/mage/cards/t/TreeOfPerdition.java +++ b/Mage.Sets/src/mage/cards/t/TreeOfPerdition.java @@ -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 Cultist’s Staff (which makes it 2/15) and the player’s 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 Cultist’s Staff) and the player’s 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; } diff --git a/Mage.Sets/src/mage/cards/t/TreeOfRedemption.java b/Mage.Sets/src/mage/cards/t/TreeOfRedemption.java index ee93f9e21c1..aefc01504ac 100644 --- a/Mage.Sets/src/mage/cards/t/TreeOfRedemption.java +++ b/Mage.Sets/src/mage/cards/t/TreeOfRedemption.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/w/WallOfTombstones.java b/Mage.Sets/src/mage/cards/w/WallOfTombstones.java index 2114624b09a..51ab1d0c411 100644 --- a/Mage.Sets/src/mage/cards/w/WallOfTombstones.java +++ b/Mage.Sets/src/mage/cards/w/WallOfTombstones.java @@ -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; } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/SetBaseToughnessSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/SetBaseToughnessSourceEffect.java index cbe57b62c56..f203194bd1d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/SetBaseToughnessSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/SetBaseToughnessSourceEffect.java @@ -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; - } - }