summaryrefslogtreecommitdiff
path: root/src/being/localplayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/being/localplayer.cpp')
-rw-r--r--src/being/localplayer.cpp681
1 files changed, 2 insertions, 679 deletions
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