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;
}
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;
}
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));
}
Aggregations