Passed
Pull Request — master (#207)
by Vincent
10:53
created

onReflectedDamage(Buff,ReflectedDamage)   A

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
dl 0
loc 1
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
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-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.fight.castable.effect.buff;
21
22
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
23
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.damage.Damage;
24
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.damage.ReflectedDamage;
25
import fr.quatrevieux.araknemu.game.fight.fighter.ActiveFighter;
26
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
27
28
/**
29
 * Hook action for apply buff effects
30
 */
31
public interface BuffHook {
32
    /**
33
     * Apply effect when fighter turn is started
34
     *
35
     * @return False if the fighter cannot start the turn
36
     */
37
    public default boolean onStartTurn(Buff buff) {
38 1
        return true;
39
    }
40
41
    /**
42
     * Apply effect on turn ending
43
     */
44 1
    public default void onEndTurn(Buff buff) {}
45
46
    /**
47
     * Start the buff
48
     */
49 1
    public default void onBuffStarted(Buff buff) {}
50
51
    /**
52
     * The buff is terminated (buff expired, debuff...)
53
     */
54 1
    public default void onBuffTerminated(Buff buff) {}
55
56
    /**
57
     * The fighter is a target of a cast
58
     *
59
     * To get the spell caster, use {@code cast.caster()}, and to get the target, use {@code buff.target()}.
60
     *
61
     * If the target is changed or removed, this method must return false.
62
     * Retuning false permit to notify that the spell targets has changed to ensure that new
63
     * target will also be taken in account, but also stop applying other "onCastTarget" hooks
64
     * on the current fighter.
65
     *
66
     * This method will be called on direct and indirect (like spell returned) targets.
67
     *
68
     * Implementation:
69
     * <pre>{@code
70
     * class MyEffectHandler implements EffectHandler, BuffHook {
71
     *     public void handle(CastScope cast, CastScope.EffectScope effect) {
72
     *         // ...
73
     *     }
74
     *
75
     *     // Add the buff to targets
76
     *     public void buff(CastScope cast, CastScope.EffectScope effect) {
77
     *         for (PassiveFighter target : effect.targets()) {
78
     *             target.buffs().add(new Buff(effect.effect(), cast.action(), cast.caster(), target, this));
79
     *         }
80
     *     }
81
     *
82
     *     // Implements the buff hook
83
     *     public void onCastTarget(Buff buff, CastScope cast) {
84
     *         if (!checkCast(cast)) {
85
     *             return true; // ignore the hook for this cast : return true to continue on this target
86
     *         }
87
     *
88
     *         // Apply buff effect...
89
     *         // ...
90
     *
91
     *         // Change the target
92
     *         // buff.target() is cast target / fighter who has the given buff applied
93
     *         cast.replaceTarget(buff.target(), getNewTarget(cast));
94
     *
95
     *         // You can also remove the current fighter from spell targets
96
     *         cast.removeTarget(buff.target());
97
     *
98
     *         return false; // The target has been changed (or removed)
99
     *     }
100
     * }
101
     * }</pre>
102
     *
103
     * @return true to continue, or false if the cast target has changed (removed or replaced)
104
     *
105
     * @see CastScope#removeTarget(PassiveFighter)
106
     * @see CastScope#replaceTarget(PassiveFighter, PassiveFighter)
107
     */
108
    public default boolean onCastTarget(Buff buff, CastScope cast) {
109 1
        return true;
110
    }
111
112
    /**
113
     * The fighter will take damages
114
     */
115 1
    public default void onDamage(Buff buff, Damage value) {}
116
117
    /**
118
     * The fighter will take damages
119
     */
120
    public default void onDirectDamage(Buff buff, ActiveFighter caster, Damage value) {
121 1
        onDamage(buff, value);
122 1
    }
123
124
    /**
125
     * The fighter will take damages by a buff (i.e. poison)
126
     *
127
     * @param buff The current buff
128
     * @param poison The poison buff
129
     * @param value The damage to apply
130
     */
131
    public default void onBuffDamage(Buff buff, Buff poison, Damage value) {
132 1
        onDamage(buff, value);
133 1
    }
134
135
    /**
136
     * The fighter life has been altered
137
     *
138
     * Unlike {@link BuffHook#onDamage(Buff, Damage)}, the effects has already been applied
139
     *
140
     * @param buff The active buff
141
     * @param value Altered life value. Negative for a damage, positive for a heal
142
     *
143
     * @see fr.quatrevieux.araknemu.game.fight.fighter.FighterLife#alter(fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter, int)
144
     */
145 1
    public default void onLifeAltered(Buff buff, int value) {}
146
147
    /**
148
     * Damage has been reflected by the cast target
149
     *
150
     * The target can be changed using {@link ReflectedDamage#changeTarget(PassiveFighter)}
151
     * Or modified using {@link ReflectedDamage#multiply(int)}
152
     *
153
     * @param buff The active buff
154
     * @param damage The reflected damage
155
     */
156
    public default void onReflectedDamage(Buff buff, ReflectedDamage damage) {}
157
}
158