use of mage.game.events.GameEvent in project mage by magefree.
the class AnowonTheRuinThiefWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
damageMap.clear();
return;
}
if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER || !((DamagedPlayerEvent) event).isCombatDamage()) {
return;
}
Permanent creature = game.getPermanent(event.getSourceId());
if (creature == null || !creature.hasSubtype(SubType.ROGUE, game)) {
return;
}
damageMap.computeIfAbsent(event.getTargetId(), x -> new HashMap<>()).compute(creature.getControllerId(), (uuid, i) -> i == null ? event.getAmount() : event.getAmount() + i);
}
use of mage.game.events.GameEvent in project mage by magefree.
the class MindlinkMechApplier method watch.
@Override
public void watch(GameEvent event, Game game) {
Permanent vehicle;
Permanent crewer;
switch(event.getType()) {
case VEHICLE_CREWED:
vehicle = game.getPermanent(event.getTargetId());
crewer = null;
break;
case CREWED_VEHICLE:
vehicle = game.getPermanent(event.getSourceId());
crewer = game.getPermanent(event.getTargetId());
break;
default:
return;
}
if (vehicle == null) {
return;
}
if (crewer == null) {
crewCount.compute(new MageObjectReference(vehicle, game), (m, i) -> i == null ? 1 : Integer.sum(i, 1));
return;
}
crewMap.computeIfAbsent(new MageObjectReference(vehicle, game), x -> new HashSet<>()).add(new MageObjectReference(crewer, game));
}
use of mage.game.events.GameEvent in project mage by magefree.
the class PilgrimOfVirtueEffect 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);
// one time use
this.used = true;
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
return true;
}
return false;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class PhyrexianHydraEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
boolean retValue = false;
GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
int damage = event.getAmount();
if (!game.replaceEvent(preventEvent)) {
event.setAmount(0);
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
retValue = true;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.addCounters(CounterType.M1M1.createInstance(damage), source.getControllerId(), source, game);
}
return retValue;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class PilgrimOfJusticeEffect 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);
// one time use
this.used = true;
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
return true;
}
return false;
}
Aggregations