Class PlayCharacterCard
java.lang.Object
it.polimi.ingsw.Controller.Actions.PlayerAction
it.polimi.ingsw.Controller.Actions.PlayCharacterCard
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OptionalValue<Integer>private final OptionalValue<PawnColour>private final OptionalValue<List<Pair<PawnColour,PawnColour>>> private final intprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionPlayCharacterCard(int playerBoardId, int selectedCard, OptionalValue<Integer> optTargetIsland, OptionalValue<PawnColour> optTargetPawn, OptionalValue<List<Pair<PawnColour, PawnColour>>> optTargetPawnPairs) Create a new instance of this class with the following inputs: -
Method Summary
Modifier and TypeMethodDescriptionprotected OptionalValue<InputValidationException>customValidation(List<PlayerAction> history, Model ctx) This function is used byPlayerAction.validate(List, Model)to check whether or not the declaredPlayerActionis possible.
This function will check for the following requirements:private CharacterCardInputgenerateCharacterCardInput(PlayerBoard caller, Model ctx) aCharacterCardrequires more information than the one contained in the constructor of thisPlayerActionto be able to function.voidunsafeExecute(Model ctx) Every class extendingPlayerActionmust implement the following method, which takes aModelreference and applies the concrete effect of the action.Methods inherited from class it.polimi.ingsw.Controller.Actions.PlayerAction
getPlayerBoardID, validate
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
selectedCard
private final int selectedCard -
optTargetIsland
-
optTargetPawn
-
optTargetPawnPairs
-
-
Constructor Details
-
PlayCharacterCard
public PlayCharacterCard(int playerBoardId, int selectedCard, OptionalValue<Integer> optTargetIsland, OptionalValue<PawnColour> optTargetPawn, OptionalValue<List<Pair<PawnColour, PawnColour>>> optTargetPawnPairs) Create a new instance of this class with the following inputs:- Parameters:
playerBoardId- the ID of the currentPlayerBoardselectedCard- the ID of theCharacterCardto be playedoptTargetIsland- if a target island is required as an input to the card, provide it hereoptTargetPawn- if a target pawn is required as an input to the card, provide it hereoptTargetPawnPairs- if a list of pawn pairs is required as an input to the card, provide it here
-
-
Method Details
-
customValidation
protected OptionalValue<InputValidationException> customValidation(List<PlayerAction> history, Model ctx) This function is used byPlayerAction.validate(List, Model)to check whether or not the declaredPlayerActionis possible.
This function will check for the following requirements:- The
GameModemust beGameMode.ADVANCED - The
GamePhasemust beGamePhase.ACTION - The selected character card must be within bounds (index 0 to 2 included)
- The player needs to have enough coins to by the card
- The
CharacterCardInputgenerated from the attributes must be correct
- Specified by:
customValidationin classPlayerAction- Parameters:
history- the controller stores aListof previousPlayerActions related to the player taking the current turn (at every new turn, the history is cleared). Some actions may use thisListto check for duplicates.ctx- a reference toModel. Some actions may use this reference to check for consistency between what the actions declares and what the Model offers.- Returns:
- An empty
OptionalValuein case of a successful validation. Otherwise the returnedOptionalValuecontains the relatedInputValidationException
- The
-
unsafeExecute
Description copied from class:PlayerActionEvery class extendingPlayerActionmust implement the following method, which takes aModelreference 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 classController, which takes adequate precautions in order to guarantee a coherent execution of the method.- Specified by:
unsafeExecutein classPlayerAction- Parameters:
ctx- theModelreference, once the method finishes running the game state will be altered.- Throws:
Exception- Should an error occur during the execution of the method, such error will be reported through the thrownException. Note that anyPlayerActioninheritor should guarantee the absence of Exceptions for any positive return value yielded byPlayerAction.validate(List, Model)
-
generateCharacterCardInput
private CharacterCardInput generateCharacterCardInput(PlayerBoard caller, Model ctx) throws InvalidContainerIndexException aCharacterCardrequires more information than the one contained in the constructor of thisPlayerActionto be able to function. During the calls to verify the action, aCharacterCardInputobject needs to be created so the internal validation mechanism of theCharacterCardcan work.- Parameters:
caller- instead of the id of the current player, a reference to the currentPlayerBoardis neededctx- theModelobject is required to allow translation of the attributes of this object into aCharacterCardInput- Returns:
- the
CharacterCardInputassociated with this object's attributes - Throws:
InvalidContainerIndexException- if the attribute of target island is pointing to an unidentified island-ID in the model, this exception is thrown
-