use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class BoneMaskEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(source.getFirstTarget())) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
this.used = true;
this.discard();
if (preventionData.getPreventedDamage() > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> cardsToMoveToExileFromTopOfLibrary = controller.getLibrary().getTopCards(game, preventionData.getPreventedDamage());
controller.moveCards(cardsToMoveToExileFromTopOfLibrary, Zone.EXILED, source, game);
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class DeflectingPalmEffect 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) {
MageObject damageDealingObject = game.getObject(target.getFirstTarget());
UUID objectControllerId = null;
if (damageDealingObject instanceof Permanent) {
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Ability) {
objectControllerId = ((Ability) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Spell) {
objectControllerId = ((Spell) damageDealingObject).getControllerId();
}
if (objectControllerId != null) {
Player objectController = game.getPlayer(objectControllerId);
if (objectController != null) {
objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class AweStrikeEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(preventionData.getPreventedDamage(), game, source);
}
this.used = true;
this.discard();
return true;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class ComeuppanceEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
if (preventionData.getPreventedDamage() > 0) {
MageObject damageDealingObject = game.getObject(event.getSourceId());
UUID objectControllerId = null;
if (damageDealingObject instanceof Permanent) {
if (damageDealingObject.isCreature(game)) {
((Permanent) damageDealingObject).damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
} else {
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
}
} else if (damageDealingObject instanceof Ability) {
objectControllerId = ((Ability) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Spell) {
objectControllerId = ((Spell) damageDealingObject).getControllerId();
}
if (objectControllerId != null) {
Player objectController = game.getPlayer(objectControllerId);
if (objectController != null) {
objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.abilities.effects.PreventionEffectData in project mage by magefree.
the class HallowPreventDamageByTargetEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionEffectData = preventDamageAction(event, source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(preventionEffectData.getPreventedDamage(), game, source);
}
return true;
}
Aggregations