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.exploration.npc.dialog.action.teleport; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.data.value.Position; |
23
|
|
|
import fr.quatrevieux.araknemu.data.world.entity.environment.npc.ResponseAction; |
24
|
|
|
import fr.quatrevieux.araknemu.game.exploration.ExplorationPlayer; |
25
|
|
|
import fr.quatrevieux.araknemu.game.exploration.interaction.action.move.ChangeMap; |
26
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.ExplorationMap; |
27
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.ExplorationMapService; |
28
|
|
|
import fr.quatrevieux.araknemu.game.exploration.npc.dialog.action.Action; |
29
|
|
|
import fr.quatrevieux.araknemu.game.exploration.npc.dialog.action.ActionFactory; |
30
|
|
|
import fr.quatrevieux.araknemu.network.game.out.info.Information; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Teleport to Astrub statue |
34
|
|
|
*/ |
35
|
|
|
public final class GoToAstrub implements Action { |
36
|
|
|
private final ExplorationMapService service; |
37
|
|
|
|
38
|
1 |
|
public GoToAstrub(ExplorationMapService service) { |
39
|
1 |
|
this.service = service; |
40
|
1 |
|
} |
41
|
|
|
|
42
|
|
|
@Override |
43
|
|
|
public boolean check(ExplorationPlayer player) { |
44
|
1 |
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
@Override |
48
|
|
|
public void apply(ExplorationPlayer player) { |
49
|
1 |
|
final Position position = player.player().race().astrubPosition(); |
50
|
1 |
|
final ExplorationMap targetMap = service.load(position.map()); |
51
|
|
|
|
52
|
1 |
|
if (position.cell() >= targetMap.size()) { |
53
|
|
|
throw new IllegalStateException("Invalid cell for astrub map " + position); |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
player.interactions().push(new ChangeMap(player, targetMap, position.cell(), 7)); |
57
|
1 |
|
player.player().setSavedPosition(position); |
58
|
1 |
|
player.send(Information.positionSaved()); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
public static final class Factory implements ActionFactory { |
62
|
|
|
private final ExplorationMapService service; |
63
|
|
|
|
64
|
1 |
|
public Factory(ExplorationMapService service) { |
65
|
1 |
|
this.service = service; |
66
|
1 |
|
} |
67
|
|
|
|
68
|
|
|
@Override |
69
|
|
|
public String type() { |
70
|
1 |
|
return "GOTO_ASTRUB"; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
@Override |
74
|
|
|
public Action create(ResponseAction entity) { |
75
|
1 |
|
return new GoToAstrub(service); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|