Package mage.abilities.effects

Examples of mage.abilities.effects.PreventionEffectData


        return preventDamage(event, source, game, Integer.MAX_VALUE);
    }

    @Override
    public PreventionEffectData preventDamage(GameEvent event, Ability source, Game game, int amountToPrevent) {
        PreventionEffectData result = new PreventionEffectData(amountToPrevent);
        if (!(event instanceof DamageEvent)) {
            result.setError(true);
            return result;
        }
        DamageEvent damageEvent = (DamageEvent) event;
        GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, damageEvent.getTargetId(), damageEvent.getSourceId(), source.getControllerId(), damageEvent.getAmount(), false);
        if (game.replaceEvent(preventEvent)) {
            result.setReplaced(true);
            return result;
        }

        if (event.getAmount() > amountToPrevent) {
            result.setPreventedDamage(amountToPrevent);
            damageEvent.setAmount(event.getAmount() - amountToPrevent);
        } else {
            result.setPreventedDamage(event.getAmount());
            damageEvent.setAmount(0);

        }
        if (amountToPrevent != Integer.MAX_VALUE) {
            // set remaining amount
            result.setRemainingAmount(amountToPrevent -= result.getPreventedDamage());
        }
        MageObject damageSource = game.getObject(damageEvent.getSourceId());
        MageObject preventionSource = game.getObject(source.getSourceId());

        if (damageSource != null && preventionSource != null) {
            MageObject targetObject = game.getObject(event.getTargetId());
            String targetName = "";
            if (targetObject == null) {
                Player targetPlayer = game.getPlayer(event.getTargetId());
                if (targetPlayer != null) {
                    targetName = targetPlayer.getName();
                }
            } else {
                targetName = targetObject.getLogName();
            }
            StringBuilder message = new StringBuilder(preventionSource.getLogName()).append(": Prevented ");
            message.append(Integer.toString(result.getPreventedDamage())).append(" damage from ").append(damageSource.getName());
            if (!targetName.isEmpty()) {
                message.append(" to ").append(targetName);
            }
            game.informPlayers(message.toString());
        }
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, damageEvent.getTargetId(), source.getSourceId(), source.getControllerId(), result.getPreventedDamage()));
        return result;

    }
View Full Code Here


        this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {       
        PreventionEffectData preventionData = preventDamageAction(event, source, game);
        this.used = true;
        this.discard(); // only one use
        if (preventionData.getPreventedDamage() > 0) {
            MageObject damageDealingObject = game.getObject(target.getFirstTarget());
            UUID objectControllerId = null;
            if (damageDealingObject instanceof Permanent) {
                objectControllerId = ((Permanent) damageDealingObject).getControllerId();
            } else if (damageDealingObject instanceof Ability) {
                objectControllerId = ((Ability) damageDealingObject).getControllerId();
            } else if (damageDealingObject instanceof Spell) {
                objectControllerId = ((Spell) damageDealingObject).getControllerId();
            }
            if (objectControllerId != null) {
                Player objectController = game.getPlayer(objectControllerId);
                if (objectController != null) {
                    objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), game, false, true);
                }
            }
        }       
        return true;
    }
View Full Code Here

        this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        PreventionEffectData preventionData = preventDamageAction(event, source, game);
        this.used = true;
        this.discard(); // only one use
        if (preventionData.getPreventedDamage() > 0) {
            Player player = game.getPlayer(source.getControllerId());
            if (player != null) {
                player.gainLife(preventionData.getPreventedDamage(), game);
            }           
        }       
        return true;
    }
View Full Code Here

        it would deal to one of the creatures, among other choices. You don't decide until the
        point at which the damage would be dealt.
        TODO: Support to select which damage to prevent
        */

        PreventionEffectData preventionData = preventDamageAction(event, source, game);
        /*
        Divine Deflection's effect is not a redirection effect. If it prevents damage,
        Divine Deflection (not the original source) deals damage to the targeted creature
        or player as part of that prevention effect. Divine Deflection is the source of
        the new damage, so the characteristics of the original source (such as its color,
        or whether it had lifelink or deathtouch) don't affect this damage. The new damage
        is not combat damage, even if the prevented damage was. Since you control the source
        of the new damage, if you targeted an opponent with Divine Deflection, you may
        have Divine Deflection deal its damage to a planeswalker that opponent controls.
        */
        // deal damage now
        int prevented = preventionData.getPreventedDamage();
        if (prevented > 0) {
            UUID dealDamageTo = source.getFirstTarget();
            /*
            Whether the targeted creature or player is still a legal target is not checked after
            Divine Deflection resolves. For example, if a creature targeted by Divine Deflection
View Full Code Here

        return new ShamanEnKorPreventionEffect(this);
    }
   
    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        PreventionEffectData preventionResult = preventDamageAction(event, source, game);
        if (preventionResult.getPreventedDamage() > 0) {
            Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (redirectTo != null) {
                game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + redirectTo.getName() + " instead.");
                DamageEvent damageEvent = (DamageEvent) event;
                redirectTo.damage(preventionResult.getPreventedDamage(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
            }
        }
        return false;
    }
View Full Code Here

        return true;
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        PreventionEffectData preventEffectData = preventDamageAction(event, source, game);
        if (preventEffectData.getPreventedDamage() > 0) {
            used = true;
            Player player = game .getPlayer(source.getControllerId());
            if(player != null){
                player.gainLife(preventEffectData.getPreventedDamage(), game);
            }
        }
        return false;
    }
View Full Code Here

        return new VassalsDutyPreventDamageTargetEffect(this);
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        PreventionEffectData preventionResult = preventDamageAction(event, source, game);
        // deal damage now
        if (preventionResult.getPreventedDamage() > 0) {
            UUID redirectTo = source.getControllerId();
            Player player = game.getPlayer(redirectTo);
            if (player != null) {
                game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + player.getName() + " instead");
                // keep the original source id as it is redirecting
                player.damage(preventionResult.getPreventedDamage(), event.getSourceId(), game, false, true);
            }
        }
        // damage amount is reduced or set to 0 so complete replacement of damage event is never neccessary
        return false;
    }
View Full Code Here

        return true;
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        PreventionEffectData preventionData = preventDamageAction(event, source, game);
        // deal damage now
        if (preventionData.getPreventedDamage() > 0) {
            Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (permanent != null) {
                game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " damage to " + permanent.getLogName() + " instead");
                // keep the original source id as it is redirecting
                permanent.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
            }
            Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
            if (player != null) {
                game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " damage to " + player.getName() + " instead");
                // keep the original source id as it is redirecting
                player.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
            }
        }
        return false;
    }
View Full Code Here

        return true;
    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
        PreventionEffectData preventionData = preventDamageAction(event, source, game);
        // deal damage now
        if (preventionData.getPreventedDamage() > 0) {
            UUID redirectTo = source.getTargets().get(1).getFirstTarget();
            Permanent permanent = game.getPermanent(redirectTo);
            if (permanent != null) {
                game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + permanent.getLogName() + " instead");
                // keep the original source id as it is redirecting
                permanent.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
            }
            Player player = game.getPlayer(redirectTo);
            if (player != null) {
                game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + player.getName() + " instead");
                // keep the original source id as it is redirecting
                player.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
            }
        }
        return false;
    }
View Full Code Here

TOP

Related Classes of mage.abilities.effects.PreventionEffectData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.