Handling preventon effects more improved.

This commit is contained in:
LevelX2 2014-04-23 20:51:21 +02:00
parent b1a930cb4f
commit 81e396555c
5 changed files with 26 additions and 76 deletions

View file

@ -28,26 +28,16 @@
package mage.sets.alarareborn;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.common.PreventAllDamageToAllEffect;
import mage.abilities.keyword.FlashAbility;
import mage.cards.CardImpl;
import mage.constants.TargetController;
import mage.filter.common.FilterCreatureOrPlayer;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.other.PlayerIdPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*

View file

@ -96,24 +96,24 @@ class DivineDeflectionPreventDamageTargetEffect extends PreventionEffectImpl<Div
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, event.getTargetId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
if (amount == -1) {
// define once
amount = source.getManaCostsToPay().getX();
}
int prevented = 0;
int prevented;
if (event.getAmount() >= this.amount) {
int damage = amount;
event.setAmount(event.getAmount() - amount);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, event.getTargetId(), source.getSourceId(), source.getControllerId(), damage));
prevented = damage;
} else {
int damage = event.getAmount();
event.setAmount(0);
amount -= damage;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, event.getTargetId(), source.getSourceId(), source.getControllerId(), damage));
prevented = damage;
}
@ -130,7 +130,7 @@ class DivineDeflectionPreventDamageTargetEffect extends PreventionEffectImpl<Div
if (player != null) {
game.informPlayers("Dealing " + prevented + " to " + player.getName() + " instead");
// keep the original source id as it is redirecting
player.damage(prevented, event.getSourceId(), game, true, false);
player.damage(prevented, event.getSourceId(), game, false, true);
}
}
}
@ -162,14 +162,11 @@ class DivineDeflectionPreventDamageTargetEffect extends PreventionEffectImpl<Div
}
}
// check player
Player player = game.getPlayer(event.getTargetId());
if (player != null) {
if (player.getId().equals(source.getControllerId())) {
if (source.getControllerId().equals(event.getTargetId())) {
// it is you
return true;
}
}
}
return false;
}

View file

@ -28,16 +28,14 @@
package mage.sets.avacynrestored;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectImpl;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
/**
@ -54,7 +52,7 @@ public class TerrifyingPresence extends CardImpl<TerrifyingPresence> {
// Prevent all combat damage that would be dealt by creatures other than target creature this turn.
this.getSpellAbility().addEffect(new TerrifyingPresenceEffect());
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addTarget(new TargetCreaturePermanent(true));
}
public TerrifyingPresence(final TerrifyingPresence card) {
@ -70,7 +68,7 @@ public class TerrifyingPresence extends CardImpl<TerrifyingPresence> {
class TerrifyingPresenceEffect extends PreventionEffectImpl<TerrifyingPresenceEffect> {
public TerrifyingPresenceEffect() {
super(Duration.EndOfTurn);
super(Duration.EndOfTurn, Integer.MAX_VALUE, true);
this.staticText = "Prevent all combat damage that would be dealt by creatures other than target creature this turn";
}
@ -83,37 +81,8 @@ class TerrifyingPresenceEffect extends PreventionEffectImpl<TerrifyingPresenceEf
return new TerrifyingPresenceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
Permanent permanent = game.getPermanent(event.getSourceId());
StringBuilder message = new StringBuilder();
if (permanent != null) {
message.append(" from ").append(permanent.getName());
}
message.insert(0, "Damage").append(" has been prevented: ").append(damage);
event.setAmount(0);
game.informPlayers(message.toString());
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game) && event instanceof DamageEvent) {
DamageEvent damageEvent = (DamageEvent) event;
if (damageEvent.isCombatDamage() && !damageEvent.getSourceId().equals(source.getFirstTarget())) {
return true;
}
}
return false;
return super.applies(event, source, game) && !event.getSourceId().equals(getTargetPointer().getFirst(game, source));
}
}

View file

@ -53,8 +53,6 @@ import java.util.UUID;
*/
public class ClingingMists extends CardImpl<ClingingMists> {
private static final FilterPermanent filter = new FilterPermanent();
public ClingingMists(UUID ownerId) {
super(ownerId, 109, "Clinging Mists", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{2}{G}");
this.expansionSetCode = "DKA";
@ -62,7 +60,7 @@ public class ClingingMists extends CardImpl<ClingingMists> {
this.color.setGreen(true);
// Prevent all combat damage that would be dealt this turn.
this.getSpellAbility().addEffect(new PreventAllDamageByAllEffect(filter, Duration.EndOfTurn, true));
this.getSpellAbility().addEffect(new PreventAllDamageByAllEffect(null, Duration.EndOfTurn, true));
// Fateful hour - If you have 5 or less life, tap all attacking creatures. Those creatures don't untap during their controller's next untap step.
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new ClingingMistsEffect(),

View file

@ -27,11 +27,12 @@
*/
package mage.abilities.effects.common;
import mage.constants.Duration;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.PreventionEffectImpl;
import mage.constants.Duration;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
@ -44,22 +45,18 @@ import mage.game.permanent.Permanent;
public class PreventAllDamageByAllEffect extends PreventionEffectImpl<PreventAllDamageByAllEffect> {
private FilterPermanent filter;
private final boolean onlyCombat;
public PreventAllDamageByAllEffect(FilterPermanent filter, Duration duration, boolean onlyCombat) {
super(duration);
this.filter = filter;
this.onlyCombat = onlyCombat;
public PreventAllDamageByAllEffect(Duration duration) {
this(null, duration, false);
}
public PreventAllDamageByAllEffect(Duration duration, boolean onlyCombat) {
super(duration);
this.onlyCombat = onlyCombat;
this(null, duration, onlyCombat);
}
public PreventAllDamageByAllEffect(Duration duration) {
super(duration);
this.onlyCombat = false;
public PreventAllDamageByAllEffect(FilterCreaturePermanent filter, Duration duration, boolean onlyCombat) {
super(duration, Integer.MAX_VALUE, false);
this.filter = filter;
}
public PreventAllDamageByAllEffect(final PreventAllDamageByAllEffect effect) {
@ -67,7 +64,6 @@ public class PreventAllDamageByAllEffect extends PreventionEffectImpl<PreventAll
if (effect.filter != null) {
this.filter = effect.filter.copy();
}
this.onlyCombat = effect.onlyCombat;
}
@Override