| 1 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  * This file is part of Araknemu. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Araknemu is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * it under the terms of the GNU Lesser General Public License as published by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Araknemu is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * GNU Lesser General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * You should have received a copy of the GNU Lesser General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * Copyright (c) 2017-2021 Vincent Quatrevieux | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | import fr.quatrevieux.araknemu.data.constant.Characteristic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | import fr.quatrevieux.araknemu.game.fight.Fight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.AlterCharacteristicHook; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | import fr.quatrevieux.araknemu.game.fight.turn.TurnPoints; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | import org.checkerframework.checker.index.qual.NonNegative; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * Buff hook for handle altering turn point characteristics (i.e. {@link Characteristic#ACTION_POINT} and {@link Characteristic#MOVEMENT_POINT}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * This hook will also update point of the current active turn, if applicable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * Use factory methods for create the hook instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | public class AlterPointHook extends AlterCharacteristicHook { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     private final Fight fight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private final TurnPointsModifier modifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     protected AlterPointHook(Fight fight, Characteristic characteristic, int multiplier, TurnPointsModifier modifier) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  |         super(fight, characteristic, multiplier, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |         this.fight = fight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 1 |  |         this.modifier = modifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     @Override | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     protected void apply(Buff buff, PassiveFighter target, int value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |         super.apply(buff, target, value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |         fight.turnList().current() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |             .filter(turn -> turn.fighter().equals(target)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |             .ifPresent(turn -> modifier.modify(turn.points(), buff.effect().min())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * Hook for add a {@link Characteristic#MOVEMENT_POINT} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @see TurnPoints#addMovementPoints(int) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @see Characteristic#MOVEMENT_POINT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public static AlterPointHook addMovementPoint(Fight fight) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1 |  |         return new AlterPointHook(fight, Characteristic.MOVEMENT_POINT, 1, TurnPoints::addMovementPoints); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * Hook for remove a {@link Characteristic#MOVEMENT_POINT} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @see TurnPoints#removeMovementPoints(int) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @see Characteristic#MOVEMENT_POINT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public static AlterPointHook removeMovementPoint(Fight fight) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 1 |  |         return new AlterPointHook(fight, Characteristic.MOVEMENT_POINT, -1, TurnPoints::removeMovementPoints); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Hook for add a {@link Characteristic#ACTION_POINT} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @see TurnPoints#addActionPoints(int) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @see Characteristic#ACTION_POINT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public static AlterPointHook addActionPoint(Fight fight) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 1 |  |         return new AlterPointHook(fight, Characteristic.ACTION_POINT, 1, TurnPoints::addActionPoints); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * Hook for remove a {@link Characteristic#ACTION_POINT} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @see TurnPoints#removeActionPoints(int) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @see Characteristic#ACTION_POINT | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     public static AlterPointHook removeActionPoint(Fight fight) { | 
            
                                                                        
                            
            
                                    
            
            
                | 94 | 1 |  |         return new AlterPointHook(fight, Characteristic.ACTION_POINT, -1, TurnPoints::removeActionPoints); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     @FunctionalInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     public interface TurnPointsModifier { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |          * Modify the given turn points with the given value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |          * @param value Value to modify. Always a positive number | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         public void modify(TurnPoints points, @NonNegative int value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |  |