Search in sources :

Example 6 with SquirrelToken

use of mage.game.permanent.token.SquirrelToken in project mage by magefree.

the class PlayerImpl method doDamage.

private int doDamage(int damage, UUID attackerId, Ability source, Game game, boolean combatDamage, boolean preventable, List<UUID> appliedEffects) {
    if (!this.isInGame()) {
        return 0;
    }
    if (damage < 1) {
        return 0;
    }
    if (!canDamage(game.getObject(attackerId), game)) {
        MageObject sourceObject = game.getObject(attackerId);
        game.informPlayers(damage + " damage " + (sourceObject == null ? "" : "from " + sourceObject.getLogName()) + " to " + getLogName() + (damage > 1 ? " were" : "was") + " prevented because of protection");
        return 0;
    }
    DamageEvent event = new DamagePlayerEvent(playerId, attackerId, playerId, damage, preventable, combatDamage);
    event.setAppliedEffects(appliedEffects);
    if (game.replaceEvent(event)) {
        return 0;
    }
    int actualDamage = event.getAmount();
    if (actualDamage < 1) {
        return 0;
    }
    UUID sourceControllerId = null;
    Abilities sourceAbilities = null;
    MageObject attacker = game.getPermanentOrLKIBattlefield(attackerId);
    if (attacker == null) {
        StackObject stackObject = game.getStack().getStackObject(attackerId);
        if (stackObject != null) {
            attacker = stackObject.getStackAbility().getSourceObject(game);
        } else {
            attacker = game.getObject(attackerId);
        }
        if (attacker instanceof Spell) {
            sourceAbilities = ((Spell) attacker).getAbilities(game);
            sourceControllerId = ((Spell) attacker).getControllerId();
        } else if (attacker instanceof Card) {
            sourceAbilities = ((Card) attacker).getAbilities(game);
            sourceControllerId = ((Card) attacker).getOwnerId();
        } else if (attacker instanceof CommandObject) {
            sourceControllerId = ((CommandObject) attacker).getControllerId();
            sourceAbilities = attacker.getAbilities();
        }
    } else {
        sourceAbilities = ((Permanent) attacker).getAbilities(game);
        sourceControllerId = ((Permanent) attacker).getControllerId();
    }
    if (event.isAsThoughInfect() || (sourceAbilities != null && sourceAbilities.containsKey(InfectAbility.getInstance().getId()))) {
        addCounters(CounterType.POISON.createInstance(actualDamage), sourceControllerId, source, game);
    } else {
        GameEvent damageToLifeLossEvent = new GameEvent(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS, playerId, source, playerId, actualDamage, combatDamage);
        if (!game.replaceEvent(damageToLifeLossEvent)) {
            this.loseLife(damageToLifeLossEvent.getAmount(), game, source, combatDamage, attackerId);
        }
    }
    if (sourceAbilities != null && sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
        if (combatDamage) {
            game.getPermanent(attackerId).markLifelink(actualDamage);
        } else {
            Player player = game.getPlayer(sourceControllerId);
            player.gainLife(actualDamage, game, source);
        }
    }
    // Unstable ability - Earl of Squirrel
    if (sourceAbilities != null && sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
        Player player = game.getPlayer(sourceControllerId);
        new SquirrelToken().putOntoBattlefield(actualDamage, game, source, player.getId());
    }
    DamagedEvent damagedEvent = new DamagedPlayerEvent(playerId, attackerId, playerId, actualDamage, combatDamage);
    game.fireEvent(damagedEvent);
    game.getState().addSimultaneousDamage(damagedEvent, game);
    return actualDamage;
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard) CommandObject(mage.game.command.CommandObject) SquirrelToken(mage.game.permanent.token.SquirrelToken)

Aggregations

SquirrelToken (mage.game.permanent.token.SquirrelToken)6 Player (mage.players.Player)4 UUID (java.util.UUID)3 Spell (mage.game.stack.Spell)3 Map (java.util.Map)2 FilterCard (mage.filter.FilterCard)2 CommandObject (mage.game.command.CommandObject)2 StackObject (mage.game.stack.StackObject)2 TargetCard (mage.target.TargetCard)2 HashMap (java.util.HashMap)1 MageObject (mage.MageObject)1 MageObjectReference (mage.MageObjectReference)1 Abilities (mage.abilities.Abilities)1 Ability (mage.abilities.Ability)1 SpellAbility (mage.abilities.SpellAbility)1 LeavesBattlefieldTriggeredAbility (mage.abilities.common.LeavesBattlefieldTriggeredAbility)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1