use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.
the class MetzaliTowerOfTriumphEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Watcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher instanceof AttackedThisTurnWatcher) {
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
List<Permanent> available = new ArrayList<>();
for (MageObjectReference mor : attackedThisTurn) {
Permanent permanent = mor.getPermanent(game);
if (permanent != null && permanent.isCreature(game)) {
available.add(permanent);
}
}
if (!available.isEmpty()) {
Permanent permanent = available.get(RandomUtil.nextInt(available.size()));
if (permanent != null) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.
the class AttacksFirstTimeTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getSourceId().equals(this.getSourceId())) {
return false;
}
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher == null) {
return false;
}
Permanent sourcePerm = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (sourcePerm == null) {
return false;
}
for (MageObjectReference mor : watcher.getAttackedThisTurnCreaturesCounts().keySet()) {
if (mor.refersTo(sourcePerm, game) && watcher.getAttackedThisTurnCreaturesCounts().get(mor) > 1) {
return false;
}
}
return true;
}
use of mage.watchers.common.AttackedThisTurnWatcher 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.AttackedThisTurnWatcher in project mage by magefree.
the class NoMoreThanOneCreatureCanBlockEachTurnEffect method canAttack.
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
if (!game.getCombat().getAttackers().isEmpty()) {
return false;
}
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher == null) {
return false;
}
Set<MageObjectReference> attackedThisTurnCreatures = watcher.getAttackedThisTurnCreatures();
return attackedThisTurnCreatures.isEmpty() || (attackedThisTurnCreatures.size() == 1 && attackedThisTurnCreatures.contains(new MageObjectReference(attacker, game)));
}
use of mage.watchers.common.AttackedThisTurnWatcher in project mage by magefree.
the class ErgRaidersCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent raiders = game.getPermanentOrLKIBattlefield(source.getSourceId());
AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
// wasControlledFromStartOfControllerTurn should be checked during resolution I guess, but shouldn't be relevant
return raiders != null && raiders.wasControlledFromStartOfControllerTurn() && watcher != null && !watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(raiders, game));
}
Aggregations