|
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 Jean-Alexandre Valentin |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.invocations; |
|
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.CastScope.EffectScope; |
|
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.FighterFactory; |
|
28
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.invocation.InvocationFighter; |
|
29
|
|
|
import fr.quatrevieux.araknemu.game.fight.team.FightTeam; |
|
30
|
|
|
import fr.quatrevieux.araknemu.game.monster.MonsterService; |
|
31
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect; |
|
32
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.turn.FighterTurnOrder; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Handle monster invocation |
|
36
|
|
|
* |
|
37
|
|
|
* A new fighter will be created and added to fight and timeline (turn list) |
|
38
|
|
|
* |
|
39
|
|
|
* Effect parameters : |
|
40
|
|
|
* - #1 (min) : monster id |
|
41
|
|
|
* - #2 (max) : grade number |
|
42
|
|
|
* |
|
43
|
|
|
* @see InvocationFighter Invoked fighter |
|
44
|
|
|
*/ |
|
45
|
|
|
public final class MonsterInvocationHandler implements EffectHandler { |
|
46
|
|
|
private final MonsterService monsterService; |
|
47
|
|
|
private final FighterFactory fighterFactory; |
|
48
|
|
|
private final Fight fight; |
|
49
|
|
|
|
|
50
|
1 |
|
public MonsterInvocationHandler(MonsterService monsterService, FighterFactory fighterFactory, Fight fight) { |
|
51
|
1 |
|
this.monsterService = monsterService; |
|
52
|
1 |
|
this.fighterFactory = fighterFactory; |
|
53
|
1 |
|
this.fight = fight; |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
@Override |
|
57
|
|
|
public void buff(CastScope cast, EffectScope effect) { |
|
58
|
1 |
|
handle(cast, effect); |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
@Override |
|
62
|
|
|
public void handle(CastScope cast, EffectScope effect) { |
|
63
|
1 |
|
final Fighter invocation = fighterFactory.generate(id -> new InvocationFighter( |
|
64
|
|
|
id, |
|
65
|
1 |
|
monsterService.load(effect.effect().min()).get(effect.effect().max()), |
|
66
|
1 |
|
(FightTeam) cast.caster().team(), |
|
67
|
1 |
|
cast.caster() |
|
68
|
|
|
)); |
|
69
|
|
|
|
|
70
|
1 |
|
invocation.joinFight(fight, cast.target()); |
|
71
|
1 |
|
fight.turnList().add(invocation); |
|
72
|
|
|
|
|
73
|
1 |
|
invocation.init(); |
|
74
|
|
|
|
|
75
|
1 |
|
fight.send(ActionEffect.addInvocation(cast.caster(), invocation)); |
|
76
|
1 |
|
fight.send(ActionEffect.packet(cast.caster(), new FighterTurnOrder(fight.turnList()))); |
|
77
|
1 |
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|