Search in sources :

Example 1 with BlockedThisTurnWatcher

use of mage.watchers.common.BlockedThisTurnWatcher 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 BlockedThisTurnWatcher

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

the class VizierOfDefermentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    AttackedThisTurnWatcher watcherAttacked = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    BlockedThisTurnWatcher watcherBlocked = game.getState().getWatcher(BlockedThisTurnWatcher.class);
    boolean attackedOrBlocked = false;
    if (watcherAttacked != null && watcherAttacked.checkIfAttacked(permanent, game)) {
        attackedOrBlocked = true;
    }
    if (watcherBlocked != null && watcherBlocked.checkIfBlocked(permanent, game)) {
        attackedOrBlocked = true;
    }
    if (controller != null && attackedOrBlocked && sourcePermanent != null) {
        if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourcePermanent.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
            Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
            effect.setText("Return that card to the battlefield under its owner's control at the beginning of the next end step");
            effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) BlockedThisTurnWatcher(mage.watchers.common.BlockedThisTurnWatcher)

Example 3 with BlockedThisTurnWatcher

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

the class NoMoreThanOneCreatureCanBlockEachTurnEffect method canBlock.

@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game, boolean canUseChooseDialogs) {
    if (!game.getCombat().getBlockers().isEmpty()) {
        return false;
    }
    BlockedThisTurnWatcher watcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
    if (watcher == null) {
        return false;
    }
    Set<MageObjectReference> blockedThisTurnCreatures = watcher.getBlockedThisTurnCreatures();
    MageObjectReference blockerReference = new MageObjectReference(blocker.getId(), blocker.getZoneChangeCounter(game), game);
    return blockedThisTurnCreatures.isEmpty() || (blockedThisTurnCreatures.size() == 1 && blockedThisTurnCreatures.contains(blockerReference));
}
Also used : BlockedThisTurnWatcher(mage.watchers.common.BlockedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Aggregations

BlockedThisTurnWatcher (mage.watchers.common.BlockedThisTurnWatcher)3 MageObjectReference (mage.MageObjectReference)2 Permanent (mage.game.permanent.Permanent)2 HashSet (java.util.HashSet)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)1 Player (mage.players.Player)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1 FixedTarget (mage.target.targetpointer.FixedTarget)1 AttackedThisTurnWatcher (mage.watchers.common.AttackedThisTurnWatcher)1 WasBlockedThisTurnWatcher (mage.watchers.common.WasBlockedThisTurnWatcher)1