Search in sources :

Example 1 with WasBlockedThisTurnWatcher

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

the class HeatStrokeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    BlockedThisTurnWatcher blockedWatcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
    WasBlockedThisTurnWatcher wasBlockedThisTurnWatcher = game.getState().getWatcher(WasBlockedThisTurnWatcher.class);
    Set<Permanent> inROI = new HashSet<>(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game));
    boolean toRet = false;
    Set<MageObjectReference> toDestroy = new HashSet<>();
    if (blockedWatcher != null) {
        toDestroy.addAll(blockedWatcher.getBlockedThisTurnCreatures());
    }
    if (wasBlockedThisTurnWatcher != null) {
        toDestroy.addAll(wasBlockedThisTurnWatcher.getWasBlockedThisTurnCreatures());
    }
    for (MageObjectReference mor : toDestroy) {
        Permanent permanent = mor.getPermanent(game);
        if (permanent != null && permanent.isCreature(game) && inROI.contains(permanent)) {
            permanent.destroy(source, game, false);
            toRet = true;
        }
    }
    return toRet;
}
Also used : Permanent(mage.game.permanent.Permanent) WasBlockedThisTurnWatcher(mage.watchers.common.WasBlockedThisTurnWatcher) BlockedThisTurnWatcher(mage.watchers.common.BlockedThisTurnWatcher) WasBlockedThisTurnWatcher(mage.watchers.common.WasBlockedThisTurnWatcher) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Example 2 with WasBlockedThisTurnWatcher

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

the class SourceWasBlockedThisTurnCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    WasBlockedThisTurnWatcher watcher = game.getState().getWatcher(WasBlockedThisTurnWatcher.class);
    return sourcePermanent != null && watcher != null && watcher.getWasBlockedThisTurnCreatures().contains(new MageObjectReference(sourcePermanent, game));
}
Also used : Permanent(mage.game.permanent.Permanent) WasBlockedThisTurnWatcher(mage.watchers.common.WasBlockedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)2 Permanent (mage.game.permanent.Permanent)2 WasBlockedThisTurnWatcher (mage.watchers.common.WasBlockedThisTurnWatcher)2 HashSet (java.util.HashSet)1 BlockedThisTurnWatcher (mage.watchers.common.BlockedThisTurnWatcher)1