use of mage.game.events.DamageEvent in project mage by magefree.
the class ImmortalCoilPreventionEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (game.replaceEvent(new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()))) {
return false;
}
int damage = event.getAmount();
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(Math.min(damage, player.getGraveyard().size()), StaticFilters.FILTER_CARD);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
player.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
event.setAmount(0);
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class MirrorStrikeEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
DamageEvent damageEvent = (DamageEvent) event;
if (controller != null) {
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
if (targetPermanent != null) {
Player targetsController = game.getPlayer(targetPermanent.getControllerId());
if (targetsController != null) {
targetsController.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
return true;
}
}
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class RedirectionEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
int damageToRedirect = event.getAmount();
if (damageToRedirect < 1) {
// if multiple replacement effect apply, the rest damage can be 0, so the effect is not applied/replaced
return false;
}
String sourceLogName = source != null ? game.getObject(source.getSourceId()).getLogName() + ": " : "";
DamageEvent damageEvent = (DamageEvent) event;
int restDamage = 0;
if (damageEvent.getAmount() > amountToRedirect) {
restDamage = damageEvent.getAmount() - amountToRedirect;
damageToRedirect = amountToRedirect;
}
if (damageToRedirect > 0 && usageType != UsageType.ACCORDING_DURATION) {
if (UsageType.ONE_USAGE_ABSOLUTE == usageType) {
this.discard();
}
if (applyEffectsCounter > 0) {
if (applyEffectsCounter < game.getState().getApplyEffectsCounter()) {
this.discard();
return false;
}
} else {
applyEffectsCounter = game.getState().getApplyEffectsCounter();
}
}
Permanent permanent = game.getPermanent(redirectTarget.getFirstTarget());
if (permanent != null) {
permanent.damage(damageToRedirect, event.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
game.informPlayers(sourceLogName + "Redirected " + damageToRedirect + " damage" + getRedirectedFromText(event, game) + " to " + permanent.getLogName());
} else {
Player player = game.getPlayer(redirectTarget.getFirstTarget());
if (player != null) {
player.damage(damageToRedirect, event.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
game.informPlayers(sourceLogName + "Redirected " + damageToRedirect + " damage" + getRedirectedFromText(event, game) + " to " + player.getLogName());
}
}
if (restDamage > 0) {
damageEvent.setAmount(restDamage);
return false;
}
return true;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class CamelEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null && sourcePermanent.isAttacking() && (event.getTargetId().equals(source.getSourceId()) || sourcePermanent.getBandedCards().contains(event.getTargetId()))) {
Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
if (filter.match(permanent, game)) {
return true;
}
}
}
return false;
}
use of mage.game.events.DamageEvent in project mage by magefree.
the class BloodOfTheMartyrEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
DamageEvent damageEvent = (DamageEvent) event;
if (controller != null) {
controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
return true;
}
return false;
}
Aggregations