Test Failed
Branch master (8e433c)
by Vincent
18:50
created

apply(ActiveFighter,SpellEffect,PassiveFighter)   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 7
loc 7
c 1
b 0
f 0
cc 1
ccs 4
cts 4
cp 1
crap 1
rs 10
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.heal;
21
22
import fr.quatrevieux.araknemu.data.constant.Characteristic;
23
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
24
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
25
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
26
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.BuffHook;
27
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler;
28
import fr.quatrevieux.araknemu.game.fight.fighter.ActiveFighter;
29
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
30
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect;
31
32
/**
33
 * Buff effect for apply a heal when the fighter receive damage
34
 *
35
 * This effect is boosted by {@link Characteristic#INTELLIGENCE} and {@link Characteristic#HEALTH_BOOST}
36
 *
37
 * @see fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buffs#onLifeAltered(int)
38
 */
39 1 View Code Duplication
public final class HealOnDamageHandler implements EffectHandler, BuffHook {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
40
    @Override
41
    public void handle(CastScope cast, CastScope.EffectScope effect) {
42
        // @fixme How to handle this case ? Used by spell 521
0 ignored issues
show
Code Smell introduced by
Tasks associated with this FIXME comment should be completed and this comment removed.
Loading history...
43 1
        for (PassiveFighter target : effect.targets()) {
44 1
            apply(cast.caster(), effect.effect(), target);
45 1
        }
46 1
    }
47
48
    @Override
49
    public void buff(CastScope cast, CastScope.EffectScope effect) {
50 1
        for (PassiveFighter target : effect.targets()) {
51 1
            target.buffs().add(new Buff(effect.effect(), cast.action(), cast.caster(), target, this));
52 1
        }
53 1
    }
54
55
    @Override
56
    public void onLifeAltered(Buff buff, int value) {
57 1
        if (value < 0) {
58 1
            apply(buff.caster(), buff.effect(), buff.target());
59
        }
60 1
    }
61
62
    private void apply(ActiveFighter caster, SpellEffect effect, PassiveFighter target) {
63 1
        final EffectValue value = new EffectValue(effect)
64 1
            .percent(caster.characteristics().get(Characteristic.INTELLIGENCE))
65 1
            .fixed(caster.characteristics().get(Characteristic.HEALTH_BOOST))
66
        ;
67
68 1
        target.life().alter(caster, value.value());
69 1
    }
70
}
71