* Fixed a bug that turn rollback did not work correctly, if player was in a buy cost process that included possible rollback (fixes #4510).

This commit is contained in:
LevelX2 2018-02-12 11:41:01 +01:00
parent fc8604e449
commit 6d848e2059
3 changed files with 24 additions and 13 deletions

View file

@ -753,7 +753,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
currentConnection.setPort(port); currentConnection.setPort(port);
String allMAC = ""; String allMAC = "";
try { try {
allMAC = currentConnection.getMAC(); allMAC = Connection.getMAC();
} catch (SocketException ex) { } catch (SocketException ex) {
} }
currentConnection.setUserIdStr(System.getProperty("user.name") + ":" + System.getProperty("os.name") + ":" + MagePreferences.getUserNames() + ":" + allMAC); currentConnection.setUserIdStr(System.getProperty("user.name") + ":" + System.getProperty("os.name") + ":" + MagePreferences.getUserNames() + ":" + allMAC);

View file

@ -2953,6 +2953,7 @@ public abstract class GameImpl implements Game, Serializable {
executingRollback = true; executingRollback = true;
for (Player playerObject : getPlayers().values()) { for (Player playerObject : getPlayers().values()) {
if (playerObject.isHuman() && playerObject.isInGame()) { if (playerObject.isHuman() && playerObject.isInGame()) {
playerObject.resetStoredBookmark(this);
playerObject.abort(); playerObject.abort();
playerObject.resetPlayerPassedActions(); playerObject.resetPlayerPassedActions();
} }

View file

@ -1182,9 +1182,11 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
protected void restoreState(int bookmark, String text, Game game) { protected void restoreState(int bookmark, String text, Game game) {
game.restoreState(bookmark, text); if (storedBookmark > -1) { // e.g. a turn rollback sets this to -1 so no more rollback of current action may be done
if (storedBookmark >= bookmark) { game.restoreState(bookmark, text);
resetStoredBookmark(game); if (storedBookmark >= bookmark) {
resetStoredBookmark(game);
}
} }
} }
@ -2334,12 +2336,13 @@ public abstract class PlayerImpl implements Player, Serializable {
count = searchedLibrary.count(target.getFilter(), game); count = searchedLibrary.count(target.getFilter(), game);
} else { } else {
Player targetPlayer = game.getPlayer(targetPlayerId); Player targetPlayer = game.getPlayer(targetPlayerId);
if (targetPlayer != null) { if (targetPlayer == null) {
if (cardsFromTop == null) { return false;
cardsFromTop = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit)); }
} else { if (cardsFromTop == null) {
cardsFromTop.retainAll(targetPlayer.getLibrary().getCards(game)); cardsFromTop = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit));
} } else {
cardsFromTop.retainAll(targetPlayer.getLibrary().getCards(game));
} }
newTarget.setCardLimit(Math.min(librarySearchLimit, cardsFromTop.size())); newTarget.setCardLimit(Math.min(librarySearchLimit, cardsFromTop.size()));
count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit); count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit);
@ -2390,7 +2393,7 @@ public abstract class PlayerImpl implements Player, Serializable {
chooseCard.setMessage("Which creature do you wish to cast from your library?"); chooseCard.setMessage("Which creature do you wish to cast from your library?");
Set<String> choice = new LinkedHashSet<>(); Set<String> choice = new LinkedHashSet<>();
for (Entry<UUID, String> entry : libraryCastableCardTracker.entrySet()) { for (Entry<UUID, String> entry : libraryCastableCardTracker.entrySet()) {
choice.add(new AbstractMap.SimpleEntry<UUID, String>(entry).getValue()); choice.add(new AbstractMap.SimpleEntry<>(entry).getValue());
} }
chooseCard.setChoices(choice); chooseCard.setChoices(choice);
while (!choice.isEmpty()) { while (!choice.isEmpty()) {
@ -2454,6 +2457,7 @@ public abstract class PlayerImpl implements Player, Serializable {
/** /**
* @param game * @param game
* @param appliedEffects * @param appliedEffects
* @param numSides Number of sides the dice has
* @return the number that the player rolled * @return the number that the player rolled
*/ */
@Override @Override
@ -3214,8 +3218,7 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
@Override @Override
public void setStoredBookmark(int storedBookmark public void setStoredBookmark(int storedBookmark) {
) {
this.storedBookmark = storedBookmark; this.storedBookmark = storedBookmark;
} }
@ -3802,4 +3805,11 @@ public abstract class PlayerImpl implements Player, Serializable {
return this.getId().equals(obj.getId()); return this.getId().equals(obj.getId());
} }
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + Objects.hashCode(this.playerId);
return hash;
}
} }