Passed
Pull Request — master (#224)
by Vincent
11:59
created

onEffectValueCast(Buff,EffectValue)   A

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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