Search in sources :

Example 1 with CreatureAttackedWhichPlayerWatcher

use of mage.watchers.common.CreatureAttackedWhichPlayerWatcher in project mage by magefree.

the class NacatlWarPrideEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent origNactalWarPride = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (origNactalWarPride == null) {
        return false;
    }
    CreatureAttackedWhichPlayerWatcher PlayerAttackedWatcher = game.getState().getWatcher(CreatureAttackedWhichPlayerWatcher.class);
    // Count the number of creatures attacked opponent controls
    UUID defenderId = PlayerAttackedWatcher.getPlayerAttackedThisTurnByCreature(source.getSourceId());
    int count = 0;
    if (defenderId != null) {
        count = game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defenderId, game);
    }
    if (count == 0) {
        return false;
    }
    List<Permanent> copies = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(controller.getId(), null, false, count, true, true);
    effect.setTargetPointer(new FixedTarget(origNactalWarPride, game));
    effect.apply(game, source);
    copies.addAll(effect.getAddedPermanents());
    if (!copies.isEmpty()) {
        FixedTargets fixedTargets = new FixedTargets(copies, game);
        ExileTargetEffect exileEffect = new ExileTargetEffect();
        exileEffect.setTargetPointer(fixedTargets).setText("exile the tokens");
        game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ArrayList(java.util.ArrayList) CreatureAttackedWhichPlayerWatcher(mage.watchers.common.CreatureAttackedWhichPlayerWatcher) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) UUID(java.util.UUID) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)1 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 FixedTarget (mage.target.targetpointer.FixedTarget)1 FixedTargets (mage.target.targetpointer.FixedTargets)1 CreatureAttackedWhichPlayerWatcher (mage.watchers.common.CreatureAttackedWhichPlayerWatcher)1