use of mage.game.events.DamageEvent in project mage by magefree.
the class KithkinArmorPreventionEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0 && !this.used) {
UUID enchantedCreatureId = (UUID) game.getState().getValue(source.getSourceId().toString() + "attachedToPermanent");
DamageEvent damageEvent = (DamageEvent) event;
if (enchantedCreatureId != null && event.getTargetId().equals(enchantedCreatureId) && damageEvent.getSourceId().equals(source.getFirstTarget())) {
this.used = true;
this.discard();
return true;
}
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class LichenthropeEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
p.addCounters(CounterType.M1M1.createInstance(damageEvent.getAmount()), source.getControllerId(), source, game);
}
return true;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class PalisadeGiantReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
// get name of old target
Permanent targetPermanent = game.getPermanent(event.getTargetId());
StringBuilder message = new StringBuilder();
message.append(sourcePermanent.getName()).append(": gets ");
message.append(damageEvent.getAmount()).append(" damage redirected from ");
if (targetPermanent != null) {
message.append(targetPermanent.getName());
} else {
Player targetPlayer = game.getPlayer(event.getTargetId());
if (targetPlayer != null) {
message.append(targetPlayer.getLogName());
} else {
message.append("unknown");
}
}
game.informPlayers(message.toString());
// redirect damage
sourcePermanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class PhytohydraEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
p.addCounters(CounterType.P1P1.createInstance(damageEvent.getAmount()), source.getControllerId(), source, game);
}
return true;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class PhyrexianUnlifeEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!event.getPlayerId().equals(source.getControllerId())) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
// and all damage in the same step has to be handled the same beause by the rules it's all done at once
if (((DamageEvent) event).isCombatDamage()) {
if (lastCheckedDamageStepNum != game.getState().getStepNum()) {
lastCheckedDamageStepNum = game.getState().getStepNum();
startedWithLifeAboveZero = player.getLife() > 0;
}
if (startedWithLifeAboveZero) {
return false;
}
}
if (player.getLife() < 1) {
return true;
}
return false;
}
Aggregations