Class PlayAssistantCard

java.lang.Object
it.polimi.ingsw.Controller.Actions.PlayerAction
it.polimi.ingsw.Controller.Actions.PlayAssistantCard
All Implemented Interfaces:
Serializable

public class PlayAssistantCard extends PlayerAction
This PlayerAction allows the caller to select the desired assistant card to be played this round. This action is linked to the Setup (Preparation) Phase.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • selectedAssistant

      private final int selectedAssistant
  • Constructor Details

    • PlayAssistantCard

      public PlayAssistantCard(int playerBoardId, int selectedAssistant)
      Create a new instance of this class with the following inputs:
      Parameters:
      playerBoardId - the ID of the current PlayerBoard
      selectedAssistant - the priority of the AssistantCard to be selected
  • Method Details

    • customValidation

      protected OptionalValue<InputValidationException> customValidation(List<PlayerAction> history, Model ctx)
      This function is used by PlayerAction.validate(List, Model) to check whether or not the declared PlayerAction is possible.
      This function will check for the following requirements:
      • The GamePhase must be GamePhase.SETUP
      • The selected assistant card must be within bounds (always greater or equal to 0, always lesser or equal to the size of the player's assistants deck
      • The player must play a card that has not been chosen by other players before (unless there are no other cards left to choose from)
      • The selected AssistantCard can only be used once by the player
      Specified by:
      customValidation in class PlayerAction
      Parameters:
      history - the controller stores a List of previous PlayerActions related to the player taking the current turn (at every new turn, the history is cleared). Some actions may use this List to check for duplicates.
      ctx - a reference to Model. Some actions may use this reference to check for consistency between what the actions declares and what the Model offers.
      Returns:
      An empty OptionalValue in case of a successful validation. Otherwise the returned OptionalValue contains the related InputValidationException
    • unsafeExecute

      public void unsafeExecute(Model ctx) throws OperationException
      Description copied from class: PlayerAction
      Every class extending PlayerAction must implement the following method, which takes a Model reference and applies the concrete effect of the action.
      Warning: this function, as implied by the name, is unsafe. it should never be called by called outside the scope of the class Controller, which takes adequate precautions in order to guarantee a coherent execution of the method.
      Specified by:
      unsafeExecute in class PlayerAction
      Parameters:
      ctx - the Model reference, once the method finishes running the game state will be altered.
      Throws:
      OperationException