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 { |
|
|
|
|
40
|
|
|
@Override |
41
|
|
|
public void handle(CastScope cast, CastScope.EffectScope effect) { |
42
|
|
|
// @fixme How to handle this case ? Used by spell 521 |
|
|
|
|
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
|
|
|
|