Search in sources :

Example 1 with SquirrelToken

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

the class ChatterfangSquirrelGeneralReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (event instanceof CreateTokenEvent) {
        CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
        SquirrelToken squirrelToken = null;
        int amount = 0;
        Map<Token, Integer> tokens = tokenEvent.getTokens();
        for (Map.Entry<Token, Integer> entry : tokens.entrySet()) {
            amount += entry.getValue();
            if (entry.getKey() instanceof SquirrelToken) {
                squirrelToken = (SquirrelToken) entry.getKey();
            }
        }
        if (squirrelToken == null) {
            squirrelToken = new SquirrelToken();
        }
        tokens.put(squirrelToken, tokens.getOrDefault(squirrelToken, 0) + amount);
    }
    return false;
}
Also used : SquirrelToken(mage.game.permanent.token.SquirrelToken) Token(mage.game.permanent.token.Token) Map(java.util.Map) SquirrelToken(mage.game.permanent.token.SquirrelToken) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Example 2 with SquirrelToken

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

the class FormOfTheSquirrelCantCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player sourceController = game.getPlayer(source.getControllerId());
    if (sourceController != null) {
        CreateTokenEffect effect = new CreateTokenEffect(new SquirrelToken());
        effect.apply(game, source);
        game.getState().setValue(source.getSourceId() + "_token", effect.getLastAddedTokenIds());
        for (UUID addedTokenId : effect.getLastAddedTokenIds()) {
            Effect loseGameEffect = new LoseGameTargetPlayerEffect();
            loseGameEffect.setTargetPointer(new FixedTarget(sourceController.getId(), game));
            LeavesBattlefieldTriggeredAbility triggerAbility = new LeavesBattlefieldTriggeredAbility(loseGameEffect, false);
            ContinuousEffect continuousEffect = new GainAbilityTargetEffect(triggerAbility, Duration.WhileOnBattlefield);
            continuousEffect.setTargetPointer(new FixedTarget(addedTokenId, game));
            game.addEffect(continuousEffect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) LeavesBattlefieldTriggeredAbility(mage.abilities.common.LeavesBattlefieldTriggeredAbility) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) LoseGameTargetPlayerEffect(mage.abilities.effects.common.LoseGameTargetPlayerEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) LoseGameTargetPlayerEffect(mage.abilities.effects.common.LoseGameTargetPlayerEffect) CantAttackYouAllEffect(mage.abilities.effects.common.combat.CantAttackYouAllEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) SquirrelToken(mage.game.permanent.token.SquirrelToken)

Example 3 with SquirrelToken

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

the class NantukoShrineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (spell != null) {
        Player controller = game.getPlayer(spell.getControllerId());
        if (controller != null) {
            int count = 0;
            String name = spell.getName();
            FilterCard filterCardName = new FilterCard();
            filterCardName.add(new NamePredicate(name));
            for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    count += player.getGraveyard().count(filterCardName, game);
                }
            }
            if (count > 0) {
                new SquirrelToken().putOntoBattlefield(count, game, source, spell.getControllerId());
            }
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) UUID(java.util.UUID) Spell(mage.game.stack.Spell) SquirrelToken(mage.game.permanent.token.SquirrelToken)

Example 4 with SquirrelToken

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

the class PermanentImpl method doDamage.

/**
 * @param damageAmount
 * @param attackerId   id of the permanent or player who make damage (source.getSourceId() in most cases)
 * @param source
 * @param game
 * @param preventable
 * @param combat
 * @param markDamage   If true, damage will be dealt later in applyDamage
 *                     method, uses only in inner markDamage.
 * @return
 */
private int doDamage(int damageAmount, UUID attackerId, Ability source, Game game, boolean preventable, boolean combat, boolean markDamage, List<UUID> appliedEffects) {
    int damageDone = 0;
    if (damageAmount < 1 || !canDamage(game.getObject(attackerId), game)) {
        return 0;
    }
    DamageEvent event = new DamagePermanentEvent(objectId, attackerId, controllerId, damageAmount, preventable, combat);
    event.setAppliedEffects(appliedEffects);
    if (game.replaceEvent(event)) {
        return 0;
    }
    int actualDamage = checkProtectionAbilities(event, attackerId, source, game);
    if (actualDamage < 1) {
        return 0;
    }
    int lethal = getLethalDamage(attackerId, game);
    MageObject attacker = game.getObject(attackerId);
    if (this.isCreature(game)) {
        if (checkWither(event, attacker, game)) {
            if (markDamage) {
                // mark damage only
                markDamage(CounterType.M1M1.createInstance(actualDamage), attacker, true);
            } else {
                Ability damageSourceAbility = null;
                if (attacker instanceof Permanent) {
                    damageSourceAbility = ((Permanent) attacker).getSpellAbility();
                }
                // deal damage immediately
                addCounters(CounterType.M1M1.createInstance(actualDamage), game.getControllerId(attackerId), damageSourceAbility, game);
            }
        } else {
            this.damage = CardUtil.overflowInc(this.damage, actualDamage);
        }
    }
    if (this.isPlaneswalker(game)) {
        int loyalty = getCounters(game).getCount(CounterType.LOYALTY);
        int countersToRemove = Math.min(actualDamage, loyalty);
        if (attacker != null && markDamage) {
            markDamage(CounterType.LOYALTY.createInstance(countersToRemove), attacker, false);
        } else {
            removeCounters(CounterType.LOYALTY.getName(), countersToRemove, source, game);
        }
    }
    DamagedEvent damagedEvent = new DamagedPermanentEvent(this.getId(), attackerId, this.getControllerId(), actualDamage, combat);
    damagedEvent.setExcess(actualDamage - lethal);
    game.fireEvent(damagedEvent);
    game.getState().addSimultaneousDamage(damagedEvent, game);
    damageDone = actualDamage;
    if (damageDone < 1) {
        return 0;
    }
    UUID sourceControllerId = null;
    Abilities sourceAbilities = null;
    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 {
            attacker = null;
        }
    } else {
        sourceAbilities = ((Permanent) attacker).getAbilities(game);
        sourceControllerId = ((Permanent) attacker).getControllerId();
    }
    if (attacker != null && sourceAbilities != null) {
        if (sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
            if (markDamage) {
                game.getPermanent(attackerId).markLifelink(damageDone);
            } else {
                Player player = game.getPlayer(sourceControllerId);
                player.gainLife(damageDone, game, source);
            }
        }
        if (sourceAbilities.containsKey(DeathtouchAbility.getInstance().getId())) {
            deathtouched = true;
        }
        if (dealtDamageByThisTurn == null) {
            dealtDamageByThisTurn = new HashSet<>();
        }
        // Unstable ability - Earl of Squirrel
        if (sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
            Player player = game.getPlayer(sourceControllerId);
            new SquirrelToken().putOntoBattlefield(damageDone, game, source, player.getId());
        }
        dealtDamageByThisTurn.add(new MageObjectReference(attacker, game));
    }
    if (attacker == null) {
        game.informPlayers(getLogName() + " gets " + damageDone + " damage");
    } else {
        game.informPlayers(attacker.getLogName() + " deals " + damageDone + " damage to " + getLogName());
    }
    return damageDone;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Abilities(mage.abilities.Abilities) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Hint(mage.abilities.hint.Hint) Spell(mage.game.stack.Spell) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) CommandObject(mage.game.command.CommandObject) SquirrelToken(mage.game.permanent.token.SquirrelToken) MageObjectReference(mage.MageObjectReference)

Example 5 with SquirrelToken

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

the class LiegeOfTheHollowsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Map<UUID, Integer> paidMana = new HashMap<>();
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                paidMana.put(player.getId(), ManaUtil.playerPaysXGenericMana(false, "Liege of the Hollows", player, source, game));
            }
        }
        // create tokens
        SquirrelToken token = new SquirrelToken();
        for (Map.Entry<UUID, Integer> entry : paidMana.entrySet()) {
            Player player = game.getPlayer(entry.getKey());
            if (player != null) {
                token.putOntoBattlefield(entry.getValue(), game, source, player.getId());
            }
        }
        game.getState().processAction(game);
        // prevent undo
        controller.resetStoredBookmark(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) 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