foul-magics/Mage/src/main/java/mage/abilities/effects/common/SetPlayerLifeSourceEffect.java
Susucre f75b1c9f0a
Code cleanup: protect all copy constructors (#10750)
* apply regex to change public copy constructors to protected
* cleanup code using now protected constructors
* fix manaBuilder weird casting of Mana into ConditionalMana
2023-08-04 19:34:58 -04:00

53 lines
1.4 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
/**
* @author LevelX2
*/
public class SetPlayerLifeSourceEffect extends OneShotEffect {
protected DynamicValue amount;
public SetPlayerLifeSourceEffect(int amount) {
this(StaticValue.get(amount));
}
public SetPlayerLifeSourceEffect(DynamicValue amount) {
super(Outcome.Neutral);
this.amount = amount;
this.staticText = setText();
}
protected SetPlayerLifeSourceEffect(final SetPlayerLifeSourceEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
public SetPlayerLifeSourceEffect copy() {
return new SetPlayerLifeSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.setLife(amount.calculate(game, source, this), game, source);
return true;
}
return false;
}
private String setText() {
StringBuilder sb = new StringBuilder("your life total becomes ");
sb.append(amount.toString());
return sb.toString();
}
}