mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Added context information for restore call to be able to set add info if restore can#t be executed.
This commit is contained in:
parent
746796ba05
commit
63cd131855
5 changed files with 13 additions and 13 deletions
|
@ -144,7 +144,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
game.removeBookmark(bookmark);
|
||||
return true;
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, ability.getRule());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ class CumulativeUpkeepEffect extends OneShotEffect {
|
|||
return true;
|
||||
}
|
||||
else{
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, source.getRule());
|
||||
}
|
||||
}
|
||||
permanent.sacrifice(source.getSourceId(), game);
|
||||
|
|
|
@ -264,7 +264,7 @@ public interface Game extends MageItem, Serializable {
|
|||
//game transaction methods
|
||||
void saveState(boolean bookmark);
|
||||
int bookmarkState();
|
||||
void restoreState(int bookmark);
|
||||
void restoreState(int bookmark, String context);
|
||||
void removeBookmark(int bookmark);
|
||||
int getSavedStateSize();
|
||||
boolean isSaveGame();
|
||||
|
|
|
@ -510,11 +510,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
|
||||
@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 (bookmark != 0) {
|
||||
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);
|
||||
removeBookmark(bookmark);
|
||||
|
@ -1032,7 +1032,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
if (player != null) {
|
||||
int bookmark = player.getStoredBookmark();
|
||||
if (bookmark != -1) {
|
||||
restoreState(bookmark);
|
||||
restoreState(bookmark, "undo");
|
||||
player.setStoredBookmark(-1);
|
||||
fireUpdatePlayersEvent();
|
||||
}
|
||||
|
@ -1122,7 +1122,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
logger.fatal("Game exception gameId: " + getId(), ex);
|
||||
ex.printStackTrace();
|
||||
this.fireErrorEvent("Game exception occurred: ", ex);
|
||||
restoreState(bookmark);
|
||||
restoreState(bookmark, "");
|
||||
bookmark = 0;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -837,7 +837,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
resetStoredBookmark(game);
|
||||
return true;
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, ability.getRule());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -881,7 +881,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, ability.getRule());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -900,7 +900,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
resetStoredBookmark(game);
|
||||
return true;
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, ability.getRule());
|
||||
}
|
||||
} else {
|
||||
int bookmark = game.bookmarkState();
|
||||
|
@ -910,7 +910,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
resetStoredBookmark(game);
|
||||
return true;
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, ability.getRule());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -928,7 +928,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, action.getRule());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -998,7 +998,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
game.restoreState(bookmark);
|
||||
game.restoreState(bookmark, source.getRule());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue