use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class SwansOfBrynArgollEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionEffectData = preventDamageAction(event, source, game);
if (preventionEffectData.getPreventedDamage() > 0) {
boolean passed = false;
MageObject sourceOfDamage = game.getObject(event.getSourceId());
if (sourceOfDamage != null) {
Spell spell = game.getStack().getSpell(sourceOfDamage.getId());
Permanent permanent = game.getPermanentOrLKIBattlefield(sourceOfDamage.getId());
CommandObject emblem = (CommandObject) game.getEmblem(sourceOfDamage.getId());
if (spell != null) {
Player controllerOfSpell = game.getPlayer(spell.getControllerId());
if (controllerOfSpell != null) {
// original event is not a draw event, so skip it in params
controllerOfSpell.drawCards(preventionEffectData.getPreventedDamage(), source, game);
passed = true;
}
}
if (permanent != null) {
Player controllerOfPermanent = game.getPlayer(permanent.getControllerId());
if (controllerOfPermanent != null) {
// original event is not a draw event, so skip it in params
controllerOfPermanent.drawCards(preventionEffectData.getPreventedDamage(), source, game);
passed = true;
}
}
if (emblem != null) {
Player controllerOfEmblem = game.getPlayer(emblem.getControllerId());
if (controllerOfEmblem != null) {
// original event is not a draw event, so skip it in params
controllerOfEmblem.drawCards(preventionEffectData.getPreventedDamage(), source, game);
}
passed = true;
}
if (!passed) {
// Needed for cards that do damage from hand e.g. Gempalm Incinerator
Card cardSource = game.getCard(event.getSourceId());
if (cardSource != null) {
Player owner = game.getPlayer(cardSource.getOwnerId());
if (owner != null) {
// original event is not a draw event, so skip it in params
owner.drawCards(preventionEffectData.getPreventedDamage(), source, game);
}
}
}
}
}
return preventionEffectData.isReplaced();
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class VengefulArchonEffect method preventDamageAction.
@Override
protected PreventionEffectData preventDamageAction(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionEffectData = super.preventDamageAction(event, source, game);
int damage = preventionEffectData.getPreventedDamage();
if (damage > 0) {
game.damagePlayerOrPlaneswalker(source.getFirstTarget(), damage, source.getSourceId(), source, game, false, true);
}
return preventionEffectData;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class ChannelHarmEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player sourceController = game.getPlayer(source.getControllerId());
PreventionEffectData preventionData = preventDamageAction(event, source, game);
if (preventionData.getPreventedDamage() > 0) {
Permanent targetCreature = game.getPermanent(source.getFirstTarget());
if (targetCreature != null) {
if (sourceController != null && sourceController.chooseUse(outcome, "Have " + preventionData.getPreventedDamage() + " damage dealt to " + targetCreature.getLogName() + "?", source, game)) {
targetCreature.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game, false, true);
}
}
}
return true;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class ChantOfVituGhaziPreventEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(preventionData.getPreventedDamage(), game, source);
}
// damage amount is reduced or set to 0 so complete replacement of damage event is never neccessary
return false;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class ChoArrimAlchemistEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
this.used = true;
// only one use
this.discard();
if (preventionData.getPreventedDamage() > 0) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(preventionData.getPreventedDamage(), game, source);
}
}
return true;
}
Aggregations