use of mage.abilities.effects.common.PreventDamageToTargetEffect in project mage by magefree.
the class WojekApothecaryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
if (target != null) {
ObjectColor color = target.getColor(game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (permanent.getColor(game).shares(color)) {
ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.PreventDamageToTargetEffect in project mage by magefree.
the class ErrantMinionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent errantMinion = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (errantMinion == null) {
return false;
}
Permanent enchantedCreature = game.getPermanentOrLKIBattlefield(errantMinion.getAttachedTo());
if (enchantedCreature == null) {
return false;
}
Player controllerOfEnchantedCreature = game.getPlayer(enchantedCreature.getControllerId());
if (controllerOfEnchantedCreature != null && controllerOfEnchantedCreature.canRespond()) {
int manaPaid = ManaUtil.playerPaysXGenericMana(false, "Errant Minion", controllerOfEnchantedCreature, source, game);
if (manaPaid > 0) {
PreventDamageToTargetEffect effect = new PreventDamageToTargetEffect(Duration.OneUse, manaPaid);
effect.setTargetPointer(new FixedTarget(controllerOfEnchantedCreature.getId()));
game.addEffect(effect, source);
DamageTargetEffect effect2 = new DamageTargetEffect(2);
effect2.setTargetPointer(new FixedTarget(controllerOfEnchantedCreature.getId()));
effect2.apply(game, source);
return true;
}
}
return false;
}
use of mage.abilities.effects.common.PreventDamageToTargetEffect in project mage by magefree.
the class GuardianAngelDelayedTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
String targetName = "";
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer == null) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent == null) {
return true;
}
targetName = targetPermanent.getIdName();
} else {
targetName = "player " + targetPlayer.getName();
}
ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, source.getManaCostsToPay().getX(), false);
effect.setTargetPointer(getTargetPointer());
game.addEffect(effect, source);
SpecialAction specialAction = new GuardianAngelAction();
specialAction.getEffects().get(0).setTargetPointer(getTargetPointer());
specialAction.getEffects().get(0).setText("Prevent the next 1 damage that would be dealt to any target this turn (" + targetName + ").");
new CreateSpecialActionEffect(specialAction).apply(game, source);
// Create a hidden delayed triggered ability to remove the special action at end of turn.
new CreateDelayedTriggeredAbilityEffect(new GuardianAngelDelayedTriggeredAbility(specialAction.getId()), false).apply(game, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.PreventDamageToTargetEffect in project mage by magefree.
the class ElvishHealerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int toPrevent = 1;
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null && permanent.isCreature(game) && permanent.getColor(game).isGreen()) {
toPrevent = 2;
}
game.addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, toPrevent).setTargetPointer(new FixedTarget(source.getFirstTarget(), game)), source);
return true;
}
use of mage.abilities.effects.common.PreventDamageToTargetEffect in project mage by magefree.
the class KitsunePalliatorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
PreventDamageToTargetEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game);
for (Permanent permanent : permanents) {
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
effect.setTargetPointer(new FixedTarget(player.getId()));
game.addEffect(effect, source);
}
}
return false;
}
Aggregations