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