| 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; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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.buff.BuffHook; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * Buff hook for handle a characteristic change effect | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * The characteristic modification can be positive (add) or negative (remove) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * Use factory methods for create the hook instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @see AlterCharacteristicHook#add(Fight, Characteristic) For add a characteristic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * @see AlterCharacteristicHook#remove(Fight, Characteristic) For remove a characteristic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | public class AlterCharacteristicHook implements BuffHook { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     private final Fight fight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private final Characteristic characteristic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     private final int multiplier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     private final boolean applyMultiplierOnPacketValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param fight Fight where the hook will take effect | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param characteristic Characteristic to alter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param multiplier Value multiplier. -1 for removing characteristic, 1 for adding | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @param applyMultiplierOnPacketValue Does the actual altered value should be sent, or the raw effect value. Set to true if the client to not handle negative value by it-self (like AP removal) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |     protected AlterCharacteristicHook(Fight fight, Characteristic characteristic, int multiplier, boolean applyMultiplierOnPacketValue) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |         this.fight = fight; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |         this.characteristic = characteristic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |         this.multiplier = multiplier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  |         this.applyMultiplierOnPacketValue = applyMultiplierOnPacketValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     @Override | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public final void onBuffStarted(Buff buff) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  |         final int effectValue = buff.effect().min(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |         final int appliedValue = effectValue * multiplier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |         apply(buff, buff.target(), appliedValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |         fight.send(ActionEffect.buff(buff, applyMultiplierOnPacketValue ? appliedValue : effectValue)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     @Override | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public final void onBuffTerminated(Buff buff) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  |         apply(buff, buff.target(), -buff.effect().min() * multiplier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * Apply the buff effect to the buff target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Can be overridden for apply custom effects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param buff Buff to apply | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param target Buff target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param value Value to apply. Negative for removing, positive for adding | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     protected void apply(Buff buff, PassiveFighter target, int value) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 80 | 1 |  |         target.characteristics().alter(characteristic, value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Create the buff hook for add the given characteristic to the fighter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public static AlterCharacteristicHook add(Fight fight, Characteristic characteristic) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 1 |  |         return new AlterCharacteristicHook(fight, characteristic, 1, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * Create the buff hook for remove the given characteristic to the fighter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     public static AlterCharacteristicHook remove(Fight fight, Characteristic characteristic) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 1 |  |         return new AlterCharacteristicHook(fight, characteristic, -1, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 96 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |  |