Skip to content

Commit

Permalink
Questing Beast - fixed rollback error on damage prevent (#6116);
Browse files Browse the repository at this point in the history
  • Loading branch information
JayDi85 committed Dec 24, 2019
1 parent 5cb0406 commit 9cf1ee2
Show file tree
Hide file tree
Showing 32 changed files with 260 additions and 223 deletions.
4 changes: 3 additions & 1 deletion Mage.Sets/src/mage/cards/a/AcolytesReward.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
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;
Expand Down Expand Up @@ -85,7 +87,7 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
} 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) {
Expand Down
16 changes: 7 additions & 9 deletions Mage.Sets/src/mage/cards/a/AuriokReplica.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@


package mage.cards.a;

import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
Expand All @@ -16,17 +13,20 @@
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);
Expand Down Expand Up @@ -77,7 +77,7 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
}

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);
Expand All @@ -88,9 +88,7 @@ private void preventDamage(GameEvent event, Ability source, UUID target, Game ga
@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;
}
Expand Down
9 changes: 5 additions & 4 deletions Mage.Sets/src/mage/cards/b/BattletideAlchemist.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

package mage.cards.b;

import java.util.UUID;

import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
Expand All @@ -13,10 +10,14 @@
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
*/
Expand Down Expand Up @@ -67,7 +68,7 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
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);
Expand Down
13 changes: 6 additions & 7 deletions Mage.Sets/src/mage/cards/b/BraceForImpact.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,12 +10,15 @@
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 {
Expand Down Expand Up @@ -69,7 +70,7 @@ public boolean apply(Game game, Ability source) {

@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();
Expand All @@ -93,9 +94,7 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
@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;
}
Expand Down
12 changes: 5 additions & 7 deletions Mage.Sets/src/mage/cards/c/CandlesGlow.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package mage.cards.c;

import mage.abilities.Ability;
Expand All @@ -10,20 +9,21 @@
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);


Expand Down Expand Up @@ -70,7 +70,7 @@ public boolean apply(Game game, Ability source) {

@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) {
Expand Down Expand Up @@ -103,9 +103,7 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
@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;
}
Expand Down
10 changes: 6 additions & 4 deletions Mage.Sets/src/mage/cards/e/EnergyField.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +12,12 @@
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
Expand Down Expand Up @@ -57,7 +59,7 @@ public EnergyFieldEffect(EnergyFieldEffect effect) {

@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);
Expand Down
15 changes: 6 additions & 9 deletions Mage.Sets/src/mage/cards/g/GhostsOfTheInnocent.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@

package mage.cards.g;

import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
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 {
Expand Down Expand Up @@ -81,7 +78,7 @@ public boolean apply(Game game, Ability source) {
@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));
Expand Down
13 changes: 6 additions & 7 deletions Mage.Sets/src/mage/cards/g/GideonsIntervention.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

package mage.cards.g;

import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
Expand All @@ -17,12 +15,15 @@
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 {
Expand Down Expand Up @@ -88,9 +89,7 @@ public boolean applies(GameEvent event, Ability source, Game game) {
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;
}
Expand Down Expand Up @@ -119,7 +118,7 @@ public boolean apply(Game game, Ability source) {

@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);
Expand Down
20 changes: 8 additions & 12 deletions Mage.Sets/src/mage/cards/g/GloomSurgeon.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -79,9 +77,7 @@ public boolean checksEventType(GameEvent event, Game game) {
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;
}
Expand Down
Loading

0 comments on commit 9cf1ee2

Please sign in to comment.