fr.quatrevieux.araknemu.game.fight.ai.simulation.effect.HealSimulator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 22
ccs 14
cts 14
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A simulate(CastSimulation,EffectScope) 0 21 4
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.arakne.utils.value.Interval;
23
import fr.quatrevieux.araknemu.data.constant.Characteristic;
24
import fr.quatrevieux.araknemu.game.fight.ai.simulation.CastSimulation;
25
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
26
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
27
import fr.quatrevieux.araknemu.game.fight.fighter.FighterData;
28
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect;
29
30
/**
31
 * Simulate simple heal effect
32
 *
33
 * @see fr.quatrevieux.araknemu.game.fight.castable.effect.handler.heal.HealHandler
34
 */
35 1
public final class HealSimulator implements EffectSimulator {
36
    @Override
37
    public void simulate(CastSimulation simulation, CastScope.EffectScope<? extends FighterData> effect) {
38 1
        final FighterData caster = simulation.caster();
39 1
        final int boost = caster.characteristics().get(Characteristic.INTELLIGENCE);
40 1
        final int fixed = caster.characteristics().get(Characteristic.HEALTH_BOOST);
41
42 1
        for (FighterData target : effect.targets()) {
43 1
            final SpellEffect spellEffect = effect.effect();
44 1
            final Interval value = EffectValue.create(spellEffect, simulation.caster(), target)
45 1
                .percent(boost)
46 1
                .fixed(fixed)
47 1
                .interval()
48
            ;
49
50 1
            final int duration = spellEffect.duration();
51
52 1
            if (duration == 0) {
53 1
                simulation.addHeal(value, target);
54
            } else {
55
                // Limit duration to 10
56 1
                simulation.addHealBuff(value, duration < 1 || duration > 10 ? 10 : duration, target);
57
            }
58 1
        }
59 1
    }
60
}
61