From f6ec543b1b8f1d342a57d404a75352c2d10d2911 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 3 Oct 2015 18:20:59 +0200 Subject: [PATCH] TestPlayer fixed that target events created by RestPlayer are reset back if ability activation failed. --- .../test/java/org/mage/test/player/TestPlayer.java | 11 ++++++++--- Mage/src/mage/players/PlayerImpl.java | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 3abe238a3b..f168cd1c3d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -370,6 +370,7 @@ public class TestPlayer implements Player { } for (Ability ability : computerPlayer.getPlayable(game, true)) { if (ability.toString().startsWith(groups[0])) { + int bookmark = game.bookmarkState(); Ability newAbility = ability.copy(); if (groups.length > 1 && !groups[1].equals("target=NO_TARGET")) { if (!addTargets(newAbility, groups, game)) { @@ -377,9 +378,13 @@ public class TestPlayer implements Player { break; } } - computerPlayer.activateAbility((ActivatedAbility) newAbility, game); - actions.remove(action); - return true; + if (computerPlayer.activateAbility((ActivatedAbility) newAbility, game)) { + actions.remove(action); + return true; + } else { + game.restoreState(bookmark, ability.getRule()); + } + } } } else if (action.getAction().startsWith("manaActivate:")) { diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 3ce3070c96..b6d6cb2405 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -1105,7 +1105,7 @@ public abstract class PlayerImpl implements Player, Serializable { return false; } - private void restoreState(int bookmark, String text, Game game) { + protected void restoreState(int bookmark, String text, Game game) { game.restoreState(bookmark, text); if (storedBookmark >= bookmark) { resetStoredBookmark(game);