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
 * Handle basic heal effect
34
 *
35
 * This effect is boosted by {@link Characteristic#INTELLIGENCE} and {@link Characteristic#HEALTH_BOOST}
36
 */
37 1 View Code Duplication
public final class HealHandler implements EffectHandler, BuffHook {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
38
    @Override
39
    public void handle(CastScope cast, CastScope.EffectScope effect) {
40 1
        for (PassiveFighter target : effect.targets()) {
41 1
            apply(cast.caster(), effect.effect(), target);
42 1
        }
43 1
    }
44
45
    @Override
46
    public void buff(CastScope cast, CastScope.EffectScope effect) {
47 1
        for (PassiveFighter target : effect.targets()) {
48 1
            target.buffs().add(new Buff(effect.effect(), cast.action(), cast.caster(), target, this));
49 1
        }
50 1
    }
51
52
    @Override
53
    public boolean onStartTurn(Buff buff) {
54 1
        apply(buff.caster(), buff.effect(), buff.target());
55
56 1
        return true;
57
    }
58
59
    private void apply(ActiveFighter caster, SpellEffect effect, PassiveFighter target) {
60 1
        final EffectValue value = new EffectValue(effect)
61 1
            .percent(caster.characteristics().get(Characteristic.INTELLIGENCE))
62 1
            .fixed(caster.characteristics().get(Characteristic.HEALTH_BOOST))
63
        ;
64
65 1
        target.life().alter(caster, value.value());
66 1
    }
67
}
68