1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2011-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 "being/crazymoves.h" |
23 |
|
|
|
24 |
|
|
#include "configuration.h" |
25 |
|
|
#include "settings.h" |
26 |
|
|
|
27 |
|
|
#include "being/localplayer.h" |
28 |
|
|
|
29 |
|
|
#include "enums/being/beingdirection.h" |
30 |
|
|
|
31 |
|
|
#include "gui/shortcut/dropshortcut.h" |
32 |
|
|
|
33 |
|
|
#include "gui/windows/outfitwindow.h" |
34 |
|
|
|
35 |
|
|
#include "net/packetlimiter.h" |
36 |
|
|
#include "net/pethandler.h" |
37 |
|
|
#include "net/playerhandler.h" |
38 |
|
|
|
39 |
|
|
#include "resources/db/emotedb.h" |
40 |
|
|
|
41 |
|
|
#include "resources/map/map.h" |
42 |
|
|
|
43 |
|
|
#include "utils/timer.h" |
44 |
|
|
|
45 |
|
|
#include "debug.h" |
46 |
|
|
|
47 |
|
|
CrazyMoves *crazyMoves = nullptr; |
48 |
|
|
|
49 |
|
|
CrazyMoves::CrazyMoves() : |
50 |
|
|
mMoveProgram(), |
51 |
|
|
mDisableCrazyMove(false) |
52 |
|
|
{ |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
void CrazyMoves::crazyMove() |
56 |
|
|
{ |
57 |
|
|
const bool oldDisableCrazyMove = mDisableCrazyMove; |
58 |
|
|
mDisableCrazyMove = true; |
59 |
|
|
switch (settings.crazyMoveType) |
60 |
|
|
{ |
61 |
|
|
case 1: |
62 |
|
|
crazyMove1(); |
63 |
|
|
break; |
64 |
|
|
case 2: |
65 |
|
|
crazyMove2(); |
66 |
|
|
break; |
67 |
|
|
case 3: |
68 |
|
|
crazyMove3(); |
69 |
|
|
break; |
70 |
|
|
case 4: |
71 |
|
|
crazyMove4(); |
72 |
|
|
break; |
73 |
|
|
case 5: |
74 |
|
|
crazyMove5(); |
75 |
|
|
break; |
76 |
|
|
case 6: |
77 |
|
|
crazyMove6(); |
78 |
|
|
break; |
79 |
|
|
case 7: |
80 |
|
|
crazyMove7(); |
81 |
|
|
break; |
82 |
|
|
case 8: |
83 |
|
|
crazyMove8(); |
84 |
|
|
break; |
85 |
|
|
case 9: |
86 |
|
|
crazyMove9(); |
87 |
|
|
break; |
88 |
|
|
case 10: |
89 |
|
|
crazyMoveA(); |
90 |
|
|
break; |
91 |
|
|
default: |
92 |
|
|
break; |
93 |
|
|
} |
94 |
|
|
mDisableCrazyMove = oldDisableCrazyMove; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
void CrazyMoves::crazyMove1() |
98 |
|
|
{ |
99 |
|
|
if ((localPlayer == nullptr) || |
100 |
|
|
(playerHandler == nullptr) || |
101 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
102 |
|
|
{ |
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
// if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
107 |
|
|
// return; |
108 |
|
|
|
109 |
|
|
switch (localPlayer->getDirection()) |
110 |
|
|
{ |
111 |
|
|
case BeingDirection::UP: |
112 |
|
|
localPlayer->setWalkingDir(BeingDirection::UP); |
113 |
|
|
localPlayer->setDirection(BeingDirection::LEFT); |
114 |
|
|
playerHandler->setDirection(BeingDirection::LEFT); |
115 |
|
|
break; |
116 |
|
|
case BeingDirection::LEFT: |
117 |
|
|
localPlayer->setWalkingDir(BeingDirection::LEFT); |
118 |
|
|
localPlayer->setDirection(BeingDirection::DOWN); |
119 |
|
|
playerHandler->setDirection(BeingDirection::DOWN); |
120 |
|
|
break; |
121 |
|
|
case BeingDirection::DOWN: |
122 |
|
|
localPlayer->setWalkingDir(BeingDirection::DOWN); |
123 |
|
|
localPlayer->setDirection(BeingDirection::RIGHT); |
124 |
|
|
playerHandler->setDirection(BeingDirection::RIGHT); |
125 |
|
|
break; |
126 |
|
|
case BeingDirection::RIGHT: |
127 |
|
|
localPlayer->setWalkingDir(BeingDirection::RIGHT); |
128 |
|
|
localPlayer->setDirection(BeingDirection::UP); |
129 |
|
|
playerHandler->setDirection(BeingDirection::UP); |
130 |
|
|
break; |
131 |
|
|
default: |
132 |
|
|
break; |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
void CrazyMoves::crazyMove2() |
137 |
|
|
{ |
138 |
|
|
if ((localPlayer == nullptr) || |
139 |
|
|
(playerHandler == nullptr) || |
140 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
141 |
|
|
{ |
142 |
|
|
return; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
// if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
146 |
|
|
// return; |
147 |
|
|
|
148 |
|
|
switch (localPlayer->getDirection()) |
149 |
|
|
{ |
150 |
|
|
case BeingDirection::UP: |
151 |
|
|
localPlayer->setWalkingDir(BeingDirection::UP | |
152 |
|
|
BeingDirection::LEFT); |
153 |
|
|
localPlayer->setDirection(BeingDirection::RIGHT); |
154 |
|
|
playerHandler->setDirection( |
155 |
|
|
BeingDirection::DOWN | BeingDirection::RIGHT); |
156 |
|
|
break; |
157 |
|
|
|
158 |
|
|
case BeingDirection::RIGHT: |
159 |
|
|
localPlayer->setWalkingDir(BeingDirection::UP | |
160 |
|
|
BeingDirection::RIGHT); |
161 |
|
|
localPlayer->setDirection(BeingDirection::DOWN); |
162 |
|
|
playerHandler->setDirection( |
163 |
|
|
BeingDirection::DOWN | BeingDirection::LEFT); |
164 |
|
|
break; |
165 |
|
|
|
166 |
|
|
case BeingDirection::DOWN: |
167 |
|
|
localPlayer->setWalkingDir(BeingDirection::DOWN | |
168 |
|
|
BeingDirection::RIGHT); |
169 |
|
|
localPlayer->setDirection(BeingDirection::LEFT); |
170 |
|
|
playerHandler->setDirection( |
171 |
|
|
BeingDirection::UP | BeingDirection::LEFT); |
172 |
|
|
break; |
173 |
|
|
|
174 |
|
|
case BeingDirection::LEFT: |
175 |
|
|
localPlayer->setWalkingDir(BeingDirection::DOWN | |
176 |
|
|
BeingDirection::LEFT); |
177 |
|
|
localPlayer->setDirection(BeingDirection::UP); |
178 |
|
|
playerHandler->setDirection( |
179 |
|
|
BeingDirection::UP | BeingDirection::RIGHT); |
180 |
|
|
break; |
181 |
|
|
|
182 |
|
|
default: |
183 |
|
|
break; |
184 |
|
|
} |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
void CrazyMoves::crazyMove3() |
188 |
|
|
{ |
189 |
|
|
if ((localPlayer == nullptr) || |
190 |
|
|
(playerHandler == nullptr) || |
191 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
192 |
|
|
{ |
193 |
|
|
return; |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
switch (settings.crazyMoveState) |
197 |
|
|
{ |
198 |
|
|
case 0: |
199 |
|
|
localPlayer->move(1, 1); |
200 |
|
|
settings.crazyMoveState = 1; |
201 |
|
|
break; |
202 |
|
|
case 1: |
203 |
|
|
localPlayer->move(1, -1); |
204 |
|
|
settings.crazyMoveState = 2; |
205 |
|
|
break; |
206 |
|
|
case 2: |
207 |
|
|
localPlayer->move(-1, -1); |
208 |
|
|
settings.crazyMoveState = 3; |
209 |
|
|
break; |
210 |
|
|
case 3: |
211 |
|
|
localPlayer->move(-1, 1); |
212 |
|
|
settings.crazyMoveState = 0; |
213 |
|
|
break; |
214 |
|
|
default: |
215 |
|
|
break; |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
// if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
219 |
|
|
// return; |
220 |
|
|
|
221 |
|
|
localPlayer->setDirection(BeingDirection::DOWN); |
222 |
|
|
playerHandler->setDirection(BeingDirection::DOWN); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
void CrazyMoves::crazyMove4() |
226 |
|
|
{ |
227 |
|
|
if ((localPlayer == nullptr) || |
228 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
229 |
|
|
{ |
230 |
|
|
return; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
switch (settings.crazyMoveState) |
234 |
|
|
{ |
235 |
|
|
case 0: |
236 |
|
|
localPlayer->move(7, 0); |
237 |
|
|
settings.crazyMoveState = 1; |
238 |
|
|
break; |
239 |
|
|
case 1: |
240 |
|
|
localPlayer->move(-7, 0); |
241 |
|
|
settings.crazyMoveState = 0; |
242 |
|
|
break; |
243 |
|
|
default: |
244 |
|
|
break; |
245 |
|
|
} |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
void CrazyMoves::crazyMove5() |
249 |
|
|
{ |
250 |
|
|
if ((localPlayer == nullptr) || |
251 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
252 |
|
|
{ |
253 |
|
|
return; |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
switch (settings.crazyMoveState) |
257 |
|
|
{ |
258 |
|
|
case 0: |
259 |
|
|
localPlayer->move(0, 7); |
260 |
|
|
settings.crazyMoveState = 1; |
261 |
|
|
break; |
262 |
|
|
case 1: |
263 |
|
|
localPlayer->move(0, -7); |
264 |
|
|
settings.crazyMoveState = 0; |
265 |
|
|
break; |
266 |
|
|
default: |
267 |
|
|
break; |
268 |
|
|
} |
269 |
|
|
} |
270 |
|
|
|
271 |
|
|
void CrazyMoves::crazyMove6() |
272 |
|
|
{ |
273 |
|
|
if ((localPlayer == nullptr) || |
274 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
275 |
|
|
{ |
276 |
|
|
return; |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
switch (settings.crazyMoveState) |
280 |
|
|
{ |
281 |
|
|
case 0: |
282 |
|
|
localPlayer->move(3, 0); |
283 |
|
|
settings.crazyMoveState = 1; |
284 |
|
|
break; |
285 |
|
|
case 1: |
286 |
|
|
localPlayer->move(2, -2); |
287 |
|
|
settings.crazyMoveState = 2; |
288 |
|
|
break; |
289 |
|
|
case 2: |
290 |
|
|
localPlayer->move(0, -3); |
291 |
|
|
settings.crazyMoveState = 3; |
292 |
|
|
break; |
293 |
|
|
case 3: |
294 |
|
|
localPlayer->move(-2, -2); |
295 |
|
|
settings.crazyMoveState = 4; |
296 |
|
|
break; |
297 |
|
|
case 4: |
298 |
|
|
localPlayer->move(-3, 0); |
299 |
|
|
settings.crazyMoveState = 5; |
300 |
|
|
break; |
301 |
|
|
case 5: |
302 |
|
|
localPlayer->move(-2, 2); |
303 |
|
|
settings.crazyMoveState = 6; |
304 |
|
|
break; |
305 |
|
|
case 6: |
306 |
|
|
localPlayer->move(0, 3); |
307 |
|
|
settings.crazyMoveState = 7; |
308 |
|
|
break; |
309 |
|
|
case 7: |
310 |
|
|
localPlayer->move(2, 2); |
311 |
|
|
settings.crazyMoveState = 0; |
312 |
|
|
break; |
313 |
|
|
default: |
314 |
|
|
break; |
315 |
|
|
} |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
void CrazyMoves::crazyMove7() |
319 |
|
|
{ |
320 |
|
|
if ((localPlayer == nullptr) || |
321 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
322 |
|
|
{ |
323 |
|
|
return; |
324 |
|
|
} |
325 |
|
|
|
326 |
|
|
switch (settings.crazyMoveState) |
327 |
|
|
{ |
328 |
|
|
case 0: |
329 |
|
|
localPlayer->move(1, 1); |
330 |
|
|
settings.crazyMoveState = 1; |
331 |
|
|
break; |
332 |
|
|
case 1: |
333 |
|
|
localPlayer->move(-1, 1); |
334 |
|
|
settings.crazyMoveState = 2; |
335 |
|
|
break; |
336 |
|
|
case 2: |
337 |
|
|
localPlayer->move(-1, -1); |
338 |
|
|
settings.crazyMoveState = 3; |
339 |
|
|
break; |
340 |
|
|
case 3: |
341 |
|
|
localPlayer->move(1, -1); |
342 |
|
|
settings.crazyMoveState = 0; |
343 |
|
|
break; |
344 |
|
|
default: |
345 |
|
|
break; |
346 |
|
|
} |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
void CrazyMoves::crazyMove8() |
350 |
|
|
{ |
351 |
|
|
if (localPlayer == nullptr || |
352 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
353 |
|
|
{ |
354 |
|
|
return; |
355 |
|
|
} |
356 |
|
|
const Map *const map = localPlayer->getMap(); |
357 |
|
|
if (map == nullptr) |
358 |
|
|
return; |
359 |
|
|
const int x = localPlayer->getTileX(); |
360 |
|
|
const int y = localPlayer->getTileY(); |
361 |
|
|
int idx = 0; |
362 |
|
|
const int dist = 1; |
363 |
|
|
|
364 |
|
|
// look |
365 |
|
|
// up, ri,do,le |
366 |
|
|
static const int movesX[][4] = |
367 |
|
|
{ |
368 |
|
|
{-1, 0, 1, 0}, // move left |
369 |
|
|
{ 0, 1, 0, -1}, // move up |
370 |
|
|
{ 1, 0, -1, 0}, // move right |
371 |
|
|
{ 0, -1, 0, 1} // move down |
372 |
|
|
}; |
373 |
|
|
|
374 |
|
|
// look |
375 |
|
|
// up, ri,do,le |
376 |
|
|
static const int movesY[][4] = |
377 |
|
|
{ |
378 |
|
|
{ 0, -1, 0, 1}, // move left |
379 |
|
|
{-1, 0, 1, 0}, // move up |
380 |
|
|
{ 0, 1, 0, -1}, // move right |
381 |
|
|
{ 1, 0, -1, 0} // move down |
382 |
|
|
}; |
383 |
|
|
|
384 |
|
|
switch (localPlayer->getDirection()) |
385 |
|
|
{ |
386 |
|
|
case BeingDirection::UP: |
387 |
|
|
idx = 0; |
388 |
|
|
break; |
389 |
|
|
|
390 |
|
|
case BeingDirection::RIGHT: |
391 |
|
|
idx = 1; |
392 |
|
|
break; |
393 |
|
|
|
394 |
|
|
case BeingDirection::DOWN: |
395 |
|
|
idx = 2; |
396 |
|
|
break; |
397 |
|
|
|
398 |
|
|
case BeingDirection::LEFT: |
399 |
|
|
idx = 3; |
400 |
|
|
break; |
401 |
|
|
|
402 |
|
|
default: |
403 |
|
|
break; |
404 |
|
|
} |
405 |
|
|
|
406 |
|
|
int mult = 1; |
407 |
|
|
const unsigned char blockWalkMask = localPlayer->getBlockWalkMask(); |
408 |
|
|
if (map->getWalk(x + movesX[idx][0], |
409 |
|
|
y + movesY[idx][0], blockWalkMask)) |
410 |
|
|
{ |
411 |
|
|
while (map->getWalk(x + movesX[idx][0] * mult, |
412 |
|
|
y + movesY[idx][0] * mult, |
413 |
|
|
blockWalkMask) && mult <= dist) |
414 |
|
|
{ |
415 |
|
|
mult ++; |
416 |
|
|
} |
417 |
|
|
localPlayer->move(movesX[idx][0] * (mult - 1), |
418 |
|
|
movesY[idx][0] * (mult - 1)); |
419 |
|
|
} |
420 |
|
|
else if (map->getWalk(x + movesX[idx][1], |
421 |
|
|
y + movesY[idx][1], blockWalkMask)) |
422 |
|
|
{ |
423 |
|
|
while (map->getWalk(x + movesX[idx][1] * mult, |
424 |
|
|
y + movesY[idx][1] * mult, |
425 |
|
|
blockWalkMask) && mult <= dist) |
426 |
|
|
{ |
427 |
|
|
mult ++; |
428 |
|
|
} |
429 |
|
|
localPlayer->move(movesX[idx][1] * (mult - 1), |
430 |
|
|
movesY[idx][1] * (mult - 1)); |
431 |
|
|
} |
432 |
|
|
else if (map->getWalk(x + movesX[idx][2], |
433 |
|
|
y + movesY[idx][2], blockWalkMask)) |
434 |
|
|
{ |
435 |
|
|
while (map->getWalk(x + movesX[idx][2] * mult, |
436 |
|
|
y + movesY[idx][2] * mult, |
437 |
|
|
blockWalkMask) && mult <= dist) |
438 |
|
|
{ |
439 |
|
|
mult ++; |
440 |
|
|
} |
441 |
|
|
localPlayer->move(movesX[idx][2] * (mult - 1), |
442 |
|
|
movesY[idx][2] * (mult - 1)); |
443 |
|
|
} |
444 |
|
|
else if (map->getWalk(x + movesX[idx][3], |
445 |
|
|
y + movesY[idx][3], blockWalkMask)) |
446 |
|
|
{ |
447 |
|
|
while (map->getWalk(x + movesX[idx][3] * mult, |
448 |
|
|
y + movesY[idx][3] * mult, |
449 |
|
|
blockWalkMask) && mult <= dist) |
450 |
|
|
{ |
451 |
|
|
mult ++; |
452 |
|
|
} |
453 |
|
|
localPlayer->move(movesX[idx][3] * (mult - 1), |
454 |
|
|
movesY[idx][3] * (mult - 1)); |
455 |
|
|
} |
456 |
|
|
} |
457 |
|
|
|
458 |
|
|
void CrazyMoves::crazyMove9() |
459 |
|
|
{ |
460 |
|
|
int dx = 0; |
461 |
|
|
int dy = 0; |
462 |
|
|
|
463 |
|
|
if (localPlayer == nullptr || |
464 |
|
|
localPlayer->getCurrentAction() == BeingAction::MOVE) |
465 |
|
|
{ |
466 |
|
|
return; |
467 |
|
|
} |
468 |
|
|
|
469 |
|
|
switch (settings.crazyMoveState) |
470 |
|
|
{ |
471 |
|
|
case 0: |
472 |
|
|
switch (localPlayer->getDirection()) |
473 |
|
|
{ |
474 |
|
|
case BeingDirection::UP : dy = -1; break; |
475 |
|
|
case BeingDirection::DOWN : dy = 1; break; |
476 |
|
|
case BeingDirection::LEFT : dx = -1; break; |
477 |
|
|
case BeingDirection::RIGHT: dx = 1; break; |
478 |
|
|
default: break; |
479 |
|
|
} |
480 |
|
|
localPlayer->move(dx, dy); |
481 |
|
|
settings.crazyMoveState = 1; |
482 |
|
|
break; |
483 |
|
|
case 1: |
484 |
|
|
settings.crazyMoveState = 2; |
485 |
|
|
if (!localPlayer->allowAction()) |
486 |
|
|
return; |
487 |
|
|
if (playerHandler != nullptr) |
488 |
|
|
playerHandler->changeAction(BeingAction::SIT); |
489 |
|
|
break; |
490 |
|
|
case 2: |
491 |
|
|
settings.crazyMoveState = 3; |
492 |
|
|
break; |
493 |
|
|
case 3: |
494 |
|
|
settings.crazyMoveState = 0; |
495 |
|
|
break; |
496 |
|
|
default: |
497 |
|
|
break; |
498 |
|
|
} |
499 |
|
|
} |
500 |
|
|
|
501 |
|
|
void CrazyMoves::crazyMoveAm() const |
502 |
|
|
{ |
503 |
|
|
if (localPlayer == nullptr) |
504 |
|
|
return; |
505 |
|
|
|
506 |
|
|
settings.crazyMoveState ++; |
507 |
|
|
if (settings.crazyMoveState < mMoveProgram.length()) |
508 |
|
|
{ |
509 |
|
|
int dx = 0; |
510 |
|
|
int dy = 0; |
511 |
|
|
|
512 |
|
|
signed char param = mMoveProgram[settings.crazyMoveState++]; |
513 |
|
|
if (param == '?') |
514 |
|
|
{ |
515 |
|
|
const char cmd[] = {'l', 'r', 'u', 'd', 'L', 'R', 'U', 'D'}; |
516 |
|
|
srand(tick_time); |
517 |
|
|
param = cmd[rand() % 8]; |
518 |
|
|
} |
519 |
|
|
switch (param) |
520 |
|
|
{ |
521 |
|
|
case 'd': |
522 |
|
|
localPlayer->move(0, 1); |
523 |
|
|
break; |
524 |
|
|
case 'u': |
525 |
|
|
localPlayer->move(0, -1); |
526 |
|
|
break; |
527 |
|
|
case 'l': |
528 |
|
|
localPlayer->move(-1, 0); |
529 |
|
|
break; |
530 |
|
|
case 'r': |
531 |
|
|
localPlayer->move(1, 0); |
532 |
|
|
break; |
533 |
|
|
case 'D': |
534 |
|
|
localPlayer->move(1, 1); |
535 |
|
|
break; |
536 |
|
|
case 'U': |
537 |
|
|
localPlayer->move(-1, -1); |
538 |
|
|
break; |
539 |
|
|
case 'L': |
540 |
|
|
localPlayer->move(-1, 1); |
541 |
|
|
break; |
542 |
|
|
case 'R': |
543 |
|
|
localPlayer->move(1, -1); |
544 |
|
|
break; |
545 |
|
|
case 'f': |
546 |
|
|
{ |
547 |
|
|
const uint8_t dir = localPlayer->getDirection(); |
548 |
|
|
if ((dir & BeingDirection::UP) != 0) |
549 |
|
|
dy = -1; |
550 |
|
|
else if ((dir & BeingDirection::DOWN) != 0) |
551 |
|
|
dy = 1; |
552 |
|
|
if ((dir & BeingDirection::LEFT) != 0) |
553 |
|
|
dx = -1; |
554 |
|
|
else if ((dir & BeingDirection::RIGHT) != 0) |
555 |
|
|
dx = 1; |
556 |
|
|
localPlayer->move(dx, dy); |
557 |
|
|
break; |
558 |
|
|
} |
559 |
|
|
case 'b': |
560 |
|
|
{ |
561 |
|
|
const uint8_t dir = localPlayer->getDirection(); |
562 |
|
|
if ((dir & BeingDirection::UP) != 0) |
563 |
|
|
dy = 1; |
564 |
|
|
else if ((dir & BeingDirection::DOWN) != 0) |
565 |
|
|
dy = -1; |
566 |
|
|
if ((dir & BeingDirection::LEFT) != 0) |
567 |
|
|
dx = 1; |
568 |
|
|
else if ((dir & BeingDirection::RIGHT) != 0) |
569 |
|
|
dx = -1; |
570 |
|
|
localPlayer->move(dx, dy); |
571 |
|
|
break; |
572 |
|
|
} |
573 |
|
|
default: |
574 |
|
|
break; |
575 |
|
|
} |
576 |
|
|
} |
577 |
|
|
} |
578 |
|
|
|
579 |
|
|
void CrazyMoves::crazyMoveAd() const |
580 |
|
|
{ |
581 |
|
|
settings.crazyMoveState ++; |
582 |
|
|
|
583 |
|
|
if (settings.crazyMoveState < mMoveProgram.length()) |
584 |
|
|
{ |
585 |
|
|
signed char param = mMoveProgram[settings.crazyMoveState++]; |
586 |
|
|
if (param == '?') |
587 |
|
|
{ |
588 |
|
|
const char cmd[] = {'l', 'r', 'u', 'd'}; |
589 |
|
|
srand(tick_time); |
590 |
|
|
param = cmd[rand() % 4]; |
591 |
|
|
} |
592 |
|
|
switch (param) |
593 |
|
|
{ |
594 |
|
|
case 'd': |
595 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
596 |
|
|
{ |
597 |
|
|
localPlayer->setDirection(BeingDirection::DOWN); |
598 |
|
|
playerHandler->setDirection( |
599 |
|
|
BeingDirection::DOWN); |
600 |
|
|
} |
601 |
|
|
break; |
602 |
|
|
case 'u': |
603 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
604 |
|
|
{ |
605 |
|
|
localPlayer->setDirection(BeingDirection::UP); |
606 |
|
|
playerHandler->setDirection( |
607 |
|
|
BeingDirection::UP); |
608 |
|
|
} |
609 |
|
|
break; |
610 |
|
|
case 'l': |
611 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
612 |
|
|
{ |
613 |
|
|
localPlayer->setDirection(BeingDirection::LEFT); |
614 |
|
|
playerHandler->setDirection( |
615 |
|
|
BeingDirection::LEFT); |
616 |
|
|
} |
617 |
|
|
break; |
618 |
|
|
case 'r': |
619 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
620 |
|
|
{ |
621 |
|
|
localPlayer->setDirection(BeingDirection::RIGHT); |
622 |
|
|
playerHandler->setDirection( |
623 |
|
|
BeingDirection::RIGHT); |
624 |
|
|
} |
625 |
|
|
break; |
626 |
|
|
case 'L': |
627 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
628 |
|
|
{ |
629 |
|
|
uint8_t dir = 0; |
630 |
|
|
switch (localPlayer->getDirection()) |
631 |
|
|
{ |
632 |
|
|
case BeingDirection::UP: |
633 |
|
|
dir = BeingDirection::LEFT; |
634 |
|
|
break; |
635 |
|
|
case BeingDirection::DOWN: |
636 |
|
|
dir = BeingDirection::RIGHT; |
637 |
|
|
break; |
638 |
|
|
case BeingDirection::LEFT: |
639 |
|
|
dir = BeingDirection::DOWN; |
640 |
|
|
break; |
641 |
|
|
case BeingDirection::RIGHT: |
642 |
|
|
dir = BeingDirection::UP; |
643 |
|
|
break; |
644 |
|
|
default: |
645 |
|
|
break; |
646 |
|
|
} |
647 |
|
|
localPlayer->setDirection(dir); |
648 |
|
|
playerHandler->setDirection(dir); |
649 |
|
|
} |
650 |
|
|
break; |
651 |
|
|
case 'R': |
652 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
653 |
|
|
{ |
654 |
|
|
uint8_t dir = 0; |
655 |
|
|
switch (localPlayer->getDirection()) |
656 |
|
|
{ |
657 |
|
|
case BeingDirection::UP: |
658 |
|
|
dir = BeingDirection::RIGHT; |
659 |
|
|
break; |
660 |
|
|
case BeingDirection::DOWN: |
661 |
|
|
dir = BeingDirection::LEFT; |
662 |
|
|
break; |
663 |
|
|
case BeingDirection::LEFT: |
664 |
|
|
dir = BeingDirection::UP; |
665 |
|
|
break; |
666 |
|
|
case BeingDirection::RIGHT: |
667 |
|
|
dir = BeingDirection::DOWN; |
668 |
|
|
break; |
669 |
|
|
default: |
670 |
|
|
break; |
671 |
|
|
} |
672 |
|
|
localPlayer->setDirection(dir); |
673 |
|
|
playerHandler->setDirection(dir); |
674 |
|
|
} |
675 |
|
|
break; |
676 |
|
|
case 'b': |
677 |
|
|
// if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) |
678 |
|
|
{ |
679 |
|
|
uint8_t dir = 0; |
680 |
|
|
switch (localPlayer->getDirection()) |
681 |
|
|
{ |
682 |
|
|
case BeingDirection::UP: |
683 |
|
|
dir = BeingDirection::DOWN; |
684 |
|
|
break; |
685 |
|
|
case BeingDirection::DOWN: |
686 |
|
|
dir = BeingDirection::UP; |
687 |
|
|
break; |
688 |
|
|
case BeingDirection::LEFT: |
689 |
|
|
dir = BeingDirection::RIGHT; |
690 |
|
|
break; |
691 |
|
|
case BeingDirection::RIGHT: |
692 |
|
|
dir = BeingDirection::LEFT; |
693 |
|
|
break; |
694 |
|
|
default: |
695 |
|
|
break; |
696 |
|
|
} |
697 |
|
|
localPlayer->setDirection(dir); |
698 |
|
|
playerHandler->setDirection(dir); |
699 |
|
|
} |
700 |
|
|
break; |
701 |
|
|
case '0': |
702 |
|
|
dropShortcut->dropFirst(); |
703 |
|
|
break; |
704 |
|
|
case 'a': |
705 |
|
|
dropShortcut->dropItems(1); |
706 |
|
|
break; |
707 |
|
|
default: |
708 |
|
|
break; |
709 |
|
|
} |
710 |
|
|
} |
711 |
|
|
} |
712 |
|
|
|
713 |
|
|
void CrazyMoves::crazyMoveAs() |
714 |
|
|
{ |
715 |
|
|
settings.crazyMoveState ++; |
716 |
|
|
if (localPlayer->toggleSit()) |
717 |
|
|
settings.crazyMoveState ++; |
718 |
|
|
} |
719 |
|
|
|
720 |
|
|
void CrazyMoves::crazyMoveAo() const |
721 |
|
|
{ |
722 |
|
|
settings.crazyMoveState ++; |
723 |
|
|
if (settings.crazyMoveState < mMoveProgram.length()) |
724 |
|
|
{ |
725 |
|
|
// wear next outfit |
726 |
|
|
if (mMoveProgram[settings.crazyMoveState] == 'n') |
727 |
|
|
{ |
728 |
|
|
settings.crazyMoveState ++; |
729 |
|
|
outfitWindow->wearNextOutfit(false); |
730 |
|
|
} |
731 |
|
|
// wear previous outfit |
732 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 'p') |
733 |
|
|
{ |
734 |
|
|
settings.crazyMoveState ++; |
735 |
|
|
outfitWindow->wearPreviousOutfit(false); |
736 |
|
|
} |
737 |
|
|
} |
738 |
|
|
} |
739 |
|
|
|
740 |
|
|
void CrazyMoves::crazyMoveAe() const |
741 |
|
|
{ |
742 |
|
|
settings.crazyMoveState ++; |
743 |
|
|
const signed char emo = mMoveProgram[settings.crazyMoveState]; |
744 |
|
|
unsigned char emoteId = 0; |
745 |
|
|
if (emo == '?') |
746 |
|
|
{ |
747 |
|
|
srand(tick_time); |
748 |
|
|
emoteId = CAST_U8( |
749 |
|
|
1 + (rand() % EmoteDB::size())); |
750 |
|
|
} |
751 |
|
|
else |
752 |
|
|
{ |
753 |
|
|
if (emo >= '0' && emo <= '9') |
754 |
|
|
emoteId = CAST_U8(emo - '0' + 1); |
755 |
|
|
else if (emo >= 'a' && emo <= 'z') |
756 |
|
|
emoteId = CAST_U8(emo - 'a' + 11); |
757 |
|
|
else if (emo >= 'A' && emo <= 'Z') |
758 |
|
|
emoteId = CAST_U8(emo - 'A' + 37); |
759 |
|
|
} |
760 |
|
|
if (mMoveProgram[settings.crazyMoveState - 1] == 'e') |
761 |
|
|
LocalPlayer::emote(emoteId); |
762 |
|
|
else if (PacketLimiter::limitPackets(PacketType::PACKET_CHAT)) |
763 |
|
|
petHandler->emote(emoteId); |
764 |
|
|
|
765 |
|
|
settings.crazyMoveState ++; |
766 |
|
|
} |
767 |
|
|
|
768 |
|
|
void CrazyMoves::crazyMoveA() |
769 |
|
|
{ |
770 |
|
|
mMoveProgram = config.getStringValue("crazyMoveProgram"); |
771 |
|
|
|
772 |
|
|
if (localPlayer->getCurrentAction() == BeingAction::MOVE) |
773 |
|
|
return; |
774 |
|
|
|
775 |
|
|
if (mMoveProgram.empty()) |
776 |
|
|
return; |
777 |
|
|
|
778 |
|
|
if (settings.crazyMoveState >= mMoveProgram.length()) |
779 |
|
|
settings.crazyMoveState = 0; |
780 |
|
|
|
781 |
|
|
// move command |
782 |
|
|
if (mMoveProgram[settings.crazyMoveState] == 'm') |
783 |
|
|
{ |
784 |
|
|
crazyMoveAm(); |
785 |
|
|
} |
786 |
|
|
// direction command |
787 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 'd') |
788 |
|
|
{ |
789 |
|
|
crazyMoveAd(); |
790 |
|
|
} |
791 |
|
|
// sit command |
792 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 's') |
793 |
|
|
{ |
794 |
|
|
crazyMoveAs(); |
795 |
|
|
} |
796 |
|
|
// wear outfits |
797 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 'o') |
798 |
|
|
{ |
799 |
|
|
crazyMoveAo(); |
800 |
|
|
} |
801 |
|
|
// pause |
802 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 'w') |
803 |
|
|
{ |
804 |
|
|
settings.crazyMoveState ++; |
805 |
|
|
} |
806 |
|
|
// pick up |
807 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 'p') |
808 |
|
|
{ |
809 |
|
|
settings.crazyMoveState ++; |
810 |
|
|
localPlayer->pickUpItems(0); |
811 |
|
|
} |
812 |
|
|
// emote |
813 |
|
|
else if (mMoveProgram[settings.crazyMoveState] == 'e' |
814 |
|
|
|| mMoveProgram[settings.crazyMoveState] == 'E') |
815 |
|
|
{ |
816 |
|
|
crazyMoveAe(); |
817 |
|
|
} |
818 |
|
|
else |
819 |
|
|
{ |
820 |
|
|
settings.crazyMoveState ++; |
821 |
|
|
} |
822 |
|
|
|
823 |
|
|
if (settings.crazyMoveState >= mMoveProgram.length()) |
824 |
|
|
settings.crazyMoveState = 0; |
825 |
|
2 |
} |