1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2012-2019 The ManaPlus Developers |
4 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
5 |
|
|
* |
6 |
|
|
* This file is part of The ManaPlus Client. |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "actions/move.h" |
23 |
|
|
|
24 |
|
|
#include "game.h" |
25 |
|
|
|
26 |
|
|
#include "actions/actiondef.h" |
27 |
|
|
#include "actions/pets.h" |
28 |
|
|
|
29 |
|
|
#include "being/crazymoves.h" |
30 |
|
|
#include "being/localplayer.h" |
31 |
|
|
|
32 |
|
|
#include "enums/being/beingdirection.h" |
33 |
|
|
|
34 |
|
|
#include "gui/windows/socialwindow.h" |
35 |
|
|
#include "gui/windows/npcdialog.h" |
36 |
|
|
#include "gui/windows/outfitwindow.h" |
37 |
|
|
|
38 |
|
|
#include "gui/popups/popupmenu.h" |
39 |
|
|
|
40 |
|
|
#include "input/inputactionoperators.h" |
41 |
|
|
|
42 |
|
|
#include "net/playerhandler.h" |
43 |
|
|
|
44 |
|
|
#include "debug.h" |
45 |
|
|
|
46 |
|
|
namespace Actions |
47 |
|
|
{ |
48 |
|
|
|
49 |
|
|
static bool closeMoveNpcDialog(bool focus) |
50 |
|
|
{ |
51 |
|
|
NpcDialog *const dialog = NpcDialog::getActive(); |
52 |
|
|
if (dialog != nullptr) |
53 |
|
|
{ |
54 |
|
|
if (dialog->isCloseState() != 0) |
55 |
|
|
{ |
56 |
|
|
dialog->closeDialog(); |
57 |
|
|
return true; |
58 |
|
|
} |
59 |
|
|
else if (focus) |
60 |
|
|
{ |
61 |
|
|
dialog->refocus(); |
62 |
|
|
} |
63 |
|
|
} |
64 |
|
|
return false; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
impHandler(moveUp) |
68 |
|
|
{ |
69 |
|
|
if (inputManager.isActionActive(InputAction::EMOTE)) |
70 |
|
|
return directUp(event); |
71 |
|
|
else if (inputManager.isActionActive(InputAction::PET_EMOTE)) |
72 |
|
|
return petDirectUp(event); |
73 |
|
|
else if (inputManager.isActionActive(InputAction::STOP_ATTACK)) |
74 |
|
|
return petMoveUp(event); |
75 |
|
|
else if (!localPlayer->canMove()) |
76 |
|
|
return directUp(event); |
77 |
|
|
if (popupMenu->isPopupVisible()) |
78 |
|
|
{ |
79 |
|
|
popupMenu->moveUp(); |
80 |
|
|
return true; |
81 |
|
|
} |
82 |
|
|
return closeMoveNpcDialog(false); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
impHandler(moveDown) |
86 |
|
|
{ |
87 |
|
|
if (inputManager.isActionActive(InputAction::EMOTE)) |
88 |
|
|
return directDown(event); |
89 |
|
|
else if (inputManager.isActionActive(InputAction::PET_EMOTE)) |
90 |
|
|
return petDirectDown(event); |
91 |
|
|
else if (inputManager.isActionActive(InputAction::STOP_ATTACK)) |
92 |
|
|
return petMoveDown(event); |
93 |
|
|
else if (!localPlayer->canMove()) |
94 |
|
|
return directDown(event); |
95 |
|
|
if (popupMenu->isPopupVisible()) |
96 |
|
|
{ |
97 |
|
|
popupMenu->moveDown(); |
98 |
|
|
return true; |
99 |
|
|
} |
100 |
|
|
return closeMoveNpcDialog(false); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
impHandler(moveLeft) |
104 |
|
|
{ |
105 |
|
|
if (outfitWindow != nullptr && |
106 |
|
|
inputManager.isActionActive(InputAction::WEAR_OUTFIT)) |
107 |
|
|
{ |
108 |
|
|
outfitWindow->wearPreviousOutfit(false); |
109 |
|
|
if (Game::instance() != nullptr) |
110 |
|
|
Game::instance()->setValidSpeed(); |
111 |
|
|
return true; |
112 |
|
|
} |
113 |
|
|
if (inputManager.isActionActive(InputAction::EMOTE)) |
114 |
|
|
return directLeft(event); |
115 |
|
|
else if (inputManager.isActionActive(InputAction::PET_EMOTE)) |
116 |
|
|
return petDirectLeft(event); |
117 |
|
|
else if (inputManager.isActionActive(InputAction::STOP_ATTACK)) |
118 |
|
|
return petMoveLeft(event); |
119 |
|
|
else if (!localPlayer->canMove()) |
120 |
|
|
return directLeft(event); |
121 |
|
|
return closeMoveNpcDialog(false); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
impHandler(moveRight) |
125 |
|
|
{ |
126 |
|
|
if (outfitWindow != nullptr && |
127 |
|
|
inputManager.isActionActive(InputAction::WEAR_OUTFIT)) |
128 |
|
|
{ |
129 |
|
|
outfitWindow->wearNextOutfit(false); |
130 |
|
|
if (Game::instance() != nullptr) |
131 |
|
|
Game::instance()->setValidSpeed(); |
132 |
|
|
return true; |
133 |
|
|
} |
134 |
|
|
if (inputManager.isActionActive(InputAction::EMOTE)) |
135 |
|
|
return directRight(event); |
136 |
|
|
else if (inputManager.isActionActive(InputAction::PET_EMOTE)) |
137 |
|
|
return petDirectRight(event); |
138 |
|
|
else if (inputManager.isActionActive(InputAction::STOP_ATTACK)) |
139 |
|
|
return petMoveRight(event); |
140 |
|
|
else if (!localPlayer->canMove()) |
141 |
|
|
return directRight(event); |
142 |
|
|
return closeMoveNpcDialog(false); |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
impHandler(moveForward) |
146 |
|
|
{ |
147 |
|
|
if (inputManager.isActionActive(InputAction::EMOTE)) |
148 |
|
|
return directRight(event); |
149 |
|
|
return closeMoveNpcDialog(false); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
impHandler(moveToPoint) |
153 |
|
|
{ |
154 |
|
|
const int num = event.action - InputAction::MOVE_TO_POINT_1; |
155 |
|
|
if ((socialWindow != nullptr) && num >= 0) |
156 |
|
|
{ |
157 |
|
|
socialWindow->selectPortal(num); |
158 |
|
|
return true; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
return false; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
impHandler0(crazyMoves) |
165 |
|
|
{ |
166 |
|
|
if (localPlayer != nullptr) |
167 |
|
|
{ |
168 |
|
|
::crazyMoves->crazyMove(); |
169 |
|
|
return true; |
170 |
|
|
} |
171 |
|
|
return false; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
impHandler0(moveToTarget) |
175 |
|
|
{ |
176 |
|
|
if (localPlayer != nullptr && |
177 |
|
|
!inputManager.isActionActive(InputAction::TARGET_ATTACK) && |
178 |
|
|
!inputManager.isActionActive(InputAction::ATTACK)) |
179 |
|
|
{ |
180 |
|
|
localPlayer->moveToTarget(-1); |
181 |
|
|
return true; |
182 |
|
|
} |
183 |
|
|
return false; |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
impHandler0(moveToHome) |
187 |
|
|
{ |
188 |
|
|
if (localPlayer != nullptr && |
189 |
|
|
!inputManager.isActionActive(InputAction::TARGET_ATTACK) && |
190 |
|
|
!inputManager.isActionActive(InputAction::ATTACK)) |
191 |
|
|
{ |
192 |
|
|
localPlayer->moveToHome(); |
193 |
|
|
if (Game::instance() != nullptr) |
194 |
|
|
Game::instance()->setValidSpeed(); |
195 |
|
|
return true; |
196 |
|
|
} |
197 |
|
|
return false; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
impHandler0(directUp) |
201 |
|
|
{ |
202 |
|
|
if (localPlayer != nullptr) |
203 |
|
|
{ |
204 |
|
|
if (localPlayer->getDirection() != BeingDirection::UP) |
205 |
|
|
{ |
206 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
207 |
|
|
{ |
208 |
|
|
localPlayer->setDirection(BeingDirection::UP); |
209 |
|
|
if (playerHandler != nullptr) |
210 |
|
|
playerHandler->setDirection(BeingDirection::UP); |
211 |
|
|
} |
212 |
|
|
} |
213 |
|
|
return true; |
214 |
|
|
} |
215 |
|
|
return false; |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
impHandler0(directDown) |
219 |
|
|
{ |
220 |
|
|
if (localPlayer != nullptr) |
221 |
|
|
{ |
222 |
|
|
if (localPlayer->getDirection() != BeingDirection::DOWN) |
223 |
|
|
{ |
224 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
225 |
|
|
{ |
226 |
|
|
localPlayer->setDirection(BeingDirection::DOWN); |
227 |
|
|
if (playerHandler != nullptr) |
228 |
|
|
{ |
229 |
|
|
playerHandler->setDirection( |
230 |
|
|
BeingDirection::DOWN); |
231 |
|
|
} |
232 |
|
|
} |
233 |
|
|
} |
234 |
|
|
return true; |
235 |
|
|
} |
236 |
|
|
return false; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
impHandler0(directLeft) |
240 |
|
|
{ |
241 |
|
|
if (localPlayer != nullptr) |
242 |
|
|
{ |
243 |
|
|
if (localPlayer->getDirection() != BeingDirection::LEFT) |
244 |
|
|
{ |
245 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
246 |
|
|
{ |
247 |
|
|
localPlayer->setDirection(BeingDirection::LEFT); |
248 |
|
|
if (playerHandler != nullptr) |
249 |
|
|
{ |
250 |
|
|
playerHandler->setDirection( |
251 |
|
|
BeingDirection::LEFT); |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
} |
255 |
|
|
return true; |
256 |
|
|
} |
257 |
|
|
return false; |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
impHandler0(directRight) |
261 |
|
|
{ |
262 |
|
|
if (localPlayer != nullptr) |
263 |
|
|
{ |
264 |
|
|
if (localPlayer->getDirection() != BeingDirection::RIGHT) |
265 |
|
|
{ |
266 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
267 |
|
|
{ |
268 |
|
|
localPlayer->setDirection(BeingDirection::RIGHT); |
269 |
|
|
if (playerHandler != nullptr) |
270 |
|
|
{ |
271 |
|
|
playerHandler->setDirection( |
272 |
|
|
BeingDirection::RIGHT); |
273 |
|
|
} |
274 |
|
|
} |
275 |
|
|
} |
276 |
|
|
return true; |
277 |
|
|
} |
278 |
|
|
return false; |
279 |
|
|
} |
280 |
|
|
|
281 |
|
2 |
} // namespace Actions |