Search in sources :

Example 1 with DiesReplacementEffect

use of mage.abilities.effects.common.replacement.DiesReplacementEffect in project mage by magefree.

the class BurnFromWithinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
        int amount = source.getManaCostsToPay().getX();
        if (creature != null) {
            game.addEffect(new DiesReplacementEffect(new MageObjectReference(creature, game), Duration.EndOfTurn), source);
            int damageDealt = creature.damage(amount, source.getSourceId(), source, game, false, true);
            if (damageDealt > 0) {
                ContinuousEffect effect = new LoseAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
                effect.setTargetPointer(new FixedTarget(creature.getId(), game));
                game.addEffect(effect, source);
            }
            return true;
        }
        Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
        if (targetPlayer != null) {
            targetPlayer.damage(amount, source.getSourceId(), source, game);
            return true;
        }
    }
    return false;
}
Also used : DiesReplacementEffect(mage.abilities.effects.common.replacement.DiesReplacementEffect) FixedTarget(mage.target.targetpointer.FixedTarget) LoseAbilityTargetEffect(mage.abilities.effects.common.continuous.LoseAbilityTargetEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 LoseAbilityTargetEffect (mage.abilities.effects.common.continuous.LoseAbilityTargetEffect)1 DiesReplacementEffect (mage.abilities.effects.common.replacement.DiesReplacementEffect)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 FixedTarget (mage.target.targetpointer.FixedTarget)1