[CLB] Fix initiativeId not being set when a player first takes the initiative. Added documentation to related functions. For #9010.

This commit is contained in:
Alex Vasile 2022-05-29 12:30:09 -06:00
parent fdbca7048a
commit 63aaf44f93
2 changed files with 25 additions and 3 deletions

View file

@ -515,12 +515,28 @@ public interface Game extends MageItem, Serializable, Copyable<Game> {
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);

View file

@ -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));
}