Search in sources :

Example 36 with CreateTokenEffect

use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.

the class EzurisPredationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    /*
         * Players can't cast spells or activate any abilities in between the
         * Beasts entering the battlefield and fighting the other creatures.
         * Ifthe Beasts entering the battlefield cause any abilities to trigger,
         * those abilities will be put onto the stack after Ezuri's Predation is
         * finished resolving.
         * You choose which Beast is fighting which creature
         * an opponent controls. Each of the "fights" happens at the same time.
         * If Ezuri's Predation creates more than one token for any given
         * creature (due to an effect such as the one Doubling Season creates),
         * the extra tokens won't fight any creature.
         */
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterCreaturePermanent filterCreature = new FilterCreaturePermanent();
        filterCreature.add(TargetController.OPPONENT.getControllerPredicate());
        List<Permanent> creaturesOfOpponents = game.getBattlefield().getActivePermanents(filterCreature, source.getControllerId(), source.getSourceId(), game);
        Set<MageObjectReference> morSet = new HashSet<>();
        if (!creaturesOfOpponents.isEmpty()) {
            CreateTokenEffect effect = new CreateTokenEffect(new PhyrexianBeastToken(), creaturesOfOpponents.size());
            effect.apply(game, source);
            for (UUID tokenId : effect.getLastAddedTokenIds()) {
                Permanent token = game.getPermanent(tokenId);
                if (token != null) {
                    if (creaturesOfOpponents.isEmpty()) {
                        break;
                    }
                    Permanent opponentCreature = creaturesOfOpponents.iterator().next();
                    creaturesOfOpponents.remove(opponentCreature);
                    // can be multiple tokens, so must be used custom BATCH_FIGHT event
                    token.fight(opponentCreature, source, game, false);
                    morSet.add(new MageObjectReference(token, game));
                    morSet.add(new MageObjectReference(opponentCreature, game));
                    game.informPlayers(token.getLogName() + " fights " + opponentCreature.getLogName());
                }
            }
            String data = UUID.randomUUID().toString();
            game.getState().setValue("batchFight_" + data, morSet);
            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BATCH_FIGHT, getId(), source, source.getControllerId(), data, 0));
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) PhyrexianBeastToken(mage.game.permanent.token.PhyrexianBeastToken) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Example 37 with CreateTokenEffect

use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.

the class GiltLeafAmbushCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        CreateTokenEffect effect = new CreateTokenEffect(new ElfWarriorToken(), 2);
        effect.apply(game, source);
        if (ClashEffect.getInstance().apply(game, source)) {
            for (UUID tokenId : effect.getLastAddedTokenIds()) {
                Permanent token = game.getPermanent(tokenId);
                if (token != null) {
                    ContinuousEffect continuousEffect = new GainAbilityTargetEffect(DeathtouchAbility.getInstance(), Duration.EndOfTurn);
                    continuousEffect.setTargetPointer(new FixedTarget(tokenId));
                    game.addEffect(continuousEffect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) ElfWarriorToken(mage.game.permanent.token.ElfWarriorToken)

Example 38 with CreateTokenEffect

use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.

the class LastStandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Target opponent loses 2 life for each Swamp you control
        Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (opponent != null) {
            int swamps = game.getBattlefield().count(filterSwamp, source.getSourceId(), source.getControllerId(), game);
            opponent.loseLife(swamps * 2, game, source, false);
        }
        // Last Stand deals damage equal to the number of Mountains you control to target creature.
        Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
        if (creature != null) {
            int mountains = game.getBattlefield().count(filterMountain, source.getSourceId(), source.getControllerId(), game);
            if (mountains > 0) {
                creature.damage(mountains, source.getSourceId(), source, game, false, true);
            }
        }
        // Create a 1/1 green Saproling creature token for each Forest you control.
        int forests = game.getBattlefield().count(filterForest, source.getSourceId(), source.getControllerId(), game);
        if (forests > 0) {
            new CreateTokenEffect(new SaprolingToken(), forests).apply(game, source);
        }
        // You gain 2 life for each Plains you control.
        int plains = game.getBattlefield().count(filterPlains, source.getSourceId(), source.getControllerId(), game);
        controller.gainLife(plains * 2, game, source);
        // Draw a card for each Island you control, then discard that many cards
        int islands = game.getBattlefield().count(filterIsland, source.getSourceId(), source.getControllerId(), game);
        if (islands > 0) {
            controller.drawCards(islands, source, game);
            controller.discard(islands, false, false, source, game);
        }
    }
    return false;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect)

Example 39 with CreateTokenEffect

use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.

the class RapaciousOneTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
        this.getEffects().clear();
        this.addEffect(new CreateTokenEffect(new EldraziSpawnToken(), event.getAmount()));
        return true;
    }
    return false;
}
Also used : CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) EldraziSpawnToken(mage.game.permanent.token.EldraziSpawnToken)

Example 40 with CreateTokenEffect

use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.

the class ValdukKeeperOfTheFlameEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent != null) {
        EquipmentAttachedCount eamount = new EquipmentAttachedCount();
        int value = eamount.calculate(game, source, this);
        AuraAttachedCount aamount = new AuraAttachedCount();
        value += aamount.calculate(game, source, this);
        CreateTokenEffect effect = new CreateTokenEffect(new ValdukElementalToken(), value);
        if (effect.apply(game, source)) {
            effect.exileTokensCreatedAtNextEndStep(game, source);
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) EquipmentAttachedCount(mage.abilities.dynamicvalue.common.EquipmentAttachedCount) ValdukElementalToken(mage.game.permanent.token.ValdukElementalToken) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) AuraAttachedCount(mage.abilities.dynamicvalue.common.AuraAttachedCount)

Aggregations

CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)68 Player (mage.players.Player)45 Permanent (mage.game.permanent.Permanent)31 UUID (java.util.UUID)25 FixedTarget (mage.target.targetpointer.FixedTarget)11 OneShotEffect (mage.abilities.effects.OneShotEffect)8 Effect (mage.abilities.effects.Effect)7 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)7 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)7 ContinuousEffect (mage.abilities.effects.ContinuousEffect)6 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)4 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)4 Cost (mage.abilities.costs.Cost)4 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)4 HashSet (java.util.HashSet)3 MageObjectReference (mage.MageObjectReference)3 Ability (mage.abilities.Ability)3 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)3