Coverage Summary for Class: EndTurnOfActionPhase (it.polimi.ingsw.Controller.Actions)
| Class | Class, % | Method, % | Branch, % | Line, % |
|---|---|---|---|---|
| EndTurnOfActionPhase | 100% (1/1) | 100% (3/3) | 40% (4/10) | 72,7% (8/11) |
1 package it.polimi.ingsw.Controller.Actions; 2 3 import it.polimi.ingsw.Exceptions.Input.GenericInputValidationException; 4 import it.polimi.ingsw.Exceptions.Input.InputValidationException; 5 import it.polimi.ingsw.Misc.OptionalValue; 6 import it.polimi.ingsw.Model.Enums.GamePhase; 7 import it.polimi.ingsw.Model.Model; 8 import it.polimi.ingsw.Model.PlayerBoard; 9 10 import java.io.Serial; 11 import java.util.List; 12 13 import static it.polimi.ingsw.Misc.Utils.countSimilarClassOccurrences; 14 15 /** 16 * The Action phase is a lengthy one and its length cannot be determined. This {@link PlayerAction} enables the caller to 17 * end an Action phase on its own accord. 18 */ 19 public class EndTurnOfActionPhase extends PlayerAction { 20 @Serial 21 private static final long serialVersionUID = 202L; // convention: 2 for controller, (01 -> 99) for objects 22 23 /** 24 * Create a new instance of this class with the following inputs: 25 * 26 * @param playerBoardId the ID of the current {@link PlayerBoard} 27 */ 28 public EndTurnOfActionPhase(int playerBoardId) { 29 super(playerBoardId, true); 30 } 31 32 /** 33 * {@inheritDoc} 34 * <ul> 35 * <li>This action can be called only after having called one and only one {@link ChooseCloudTile} action</li> 36 * <li>The previous {@link PlayerAction}s must be either {@link ChooseCloudTile} or {@link PlayCharacterCard}</li> 37 * </ul> 38 * 39 * @param history the controller stores a {@link List} of previous {@link PlayerAction}s related to the player taking 40 * the current turn (at every new turn, the history is cleared). 41 * Some actions may use this {@link List} to check for duplicates. 42 * @param ctx a reference to {@link Model}. Some actions may use this reference to check for consistency between what 43 * the actions declares and what the Model offers. 44 * @return An empty {@link OptionalValue} in case of a successful validation. Otherwise the returned {@link OptionalValue} 45 * contains the related {@link InputValidationException} 46 */ 47 @Override 48 protected OptionalValue<InputValidationException> customValidation(List<PlayerAction> history, Model ctx) { 49 50 if (countSimilarClassOccurrences(ChooseCloudTile.class, history) != 1) { 51 return OptionalValue.of(new GenericInputValidationException("History", "ChooseCloudTile action has not been executed")); 52 } 53 if (!(history.get(history.size() - 1).getClass() == ChooseCloudTile.class || (history.get(history.size() - 1).getClass() == PlayCharacterCard.class))) { 54 return OptionalValue.of(new GenericInputValidationException("History", "this action can only be executed after a ChooseCloudTile action or PlayCharacterCard action")); 55 } 56 57 return OptionalValue.empty(); 58 } 59 60 @Override 61 public void unsafeExecute(Model ctx) throws Exception { 62 // reset effects through EffectTracker 63 ctx.getMutableEffects().reset(); 64 ctx.getMutableTurnOrder().stepToNextPlayer(); 65 if (ctx.getMutableTurnOrder().getGamePhase() != GamePhase.ACTION) { 66 if (ctx.getMutableStudentBag().getSize() > 0) { 67 ctx.refillClouds(); 68 } 69 } 70 } 71 72 73 }