From 63aaf44f93627114a7a95dc603e4a57479b8c9ca Mon Sep 17 00:00:00 2001 From: Alex Vasile <48962821+Alex-Vasile@users.noreply.github.com> Date: Sun, 29 May 2022 12:30:09 -0600 Subject: [PATCH] [CLB] Fix initiativeId not being set when a player first takes the initiative. Added documentation to related functions. For #9010. --- Mage/src/main/java/mage/game/Game.java | 16 ++++++++++++++++ Mage/src/main/java/mage/game/GameImpl.java | 12 +++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Mage/src/main/java/mage/game/Game.java b/Mage/src/main/java/mage/game/Game.java index ca7191e97a7..96d34899d76 100644 --- a/Mage/src/main/java/mage/game/Game.java +++ b/Mage/src/main/java/mage/game/Game.java @@ -515,12 +515,28 @@ public interface Game extends MageItem, Serializable, Copyable { Counters getEnterWithCounters(UUID sourceId); + /** + * Get the UUID of the current player who is the Monarch, or null if nobody has it. + * + * @return UUID of the Monarch (null if nobody has it). + */ UUID getMonarchId(); void setMonarchId(Ability source, UUID monarchId); + /** + * Get the UUID of the current player who has the initiative, or null if nobody has it. + * + * @return UUID of the player who currently has the Initiative (null if nobody has it). + */ UUID getInitiativeId(); + /** + * Function to call for a player to take the initiative. + * + * @param source The ability granting initiative. + * @param initiativeId UUID of the player taking the initiative + */ void takeInitiative(Ability source, UUID initiativeId); int damagePlayerOrPlaneswalker(UUID playerOrWalker, int damage, UUID attackerId, Ability source, Game game, boolean combatDamage, boolean preventable); diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 9dbbe2de516..955d3fd510d 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -3703,11 +3703,17 @@ public abstract class GameImpl implements Game { @Override public void takeInitiative(Ability source, UUID initiativeId) { - if (getInitiativeId() == null) { + // First time someone takes the initiative + if (getInitiativeId() == null) { // 1. Nobody has initiative getState().addDesignation(new Initiative(), this, initiativeId); - } else if (!getInitiativeId().equals(initiativeId)) { - getState().setInitiativeId(initiativeId); } + + // Update it every time, even if it doesn't have to change to make the code simpler. + // It only really has to change under 2 circumstances: + // 1. First time someone takes the initiative + // 2. A player taking the initiative when another player currently has it. + getState().setInitiativeId(initiativeId); + informPlayers(getPlayer(initiativeId).getLogName() + " takes the initiative"); fireEvent(new GameEvent(GameEvent.EventType.TOOK_INITIATIVE, initiativeId, source, initiativeId)); }