simulate(CastSimulation,EffectScope)   B
last analyzed

Complexity

Conditions 8

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 18
dl 0
loc 31
ccs 16
cts 16
cp 1
crap 8
rs 7.3333
c 1
b 0
f 0
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.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.Element;
26
import fr.quatrevieux.araknemu.game.fight.fighter.FighterData;
27
import fr.quatrevieux.araknemu.game.world.creature.characteristics.Characteristics;
28
29
import java.util.EnumSet;
30
import java.util.Set;
31
32 1
public final class ArmorSimulator implements EffectSimulator {
33
    @Override
34
    public void simulate(CastSimulation simulation, CastScope.EffectScope<? extends FighterData> effect) {
35 1
        int duration = effect.effect().duration();
36
37 1
        if (duration == 0) {
38 1
            return;
39
        }
40
41
        // Limit duration to 10 for compute score
42 1
        if (duration == -1 || duration > 10) {
43 1
            duration = 10;
44
        }
45
46 1
        final Set<Element> elements = effect.effect().special() == 0
47 1
            ? EnumSet.allOf(Element.class)
48 1
            : Element.fromBitSet(effect.effect().special())
49
        ;
50
51 1
        for (FighterData target : effect.targets()) {
52 1
            for (Element element : elements) {
53 1
                int armor = effect.effect().min();
54
55
                // Compute boost only for caster characteristics, because we shouldn't know other fighters one
56 1
                if (target.equals(simulation.caster())) {
57 1
                    final Characteristics characteristics = simulation.caster().characteristics();
58 1
                    final int boost = 200 + characteristics.get(Characteristic.INTELLIGENCE) + characteristics.get(element.boost());
59
60 1
                    armor = armor * boost / 200;
61
                }
62
63 1
                simulation.addBoost(armor * duration, target);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this multiplication to double.
Loading history...
64 1
            }
65 1
        }
66 1
    }
67
}
68