Search in sources :

Example 1 with AttackedOrBlockedThisCombatWatcher

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

the class KytheonHeroOfAkrosCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (sourceObject != null) {
        AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
        if (watcher != null) {
            boolean sourceFound = false;
            int number = 0;
            for (MageObjectReference mor : watcher.getAttackedThisTurnCreatures()) {
                if (mor.refersTo(sourceObject, game)) {
                    sourceFound = true;
                } else {
                    number++;
                }
            }
            return sourceFound && number >= 2;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedOrBlockedThisCombatWatcher(mage.watchers.common.AttackedOrBlockedThisCombatWatcher) MageObjectReference(mage.MageObjectReference)

Example 2 with AttackedOrBlockedThisCombatWatcher

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

the class TotalWarDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    if (activePlayer != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(activePlayer.getId())) {
            // Noncreature cards are safe.
            if (!permanent.isCreature(game)) {
                continue;
            }
            // Tapped cards are safe.
            if (permanent.isTapped()) {
                continue;
            }
            // Walls are safe.
            if (permanent.hasSubtype(SubType.WALL, game)) {
                continue;
            }
            // Creatures that attacked are safe.
            AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
            if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
                continue;
            }
            // Creatures that weren't controlled since the beginning of turn are safe.
            if (!permanent.wasControlledFromStartOfControllerTurn()) {
                continue;
            }
            // Destroy the rest.
            permanent.destroy(source, game, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AttackedOrBlockedThisCombatWatcher(mage.watchers.common.AttackedOrBlockedThisCombatWatcher) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)2 Permanent (mage.game.permanent.Permanent)2 AttackedOrBlockedThisCombatWatcher (mage.watchers.common.AttackedOrBlockedThisCombatWatcher)2 Player (mage.players.Player)1