Search in sources :

Example 11 with AttackedThisTurnWatcher

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

the class AngelsTrumpetTapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player != null) {
        int count = 0;
        for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game)) {
            // Untapped creatures are safe.
            if (creature.isTapped()) {
                continue;
            }
            // Creatures that attacked are safe.
            AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
            if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(creature, game))) {
                continue;
            }
            // Tap the rest.
            creature.tap(source, game);
            count++;
        }
        if (count > 0) {
            player.damage(count, source.getSourceId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Aggregations

AttackedThisTurnWatcher (mage.watchers.common.AttackedThisTurnWatcher)11 MageObjectReference (mage.MageObjectReference)9 Permanent (mage.game.permanent.Permanent)9 Player (mage.players.Player)5 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Ability (mage.abilities.Ability)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 RequirementEffect (mage.abilities.effects.RequirementEffect)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 DestroyTargetEffect (mage.abilities.effects.common.DestroyTargetEffect)1 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)1 AttacksIfAbleAllEffect (mage.abilities.effects.common.combat.AttacksIfAbleAllEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1