ManaPlus
crazymoves.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "being/crazymoves.h"
22 
23 #include "configuration.h"
24 #include "settings.h"
25 
26 #include "being/localplayer.h"
27 
29 
31 
33 
34 #include "net/packetlimiter.h"
35 #include "net/pethandler.h"
36 #include "net/playerhandler.h"
37 
38 #include "resources/db/emotedb.h"
39 
40 #include "resources/map/map.h"
41 
42 #include "utils/timer.h"
43 
44 #include "debug.h"
45 
47 
49  mMoveProgram(),
50  mDisableCrazyMove(false)
51 {
52 }
53 
55 {
56  const bool oldDisableCrazyMove = mDisableCrazyMove;
57  mDisableCrazyMove = true;
58  switch (settings.crazyMoveType)
59  {
60  case 1:
61  crazyMove1();
62  break;
63  case 2:
64  crazyMove2();
65  break;
66  case 3:
67  crazyMove3();
68  break;
69  case 4:
70  crazyMove4();
71  break;
72  case 5:
73  crazyMove5();
74  break;
75  case 6:
76  crazyMove6();
77  break;
78  case 7:
79  crazyMove7();
80  break;
81  case 8:
82  crazyMove8();
83  break;
84  case 9:
85  crazyMove9();
86  break;
87  case 10:
88  crazyMoveA();
89  break;
90  default:
91  break;
92  }
93  mDisableCrazyMove = oldDisableCrazyMove;
94 }
95 
97 {
98  if ((localPlayer == nullptr) ||
99  (playerHandler == nullptr) ||
101  {
102  return;
103  }
104 
105 // if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
106 // return;
107 
108  switch (localPlayer->getDirection())
109  {
110  case BeingDirection::UP:
114  break;
119  break;
124  break;
129  break;
130  default:
131  break;
132  }
133 }
134 
136 {
137  if ((localPlayer == nullptr) ||
138  (playerHandler == nullptr) ||
140  {
141  return;
142  }
143 
144 // if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
145 // return;
146 
147  switch (localPlayer->getDirection())
148  {
149  case BeingDirection::UP:
155  break;
156 
163  break;
164 
171  break;
172 
179  break;
180 
181  default:
182  break;
183  }
184 }
185 
187 {
188  if ((localPlayer == nullptr) ||
189  (playerHandler == nullptr) ||
191  {
192  return;
193  }
194 
195  switch (settings.crazyMoveState)
196  {
197  case 0:
198  localPlayer->move(1, 1);
200  break;
201  case 1:
202  localPlayer->move(1, -1);
204  break;
205  case 2:
206  localPlayer->move(-1, -1);
208  break;
209  case 3:
210  localPlayer->move(-1, 1);
212  break;
213  default:
214  break;
215  }
216 
217 // if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
218 // return;
219 
222 }
223 
225 {
226  if ((localPlayer == nullptr) ||
228  {
229  return;
230  }
231 
232  switch (settings.crazyMoveState)
233  {
234  case 0:
235  localPlayer->move(7, 0);
237  break;
238  case 1:
239  localPlayer->move(-7, 0);
241  break;
242  default:
243  break;
244  }
245 }
246 
248 {
249  if ((localPlayer == nullptr) ||
251  {
252  return;
253  }
254 
255  switch (settings.crazyMoveState)
256  {
257  case 0:
258  localPlayer->move(0, 7);
260  break;
261  case 1:
262  localPlayer->move(0, -7);
264  break;
265  default:
266  break;
267  }
268 }
269 
271 {
272  if ((localPlayer == nullptr) ||
274  {
275  return;
276  }
277 
278  switch (settings.crazyMoveState)
279  {
280  case 0:
281  localPlayer->move(3, 0);
283  break;
284  case 1:
285  localPlayer->move(2, -2);
287  break;
288  case 2:
289  localPlayer->move(0, -3);
291  break;
292  case 3:
293  localPlayer->move(-2, -2);
295  break;
296  case 4:
297  localPlayer->move(-3, 0);
299  break;
300  case 5:
301  localPlayer->move(-2, 2);
303  break;
304  case 6:
305  localPlayer->move(0, 3);
307  break;
308  case 7:
309  localPlayer->move(2, 2);
311  break;
312  default:
313  break;
314  }
315 }
316 
318 {
319  if ((localPlayer == nullptr) ||
321  {
322  return;
323  }
324 
325  switch (settings.crazyMoveState)
326  {
327  case 0:
328  localPlayer->move(1, 1);
330  break;
331  case 1:
332  localPlayer->move(-1, 1);
334  break;
335  case 2:
336  localPlayer->move(-1, -1);
338  break;
339  case 3:
340  localPlayer->move(1, -1);
342  break;
343  default:
344  break;
345  }
346 }
347 
349 {
350  if (localPlayer == nullptr ||
352  {
353  return;
354  }
355  const Map *const map = localPlayer->getMap();
356  if (map == nullptr)
357  return;
358  const int x = localPlayer->getTileX();
359  const int y = localPlayer->getTileY();
360  int idx = 0;
361  const int dist = 1;
362 
363 // look
364 // up, ri,do,le
365  static const int movesX[][4] =
366  {
367  {-1, 0, 1, 0}, // move left
368  { 0, 1, 0, -1}, // move up
369  { 1, 0, -1, 0}, // move right
370  { 0, -1, 0, 1} // move down
371  };
372 
373 // look
374 // up, ri,do,le
375  static const int movesY[][4] =
376  {
377  { 0, -1, 0, 1}, // move left
378  {-1, 0, 1, 0}, // move up
379  { 0, 1, 0, -1}, // move right
380  { 1, 0, -1, 0} // move down
381  };
382 
383  switch (localPlayer->getDirection())
384  {
385  case BeingDirection::UP:
386  idx = 0;
387  break;
388 
390  idx = 1;
391  break;
392 
394  idx = 2;
395  break;
396 
398  idx = 3;
399  break;
400 
401  default:
402  break;
403  }
404 
405  int mult = 1;
406  const unsigned char blockWalkMask = localPlayer->getBlockWalkMask();
407  if (map->getWalk(x + movesX[idx][0],
408  y + movesY[idx][0], blockWalkMask))
409  {
410  while (map->getWalk(x + movesX[idx][0] * mult,
411  y + movesY[idx][0] * mult,
412  blockWalkMask) && mult <= dist)
413  {
414  mult ++;
415  }
416  localPlayer->move(movesX[idx][0] * (mult - 1),
417  movesY[idx][0] * (mult - 1));
418  }
419  else if (map->getWalk(x + movesX[idx][1],
420  y + movesY[idx][1], blockWalkMask))
421  {
422  while (map->getWalk(x + movesX[idx][1] * mult,
423  y + movesY[idx][1] * mult,
424  blockWalkMask) && mult <= dist)
425  {
426  mult ++;
427  }
428  localPlayer->move(movesX[idx][1] * (mult - 1),
429  movesY[idx][1] * (mult - 1));
430  }
431  else if (map->getWalk(x + movesX[idx][2],
432  y + movesY[idx][2], blockWalkMask))
433  {
434  while (map->getWalk(x + movesX[idx][2] * mult,
435  y + movesY[idx][2] * mult,
436  blockWalkMask) && mult <= dist)
437  {
438  mult ++;
439  }
440  localPlayer->move(movesX[idx][2] * (mult - 1),
441  movesY[idx][2] * (mult - 1));
442  }
443  else if (map->getWalk(x + movesX[idx][3],
444  y + movesY[idx][3], blockWalkMask))
445  {
446  while (map->getWalk(x + movesX[idx][3] * mult,
447  y + movesY[idx][3] * mult,
448  blockWalkMask) && mult <= dist)
449  {
450  mult ++;
451  }
452  localPlayer->move(movesX[idx][3] * (mult - 1),
453  movesY[idx][3] * (mult - 1));
454  }
455 }
456 
458 {
459  int dx = 0;
460  int dy = 0;
461 
462  if (localPlayer == nullptr ||
464  {
465  return;
466  }
467 
468  switch (settings.crazyMoveState)
469  {
470  case 0:
471  switch (localPlayer->getDirection())
472  {
473  case BeingDirection::UP : dy = -1; break;
474  case BeingDirection::DOWN : dy = 1; break;
475  case BeingDirection::LEFT : dx = -1; break;
476  case BeingDirection::RIGHT: dx = 1; break;
477  default: break;
478  }
479  localPlayer->move(dx, dy);
481  break;
482  case 1:
484  if (!localPlayer->allowAction())
485  return;
486  if (playerHandler != nullptr)
488  break;
489  case 2:
491  break;
492  case 3:
494  break;
495  default:
496  break;
497  }
498 }
499 
501 {
502  if (localPlayer == nullptr)
503  return;
504 
506  if (settings.crazyMoveState < mMoveProgram.length())
507  {
508  int dx = 0;
509  int dy = 0;
510 
511  signed char param = mMoveProgram[settings.crazyMoveState++];
512  if (param == '?')
513  {
514  const char cmd[] = {'l', 'r', 'u', 'd', 'L', 'R', 'U', 'D'};
515  srand(tick_time);
516  param = cmd[rand() % 8];
517  }
518  switch (param)
519  {
520  case 'd':
521  localPlayer->move(0, 1);
522  break;
523  case 'u':
524  localPlayer->move(0, -1);
525  break;
526  case 'l':
527  localPlayer->move(-1, 0);
528  break;
529  case 'r':
530  localPlayer->move(1, 0);
531  break;
532  case 'D':
533  localPlayer->move(1, 1);
534  break;
535  case 'U':
536  localPlayer->move(-1, -1);
537  break;
538  case 'L':
539  localPlayer->move(-1, 1);
540  break;
541  case 'R':
542  localPlayer->move(1, -1);
543  break;
544  case 'f':
545  {
546  const uint8_t dir = localPlayer->getDirection();
547  if ((dir & BeingDirection::UP) != 0)
548  dy = -1;
549  else if ((dir & BeingDirection::DOWN) != 0)
550  dy = 1;
551  if ((dir & BeingDirection::LEFT) != 0)
552  dx = -1;
553  else if ((dir & BeingDirection::RIGHT) != 0)
554  dx = 1;
555  localPlayer->move(dx, dy);
556  break;
557  }
558  case 'b':
559  {
560  const uint8_t dir = localPlayer->getDirection();
561  if ((dir & BeingDirection::UP) != 0)
562  dy = 1;
563  else if ((dir & BeingDirection::DOWN) != 0)
564  dy = -1;
565  if ((dir & BeingDirection::LEFT) != 0)
566  dx = 1;
567  else if ((dir & BeingDirection::RIGHT) != 0)
568  dx = -1;
569  localPlayer->move(dx, dy);
570  break;
571  }
572  default:
573  break;
574  }
575  }
576 }
577 
579 {
581 
582  if (settings.crazyMoveState < mMoveProgram.length())
583  {
584  signed char param = mMoveProgram[settings.crazyMoveState++];
585  if (param == '?')
586  {
587  const char cmd[] = {'l', 'r', 'u', 'd'};
588  srand(tick_time);
589  param = cmd[rand() % 4];
590  }
591  switch (param)
592  {
593  case 'd':
594 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
595  {
599  }
600  break;
601  case 'u':
602 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
603  {
607  }
608  break;
609  case 'l':
610 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
611  {
615  }
616  break;
617  case 'r':
618 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
619  {
623  }
624  break;
625  case 'L':
626 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
627  {
628  uint8_t dir = 0;
629  switch (localPlayer->getDirection())
630  {
631  case BeingDirection::UP:
632  dir = BeingDirection::LEFT;
633  break;
635  dir = BeingDirection::RIGHT;
636  break;
638  dir = BeingDirection::DOWN;
639  break;
641  dir = BeingDirection::UP;
642  break;
643  default:
644  break;
645  }
648  }
649  break;
650  case 'R':
651 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
652  {
653  uint8_t dir = 0;
654  switch (localPlayer->getDirection())
655  {
656  case BeingDirection::UP:
657  dir = BeingDirection::RIGHT;
658  break;
660  dir = BeingDirection::LEFT;
661  break;
663  dir = BeingDirection::UP;
664  break;
666  dir = BeingDirection::DOWN;
667  break;
668  default:
669  break;
670  }
673  }
674  break;
675  case 'b':
676 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
677  {
678  uint8_t dir = 0;
679  switch (localPlayer->getDirection())
680  {
681  case BeingDirection::UP:
682  dir = BeingDirection::DOWN;
683  break;
685  dir = BeingDirection::UP;
686  break;
688  dir = BeingDirection::RIGHT;
689  break;
691  dir = BeingDirection::LEFT;
692  break;
693  default:
694  break;
695  }
698  }
699  break;
700  case '0':
702  break;
703  case 'a':
705  break;
706  default:
707  break;
708  }
709  }
710 }
711 
713 {
715  if (localPlayer->toggleSit())
717 }
718 
720 {
722  if (settings.crazyMoveState < mMoveProgram.length())
723  {
724  // wear next outfit
726  {
729  }
730  // wear previous outfit
731  else if (mMoveProgram[settings.crazyMoveState] == 'p')
732  {
735  }
736  }
737 }
738 
740 {
742  const signed char emo = mMoveProgram[settings.crazyMoveState];
743  unsigned char emoteId = 0;
744  if (emo == '?')
745  {
746  srand(tick_time);
747  emoteId = CAST_U8(
748  1 + (rand() % EmoteDB::size()));
749  }
750  else
751  {
752  if (emo >= '0' && emo <= '9')
753  emoteId = CAST_U8(emo - '0' + 1);
754  else if (emo >= 'a' && emo <= 'z')
755  emoteId = CAST_U8(emo - 'a' + 11);
756  else if (emo >= 'A' && emo <= 'Z')
757  emoteId = CAST_U8(emo - 'A' + 37);
758  }
759  if (mMoveProgram[settings.crazyMoveState - 1] == 'e')
760  LocalPlayer::emote(emoteId);
762  petHandler->emote(emoteId);
763 
765 }
766 
768 {
769  mMoveProgram = config.getStringValue("crazyMoveProgram");
770 
772  return;
773 
774  if (mMoveProgram.empty())
775  return;
776 
777  if (settings.crazyMoveState >= mMoveProgram.length())
779 
780  // move command
782  {
783  crazyMoveAm();
784  }
785  // direction command
786  else if (mMoveProgram[settings.crazyMoveState] == 'd')
787  {
788  crazyMoveAd();
789  }
790  // sit command
791  else if (mMoveProgram[settings.crazyMoveState] == 's')
792  {
793  crazyMoveAs();
794  }
795  // wear outfits
796  else if (mMoveProgram[settings.crazyMoveState] == 'o')
797  {
798  crazyMoveAo();
799  }
800  // pause
801  else if (mMoveProgram[settings.crazyMoveState] == 'w')
802  {
804  }
805  // pick up
806  else if (mMoveProgram[settings.crazyMoveState] == 'p')
807  {
810  }
811  // emote
812  else if (mMoveProgram[settings.crazyMoveState] == 'e'
814  {
815  crazyMoveAe();
816  }
817  else
818  {
820  }
821 
822  if (settings.crazyMoveState >= mMoveProgram.length())
824 }
Net::PlayerHandler * playerHandler
Definition: net.cpp:89
std::string getStringValue(const std::string &key) const
DropShortcut * dropShortcut
static void crazyMove8()
Definition: crazymoves.cpp:348
void move(const int dX, const int dY)
int getTileY() const
Definition: being.h:173
#define CAST_U8
Definition: cast.h:26
volatile int tick_time
Definition: timer.cpp:52
void setWalkingDir(const unsigned char dir)
static void crazyMove7()
Definition: crazymoves.cpp:317
OutfitWindow * outfitWindow
Net::PetHandler * petHandler
Definition: net.cpp:88
unsigned int crazyMoveState
Definition: settings.h:143
unsigned char getBlockWalkMask() const A_CONST
Configuration config
void crazyMoveAo() const
Definition: crazymoves.cpp:719
bool limitPackets(const PacketTypeT type)
if(!vert) return
static void crazyMove5()
Definition: crazymoves.cpp:247
uint8_t getDirection() const
Definition: being.h:487
void dropFirst() const
void wearNextOutfit(const bool all)
void crazyMoveAm() const
Definition: crazymoves.cpp:500
static void crazyMove1()
Definition: crazymoves.cpp:96
bool pickUpItems(int pickUpType)
static void crazyMove3()
Definition: crazymoves.cpp:186
virtual void setDirection(const uint8_t direction)
Definition: being.cpp:1661
static void crazyMove9()
Definition: crazymoves.cpp:457
Settings settings
Definition: settings.cpp:31
virtual void setDirection(const unsigned char direction) const =0
CrazyMoves * crazyMoves
Definition: crazymoves.cpp:46
LocalPlayer * localPlayer
BeingActionT getCurrentAction() const
Definition: being.h:475
virtual void changeAction(const BeingActionT &action) const =0
std::string mMoveProgram
Definition: crazymoves.h:54
void dropItems(const int cnt)
void crazyMoveAd() const
Definition: crazymoves.cpp:578
static bool emote(const uint8_t emotion)
static void crazyMoveAs()
Definition: crazymoves.cpp:712
static void crazyMove2()
Definition: crazymoves.cpp:135
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:773
Definition: map.h:68
int size()
Definition: emotedb.cpp:305
bool allowAction()
static void crazyMove4()
Definition: crazymoves.cpp:224
virtual void emote(const uint8_t emoteId)=0
void crazyMoveAe() const
Definition: crazymoves.cpp:739
bool toggleSit() const
int getTileX() const
Definition: being.h:167
void crazyMove()
Definition: crazymoves.cpp:54
void crazyMoveA()
Definition: crazymoves.cpp:767
void wearPreviousOutfit(const bool all)
bool mDisableCrazyMove
Definition: crazymoves.h:57
static void crazyMove6()
Definition: crazymoves.cpp:270
const Map * getMap() const
Definition: actor.h:129
unsigned int crazyMoveType
Definition: settings.h:132