summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-02-23 23:03:32 +0300
committerAndrei Karas <akaras@inbox.ru>2015-02-23 23:03:32 +0300
commit797a2919283659b537a2f8024a758281d0cee8e9 (patch)
tree7e25c5d5a360af2ed536194d59edf9475883a848 /src/being
parent0a3d203f6f311da4a7907863586068827cdedfed (diff)
downloadmanaplus-797a2919283659b537a2f8024a758281d0cee8e9.tar.gz
manaplus-797a2919283659b537a2f8024a758281d0cee8e9.tar.bz2
manaplus-797a2919283659b537a2f8024a758281d0cee8e9.tar.xz
manaplus-797a2919283659b537a2f8024a758281d0cee8e9.zip
Move crazy moves code from local player into separate file.
Diffstat (limited to 'src/being')
-rw-r--r--src/being/crazymoves.cpp756
-rw-r--r--src/being/crazymoves.h53
-rw-r--r--src/being/localplayer.cpp681
-rw-r--r--src/being/localplayer.h14
4 files changed, 811 insertions, 693 deletions
diff --git a/src/being/crazymoves.cpp b/src/being/crazymoves.cpp
new file mode 100644
index 000000000..0c98187d8
--- /dev/null
+++ b/src/being/crazymoves.cpp
@@ -0,0 +1,756 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "being/crazymoves.h"
+
+#include "configuration.h"
+#include "dropshortcut.h"
+#include "settings.h"
+
+#include "being/localplayer.h"
+
+#include "enums/net/packettypes.h"
+
+#include "gui/windows/outfitwindow.h"
+
+#include "net/packetlimiter.h"
+#include "net/pethandler.h"
+#include "net/playerhandler.h"
+
+#include "resources/db/emotedb.h"
+
+#include "resources/map/map.h"
+
+#include "utils/timer.h"
+
+#include "debug.h"
+
+CrazyMoves *crazyMoves = nullptr;
+
+CrazyMoves::CrazyMoves() :
+ mDisableCrazyMove(false)
+{
+}
+
+void CrazyMoves::crazyMove()
+{
+ const bool oldDisableCrazyMove = mDisableCrazyMove;
+ mDisableCrazyMove = true;
+ switch (settings.crazyMoveType)
+ {
+ case 1:
+ crazyMove1();
+ break;
+ case 2:
+ crazyMove2();
+ break;
+ case 3:
+ crazyMove3();
+ break;
+ case 4:
+ crazyMove4();
+ break;
+ case 5:
+ crazyMove5();
+ break;
+ case 6:
+ crazyMove6();
+ break;
+ case 7:
+ crazyMove7();
+ break;
+ case 8:
+ crazyMove8();
+ break;
+ case 9:
+ crazyMove9();
+ break;
+ case 10:
+ crazyMoveA();
+ break;
+ default:
+ break;
+ }
+ mDisableCrazyMove = oldDisableCrazyMove;
+}
+
+void CrazyMoves::crazyMove1()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+// if (!PacketLimiter::limitPackets(PACKET_DIRECTION))
+// return;
+
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP:
+ localPlayer->setWalkingDir(BeingDirection::UP);
+ localPlayer->setDirection(BeingDirection::LEFT);
+ playerHandler->setDirection(BeingDirection::LEFT);
+ break;
+ case BeingDirection::LEFT:
+ localPlayer->setWalkingDir(BeingDirection::LEFT);
+ localPlayer->setDirection(BeingDirection::DOWN);
+ playerHandler->setDirection(BeingDirection::DOWN);
+ break;
+ case BeingDirection::DOWN:
+ localPlayer->setWalkingDir(BeingDirection::DOWN);
+ localPlayer->setDirection(BeingDirection::RIGHT);
+ playerHandler->setDirection(BeingDirection::RIGHT);
+ break;
+ case BeingDirection::RIGHT:
+ localPlayer->setWalkingDir(BeingDirection::RIGHT);
+ localPlayer->setDirection(BeingDirection::UP);
+ playerHandler->setDirection(BeingDirection::UP);
+ break;
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMove2()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+// if (!PacketLimiter::limitPackets(PACKET_DIRECTION))
+// return;
+
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP:
+ localPlayer->setWalkingDir(BeingDirection::UP | BeingDirection::LEFT);
+ localPlayer->setDirection(BeingDirection::RIGHT);
+ playerHandler->setDirection(
+ BeingDirection::DOWN | BeingDirection::RIGHT);
+ break;
+
+ case BeingDirection::RIGHT:
+ localPlayer->setWalkingDir(BeingDirection::UP | BeingDirection::RIGHT);
+ localPlayer->setDirection(BeingDirection::DOWN);
+ playerHandler->setDirection(
+ BeingDirection::DOWN | BeingDirection::LEFT);
+ break;
+
+ case BeingDirection::DOWN:
+ localPlayer->setWalkingDir(BeingDirection::DOWN | BeingDirection::RIGHT);
+ localPlayer->setDirection(BeingDirection::LEFT);
+ playerHandler->setDirection(
+ BeingDirection::UP | BeingDirection::LEFT);
+ break;
+
+ case BeingDirection::LEFT:
+ localPlayer->setWalkingDir(BeingDirection::DOWN | BeingDirection::LEFT);
+ localPlayer->setDirection(BeingDirection::UP);
+ playerHandler->setDirection(
+ BeingDirection::UP | BeingDirection::RIGHT);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMove3()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ switch (settings.crazyMoveState)
+ {
+ case 0:
+ localPlayer->move(1, 1);
+ settings.crazyMoveState = 1;
+ break;
+ case 1:
+ localPlayer->move(1, -1);
+ settings.crazyMoveState = 2;
+ break;
+ case 2:
+ localPlayer->move(-1, -1);
+ settings.crazyMoveState = 3;
+ break;
+ case 3:
+ localPlayer->move(-1, 1);
+ settings.crazyMoveState = 0;
+ break;
+ default:
+ break;
+ }
+
+// if (!PacketLimiter::limitPackets(PACKET_DIRECTION))
+// return;
+
+ localPlayer->setDirection(BeingDirection::DOWN);
+ playerHandler->setDirection(BeingDirection::DOWN);
+}
+
+void CrazyMoves::crazyMove4()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ switch (settings.crazyMoveState)
+ {
+ case 0:
+ localPlayer->move(7, 0);
+ settings.crazyMoveState = 1;
+ break;
+ case 1:
+ localPlayer->move(-7, 0);
+ settings.crazyMoveState = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMove5()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ switch (settings.crazyMoveState)
+ {
+ case 0:
+ localPlayer->move(0, 7);
+ settings.crazyMoveState = 1;
+ break;
+ case 1:
+ localPlayer->move(0, -7);
+ settings.crazyMoveState = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMove6()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ switch (settings.crazyMoveState)
+ {
+ case 0:
+ localPlayer->move(3, 0);
+ settings.crazyMoveState = 1;
+ break;
+ case 1:
+ localPlayer->move(2, -2);
+ settings.crazyMoveState = 2;
+ break;
+ case 2:
+ localPlayer->move(0, -3);
+ settings.crazyMoveState = 3;
+ break;
+ case 3:
+ localPlayer->move(-2, -2);
+ settings.crazyMoveState = 4;
+ break;
+ case 4:
+ localPlayer->move(-3, 0);
+ settings.crazyMoveState = 5;
+ break;
+ case 5:
+ localPlayer->move(-2, 2);
+ settings.crazyMoveState = 6;
+ break;
+ case 6:
+ localPlayer->move(0, 3);
+ settings.crazyMoveState = 7;
+ break;
+ case 7:
+ localPlayer->move(2, 2);
+ settings.crazyMoveState = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMove7()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ switch (settings.crazyMoveState)
+ {
+ case 0:
+ localPlayer->move(1, 1);
+ settings.crazyMoveState = 1;
+ break;
+ case 1:
+ localPlayer->move(-1, 1);
+ settings.crazyMoveState = 2;
+ break;
+ case 2:
+ localPlayer->move(-1, -1);
+ settings.crazyMoveState = 3;
+ break;
+ case 3:
+ localPlayer->move(1, -1);
+ settings.crazyMoveState = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMove8()
+{
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+ const Map *const map = localPlayer->getMap();
+ if (!map)
+ return;
+ const int x = localPlayer->getTileX();
+ const int y = localPlayer->getTileY();
+ int idx = 0;
+ const int dist = 1;
+
+// look
+// up, ri,do,le
+ static const int movesX[][4] =
+ {
+ {-1, 0, 1, 0}, // move left
+ { 0, 1, 0, -1}, // move up
+ { 1, 0, -1, 0}, // move right
+ { 0, -1, 0, 1} // move down
+ };
+
+// look
+// up, ri,do,le
+ static const int movesY[][4] =
+ {
+ { 0, -1, 0, 1}, // move left
+ {-1, 0, 1, 0}, // move up
+ { 0, 1, 0, -1}, // move right
+ { 1, 0, -1, 0} // move down
+ };
+
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP:
+ idx = 0;
+ break;
+
+ case BeingDirection::RIGHT:
+ idx = 1;
+ break;
+
+ case BeingDirection::DOWN:
+ idx = 2;
+ break;
+
+ case BeingDirection::LEFT:
+ idx = 3;
+ break;
+
+ default:
+ break;
+ }
+
+ int mult = 1;
+ const unsigned char blockWalkMask = localPlayer->getBlockWalkMask();
+ if (map->getWalk(x + movesX[idx][0],
+ y + movesY[idx][0], blockWalkMask))
+ {
+ while (map->getWalk(x + movesX[idx][0] * mult,
+ y + movesY[idx][0] * mult,
+ blockWalkMask) && mult <= dist)
+ {
+ mult ++;
+ }
+ localPlayer->move(movesX[idx][0] * (mult - 1), movesY[idx][0] * (mult - 1));
+ }
+ else if (map->getWalk(x + movesX[idx][1],
+ y + movesY[idx][1], blockWalkMask))
+ {
+ while (map->getWalk(x + movesX[idx][1] * mult,
+ y + movesY[idx][1] * mult,
+ blockWalkMask) && mult <= dist)
+ {
+ mult ++;
+ }
+ localPlayer->move(movesX[idx][1] * (mult - 1), movesY[idx][1] * (mult - 1));
+ }
+ else if (map->getWalk(x + movesX[idx][2],
+ y + movesY[idx][2], blockWalkMask))
+ {
+ while (map->getWalk(x + movesX[idx][2] * mult,
+ y + movesY[idx][2] * mult,
+ blockWalkMask) && mult <= dist)
+ {
+ mult ++;
+ }
+ localPlayer->move(movesX[idx][2] * (mult - 1), movesY[idx][2] * (mult - 1));
+ }
+ else if (map->getWalk(x + movesX[idx][3],
+ y + movesY[idx][3], blockWalkMask))
+ {
+ while (map->getWalk(x + movesX[idx][3] * mult,
+ y + movesY[idx][3] * mult,
+ blockWalkMask) && mult <= dist)
+ {
+ mult ++;
+ }
+ localPlayer->move(movesX[idx][3] * (mult - 1), movesY[idx][3] * (mult - 1));
+ }
+}
+
+void CrazyMoves::crazyMove9()
+{
+ int dx = 0;
+ int dy = 0;
+
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ switch (settings.crazyMoveState)
+ {
+ case 0:
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP : dy = -1; break;
+ case BeingDirection::DOWN : dy = 1; break;
+ case BeingDirection::LEFT : dx = -1; break;
+ case BeingDirection::RIGHT: dx = 1; break;
+ default: break;
+ }
+ localPlayer->move(dx, dy);
+ settings.crazyMoveState = 1;
+ break;
+ case 1:
+ settings.crazyMoveState = 2;
+ if (!localPlayer->allowAction())
+ return;
+ playerHandler->changeAction(BeingAction::SIT);
+ break;
+ case 2:
+ settings.crazyMoveState = 3;
+ break;
+ case 3:
+ settings.crazyMoveState = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void CrazyMoves::crazyMoveA()
+{
+ const std::string mMoveProgram(config.getStringValue("crazyMoveProgram"));
+
+ if (localPlayer->getCurrentAction() == BeingAction::MOVE)
+ return;
+
+ if (mMoveProgram.empty())
+ return;
+
+ if (settings.crazyMoveState >= mMoveProgram.length())
+ settings.crazyMoveState = 0;
+
+ // move command
+ if (mMoveProgram[settings.crazyMoveState] == 'm')
+ {
+ settings.crazyMoveState ++;
+ if (settings.crazyMoveState < mMoveProgram.length())
+ {
+ int dx = 0;
+ int dy = 0;
+
+ signed char param = mMoveProgram[settings.crazyMoveState++];
+ if (param == '?')
+ {
+ const char cmd[] = {'l', 'r', 'u', 'd', 'L', 'R', 'U', 'D'};
+ srand(tick_time);
+ param = cmd[rand() % 8];
+ }
+ switch (param)
+ {
+ case 'd':
+ localPlayer->move(0, 1);
+ break;
+ case 'u':
+ localPlayer->move(0, -1);
+ break;
+ case 'l':
+ localPlayer->move(-1, 0);
+ break;
+ case 'r':
+ localPlayer->move(1, 0);
+ break;
+ case 'D':
+ localPlayer->move(1, 1);
+ break;
+ case 'U':
+ localPlayer->move(-1, -1);
+ break;
+ case 'L':
+ localPlayer->move(-1, 1);
+ break;
+ case 'R':
+ localPlayer->move(1, -1);
+ break;
+ case 'f':
+ {
+ const uint8_t dir = localPlayer->getDirection();
+ if (dir & BeingDirection::UP)
+ dy = -1;
+ else if (dir & BeingDirection::DOWN)
+ dy = 1;
+ if (dir & BeingDirection::LEFT)
+ dx = -1;
+ else if (dir & BeingDirection::RIGHT)
+ dx = 1;
+ localPlayer->move(dx, dy);
+ break;
+ }
+ case 'b':
+ {
+ const uint8_t dir = localPlayer->getDirection();
+ if (dir & BeingDirection::UP)
+ dy = 1;
+ else if (dir & BeingDirection::DOWN)
+ dy = -1;
+ if (dir & BeingDirection::LEFT)
+ dx = 1;
+ else if (dir & BeingDirection::RIGHT)
+ dx = -1;
+ localPlayer->move(dx, dy);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+ // direction command
+ else if (mMoveProgram[settings.crazyMoveState] == 'd')
+ {
+ settings.crazyMoveState ++;
+
+ if (settings.crazyMoveState < mMoveProgram.length())
+ {
+ signed char param = mMoveProgram[settings.crazyMoveState++];
+ if (param == '?')
+ {
+ const char cmd[] = {'l', 'r', 'u', 'd'};
+ srand(tick_time);
+ param = cmd[rand() % 4];
+ }
+ switch (param)
+ {
+ case 'd':
+
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ localPlayer->setDirection(BeingDirection::DOWN);
+ playerHandler->setDirection(
+ BeingDirection::DOWN);
+ }
+ break;
+ case 'u':
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ localPlayer->setDirection(BeingDirection::UP);
+ playerHandler->setDirection(
+ BeingDirection::UP);
+ }
+ break;
+ case 'l':
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ localPlayer->setDirection(BeingDirection::LEFT);
+ playerHandler->setDirection(
+ BeingDirection::LEFT);
+ }
+ break;
+ case 'r':
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ localPlayer->setDirection(BeingDirection::RIGHT);
+ playerHandler->setDirection(
+ BeingDirection::RIGHT);
+ }
+ break;
+ case 'L':
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ uint8_t dir = 0;
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP:
+ dir = BeingDirection::LEFT;
+ break;
+ case BeingDirection::DOWN:
+ dir = BeingDirection::RIGHT;
+ break;
+ case BeingDirection::LEFT:
+ dir = BeingDirection::DOWN;
+ break;
+ case BeingDirection::RIGHT:
+ dir = BeingDirection::UP;
+ break;
+ default:
+ break;
+ }
+ localPlayer->setDirection(dir);
+ playerHandler->setDirection(dir);
+ }
+ break;
+ case 'R':
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ uint8_t dir = 0;
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP:
+ dir = BeingDirection::RIGHT;
+ break;
+ case BeingDirection::DOWN:
+ dir = BeingDirection::LEFT;
+ break;
+ case BeingDirection::LEFT:
+ dir = BeingDirection::UP;
+ break;
+ case BeingDirection::RIGHT:
+ dir = BeingDirection::DOWN;
+ break;
+ default:
+ break;
+ }
+ localPlayer->setDirection(dir);
+ playerHandler->setDirection(dir);
+ }
+ break;
+ case 'b':
+// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
+ {
+ uint8_t dir = 0;
+ switch (localPlayer->getDirection())
+ {
+ case BeingDirection::UP:
+ dir = BeingDirection::DOWN;
+ break;
+ case BeingDirection::DOWN:
+ dir = BeingDirection::UP;
+ break;
+ case BeingDirection::LEFT:
+ dir = BeingDirection::RIGHT;
+ break;
+ case BeingDirection::RIGHT:
+ dir = BeingDirection::LEFT;
+ break;
+ default:
+ break;
+ }
+ localPlayer->setDirection(dir);
+ playerHandler->setDirection(dir);
+ }
+ break;
+ case '0':
+ dropShortcut->dropFirst();
+ break;
+ case 'a':
+ dropShortcut->dropItems();
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ // sit command
+ else if (mMoveProgram[settings.crazyMoveState] == 's')
+ {
+ settings.crazyMoveState ++;
+ if (localPlayer->toggleSit())
+ settings.crazyMoveState ++;
+ }
+ // wear outfits
+ else if (mMoveProgram[settings.crazyMoveState] == 'o')
+ {
+ settings.crazyMoveState ++;
+ if (settings.crazyMoveState < mMoveProgram.length())
+ {
+ // wear next outfit
+ if (mMoveProgram[settings.crazyMoveState] == 'n')
+ {
+ settings.crazyMoveState ++;
+ outfitWindow->wearNextOutfit();
+ }
+ // wear previous outfit
+ else if (mMoveProgram[settings.crazyMoveState] == 'p')
+ {
+ settings.crazyMoveState ++;
+ outfitWindow->wearPreviousOutfit();
+ }
+ }
+ }
+ // pause
+ else if (mMoveProgram[settings.crazyMoveState] == 'w')
+ {
+ settings.crazyMoveState ++;
+ }
+ // pick up
+ else if (mMoveProgram[settings.crazyMoveState] == 'p')
+ {
+ settings.crazyMoveState ++;
+ localPlayer->pickUpItems();
+ }
+ // emote
+ else if (mMoveProgram[settings.crazyMoveState] == 'e'
+ || mMoveProgram[settings.crazyMoveState] == 'E')
+ {
+ settings.crazyMoveState ++;
+ const signed char emo = mMoveProgram[settings.crazyMoveState];
+ unsigned char emoteId = 0;
+ if (emo == '?')
+ {
+ srand(tick_time);
+ emoteId = static_cast<unsigned char>(
+ 1 + (rand() % EmoteDB::size()));
+ }
+ else
+ {
+ if (emo >= '0' && emo <= '9')
+ emoteId = static_cast<unsigned char>(emo - '0' + 1);
+ else if (emo >= 'a' && emo <= 'z')
+ emoteId = static_cast<unsigned char>(emo - 'a' + 11);
+ else if (emo >= 'A' && emo <= 'Z')
+ emoteId = static_cast<unsigned char>(emo - 'A' + 37);
+ }
+ if (mMoveProgram[settings.crazyMoveState - 1] == 'e')
+ localPlayer->emote(emoteId);
+ else if (PacketLimiter::limitPackets(PACKET_CHAT))
+ petHandler->emote(emoteId, 0);
+
+ settings.crazyMoveState ++;
+ }
+ else
+ {
+ settings.crazyMoveState ++;
+ }
+
+ if (settings.crazyMoveState >= mMoveProgram.length())
+ settings.crazyMoveState = 0;
+}
diff --git a/src/being/crazymoves.h b/src/being/crazymoves.h
new file mode 100644
index 000000000..c97d8db45
--- /dev/null
+++ b/src/being/crazymoves.h
@@ -0,0 +1,53 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef BEING_CRAZYMOVES_H
+#define BEING_CRAZYMOVES_H
+
+#include "localconsts.h"
+
+class CrazyMoves final
+{
+ public:
+ CrazyMoves();
+ A_DELETE_COPY(CrazyMoves)
+ void crazyMove();
+
+ protected:
+ void crazyMove1();
+ void crazyMove2();
+ void crazyMove3();
+ void crazyMove4();
+ void crazyMove5();
+ void crazyMove6();
+ void crazyMove7();
+ void crazyMove8();
+ void crazyMove9();
+ void crazyMoveA();
+
+ // temporary disable crazy moves in moves
+ bool mDisableCrazyMove;
+};
+
+extern CrazyMoves *crazyMoves;
+
+#endif // BEING_CRAZYMOVES_H
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 4ed1356af..79f68dfbe 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -37,6 +37,7 @@
#include "resources/map/walklayer.h"
#include "being/beingflag.h"
+#include "being/crazymoves.h"
#include "being/playerinfo.h"
#include "being/playerrelations.h"
@@ -171,7 +172,6 @@ LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) :
mShowJobExp(config.getBoolValue("showJobExp")),
mShowServerPos(config.getBoolValue("showserverpos")),
mNextStep(false),
- mDisableCrazyMove(false),
mGoingToTarget(false),
mKeepAttacking(false),
mPathSetByMouse(false),
@@ -1329,683 +1329,6 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
}
}
-void LocalPlayer::crazyMove()
-{
- const bool oldDisableCrazyMove = mDisableCrazyMove;
- mDisableCrazyMove = true;
- switch (settings.crazyMoveType)
- {
- case 1:
- crazyMove1();
- break;
- case 2:
- crazyMove2();
- break;
- case 3:
- crazyMove3();
- break;
- case 4:
- crazyMove4();
- break;
- case 5:
- crazyMove5();
- break;
- case 6:
- crazyMove6();
- break;
- case 7:
- crazyMove7();
- break;
- case 8:
- crazyMove8();
- break;
- case 9:
- crazyMove9();
- break;
- case 10:
- crazyMoveA();
- break;
- default:
- break;
- }
- mDisableCrazyMove = oldDisableCrazyMove;
-}
-
-void LocalPlayer::crazyMove1()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
-// if (!PacketLimiter::limitPackets(PACKET_DIRECTION))
-// return;
-
- if (mDirection == BeingDirection::UP)
- {
- setWalkingDir(BeingDirection::UP);
- setDirection(BeingDirection::LEFT);
- playerHandler->setDirection(BeingDirection::LEFT);
- }
- else if (mDirection == BeingDirection::LEFT)
- {
- setWalkingDir(BeingDirection::LEFT);
- setDirection(BeingDirection::DOWN);
- playerHandler->setDirection(BeingDirection::DOWN);
- }
- else if (mDirection == BeingDirection::DOWN)
- {
- setWalkingDir(BeingDirection::DOWN);
- setDirection(BeingDirection::RIGHT);
- playerHandler->setDirection(BeingDirection::RIGHT);
- }
- else if (mDirection == BeingDirection::RIGHT)
- {
- setWalkingDir(BeingDirection::RIGHT);
- setDirection(BeingDirection::UP);
- playerHandler->setDirection(BeingDirection::UP);
- }
-}
-
-void LocalPlayer::crazyMove2()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
-// if (!PacketLimiter::limitPackets(PACKET_DIRECTION))
-// return;
-
- if (mDirection == BeingDirection::UP)
- {
- setWalkingDir(BeingDirection::UP | BeingDirection::LEFT);
- setDirection(BeingDirection::RIGHT);
- playerHandler->setDirection(
- BeingDirection::DOWN | BeingDirection::RIGHT);
- }
- else if (mDirection == BeingDirection::RIGHT)
- {
- setWalkingDir(BeingDirection::UP | BeingDirection::RIGHT);
- setDirection(BeingDirection::DOWN);
- playerHandler->setDirection(
- BeingDirection::DOWN | BeingDirection::LEFT);
- }
- else if (mDirection == BeingDirection::DOWN)
- {
- setWalkingDir(BeingDirection::DOWN | BeingDirection::RIGHT);
- setDirection(BeingDirection::LEFT);
- playerHandler->setDirection(
- BeingDirection::UP | BeingDirection::LEFT);
- }
- else if (mDirection == BeingDirection::LEFT)
- {
- setWalkingDir(BeingDirection::DOWN | BeingDirection::LEFT);
- setDirection(BeingDirection::UP);
- playerHandler->setDirection(
- BeingDirection::UP | BeingDirection::RIGHT);
- }
-}
-
-void LocalPlayer::crazyMove3()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
- switch (settings.crazyMoveState)
- {
- case 0:
- move(1, 1);
- settings.crazyMoveState = 1;
- break;
- case 1:
- move(1, -1);
- settings.crazyMoveState = 2;
- break;
- case 2:
- move(-1, -1);
- settings.crazyMoveState = 3;
- break;
- case 3:
- move(-1, 1);
- settings.crazyMoveState = 0;
- break;
- default:
- break;
- }
-
-// if (!PacketLimiter::limitPackets(PACKET_DIRECTION))
-// return;
-
- setDirection(BeingDirection::DOWN);
- playerHandler->setDirection(BeingDirection::DOWN);
-}
-
-void LocalPlayer::crazyMove4()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
- switch (settings.crazyMoveState)
- {
- case 0:
- move(7, 0);
- settings.crazyMoveState = 1;
- break;
- case 1:
- move(-7, 0);
- settings.crazyMoveState = 0;
- break;
- default:
- break;
- }
-}
-
-void LocalPlayer::crazyMove5()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
- switch (settings.crazyMoveState)
- {
- case 0:
- move(0, 7);
- settings.crazyMoveState = 1;
- break;
- case 1:
- move(0, -7);
- settings.crazyMoveState = 0;
- break;
- default:
- break;
- }
-}
-
-void LocalPlayer::crazyMove6()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
- switch (settings.crazyMoveState)
- {
- case 0:
- move(3, 0);
- settings.crazyMoveState = 1;
- break;
- case 1:
- move(2, -2);
- settings.crazyMoveState = 2;
- break;
- case 2:
- move(0, -3);
- settings.crazyMoveState = 3;
- break;
- case 3:
- move(-2, -2);
- settings.crazyMoveState = 4;
- break;
- case 4:
- move(-3, 0);
- settings.crazyMoveState = 5;
- break;
- case 5:
- move(-2, 2);
- settings.crazyMoveState = 6;
- break;
- case 6:
- move(0, 3);
- settings.crazyMoveState = 7;
- break;
- case 7:
- move(2, 2);
- settings.crazyMoveState = 0;
- break;
- default:
- break;
- }
-}
-
-void LocalPlayer::crazyMove7()
-{
- if (mAction == BeingAction::MOVE)
- return;
-
- switch (settings.crazyMoveState)
- {
- case 0:
- move(1, 1);
- settings.crazyMoveState = 1;
- break;
- case 1:
- move(-1, 1);
- settings.crazyMoveState = 2;
- break;
- case 2:
- move(-1, -1);
- settings.crazyMoveState = 3;
- break;
- case 3:
- move(1, -1);
- settings.crazyMoveState = 0;
- break;
- default:
- break;
- }
-}
-
-void LocalPlayer::crazyMove8()
-{
- if (mAction == BeingAction::MOVE || !mMap)
- return;
- int idx = 0;
- const int dist = 1;
-
-// look
-// up, ri,do,le
- static const int movesX[][4] =
- {
- {-1, 0, 1, 0}, // move left
- { 0, 1, 0, -1}, // move up
- { 1, 0, -1, 0}, // move right
- { 0, -1, 0, 1} // move down
- };
-
-// look
-// up, ri,do,le
- static const int movesY[][4] =
- {
- { 0, -1, 0, 1}, // move left
- {-1, 0, 1, 0}, // move up
- { 0, 1, 0, -1}, // move right
- { 1, 0, -1, 0} // move down
- };
-
- if (mDirection == BeingDirection::UP)
- idx = 0;
- else if (mDirection == BeingDirection::RIGHT)
- idx = 1;
- else if (mDirection == BeingDirection::DOWN)
- idx = 2;
- else if (mDirection == BeingDirection::LEFT)
- idx = 3;
-
-
- int mult = 1;
- const unsigned char blockWalkMask = getBlockWalkMask();
- if (mMap->getWalk(mX + movesX[idx][0],
- mY + movesY[idx][0], blockWalkMask))
- {
- while (mMap->getWalk(mX + movesX[idx][0] * mult,
- mY + movesY[idx][0] * mult,
- getBlockWalkMask()) && mult <= dist)
- {
- mult ++;
- }
- move(movesX[idx][0] * (mult - 1), movesY[idx][0] * (mult - 1));
- }
- else if (mMap->getWalk(mX + movesX[idx][1],
- mY + movesY[idx][1], blockWalkMask))
- {
- while (mMap->getWalk(mX + movesX[idx][1] * mult,
- mY + movesY[idx][1] * mult,
- getBlockWalkMask()) && mult <= dist)
- {
- mult ++;
- }
- move(movesX[idx][1] * (mult - 1), movesY[idx][1] * (mult - 1));
- }
- else if (mMap->getWalk(mX + movesX[idx][2],
- mY + movesY[idx][2], blockWalkMask))
- {
- while (mMap->getWalk(mX + movesX[idx][2] * mult,
- mY + movesY[idx][2] * mult,
- getBlockWalkMask()) && mult <= dist)
- {
- mult ++;
- }
- move(movesX[idx][2] * (mult - 1), movesY[idx][2] * (mult - 1));
- }
- else if (mMap->getWalk(mX + movesX[idx][3],
- mY + movesY[idx][3], blockWalkMask))
- {
- while (mMap->getWalk(mX + movesX[idx][3] * mult,
- mY + movesY[idx][3] * mult,
- getBlockWalkMask()) && mult <= dist)
- {
- mult ++;
- }
- move(movesX[idx][3] * (mult - 1), movesY[idx][3] * (mult - 1));
- }
-}
-
-void LocalPlayer::crazyMove9()
-{
- int dx = 0;
- int dy = 0;
-
- if (mAction == BeingAction::MOVE)
- return;
-
- switch (settings.crazyMoveState)
- {
- case 0:
- switch (mDirection)
- {
- case BeingDirection::UP : dy = -1; break;
- case BeingDirection::DOWN : dy = 1; break;
- case BeingDirection::LEFT : dx = -1; break;
- case BeingDirection::RIGHT: dx = 1; break;
- default: break;
- }
- move(dx, dy);
- settings.crazyMoveState = 1;
- break;
- case 1:
- settings.crazyMoveState = 2;
- if (!allowAction())
- return;
- playerHandler->changeAction(BeingAction::SIT);
- break;
- case 2:
- settings.crazyMoveState = 3;
- break;
- case 3:
- settings.crazyMoveState = 0;
- break;
- default:
- break;
- }
-}
-
-void LocalPlayer::crazyMoveA()
-{
- const std::string mMoveProgram(config.getStringValue("crazyMoveProgram"));
-
- if (mAction == BeingAction::MOVE)
- return;
-
- if (mMoveProgram.empty())
- return;
-
- if (settings.crazyMoveState >= mMoveProgram.length())
- settings.crazyMoveState = 0;
-
- // move command
- if (mMoveProgram[settings.crazyMoveState] == 'm')
- {
- settings.crazyMoveState ++;
- if (settings.crazyMoveState < mMoveProgram.length())
- {
- int dx = 0;
- int dy = 0;
-
- signed char param = mMoveProgram[settings.crazyMoveState++];
- if (param == '?')
- {
- const char cmd[] = {'l', 'r', 'u', 'd', 'L', 'R', 'U', 'D'};
- srand(tick_time);
- param = cmd[rand() % 8];
- }
- switch (param)
- {
- case 'd':
- move(0, 1);
- break;
- case 'u':
- move(0, -1);
- break;
- case 'l':
- move(-1, 0);
- break;
- case 'r':
- move(1, 0);
- break;
- case 'D':
- move(1, 1);
- break;
- case 'U':
- move(-1, -1);
- break;
- case 'L':
- move(-1, 1);
- break;
- case 'R':
- move(1, -1);
- break;
- case 'f':
- if (mDirection & BeingDirection::UP)
- dy = -1;
- else if (mDirection & BeingDirection::DOWN)
- dy = 1;
- if (mDirection & BeingDirection::LEFT)
- dx = -1;
- else if (mDirection & BeingDirection::RIGHT)
- dx = 1;
- move(dx, dy);
- break;
- case 'b':
- if (mDirection & BeingDirection::UP)
- dy = 1;
- else if (mDirection & BeingDirection::DOWN)
- dy = -1;
- if (mDirection & BeingDirection::LEFT)
- dx = 1;
- else if (mDirection & BeingDirection::RIGHT)
- dx = -1;
- move(dx, dy);
- break;
- default:
- break;
- }
- }
- }
- // direction command
- else if (mMoveProgram[settings.crazyMoveState] == 'd')
- {
- settings.crazyMoveState ++;
-
- if (settings.crazyMoveState < mMoveProgram.length())
- {
- signed char param = mMoveProgram[settings.crazyMoveState++];
- if (param == '?')
- {
- const char cmd[] = {'l', 'r', 'u', 'd'};
- srand(tick_time);
- param = cmd[rand() % 4];
- }
- switch (param)
- {
- case 'd':
-
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- setDirection(BeingDirection::DOWN);
- playerHandler->setDirection(
- BeingDirection::DOWN);
- }
- break;
- case 'u':
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- setDirection(BeingDirection::UP);
- playerHandler->setDirection(
- BeingDirection::UP);
- }
- break;
- case 'l':
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- setDirection(BeingDirection::LEFT);
- playerHandler->setDirection(
- BeingDirection::LEFT);
- }
- break;
- case 'r':
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- setDirection(BeingDirection::RIGHT);
- playerHandler->setDirection(
- BeingDirection::RIGHT);
- }
- break;
- case 'L':
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- uint8_t dir = 0;
- switch (mDirection)
- {
- case BeingDirection::UP:
- dir = BeingDirection::LEFT;
- break;
- case BeingDirection::DOWN:
- dir = BeingDirection::RIGHT;
- break;
- case BeingDirection::LEFT:
- dir = BeingDirection::DOWN;
- break;
- case BeingDirection::RIGHT:
- dir = BeingDirection::UP;
- break;
- default:
- break;
- }
- setDirection(dir);
- playerHandler->setDirection(dir);
- }
- break;
- case 'R':
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- uint8_t dir = 0;
- switch (mDirection)
- {
- case BeingDirection::UP:
- dir = BeingDirection::RIGHT;
- break;
- case BeingDirection::DOWN:
- dir = BeingDirection::LEFT;
- break;
- case BeingDirection::LEFT:
- dir = BeingDirection::UP;
- break;
- case BeingDirection::RIGHT:
- dir = BeingDirection::DOWN;
- break;
- default:
- break;
- }
- setDirection(dir);
- playerHandler->setDirection(dir);
- }
- break;
- case 'b':
-// if (PacketLimiter::limitPackets(PACKET_DIRECTION))
- {
- uint8_t dir = 0;
- switch (mDirection)
- {
- case BeingDirection::UP:
- dir = BeingDirection::DOWN;
- break;
- case BeingDirection::DOWN:
- dir = BeingDirection::UP;
- break;
- case BeingDirection::LEFT:
- dir = BeingDirection::RIGHT;
- break;
- case BeingDirection::RIGHT:
- dir = BeingDirection::LEFT;
- break;
- default:
- break;
- }
- setDirection(dir);
- playerHandler->setDirection(dir);
- }
- break;
- case '0':
- dropShortcut->dropFirst();
- break;
- case 'a':
- dropShortcut->dropItems();
- break;
- default:
- break;
- }
- }
- }
- // sit command
- else if (mMoveProgram[settings.crazyMoveState] == 's')
- {
- settings.crazyMoveState ++;
- if (toggleSit())
- settings.crazyMoveState ++;
- }
- // wear outfits
- else if (mMoveProgram[settings.crazyMoveState] == 'o')
- {
- settings.crazyMoveState ++;
- if (settings.crazyMoveState < mMoveProgram.length())
- {
- // wear next outfit
- if (mMoveProgram[settings.crazyMoveState] == 'n')
- {
- settings.crazyMoveState ++;
- outfitWindow->wearNextOutfit();
- }
- // wear previous outfit
- else if (mMoveProgram[settings.crazyMoveState] == 'p')
- {
- settings.crazyMoveState ++;
- outfitWindow->wearPreviousOutfit();
- }
- }
- }
- // pause
- else if (mMoveProgram[settings.crazyMoveState] == 'w')
- {
- settings.crazyMoveState ++;
- }
- // pick up
- else if (mMoveProgram[settings.crazyMoveState] == 'p')
- {
- settings.crazyMoveState ++;
- pickUpItems();
- }
- // emote
- else if (mMoveProgram[settings.crazyMoveState] == 'e'
- || mMoveProgram[settings.crazyMoveState] == 'E')
- {
- settings.crazyMoveState ++;
- const signed char emo = mMoveProgram[settings.crazyMoveState];
- unsigned char emoteId = 0;
- if (emo == '?')
- {
- srand(tick_time);
- emoteId = static_cast<unsigned char>(
- 1 + (rand() % EmoteDB::size()));
- }
- else
- {
- if (emo >= '0' && emo <= '9')
- emoteId = static_cast<unsigned char>(emo - '0' + 1);
- else if (emo >= 'a' && emo <= 'z')
- emoteId = static_cast<unsigned char>(emo - 'a' + 11);
- else if (emo >= 'A' && emo <= 'Z')
- emoteId = static_cast<unsigned char>(emo - 'A' + 37);
- }
- if (mMoveProgram[settings.crazyMoveState - 1] == 'e')
- emote(emoteId);
- else if (PacketLimiter::limitPackets(PACKET_CHAT))
- petHandler->emote(emoteId, 0);
-
- settings.crazyMoveState ++;
- }
- else
- {
- settings.crazyMoveState ++;
- }
-
- if (settings.crazyMoveState >= mMoveProgram.length())
- settings.crazyMoveState = 0;
-}
-
bool LocalPlayer::isReachable(Being *const being,
const int maxCost)
{
@@ -2209,7 +1532,7 @@ void LocalPlayer::specialMove(const unsigned char direction)
else
{
mMoveState = 0;
- crazyMove();
+ crazyMoves->crazyMove();
}
}
else
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index c8efcb4ff..aa297dcb1 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -208,8 +208,6 @@ class LocalPlayer final : public Being,
bool pickUpItems(int pickUpType = 0);
- void crazyMove();
-
void move(const int dX, const int dY);
void moveToTarget(int dist = -1);
@@ -422,17 +420,6 @@ class LocalPlayer final : public Being,
static void tryMagic(const std::string &spell, const int baseMagic,
const int schoolMagic, const int mana);
- void crazyMove1();
- void crazyMove2();
- void crazyMove3();
- void crazyMove4();
- void crazyMove5();
- void crazyMove6();
- void crazyMove7();
- void crazyMove8();
- void crazyMove9();
- void crazyMoveA();
-
void loadHomes();
int mGMLevel;
@@ -506,7 +493,6 @@ class LocalPlayer final : public Being,
bool mShowServerPos;
bool mNextStep;
// temporary disable crazy moves in moves
- bool mDisableCrazyMove;
bool mGoingToTarget;
// Whether or not to continue to attack
bool mKeepAttacking;