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

41 lines
1.1 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
/**
* @author Styxo
*/
public class LoseHalfLifeTargetEffect extends OneShotEffect {
public LoseHalfLifeTargetEffect() {
super(Outcome.Damage);
staticText = "that player loses half their life, rounded up";
}
protected LoseHalfLifeTargetEffect(final LoseHalfLifeTargetEffect effect) {
super(effect);
}
@Override
public LoseHalfLifeTargetEffect copy() {
return new LoseHalfLifeTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
Integer amount = (int) Math.ceil(player.getLife() / 2f);
if (amount > 0) {
player.loseLife(amount, game, source, false);
return true;
}
}
return false;
}
}