Search in sources :

Example 1 with PhyrexianBeastToken

use of mage.game.permanent.token.PhyrexianBeastToken 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)

Aggregations

HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 Permanent (mage.game.permanent.Permanent)1 PhyrexianBeastToken (mage.game.permanent.token.PhyrexianBeastToken)1 Player (mage.players.Player)1