use of mage.game.events.DamageEvent in project mage by magefree.
the class TreacherousLinkEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
Player controller = game.getPlayer(source.getControllerId());
DamageEvent damageEvent = (DamageEvent) event;
if (controller != null && enchantment != null) {
Permanent enchantedCreature = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
if (enchantedCreature != null) {
return enchantedCreature.getId().equals(damageEvent.getTargetId());
}
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class TreacherousLinkEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent enchantedCreature = game.getPermanentOrLKIBattlefield(damageEvent.getTargetId());
if (enchantedCreature == null) {
return false;
}
Player controller = game.getPlayer(enchantedCreature.getControllerId());
if (controller == null) {
return false;
}
controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
return true;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class PlaneswalkerRedirectionEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
UUID playerId = getSourceControllerId(event.getSourceId(), game);
if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) {
Player target = game.getPlayer(event.getTargetId());
Player player = game.getPlayer(playerId);
if (target != null && player != null) {
int numPlaneswalkers = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_PLANESWALKER, target.getId(), game);
if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", source, game)) {
redirectTarget = new TargetPermanent(StaticFilters.FILTER_PERMANENT_PLANESWALKER);
if (numPlaneswalkers == 1) {
List<Permanent> planeswalker = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_PLANESWALKER, target.getId(), game);
if (!planeswalker.isEmpty()) {
redirectTarget.add(planeswalker.get(0).getId(), game);
}
} else {
player.choose(Outcome.Damage, redirectTarget, null, game);
}
if (!game.isSimulation()) {
Permanent redirectTo = game.getPermanent(redirectTarget.getFirstTarget());
if (redirectTo != null) {
game.informPlayers(player.getLogName() + " redirects " + event.getAmount() + " damage to " + redirectTo.getLogName());
}
}
return true;
}
}
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class EyeForAnEyeEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
DamageEvent damageEvent = (DamageEvent) event;
if (controller != null) {
if (controller.getId().equals(damageEvent.getTargetId()) && damageEvent.getSourceId().equals(damageSource.getFirstTarget())) {
this.discard();
return true;
}
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class GoblinPsychopathEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
MageObject object = game.getObject(event.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || object == null || !(this.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0)) {
return false;
}
DamageEvent damageEvent = (DamageEvent) event;
if (!damageEvent.isCombatDamage() || wonFlip) {
return false;
}
// TODO: make this redirect damage from all blockers
controller.damage(event.getAmount(), source.getSourceId(), source, game);
String sourceLogName = game.getObject(source.getSourceId()).getLogName() + ": ";
game.informPlayers(sourceLogName + "Redirected " + event.getAmount() + " damage to " + controller.getLogName());
this.discard();
return true;
}
Aggregations