From 9cf1ee2f426ebd7ed83bf6c324f3b9cd03a0e16f Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 24 Dec 2019 10:53:51 +0400 Subject: [PATCH] Questing Beast - fixed rollback error on damage prevent (#6116); --- .../src/mage/cards/a/AcolytesReward.java | 4 +- Mage.Sets/src/mage/cards/a/AuriokReplica.java | 16 +++--- .../src/mage/cards/b/BattletideAlchemist.java | 9 +-- .../src/mage/cards/b/BraceForImpact.java | 13 ++--- Mage.Sets/src/mage/cards/c/CandlesGlow.java | 12 ++-- Mage.Sets/src/mage/cards/e/EnergyField.java | 10 ++-- .../src/mage/cards/g/GhostsOfTheInnocent.java | 15 ++--- .../src/mage/cards/g/GideonsIntervention.java | 13 ++--- Mage.Sets/src/mage/cards/g/GloomSurgeon.java | 20 +++---- Mage.Sets/src/mage/cards/g/Godtoucher.java | 17 +++--- Mage.Sets/src/mage/cards/h/HazeFrog.java | 16 +++--- Mage.Sets/src/mage/cards/h/HeartOfLight.java | 19 +++---- Mage.Sets/src/mage/cards/i/ImmortalCoil.java | 15 +++-- Mage.Sets/src/mage/cards/m/MagebaneArmor.java | 23 +++----- .../src/mage/cards/p/PersonalSanctuary.java | 11 ++-- .../src/mage/cards/p/PhyrexianHydra.java | 18 +++--- .../src/mage/cards/p/PilgrimOfJustice.java | 29 +++++----- .../src/mage/cards/p/PilgrimOfVirtue.java | 22 +++----- Mage.Sets/src/mage/cards/q/QuestingBeast.java | 4 +- .../src/mage/cards/s/ShieldOfTheAvatar.java | 4 +- .../src/mage/cards/s/StonewiseFortifier.java | 17 +++--- Mage.Sets/src/mage/cards/t/Temper.java | 13 ++--- Mage.Sets/src/mage/cards/t/TestOfFaith.java | 15 +++-- .../src/mage/cards/u/UnbreathingHorde.java | 15 +++-- Mage.Sets/src/mage/cards/v/Vigor.java | 27 ++++----- .../continuous/ConditionalPreventionTest.java | 56 +++++++++++++++++++ .../java/org/mage/test/load/LoadTest.java | 7 +-- ...reventDamageToTargetMultiAmountEffect.java | 12 ++-- Mage/src/main/java/mage/game/GameImpl.java | 2 +- .../main/java/mage/game/events/GameEvent.java | 1 + .../mage/game/events/PreventDamageEvent.java | 17 ++++++ .../mage/game/permanent/PermanentImpl.java | 11 ++-- 32 files changed, 260 insertions(+), 223 deletions(-) create mode 100644 Mage/src/main/java/mage/game/events/PreventDamageEvent.java diff --git a/Mage.Sets/src/mage/cards/a/AcolytesReward.java b/Mage.Sets/src/mage/cards/a/AcolytesReward.java index 8bbb118fee..6dfe74d903 100644 --- a/Mage.Sets/src/mage/cards/a/AcolytesReward.java +++ b/Mage.Sets/src/mage/cards/a/AcolytesReward.java @@ -11,7 +11,9 @@ import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.Duration; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetAnyTarget; @@ -85,7 +87,7 @@ class AcolytesRewardEffect extends PreventionEffectImpl { } else { amount = 0; } - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getControllerId(), source.getSourceId(), source.getControllerId(), toPrevent, false); + GameEvent preventEvent = new PreventDamageEvent(source.getControllerId(), source.getSourceId(), source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { Permanent targetCreature = game.getPermanent(source.getFirstTarget()); if (targetCreature != null) { diff --git a/Mage.Sets/src/mage/cards/a/AuriokReplica.java b/Mage.Sets/src/mage/cards/a/AuriokReplica.java index fec795b60a..e8c4105c65 100644 --- a/Mage.Sets/src/mage/cards/a/AuriokReplica.java +++ b/Mage.Sets/src/mage/cards/a/AuriokReplica.java @@ -1,8 +1,5 @@ - - package mage.cards.a; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; @@ -16,17 +13,20 @@ import mage.constants.Duration; import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.target.TargetSource; +import java.util.UUID; + /** - * * @author BetaSteward_at_googlemail.com */ public final class AuriokReplica extends CardImpl { public AuriokReplica(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{3}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); this.subtype.add(SubType.CLERIC); this.power = new MageInt(2); this.toughness = new MageInt(2); @@ -77,7 +77,7 @@ class AuriokReplicaEffect extends PreventionEffectImpl { } private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(target, source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); @@ -88,9 +88,7 @@ class AuriokReplicaEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(this.getTargetPointer().getFirst(game, source))) { - return true; - } + return event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(this.getTargetPointer().getFirst(game, source)); } return false; } diff --git a/Mage.Sets/src/mage/cards/b/BattletideAlchemist.java b/Mage.Sets/src/mage/cards/b/BattletideAlchemist.java index 345086c7df..8a03fb89a7 100644 --- a/Mage.Sets/src/mage/cards/b/BattletideAlchemist.java +++ b/Mage.Sets/src/mage/cards/b/BattletideAlchemist.java @@ -1,8 +1,5 @@ - package mage.cards.b; -import java.util.UUID; - import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -13,10 +10,14 @@ import mage.cards.CardSetInfo; import mage.constants.*; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; +import mage.game.events.PreventDamageEvent; import mage.players.Player; +import java.util.UUID; + /** * @author emerald000 */ @@ -67,7 +68,7 @@ class BattletideAlchemistEffect extends PreventionEffectImpl { int numberOfClericsControlled = new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent(SubType.CLERIC, "Clerics")).calculate(game, source, this); int toPrevent = Math.min(numberOfClericsControlled, event.getAmount()); if (toPrevent > 0 && controller.chooseUse(Outcome.PreventDamage, "Prevent " + toPrevent + " damage to " + targetPlayer.getName() + '?', source, game)) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, targetPlayer.getId(), source.getSourceId(), source.getControllerId(), toPrevent, false); + GameEvent preventEvent = new PreventDamageEvent(targetPlayer.getId(), source.getSourceId(), source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { if (event.getAmount() >= toPrevent) { event.setAmount(event.getAmount() - toPrevent); diff --git a/Mage.Sets/src/mage/cards/b/BraceForImpact.java b/Mage.Sets/src/mage/cards/b/BraceForImpact.java index 6b5a458592..507b658c5a 100644 --- a/Mage.Sets/src/mage/cards/b/BraceForImpact.java +++ b/Mage.Sets/src/mage/cards/b/BraceForImpact.java @@ -1,7 +1,5 @@ - package mage.cards.b; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.PreventionEffectImpl; import mage.cards.CardImpl; @@ -12,12 +10,15 @@ import mage.counters.CounterType; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.MulticoloredPredicate; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** - * * @author TheElk801 */ public final class BraceForImpact extends CardImpl { @@ -69,7 +70,7 @@ class BraceForImpactPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int prevented = 0; int damage = event.getAmount(); @@ -93,9 +94,7 @@ class BraceForImpactPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (!this.used && super.applies(event, source, game)) { - if (source.getTargets().getFirstTarget().equals(event.getTargetId())) { - return true; - } + return source.getTargets().getFirstTarget().equals(event.getTargetId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/c/CandlesGlow.java b/Mage.Sets/src/mage/cards/c/CandlesGlow.java index 7bf8e711e2..8c9d5388e7 100644 --- a/Mage.Sets/src/mage/cards/c/CandlesGlow.java +++ b/Mage.Sets/src/mage/cards/c/CandlesGlow.java @@ -1,4 +1,3 @@ - package mage.cards.c; import mage.abilities.Ability; @@ -10,20 +9,21 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.constants.SubType; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.players.Player; import mage.target.common.TargetAnyTarget; import java.util.UUID; /** - * * @author LevelX2 */ public final class CandlesGlow extends CardImpl { public CandlesGlow(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); this.subtype.add(SubType.ARCANE); @@ -70,7 +70,7 @@ class CandlesGlowPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int prevented; if (event.getAmount() >= this.amount) { @@ -103,9 +103,7 @@ class CandlesGlowPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (!this.used && super.applies(event, source, game)) { - if (source.getTargets().getFirstTarget().equals(event.getTargetId())) { - return true; - } + return source.getTargets().getFirstTarget().equals(event.getTargetId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/e/EnergyField.java b/Mage.Sets/src/mage/cards/e/EnergyField.java index 21c02de9db..1b5fb3d65c 100644 --- a/Mage.Sets/src/mage/cards/e/EnergyField.java +++ b/Mage.Sets/src/mage/cards/e/EnergyField.java @@ -1,8 +1,5 @@ - package mage.cards.e; -import java.util.Objects; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.PutCardIntoGraveFromAnywhereAllTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; @@ -15,7 +12,12 @@ import mage.constants.Duration; import mage.constants.TargetController; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; + +import java.util.Objects; +import java.util.UUID; /** * @author Plopman @@ -57,7 +59,7 @@ class EnergyFieldEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); diff --git a/Mage.Sets/src/mage/cards/g/GhostsOfTheInnocent.java b/Mage.Sets/src/mage/cards/g/GhostsOfTheInnocent.java index 0794ca9b82..46c1c582f2 100644 --- a/Mage.Sets/src/mage/cards/g/GhostsOfTheInnocent.java +++ b/Mage.Sets/src/mage/cards/g/GhostsOfTheInnocent.java @@ -1,7 +1,5 @@ - package mage.cards.g; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -9,17 +7,16 @@ import mage.abilities.effects.PreventionEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; +import mage.game.events.PreventDamageEvent; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class GhostsOfTheInnocent extends CardImpl { @@ -81,7 +78,7 @@ class GhostsOfTheInnocentPreventDamageEffect extends ReplacementEffectImpl imple @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { int amount = (int) Math.ceil(event.getAmount() / 2.0); - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, event.getTargetId(), source.getSourceId(), source.getControllerId(), amount, false); + GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source.getControllerId(), amount, ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { event.setAmount(event.getAmount() - amount); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, event.getTargetId(), source.getSourceId(), source.getControllerId(), amount)); diff --git a/Mage.Sets/src/mage/cards/g/GideonsIntervention.java b/Mage.Sets/src/mage/cards/g/GideonsIntervention.java index 91e539b291..9ab17cfb9b 100644 --- a/Mage.Sets/src/mage/cards/g/GideonsIntervention.java +++ b/Mage.Sets/src/mage/cards/g/GideonsIntervention.java @@ -1,7 +1,5 @@ - package mage.cards.g; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.AsEntersBattlefieldAbility; @@ -17,12 +15,15 @@ import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author spjspj */ public final class GideonsIntervention extends CardImpl { @@ -88,9 +89,7 @@ class GideonsInterventionCantCastEffect extends ContinuousRuleModifyingEffectImp String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { MageObject object = game.getObject(event.getSourceId()); - if (object != null && object.getName().equals(cardName)) { - return true; - } + return object != null && object.getName().equals(cardName); } return false; } @@ -119,7 +118,7 @@ class GideonsInterventionPreventAllDamageEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); diff --git a/Mage.Sets/src/mage/cards/g/GloomSurgeon.java b/Mage.Sets/src/mage/cards/g/GloomSurgeon.java index 6cc105ef46..cad1dd1723 100644 --- a/Mage.Sets/src/mage/cards/g/GloomSurgeon.java +++ b/Mage.Sets/src/mage/cards/g/GloomSurgeon.java @@ -1,30 +1,28 @@ - package mage.cards.g; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.events.DamageCreatureEvent; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.players.Player; +import java.util.UUID; + /** * @author noxx */ public final class GloomSurgeon extends CardImpl { public GloomSurgeon(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B}"); this.subtype.add(SubType.SPIRIT); this.power = new MageInt(2); @@ -57,7 +55,7 @@ class GloomSurgeonEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int preventedDamage = event.getAmount(); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), preventedDamage)); @@ -79,9 +77,7 @@ class GloomSurgeonEffect extends ReplacementEffectImpl { public boolean applies(GameEvent event, Ability source, Game game) { if (event.getTargetId().equals(source.getSourceId())) { DamageCreatureEvent damageEvent = (DamageCreatureEvent) event; - if (damageEvent.isCombatDamage()) { - return true; - } + return damageEvent.isCombatDamage(); } return false; } diff --git a/Mage.Sets/src/mage/cards/g/Godtoucher.java b/Mage.Sets/src/mage/cards/g/Godtoucher.java index 5040f7f519..3fcb348b95 100644 --- a/Mage.Sets/src/mage/cards/g/Godtoucher.java +++ b/Mage.Sets/src/mage/cards/g/Godtoucher.java @@ -1,7 +1,5 @@ - package mage.cards.g; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; @@ -10,19 +8,18 @@ import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.PreventionEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.ComparisonType; -import mage.constants.Duration; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.PowerPredicate; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** - * * @author North */ public final class Godtoucher extends CardImpl { @@ -34,7 +31,7 @@ public final class Godtoucher extends CardImpl { } public Godtoucher(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}"); this.subtype.add(SubType.ELF); this.subtype.add(SubType.CLERIC); @@ -82,7 +79,7 @@ class GodtoucherEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); diff --git a/Mage.Sets/src/mage/cards/h/HazeFrog.java b/Mage.Sets/src/mage/cards/h/HazeFrog.java index 7c8cb06c7b..27c439dfcc 100644 --- a/Mage.Sets/src/mage/cards/h/HazeFrog.java +++ b/Mage.Sets/src/mage/cards/h/HazeFrog.java @@ -1,7 +1,5 @@ - package mage.cards.h; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; @@ -10,21 +8,23 @@ import mage.abilities.keyword.FlashAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author jeffwadsworth */ public final class HazeFrog extends CardImpl { public HazeFrog(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}{G}"); this.subtype.add(SubType.FROG); this.power = new MageInt(2); @@ -70,7 +70,7 @@ class HazeFrogEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); Permanent permanent = game.getPermanent(event.getSourceId()); @@ -90,9 +90,7 @@ class HazeFrogEffect extends PreventionEffectImpl { 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.getSourceId())) { - return true; - } + return damageEvent.isCombatDamage() && !damageEvent.getSourceId().equals(source.getSourceId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/h/HeartOfLight.java b/Mage.Sets/src/mage/cards/h/HeartOfLight.java index 394934b599..1522a9fd0f 100644 --- a/Mage.Sets/src/mage/cards/h/HeartOfLight.java +++ b/Mage.Sets/src/mage/cards/h/HeartOfLight.java @@ -1,7 +1,5 @@ - package mage.cards.h; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.PreventionEffectImpl; @@ -9,25 +7,24 @@ import mage.abilities.effects.common.AttachEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** * @author LevelX2 */ public final class HeartOfLight extends CardImpl { public HeartOfLight(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); this.subtype.add(SubType.AURA); @@ -75,7 +72,7 @@ class HeartOfLightEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); @@ -89,9 +86,7 @@ class HeartOfLightEffect extends PreventionEffectImpl { if (super.applies(event, source, game) && event instanceof DamageEvent) { Permanent aura = game.getPermanent(source.getSourceId()); if (aura != null && aura.getAttachedTo() != null) { - if (event.getSourceId().equals(aura.getAttachedTo()) || event.getTargetId().equals(aura.getAttachedTo())) { - return true; - } + return event.getSourceId().equals(aura.getAttachedTo()) || event.getTargetId().equals(aura.getAttachedTo()); } } return false; diff --git a/Mage.Sets/src/mage/cards/i/ImmortalCoil.java b/Mage.Sets/src/mage/cards/i/ImmortalCoil.java index bbee2875fe..6c52b2592a 100644 --- a/Mage.Sets/src/mage/cards/i/ImmortalCoil.java +++ b/Mage.Sets/src/mage/cards/i/ImmortalCoil.java @@ -1,7 +1,5 @@ - package mage.cards.i; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.StateTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; @@ -21,18 +19,21 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.FilterCard; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.players.Player; import mage.target.common.TargetCardInYourGraveyard; +import java.util.UUID; + /** - * * @author Plopman */ public final class ImmortalCoil extends CardImpl { public ImmortalCoil(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{2}{B}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}{B}{B}"); // {tap}, Exile two cards from your graveyard: Draw a card. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), new TapSourceCost()); @@ -133,7 +134,7 @@ class PreventAllDamageToControllerEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); Player player = game.getPlayer(source.getControllerId()); @@ -157,9 +158,7 @@ class PreventAllDamageToControllerEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId())) { - return true; - } + return event.getTargetId().equals(source.getControllerId()); } return false; diff --git a/Mage.Sets/src/mage/cards/m/MagebaneArmor.java b/Mage.Sets/src/mage/cards/m/MagebaneArmor.java index 2f320ff8fc..794fc2f3c4 100644 --- a/Mage.Sets/src/mage/cards/m/MagebaneArmor.java +++ b/Mage.Sets/src/mage/cards/m/MagebaneArmor.java @@ -1,7 +1,5 @@ - package mage.cards.m; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.StaticAbility; import mage.abilities.common.SimpleStaticAbility; @@ -13,25 +11,22 @@ import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.AttachmentType; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author North */ public final class MagebaneArmor extends CardImpl { public MagebaneArmor(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{3}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); this.subtype.add(SubType.EQUIPMENT); // Equipped creature gets +2/+4 and loses flying. @@ -99,7 +94,7 @@ class MagebaneArmorPreventionEffect extends PreventionEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent equipment = game.getPermanent(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, equipment.getAttachedTo(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(equipment.getAttachedTo(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); @@ -114,10 +109,8 @@ class MagebaneArmorPreventionEffect extends PreventionEffectImpl { public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game) && !((DamageEvent) event).isCombatDamage()) { Permanent equipment = game.getPermanent(source.getSourceId()); - if (equipment != null && equipment.getAttachedTo() != null - && event.getTargetId().equals(equipment.getAttachedTo())) { - return true; - } + return equipment != null && equipment.getAttachedTo() != null + && event.getTargetId().equals(equipment.getAttachedTo()); } return false; } diff --git a/Mage.Sets/src/mage/cards/p/PersonalSanctuary.java b/Mage.Sets/src/mage/cards/p/PersonalSanctuary.java index 2a0cdb373b..56a263d736 100644 --- a/Mage.Sets/src/mage/cards/p/PersonalSanctuary.java +++ b/Mage.Sets/src/mage/cards/p/PersonalSanctuary.java @@ -1,7 +1,5 @@ - package mage.cards.p; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.PreventionEffectImpl; @@ -11,16 +9,19 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; + +import java.util.UUID; /** - * * @author nantuko */ public final class PersonalSanctuary extends CardImpl { public PersonalSanctuary(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); // During your turn, prevent all damage that would be dealt to you. @@ -50,7 +51,7 @@ class PersonalSanctuaryEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); diff --git a/Mage.Sets/src/mage/cards/p/PhyrexianHydra.java b/Mage.Sets/src/mage/cards/p/PhyrexianHydra.java index a1ca5c20d1..390f8a5ca6 100644 --- a/Mage.Sets/src/mage/cards/p/PhyrexianHydra.java +++ b/Mage.Sets/src/mage/cards/p/PhyrexianHydra.java @@ -1,8 +1,5 @@ - - package mage.cards.p; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -11,22 +8,25 @@ import mage.abilities.keyword.InfectAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author BetaSteward_at_googlemail.com */ public final class PhyrexianHydra extends CardImpl { public PhyrexianHydra(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}{G}"); this.subtype.add(SubType.HYDRA); this.power = new MageInt(7); @@ -71,7 +71,7 @@ class PhyrexianHydraEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { boolean retValue = false; - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); int damage = event.getAmount(); if (!game.replaceEvent(preventEvent)) { event.setAmount(0); @@ -88,9 +88,7 @@ class PhyrexianHydraEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getSourceId())) { - return true; - } + return event.getTargetId().equals(source.getSourceId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/p/PilgrimOfJustice.java b/Mage.Sets/src/mage/cards/p/PilgrimOfJustice.java index 3f2887bf10..728b63f226 100644 --- a/Mage.Sets/src/mage/cards/p/PilgrimOfJustice.java +++ b/Mage.Sets/src/mage/cards/p/PilgrimOfJustice.java @@ -1,7 +1,5 @@ - package mage.cards.p; -import java.util.UUID; import mage.MageInt; import mage.ObjectColor; import mage.abilities.Ability; @@ -12,25 +10,24 @@ import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.target.TargetSource; +import java.util.UUID; + /** - * * @author cbt33, Plopman (Circle of Protection: Red) */ public final class PilgrimOfJustice extends CardImpl { - + public PilgrimOfJustice(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}"); this.subtype.add(SubType.HUMAN); this.subtype.add(SubType.CLERIC); @@ -58,15 +55,17 @@ public final class PilgrimOfJustice extends CardImpl { class PilgrimOfJusticeEffect extends PreventionEffectImpl { private static final FilterObject filter = new FilterObject("red source"); - static{ + + static { filter.add(new ColorPredicate(ObjectColor.RED)); } + private TargetSource target; public PilgrimOfJusticeEffect() { super(Duration.EndOfTurn); target = new TargetSource(filter); - + staticText = "The next time a red source of your choice would deal damage to you this turn, prevent that damage"; } @@ -100,7 +99,7 @@ class PilgrimOfJusticeEffect extends PreventionEffectImpl { } private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(target, source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); @@ -112,9 +111,7 @@ class PilgrimOfJusticeEffect extends PreventionEffectImpl { @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(target.getFirstTarget())) { - return true; - } + return event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget()); } return false; } diff --git a/Mage.Sets/src/mage/cards/p/PilgrimOfVirtue.java b/Mage.Sets/src/mage/cards/p/PilgrimOfVirtue.java index 7e989ecbc1..6dc3426496 100644 --- a/Mage.Sets/src/mage/cards/p/PilgrimOfVirtue.java +++ b/Mage.Sets/src/mage/cards/p/PilgrimOfVirtue.java @@ -1,7 +1,5 @@ - package mage.cards.p; -import java.util.UUID; import mage.MageInt; import mage.ObjectColor; import mage.abilities.Ability; @@ -12,25 +10,24 @@ import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.target.TargetSource; +import java.util.UUID; + /** - * * @author cbt33, Plopman (Circle of Protection: Red) */ public final class PilgrimOfVirtue extends CardImpl { public PilgrimOfVirtue(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}"); this.subtype.add(SubType.HUMAN); this.subtype.add(SubType.CLERIC); @@ -62,6 +59,7 @@ class PilgrimOfVirtueEffect extends PreventionEffectImpl { static { filter.add(new ColorPredicate(ObjectColor.BLACK)); } + private final TargetSource target; public PilgrimOfVirtueEffect() { @@ -101,7 +99,7 @@ class PilgrimOfVirtueEffect extends PreventionEffectImpl { } private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(target, source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); event.setAmount(0); @@ -113,9 +111,7 @@ class PilgrimOfVirtueEffect extends PreventionEffectImpl { @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(target.getFirstTarget())) { - return true; - } + return event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget()); } return false; } diff --git a/Mage.Sets/src/mage/cards/q/QuestingBeast.java b/Mage.Sets/src/mage/cards/q/QuestingBeast.java index 0a4193b7ef..5ff8e7b120 100644 --- a/Mage.Sets/src/mage/cards/q/QuestingBeast.java +++ b/Mage.Sets/src/mage/cards/q/QuestingBeast.java @@ -20,9 +20,9 @@ import mage.filter.common.FilterPlaneswalkerPermanent; import mage.filter.predicate.mageobject.PowerPredicate; import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.game.Game; -import mage.game.events.DamageEvent; import mage.game.events.DamagedEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetPermanent; @@ -101,7 +101,7 @@ class QuestingBeastPreventionEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (!((DamageEvent) event).isCombatDamage()) { + if (!((PreventDamageEvent) event).isCombatDamage()) { return false; } Permanent permanent = game.getPermanent(event.getSourceId()); diff --git a/Mage.Sets/src/mage/cards/s/ShieldOfTheAvatar.java b/Mage.Sets/src/mage/cards/s/ShieldOfTheAvatar.java index 7439718122..085410a9fe 100644 --- a/Mage.Sets/src/mage/cards/s/ShieldOfTheAvatar.java +++ b/Mage.Sets/src/mage/cards/s/ShieldOfTheAvatar.java @@ -11,7 +11,9 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import java.util.UUID; @@ -72,7 +74,7 @@ class ShieldOfTheAvatarPreventionEffect extends PreventionEffectImpl { if (equipment != null && equipment.getAttachedTo() != null) { int numberOfCreaturesControlled = CreaturesYouControlCount.instance.calculate(game, source, this); int toPrevent = Math.min(numberOfCreaturesControlled, event.getAmount()); - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, equipment.getAttachedTo(), source.getSourceId(), source.getControllerId(), toPrevent, false); + GameEvent preventEvent = new PreventDamageEvent(equipment.getAttachedTo(), source.getSourceId(), source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { if (event.getAmount() >= toPrevent) { event.setAmount(event.getAmount() - toPrevent); diff --git a/Mage.Sets/src/mage/cards/s/StonewiseFortifier.java b/Mage.Sets/src/mage/cards/s/StonewiseFortifier.java index 67848f60fa..7c9fffb455 100644 --- a/Mage.Sets/src/mage/cards/s/StonewiseFortifier.java +++ b/Mage.Sets/src/mage/cards/s/StonewiseFortifier.java @@ -1,7 +1,5 @@ - package mage.cards.s; -import java.util.UUID; import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; @@ -11,21 +9,24 @@ import mage.abilities.effects.PreventionEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class StonewiseFortifier extends CardImpl { public StonewiseFortifier(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}"); this.subtype.add(SubType.HUMAN); this.subtype.add(SubType.WIZARD); @@ -71,7 +72,7 @@ class StonewiseFortifierPreventAllDamageToEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, event.getTargetId(), event.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), event.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int preventedDamage = event.getAmount(); MageObject damageSource = game.getObject(event.getSourceId()); @@ -91,9 +92,7 @@ class StonewiseFortifierPreventAllDamageToEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId())) { - if (event.getSourceId().equals(targetPointer.getFirst(game, source))) { - return true; - } + return event.getSourceId().equals(targetPointer.getFirst(game, source)); } return false; } diff --git a/Mage.Sets/src/mage/cards/t/Temper.java b/Mage.Sets/src/mage/cards/t/Temper.java index b0bdd776b1..6ce5de5ee1 100644 --- a/Mage.Sets/src/mage/cards/t/Temper.java +++ b/Mage.Sets/src/mage/cards/t/Temper.java @@ -1,7 +1,5 @@ - package mage.cards.t; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue; @@ -12,12 +10,15 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.counters.CounterType; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** - * * @author TheElk801 */ public final class Temper extends CardImpl { @@ -76,7 +77,7 @@ class TemperPreventDamageTargetEffect extends PreventionEffectImpl { amount = dVal.calculate(game, source, this); initialized = true; } - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int prevented = 0; if (event.getAmount() >= this.amount) { @@ -109,9 +110,7 @@ class TemperPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (!this.used && super.applies(event, source, game)) { - if (source.getTargets().getFirstTarget().equals(event.getTargetId())) { - return true; - } + return source.getTargets().getFirstTarget().equals(event.getTargetId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/t/TestOfFaith.java b/Mage.Sets/src/mage/cards/t/TestOfFaith.java index 4314b4dea3..c3fc560519 100644 --- a/Mage.Sets/src/mage/cards/t/TestOfFaith.java +++ b/Mage.Sets/src/mage/cards/t/TestOfFaith.java @@ -1,7 +1,5 @@ - package mage.cards.t; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.PreventionEffectImpl; import mage.cards.CardImpl; @@ -10,18 +8,21 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.counters.CounterType; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class TestOfFaith extends CardImpl { public TestOfFaith(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); // Prevent the next 3 damage that would be dealt to target creature this turn. For each 1 damage prevented this way, put a +1/+1 counter on that creature. this.getSpellAbility().addEffect(new TestOfFaithPreventDamageTargetEffect(Duration.EndOfTurn)); @@ -64,7 +65,7 @@ class TestOfFaithPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int prevented = 0; if (event.getAmount() >= this.amount) { @@ -97,9 +98,7 @@ class TestOfFaithPreventDamageTargetEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (!this.used && super.applies(event, source, game)) { - if (source.getTargets().getFirstTarget().equals(event.getTargetId())) { - return true; - } + return source.getTargets().getFirstTarget().equals(event.getTargetId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java b/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java index 5e3bbe7f5d..bbf8ba0809 100644 --- a/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java +++ b/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java @@ -1,7 +1,5 @@ - package mage.cards.u; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAbility; @@ -16,18 +14,21 @@ import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** - * * @author BetaSteward */ public final class UnbreathingHorde extends CardImpl { public UnbreathingHorde(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}"); this.subtype.add(SubType.ZOMBIE); this.power = new MageInt(0); @@ -115,7 +116,7 @@ class UnbreathingHordeEffect2 extends PreventionEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { boolean retValue = false; - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); int damage = event.getAmount(); if (!game.replaceEvent(preventEvent)) { event.setAmount(0); @@ -132,9 +133,7 @@ class UnbreathingHordeEffect2 extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getSourceId())) { - return true; - } + return event.getTargetId().equals(source.getSourceId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/v/Vigor.java b/Mage.Sets/src/mage/cards/v/Vigor.java index cf1b6292eb..10296ede3b 100644 --- a/Mage.Sets/src/mage/cards/v/Vigor.java +++ b/Mage.Sets/src/mage/cards/v/Vigor.java @@ -1,7 +1,5 @@ - package mage.cards.v; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.PutIntoGraveFromAnywhereSourceTriggeredAbility; @@ -11,24 +9,23 @@ import mage.abilities.effects.common.ShuffleIntoLibrarySourceEffect; import mage.abilities.keyword.TrampleAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.counters.CounterType; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author emerald000 */ public final class Vigor extends CardImpl { public Vigor(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}{G}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}{G}{G}"); this.subtype.add(SubType.ELEMENTAL); this.subtype.add(SubType.INCARNATION); @@ -37,10 +34,10 @@ public final class Vigor extends CardImpl { // Trample this.addAbility(TrampleAbility.getInstance()); - + // If damage would be dealt to a creature you control other than Vigor, prevent that damage. Put a +1/+1 counter on that creature for each 1 damage prevented this way. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new VigorReplacementEffect())); - + // When Vigor is put into a graveyard from anywhere, shuffle it into its owner's library. this.addAbility(new PutIntoGraveFromAnywhereSourceTriggeredAbility(new ShuffleIntoLibrarySourceEffect())); } @@ -68,7 +65,7 @@ class VigorReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int preventedDamage = event.getAmount(); event.setAmount(0); @@ -81,15 +78,15 @@ class VigorReplacementEffect extends ReplacementEffectImpl { } return false; } - + @Override public boolean checksEventType(GameEvent event, Game game) { return event.getType() == GameEvent.EventType.DAMAGE_CREATURE; } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getPlayerId().equals(source.getControllerId()) + return event.getPlayerId().equals(source.getControllerId()) && !event.getTargetId().equals(source.getSourceId()); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ConditionalPreventionTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ConditionalPreventionTest.java index 42c8b0bb6f..2a7e23d40a 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ConditionalPreventionTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ConditionalPreventionTest.java @@ -134,4 +134,60 @@ public class ConditionalPreventionTest extends CardTestPlayerBase { assertHandCount(playerA, "Lightning Bolt", 0); } + @Test + public void test_PrentableCombatDamage() { + // Prevent all damage that would be dealt to creatures. + addCard(Zone.BATTLEFIELD, playerA, "Bubble Matrix", 1); + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); + // + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // player A must do damage + attack(1, playerA, "Balduvian Bears", playerB); + + // player B can't do damage (bears must block and safe) + attack(4, playerB, "Balduvian Bears", playerA); + block(4, playerA, "Balduvian Bears", "Balduvian Bears"); + + setStrictChooseMode(true); + setStopAt(4, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPermanentCount(playerA, "Balduvian Bears", 1); + assertPermanentCount(playerB, "Balduvian Bears", 1); + assertLife(playerA, 20); + assertLife(playerB, 20 - 2); + } + + @Test + public void test_UnpreventableCombatDamage() { + // Combat damage that would be dealt by creatures you control can't be prevented. + addCard(Zone.BATTLEFIELD, playerB, "Questing Beast", 1); + // + // Prevent all damage that would be dealt to creatures. + addCard(Zone.BATTLEFIELD, playerA, "Bubble Matrix", 1); + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); + // + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // player A must do damage + attack(1, playerA, "Balduvian Bears", playerB); + + // player B must be prevented by Bubble Matrix, but can't (Questing Beast) + // a -> b -- can't do damage (matrix) + // b -> a -- can do damage (matrix -> quest) + attack(4, playerB, "Balduvian Bears", playerA); + block(4, playerA, "Balduvian Bears", "Balduvian Bears"); + + setStrictChooseMode(true); + setStopAt(4, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPermanentCount(playerA, "Balduvian Bears", 0); + assertPermanentCount(playerB, "Balduvian Bears", 1); + assertLife(playerA, 20); + assertLife(playerB, 20 - 2); + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java b/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java index c5e978876e..2cf830defb 100644 --- a/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java @@ -260,17 +260,16 @@ public class LoadTest { @Ignore public void test_TwoAIPlayGame_Multiple() { - int singleGameSID = -1554824422; // for one game test with same deck - int singleGamePlaysAmount = 1000; // multiple run of one game test + int singleGameSID = 0; // for one game test with same deck + int gamesAmount = 1000; // multiple run of one game test // save random seeds for repeated results (in decks generating) List seedsList = new ArrayList<>(); if (singleGameSID != 0) { - for (int i = 1; i <= singleGamePlaysAmount; i++) { + for (int i = 1; i <= gamesAmount; i++) { seedsList.add(singleGameSID); } } else { - int gamesAmount = 1000; for (int i = 1; i <= gamesAmount; i++) { seedsList.add(RandomUtil.nextInt()); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToTargetMultiAmountEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToTargetMultiAmountEffect.java index 0e832aeac6..7aa79be735 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToTargetMultiAmountEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToTargetMultiAmountEffect.java @@ -1,8 +1,5 @@ package mage.abilities.effects.common; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.Mode; @@ -10,14 +7,19 @@ import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.PreventionEffectImpl; import mage.constants.Duration; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; +import mage.game.events.PreventDamageEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.Target; import mage.target.TargetAmount; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + /** - * * @author LevelX2 */ public class PreventDamageToTargetMultiAmountEffect extends PreventionEffectImpl { @@ -77,7 +79,7 @@ public class PreventDamageToTargetMultiAmountEffect extends PreventionEffectImpl @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { int targetAmount = targetAmountMap.get(event.getTargetId()); - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, event.getTargetId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { if (event.getAmount() >= targetAmount) { int damage = targetAmount; diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 38b7b03eb1..b65b17719f 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -2638,7 +2638,7 @@ public abstract class GameImpl implements Game, Serializable { return result; } DamageEvent damageEvent = (DamageEvent) event; - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, damageEvent.getTargetId(), damageEvent.getSourceId(), source.getControllerId(), damageEvent.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(damageEvent.getTargetId(), damageEvent.getSourceId(), source.getControllerId(), damageEvent.getAmount(), damageEvent.isCombatDamage()); if (game.replaceEvent(preventEvent)) { result.setReplaced(true); return result; diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 71ea031c5e..fb854bcdf1 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -22,6 +22,7 @@ public class GameEvent implements Serializable { // for counters: event is result of effect (+1 from planeswalkers is cost, not effect) // for combat damage: event is preventable damage // for discard: event is result of effect (1) or result of cost (0) + // for prevent damage: try to prevent combat damage (1) or other damage (0) protected boolean flag; protected String data; protected Zone zone; diff --git a/Mage/src/main/java/mage/game/events/PreventDamageEvent.java b/Mage/src/main/java/mage/game/events/PreventDamageEvent.java new file mode 100644 index 0000000000..49d9623afa --- /dev/null +++ b/Mage/src/main/java/mage/game/events/PreventDamageEvent.java @@ -0,0 +1,17 @@ +package mage.game.events; + +import java.util.UUID; + +/** + * @author JayDi85 + */ +public class PreventDamageEvent extends GameEvent { + + public PreventDamageEvent(UUID targetId, UUID sourceId, UUID playerId, int damageToPrevent, boolean isCombatDamage) { + super(EventType.PREVENT_DAMAGE, targetId, sourceId, playerId, damageToPrevent, isCombatDamage); + } + + public boolean isCombatDamage() { + return flag; + } +} diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index e1f020ebf4..a40e9aa5ad 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -1,6 +1,5 @@ package mage.game.permanent; -import java.util.*; import mage.MageObject; import mage.MageObjectReference; import mage.ObjectColor; @@ -38,6 +37,8 @@ import mage.util.GameLog; import mage.util.ThreadLocalStringBuilder; import org.apache.log4j.Logger; +import java.util.*; + /** * @author BetaSteward_at_googlemail.com */ @@ -761,7 +762,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { this.attachedTo = attachToObjectId; this.attachedToZoneChangeCounter = game.getState().getZoneChangeCounter(attachToObjectId); for (Ability ability : this.getAbilities()) { - for (Iterator ite = ability.getEffects(game, EffectType.CONTINUOUS).iterator(); ite.hasNext();) { + for (Iterator ite = ability.getEffects(game, EffectType.CONTINUOUS).iterator(); ite.hasNext(); ) { ContinuousEffect effect = (ContinuousEffect) ite.next(); game.getContinuousEffects().setOrder(effect); // It's important to update the timestamp of the copied effect in ContinuousEffects because it does the action @@ -816,8 +817,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { * @param game * @param preventable * @param combat - * @param markDamage If true, damage will be dealt later in applyDamage - * method + * @param markDamage If true, damage will be dealt later in applyDamage + * method * @return */ private int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage, List appliedEffects) { @@ -969,7 +970,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { private int checkProtectionAbilities(GameEvent event, UUID sourceId, Game game) { MageObject source = game.getObject(sourceId); if (source != null && hasProtectionFrom(source, game)) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, this.objectId, sourceId, this.controllerId, event.getAmount(), false); + GameEvent preventEvent = new PreventDamageEvent(this.objectId, sourceId, this.controllerId, event.getAmount(), ((DamageEvent) event).isCombatDamage()); if (!game.replaceEvent(preventEvent)) { int preventedDamage = event.getAmount(); event.setAmount(0);