use of mage.game.events.GameEvent in project mage by magefree.
the class BeamsplitterMageApplier method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!isControlledBy(event.getPlayerId())) {
return false;
}
Spell spell = game.getSpellOrLKIStack(event.getTargetId());
if (spell == null || !spell.isInstantOrSorcery(game)) {
return false;
}
if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).anyMatch(uuid -> !getSourceId().equals(uuid) && uuid != null)) {
return false;
}
this.getEffects().setValue("spellCast", spell);
return true;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class FrontierWarmongerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Set<UUID> opponents = game.getOpponents(this.getControllerId());
Predicate<UUID> predicate = uuid -> opponents.contains(game.getCombat().getDefendingPlayerId(uuid, game));
if (game.getCombat().getAttackers().stream().noneMatch(predicate)) {
return false;
}
List<Permanent> permanents = game.getCombat().getAttackers().stream().filter(predicate).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
this.getEffects().setTargetPointer(new FixedTargets(permanents, game));
return true;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class HeartOfLightEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
}
return false;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class HazeFrogEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
Permanent permanent = game.getPermanent(event.getSourceId());
StringBuilder message = new StringBuilder();
if (permanent != null) {
message.append(" from ").append(permanent.getName());
}
message.insert(0, "Damage").append(" has been prevented: ").append(damage);
event.setAmount(0);
game.informPlayers(message.toString());
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
}
return false;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) {
morMap.entrySet().removeIf(e -> !e.getKey().zoneCounterIsCurrent(game));
morMap.values().stream().flatMap(Collection::stream).map(set -> set.removeIf(mor -> !mor.zoneCounterIsCurrent(game)));
morMap.values().removeIf(Set::isEmpty);
return;
}
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null) {
return;
}
morMap.getOrDefault(event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()).removeIf(set -> set.stream().anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId()) && mor.getZoneChangeCounter() + 1 == spell.getZoneChangeCounter(game)));
}
Aggregations