Passed
Pull Request — master (#193)
by Vincent
11:12
created

fr.quatrevieux.araknemu.game.fight.ai.simulation.effect.ArmorSimulator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 25
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B simulate(CastSimulation,EffectScope) 0 24 6
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.PassiveFighter;
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 effect) {
35 1
        if (effect.effect().duration() < 1) {
36 1
            return;
37
        }
38
39 1
        final Set<Element> elements = effect.effect().special() == 0
40 1
            ? EnumSet.allOf(Element.class)
41 1
            : Element.fromBitSet(effect.effect().special())
42
        ;
43
44 1
        for (PassiveFighter target : effect.targets()) {
45 1
            for (Element element : elements) {
46 1
                int armor = effect.effect().min();
47
48
                // Compute boost only for caster characteristics, because we shouldn't know other fighters one
49 1
                if (target.equals(simulation.caster())) {
50 1
                    final Characteristics characteristics = simulation.caster().characteristics();
51 1
                    final int boost = 200 + characteristics.get(Characteristic.INTELLIGENCE) + characteristics.get(element.boost());
52
53 1
                    armor = armor * boost / 200;
54
                }
55
56 1
                simulation.addBoost(armor * effect.effect().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...
57 1
            }
58 1
        }
59 1
    }
60
}
61