* Added context information for restore call to be able to set add info if restore can#t be executed.

This commit is contained in:
LevelX2 2014-10-12 12:37:10 +02:00
parent 746796ba05
commit 63cd131855
5 changed files with 13 additions and 13 deletions

View file

@ -144,7 +144,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
game.removeBookmark(bookmark); game.removeBookmark(bookmark);
return true; return true;
} }
game.restoreState(bookmark); game.restoreState(bookmark, ability.getRule());
return false; return false;
} }

View file

@ -131,7 +131,7 @@ class CumulativeUpkeepEffect extends OneShotEffect {
return true; return true;
} }
else{ else{
game.restoreState(bookmark); game.restoreState(bookmark, source.getRule());
} }
} }
permanent.sacrifice(source.getSourceId(), game); permanent.sacrifice(source.getSourceId(), game);

View file

@ -264,7 +264,7 @@ public interface Game extends MageItem, Serializable {
//game transaction methods //game transaction methods
void saveState(boolean bookmark); void saveState(boolean bookmark);
int bookmarkState(); int bookmarkState();
void restoreState(int bookmark); void restoreState(int bookmark, String context);
void removeBookmark(int bookmark); void removeBookmark(int bookmark);
int getSavedStateSize(); int getSavedStateSize();
boolean isSaveGame(); boolean isSaveGame();

View file

@ -510,11 +510,11 @@ public abstract class GameImpl implements Game, Serializable {
} }
@Override @Override
public void restoreState(int bookmark) { public void restoreState(int bookmark, String context) {
if (!simulation && !this.hasEnded()) { // if player left or game is over no undo is possible - this could lead to wrong winner if (!simulation && !this.hasEnded()) { // if player left or game is over no undo is possible - this could lead to wrong winner
if (bookmark != 0) { if (bookmark != 0) {
if (!savedStates.contains(bookmark - 1)) { if (!savedStates.contains(bookmark - 1)) {
throw new UnsupportedOperationException("It was not possible to do the requested undo operation (bookmark " + (bookmark -1) + " does not exist)"); throw new UnsupportedOperationException("It was not possible to do the requested undo operation (bookmark " + (bookmark -1) + " does not exist) context: " + context);
} }
int stateNum = savedStates.get(bookmark - 1); int stateNum = savedStates.get(bookmark - 1);
removeBookmark(bookmark); removeBookmark(bookmark);
@ -1032,7 +1032,7 @@ public abstract class GameImpl implements Game, Serializable {
if (player != null) { if (player != null) {
int bookmark = player.getStoredBookmark(); int bookmark = player.getStoredBookmark();
if (bookmark != -1) { if (bookmark != -1) {
restoreState(bookmark); restoreState(bookmark, "undo");
player.setStoredBookmark(-1); player.setStoredBookmark(-1);
fireUpdatePlayersEvent(); fireUpdatePlayersEvent();
} }
@ -1122,7 +1122,7 @@ public abstract class GameImpl implements Game, Serializable {
logger.fatal("Game exception gameId: " + getId(), ex); logger.fatal("Game exception gameId: " + getId(), ex);
ex.printStackTrace(); ex.printStackTrace();
this.fireErrorEvent("Game exception occurred: ", ex); this.fireErrorEvent("Game exception occurred: ", ex);
restoreState(bookmark); restoreState(bookmark, "");
bookmark = 0; bookmark = 0;
continue; continue;
} }

View file

@ -837,7 +837,7 @@ public abstract class PlayerImpl implements Player, Serializable {
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
} }
game.restoreState(bookmark); game.restoreState(bookmark, ability.getRule());
} }
} }
return false; return false;
@ -881,7 +881,7 @@ public abstract class PlayerImpl implements Player, Serializable {
return true; return true;
} }
} }
game.restoreState(bookmark); game.restoreState(bookmark, ability.getRule());
} }
return false; return false;
} }
@ -900,7 +900,7 @@ public abstract class PlayerImpl implements Player, Serializable {
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
} }
game.restoreState(bookmark); game.restoreState(bookmark, ability.getRule());
} }
} else { } else {
int bookmark = game.bookmarkState(); int bookmark = game.bookmarkState();
@ -910,7 +910,7 @@ public abstract class PlayerImpl implements Player, Serializable {
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
} }
game.restoreState(bookmark); game.restoreState(bookmark, ability.getRule());
} }
return false; return false;
} }
@ -928,7 +928,7 @@ public abstract class PlayerImpl implements Player, Serializable {
return true; return true;
} }
} }
game.restoreState(bookmark); game.restoreState(bookmark, action.getRule());
} }
return false; return false;
} }
@ -998,7 +998,7 @@ public abstract class PlayerImpl implements Player, Serializable {
return true; return true;
} }
} }
game.restoreState(bookmark); game.restoreState(bookmark, source.getRule());
return false; return false;
} }