refactor SavedGainedLifeValue instead of getValue("gainedLife")

This commit is contained in:
Susucre 2024-06-04 11:19:14 +02:00
parent 53a5f53f78
commit 24b184c28f
16 changed files with 198 additions and 380 deletions

View file

@ -1,6 +1,7 @@
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.dynamicvalue.common.SavedGainedLifeValue;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
@ -46,7 +47,7 @@ public class GainLifeControllerTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.getControllerId())) {
this.getEffects().setValue("gainedLife", event.getAmount());
this.getEffects().setValue(SavedGainedLifeValue.VALUE_KEY, event.getAmount());
if (setTargetPointer) {
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
}

View file

@ -0,0 +1,45 @@
package mage.abilities.dynamicvalue.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.game.Game;
import java.util.Optional;
/**
* Stores gained life value in relevant triggers, to pass down on effects.
*
* @author Susucr
*/
public enum SavedGainedLifeValue implements DynamicValue {
MANY("many"),
MUCH("much");
private final String message;
public static final String VALUE_KEY = "gainedLife";
SavedGainedLifeValue(String message) {
this.message = "that " + message;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return Optional.ofNullable((Integer) effect.getValue(VALUE_KEY)).orElse(0);
}
@Override
public SavedGainedLifeValue copy() {
return this;
}
@Override
public String toString() {
return message;
}
@Override
public String getMessage() {
return "";
}
}

View file

@ -35,6 +35,10 @@ public class AddCountersSourceEffect extends OneShotEffect {
this(counter, StaticValue.get(0), informPlayers);
}
public AddCountersSourceEffect(Counter counter, DynamicValue amount) {
this(counter, amount, true);
}
public AddCountersSourceEffect(Counter counter, DynamicValue amount, boolean informPlayers) {
this(counter, amount, informPlayers, false);
}