# Class UpdateHandler

java.lang.Object
it.polimi.ingsw.is25am31.network.UpdateHandler

public class UpdateHandler extends Object
The `UpdateHandler` class provides static methods to manage and dispatch game updates to connected clients. It handles various scenarios related to drawing cards and resolving card effects, ensuring that clients receive the correct information and turn changes.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `UpdateHandler()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `drawCardTurnHandler(Card card, Controller controller, Map<UUID,ClientData> clients, Map<UUID,ClientData> passiveClients, Game model, AsyncRunner dispatcher)`
  Handles the turn logic after a card has been drawn.
  `static void`
  `effectContextTurnHandler(UUID clientId, int res, Map<UUID,ClientData> clients, Map<UUID,ClientData> passiveClients, Game model, AsyncRunner dispatcher)`
  Handles turn logic based on the resolution of a card effect context.
  `static void`
  `newLeader(Map<UUID,ClientData> activeClients, Map<UUID,ClientData> passiveClients, Controller controller, AsyncRunner dispatcher, Game model)`
  Handles the logic for a new leader scenario, or concludes the game if a final ranking is available.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### UpdateHandler

    public UpdateHandler()

- ## Method Details

  - ### drawCardTurnHandler

    public static boolean drawCardTurnHandler(Card card, Controller controller, Map<UUID,ClientData> clients, Map<UUID,ClientData> passiveClients, Game model, AsyncRunner dispatcher) throws Exception
    Handles the turn logic after a card has been drawn. This method dictates later actions based on the type of card drawn, such as updating positions, changing turns.
    Parameters:
      `card` - The `Card` that was drawn.
      `controller` - The game `Controller` instance.
      `clients` - A map of active client UUIDs to their `ClientData`.
      `passiveClients` - A map of passive client UUIDs to their `ClientData`.
      `model` - The current `Game` model.
      `dispatcher` - The `AsyncRunner` used for asynchronous task execution to clients.
    Returns:
      `true` if the turn handling logic concludes successfully and the turn can proceed, `false` if the current player's turn needs to be passed.
    Throws:
      `Exception` - If an error occurs during client communication or model manipulation.

  - ### effectContextTurnHandler

    public static void effectContextTurnHandler(UUID clientId, int res, Map<UUID,ClientData> clients, Map<UUID,ClientData> passiveClients, Game model, AsyncRunner dispatcher) throws Exception
    Handles turn logic based on the resolution of a card effect context. This method dispatches specific updates to clients depending on the current card type and the result of the effect. This includes updating ship positions, showing ships, and managing turn changes.
    Parameters:
      `clientId` - The `UUID` of the client whose effect context is being resolved.
      `res` - An integer representing the result or choice made during the effect resolution.
      `clients` - A map of active client UUIDs to their `ClientData`.
      `passiveClients` - A map of passive client UUIDs to their `ClientData`.
      `model` - The current `Game` model.
      `dispatcher` - The `AsyncRunner` used for asynchronous task execution to clients.
    Throws:
      `Exception` - If an error occurs during client communication or model manipulation.

  - ### newLeader

    public static void newLeader(Map<UUID,ClientData> activeClients, Map<UUID,ClientData> passiveClients, Controller controller, AsyncRunner dispatcher, Game model) throws Exception
    Handles the logic for a new leader scenario, or concludes the game if a final ranking is available. This method is called when the game needs to determine a new leader or if the game has ended due to the deck being empty. It dispatches updates to both active and passive clients.
    Parameters:
      `activeClients` - A map of active client UUIDs to their `ClientData`.
      `passiveClients` - A map of passive client UUIDs to their `ClientData`.
      `controller` - The game `Controller` instance.
      `dispatcher` - The `AsyncRunner` used for asynchronous task execution to clients.
      `model` - The current `Game` model.
    Throws:
      `Exception` - If an error occurs during client communication or model manipulation.