diff options
-rw-r--r-- | src/localplayer.cpp | 22 | ||||
-rw-r--r-- | src/localplayer.h | 51 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.h | 2 | ||||
-rw-r--r-- | src/net/playerhandler.h | 6 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 5 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.h | 2 |
7 files changed, 26 insertions, 70 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 1e790d44..28f26755 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -74,7 +74,6 @@ LocalPlayer::LocalPlayer(int id, int subtype): mWalkingDir(0), mPathSetByMouse(false), mLocalWalkTime(-1), - mKeyboardMoveDelay(500), mMessageTime(0), mShowIp(false), mAwayDialog(0), @@ -712,10 +711,14 @@ void LocalPlayer::setWalkingDir(int dir) { // This function is called by Game::handleInput() - // First if player is pressing key for the direction he is already - // going, do nothing more... + // Don't compute a new path before the last one set by keyboard is finished. + // This permits to avoid movement glitches and server spamming. + const Vector &pos = getPosition(); + const Vector &dest = getDestination(); + if (!isPathSetByMouse() && (pos.x != dest.x || pos.y != dest.y)) + return; - // Else if he is pressing a key, and its different from what he has + // If the player is pressing a key, and its different from what he has // been pressing, stop (do not send this stop to the server) and // start in the new direction if (dir && (dir != getWalkingDir())) @@ -728,12 +731,7 @@ void LocalPlayer::setWalkingDir(int dir) else if (!dir) return; - // If the delay to send another walk message to the server hasn't expired, - // don't do anything or we could get disconnected for spamming the server - if (get_elapsed_time(mLocalWalkTime) < mKeyboardMoveDelay) - return; mLocalWalkTime = tick_time; - mWalkingDir = dir; // If we're not already walking, start walking. @@ -798,12 +796,6 @@ void LocalPlayer::stopWalking(bool sendToServer) clearPath(); } -void LocalPlayer::setMoveSpeed(const Vector& speed) -{ - Being::setMoveSpeed(speed); - mKeyboardMoveDelay = Net::getPlayerHandler()->getKeyboardMoveDelay(speed); -} - void LocalPlayer::toggleSit() { if (mLastAction != -1) diff --git a/src/localplayer.h b/src/localplayer.h index e3849126..554312c8 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -79,23 +79,6 @@ class LocalPlayer : public Being virtual void setAction(Action action, int attackId = 1); /** - * Compute the next pathnode location when walking using keyboard. - * used by nextTile(). - */ - Position getNextWalkPosition(unsigned char dir); - - /** - * Adds a new tile to the path when walking. - * @note Eathena - * Also, when specified, it picks up an item at the end of a path - * or attack target. - */ - virtual void nextTile() - { nextTile(0); } - - virtual void nextTile(unsigned char dir); - - /** * Check the player has permission to invite users to specific guild */ bool checkInviteRights(const std::string &guildName); @@ -147,15 +130,14 @@ class LocalPlayer : public Being */ void setTarget(Being *target); - void setMoveSpeed(const Vector &speed); - /** * Sets a new destination for this being to walk to. */ virtual void setDestination(int x, int y); /** - * Sets a new direction to keep walking in. + * Sets a new direction to keep walking in, when using the keyboard + * or the joystick. */ void setWalkingDir(int dir); @@ -175,11 +157,6 @@ class LocalPlayer : public Being */ bool withinAttackRange(Being *target); - /** - * Stops the player dead in his tracks - */ - void stopWalking(bool sendToServer = true); - void toggleSit(); void emote(uint8_t emotion); @@ -233,8 +210,25 @@ class LocalPlayer : public Being /** Whether or not the name settings have changed */ bool mUpdateName; + /** Make the character starts to walk. */ void startWalking(unsigned char dir); + /** + * Stops the player dead in his tracks + */ + void stopWalking(bool sendToServer = true); + + /** + * set the next path tile when walking and using the keyboard. + */ + virtual void nextTile(unsigned char dir); + + /** + * Compute the next pathnode location when walking using keyboard. + * used by nextTile(). + */ + Position getNextWalkPosition(unsigned char dir); + int mAttackRange; int mTargetTime; /** How long the being has been targeted **/ @@ -255,13 +249,6 @@ class LocalPlayer : public Being int mLocalWalkTime; /**< Timestamp used to control keyboard walk messages flooding */ - /** - * The delay between two permitted setDestination() call using - * the keyboard. - * It's set in milliseconds per tile. - */ - int mKeyboardMoveDelay; - typedef std::pair<std::string, int> MessagePair; /** Queued messages*/ std::list<MessagePair> mMessages; diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 43af40f5..aa670ad8 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -442,12 +442,4 @@ Vector PlayerHandler::getPixelsPerTickMoveSpeed(const Vector &speed, Map *map) return speedInTicks; } -int PlayerHandler::getKeyboardMoveDelay(const Vector& speed) -{ - int maxSpeed = std::max(speed.x, speed.y); - if (maxSpeed <= 0) - maxSpeed = 2; - return 1000 / maxSpeed; -} - } // namespace ManaServ diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h index 0edb4354..3e3f8aad 100644 --- a/src/net/manaserv/playerhandler.h +++ b/src/net/manaserv/playerhandler.h @@ -69,8 +69,6 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0); - int getKeyboardMoveDelay(const Vector& speed); - bool usePixelPrecision() { return true; } diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index b52b6315..6ac28b62 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -77,12 +77,6 @@ class PlayerHandler Map *map = 0) = 0; /** - * Convert the original speed into the keyboard move delay. - * The delay is set in milliseconds per tiles. - */ - virtual int getKeyboardMoveDelay(const Vector& speed) = 0; - - /** * Tells whether the client has to use pixel paths. * Return false when tiles-center positions only are to be used. */ diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f91d8573..132e45ee 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -662,9 +662,4 @@ Vector PlayerHandler::getPixelsPerTickMoveSpeed(const Vector &speed, Map *map) return speedInTicks; } -int PlayerHandler::getKeyboardMoveDelay(const Vector& speed) -{ - return std::min(speed.x, speed.y) * MILLISECONDS_IN_A_TICK; -} - } // namespace TmwAthena diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index 3e22be22..63812f47 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -62,8 +62,6 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0); - int getKeyboardMoveDelay(const Vector& speed); - bool usePixelPrecision() { return false; } }; |