| 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-2022 Vincent Quatrevieux | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | package fr.quatrevieux.araknemu.game.fight.ai.simulation.effect; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | import fr.quatrevieux.araknemu.data.constant.Characteristic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | import fr.quatrevieux.araknemu.game.fight.ai.simulation.CastSimulation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | import fr.quatrevieux.araknemu.game.fight.castable.CastScope; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | import org.checkerframework.checker.index.qual.Positive; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * Simulation points removals (AP or MP) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * Note: an approximation is used instead of actual algorithm for compute removed points | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | public final class RemovePointsSimulator implements EffectSimulator { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     private final Characteristic pointCharacteristic; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     private final Characteristic resistanceCharacteristic; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     private final @Positive int multiplier; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * @param pointCharacteristic Removed point characteristic (i.e. Characteristic.ACTION_POINT or Characteristic.MOVEMENT_POINT) | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @param resistanceCharacteristic Characteristic use for dodge point removal | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @param multiplier Boost multiplier. Must be a positive integer | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 | 1 |  |     public RemovePointsSimulator(Characteristic pointCharacteristic, Characteristic resistanceCharacteristic, @Positive int multiplier) { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 1 |  |         this.pointCharacteristic = pointCharacteristic; | 
            
                                                                        
                            
            
                                    
            
            
                | 46 | 1 |  |         this.resistanceCharacteristic = resistanceCharacteristic; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 | 1 |  |         this.multiplier = multiplier; | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     @Override | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     public void simulate(CastSimulation simulation, CastScope.EffectScope effect) { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 1 |  |         final int casterChance = Math.max(simulation.caster().characteristics().get(Characteristic.WISDOM) / 10, 1); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 1 |  |         int duration = effect.effect().duration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 1 |  |         if (duration == -1 || duration > 10) { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 1 |  |             duration = 10; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 1 |  |         if (duration == 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 61 | 1 |  |             duration = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 1 |  |         for (PassiveFighter target : effect.targets()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             // @todo actual turn AP is target is current fighter | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 1 |  |             final int currentPoints = target.characteristics().get(pointCharacteristic); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 1 |  |             if (currentPoints <= 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 1 |  |                 continue; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 | 1 |  |             final int targetResistance = Math.max(target.characteristics().get(resistanceCharacteristic), 1); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 1 |  |             final double percent = Math.min(0.5 * casterChance / targetResistance, 1.0); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 1 |  |             final int value = multiplier * EffectValue.create(effect.effect(), simulation.caster(), target).value(); | 
            
                                                                        
                            
            
                                    
            
            
                | 75 | 1 |  |             final int maxValue = currentPoints * multiplier; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 | 1 |  |             simulation.addBoost( | 
            
                                                                        
                            
            
                                    
            
            
                | 78 | 1 |  |                 - Math.min(maxValue, percent * value) * duration, | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |                 target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 1 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  |