|
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.shifting; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.game.fight.Fight; |
|
23
|
|
|
import fr.quatrevieux.araknemu.game.fight.castable.CastScope; |
|
24
|
|
|
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectsUtils; |
|
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
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Buff effect for switch position between buff caster and target when the target will take damage |
|
33
|
|
|
* This effect will also replace the cast target |
|
34
|
|
|
* |
|
35
|
|
|
* @see CastScope#replaceTarget(PassiveFighter, PassiveFighter) |
|
36
|
|
|
*/ |
|
37
|
|
|
public final class SwitchPositionOnAttackHandler implements EffectHandler, BuffHook { |
|
38
|
|
|
private final SwitchPositionApplier applier; |
|
39
|
|
|
|
|
40
|
|
|
public SwitchPositionOnAttackHandler(Fight fight) { |
|
41
|
|
|
this.applier = new SwitchPositionApplier(fight); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
@Override |
|
45
|
|
|
public void handle(CastScope cast, CastScope.EffectScope effect) { |
|
46
|
|
|
throw new UnsupportedOperationException("Switch position on damage is a buff effect"); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
@Override |
|
50
|
|
|
public void buff(CastScope cast, CastScope.EffectScope effect) { |
|
51
|
|
|
final ActiveFighter caster = cast.caster(); |
|
52
|
|
|
|
|
53
|
|
|
for (PassiveFighter target : effect.targets()) { |
|
54
|
|
|
if (!target.equals(caster)) { |
|
55
|
|
|
target.buffs().add(new Buff(effect.effect(), cast.action(), caster, target, this)); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
@Override |
|
61
|
|
|
public boolean onCastTarget(Buff buff, CastScope cast) { |
|
62
|
|
|
if (!isDamageCast(cast)) { |
|
63
|
|
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
final ActiveFighter buffCaster = buff.caster(); |
|
67
|
|
|
final PassiveFighter target = buff.target(); |
|
68
|
|
|
|
|
69
|
|
|
applier.apply(buffCaster, target); |
|
70
|
|
|
cast.replaceTarget(target, buffCaster); |
|
71
|
|
|
|
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Check if the action is direct damage attack |
|
77
|
|
|
* |
|
78
|
|
|
* @param cast The action to check |
|
79
|
|
|
* |
|
80
|
|
|
* @return true if the cast can be dodged |
|
81
|
|
|
*/ |
|
82
|
|
|
private boolean isDamageCast(CastScope cast) { |
|
83
|
|
|
return cast.effects().stream() |
|
84
|
|
|
.map(CastScope.EffectScope::effect) |
|
85
|
|
|
// Should return only direct damage effects |
|
86
|
|
|
.anyMatch(effect -> EffectsUtils.isDamageEffect(effect.effect()) && effect.duration() == 0) |
|
87
|
|
|
; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|