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.handler.game; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.core.network.exception.CloseImmediately; |
23
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.PacketHandler; |
24
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.ExplorationMap; |
25
|
|
|
import fr.quatrevieux.araknemu.game.fight.Fight; |
26
|
|
|
import fr.quatrevieux.araknemu.game.fight.FightService; |
27
|
|
|
import fr.quatrevieux.araknemu.game.fight.state.PlacementState; |
28
|
|
|
import fr.quatrevieux.araknemu.game.fight.team.FightTeam; |
29
|
|
|
import fr.quatrevieux.araknemu.game.fight.team.TeamOptions; |
30
|
|
|
import fr.quatrevieux.araknemu.network.game.GameSession; |
31
|
|
|
import fr.quatrevieux.araknemu.network.game.in.game.AskExtraInfo; |
32
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.FightOption; |
33
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.exploration.AddTeamFighters; |
34
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.exploration.FightsCount; |
35
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.exploration.ShowFight; |
36
|
|
|
import fr.quatrevieux.araknemu.network.game.out.game.AddSprites; |
37
|
|
|
import fr.quatrevieux.araknemu.network.game.out.game.MapReady; |
38
|
|
|
import org.checkerframework.checker.nullness.util.NullnessUtil; |
39
|
|
|
|
40
|
|
|
import java.util.Collection; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Load map extra info for join the map |
44
|
|
|
* |
45
|
|
|
* @todo refactor with extract info provider |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
public final class LoadExtraInfo implements PacketHandler<GameSession, AskExtraInfo> { |
48
|
|
|
private final FightService fightService; |
49
|
|
|
|
50
|
1 |
|
public LoadExtraInfo(FightService fightService) { |
51
|
1 |
|
this.fightService = fightService; |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
@Override |
55
|
|
|
public void handle(GameSession session, AskExtraInfo packet) throws Exception { |
56
|
1 |
|
final ExplorationMap map = NullnessUtil.castNonNull(session.exploration()).map(); |
57
|
|
|
|
58
|
1 |
|
if (map == null) { |
59
|
|
|
throw new CloseImmediately("A map should be loaded before get extra info"); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
session.send(new AddSprites(map.sprites())); |
63
|
|
|
|
64
|
1 |
|
final Collection<Fight> fights = fightService.fightsByMap(map.id()); |
65
|
|
|
|
66
|
1 |
|
for (Fight fight : fights) { |
67
|
1 |
|
if (!(fight.state() instanceof PlacementState)) { |
68
|
1 |
|
continue; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
session.send(new ShowFight(fight)); |
72
|
|
|
|
73
|
1 |
|
for (FightTeam team : fight.teams()) { |
74
|
1 |
|
session.send(new AddTeamFighters(team)); |
75
|
|
|
|
76
|
1 |
|
final TeamOptions options = team.options(); |
77
|
|
|
|
78
|
1 |
|
if (options.allowJoinTeamHasBeenUpdated()) { |
79
|
1 |
|
session.send(FightOption.blockJoiner(options)); |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
if (options.allowSpectatorHasBeenUpdated()) { |
83
|
1 |
|
session.send(FightOption.blockSpectators(options)); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
if (options.needHelpHasBeenUpdated()) { |
87
|
1 |
|
session.send(FightOption.needHelp(options)); |
88
|
|
|
} |
89
|
1 |
|
} |
90
|
1 |
|
} |
91
|
|
|
|
92
|
1 |
|
session.send(new FightsCount(fights.size())); |
93
|
|
|
|
94
|
1 |
|
session.send(new MapReady()); |
95
|
1 |
|
} |
96
|
|
|
|
97
|
|
|
@Override |
98
|
|
|
public Class<AskExtraInfo> packet() { |
99
|
1 |
|
return AskExtraInfo.class; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|