foul-magics/Mage/src/main/java/mage/abilities/effects/common/GainLifeEffect.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

73 lines
1.9 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
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 BetaSteward_at_googlemail.com
*/
public class GainLifeEffect extends OneShotEffect {
private DynamicValue life;
public GainLifeEffect(int life) {
this(StaticValue.get(life));
}
public GainLifeEffect(DynamicValue life) {
super(Outcome.GainLife);
this.life = life;
}
public GainLifeEffect(DynamicValue life, String rule) {
super(Outcome.GainLife);
this.life = life;
staticText = rule;
}
protected GainLifeEffect(final GainLifeEffect effect) {
super(effect);
this.life = effect.life.copy();
}
@Override
public GainLifeEffect copy() {
return new GainLifeEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(life.calculate(game, source, this), game, source);
}
return true;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
String message = life.getMessage();
sb.append("you gain ");
if (message.isEmpty() || !life.toString().equals("1")) {
sb.append(life).append(' ');
}
sb.append("life");
if (!message.isEmpty()) {
sb.append(life.toString().equals("1") ? " equal to the number of " : " for each ");
sb.append(message);
}
return sb.toString();
}
}