Passed
Pull Request — master (#266)
by Vincent
14:00
created

BoostSpellHandler(Modifier)   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
ccs 2
cts 2
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-2022 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.modifier;
21
22
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
23
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
24
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.BuffHook;
25
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler;
26
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
27
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
28
import fr.quatrevieux.araknemu.game.spell.boost.SpellsBoosts;
29
30
/**
31
 * Add a spell boost to a fighter
32
 * The boost is applied on buff start, and removed on buff termination
33
 *
34
 * Parameters:
35
 * - The first effect parameter (i.e. min) is the spell id
36
 * - The third effect parameter (i.e. special) is the boost value
37
 *
38
 * Note: There is no game action packet related to this effect
39
 *
40
 * @see fr.quatrevieux.araknemu.game.fight.fighter.FighterSpellList#boost(int, SpellsBoosts.Modifier, int)
41
 * @see BuffHook#onBuffStarted(Buff) Hook used for apply the boost
42
 * @see BuffHook#onBuffTerminated(Buff) Hook used for removed the boost
43
 */
44
public final class BoostSpellHandler implements EffectHandler, BuffHook {
45
    private final SpellsBoosts.Modifier modifier;
46
47
    /**
48
     * @param modifier Spell modifier to apply
49
     */
50 1
    public BoostSpellHandler(SpellsBoosts.Modifier modifier) {
51 1
        this.modifier = modifier;
52 1
    }
53
54
    @Override
55
    public void handle(CastScope cast, CastScope.EffectScope effect) {
56 1
        throw new UnsupportedOperationException("Boost spell can only be used as buff");
57
    }
58
59
    @Override
60
    public void buff(CastScope cast, CastScope.EffectScope effect) {
61 1
        for (PassiveFighter target : effect.targets()) {
62 1
            target.buffs().add(new Buff(effect.effect(), cast.action(), cast.caster(), target, this));
63 1
        }
64 1
    }
65
66
    @Override
67
    public void onBuffStarted(Buff buff) {
68 1
        final PassiveFighter target = buff.target();
69
70 1
        if (!(target instanceof Fighter)) {
71 1
            return;
72
        }
73
74 1
        final Fighter fighter = (Fighter) target;
75 1
        fighter.spells().boost(buff.effect().min(), modifier, buff.effect().special());
76 1
    }
77
78
    @Override
79
    public void onBuffTerminated(Buff buff) {
80 1
        final PassiveFighter target = buff.target();
81
82 1
        if (!(target instanceof Fighter)) {
83 1
            return;
84
        }
85
86 1
        final Fighter fighter = (Fighter) target;
87 1
        fighter.spells().boost(buff.effect().min(), modifier, -buff.effect().special());
88 1
    }
89
}
90