From 919d790980be710ec991af3654521225e97b5f79 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Apr 2013 18:53:53 +0300 Subject: improve playerhandler class. --- src/net/tmwa/playerhandler.cpp | 33 +++++++++++++++++---------------- src/net/tmwa/playerhandler.h | 29 +++++++++++++++-------------- 2 files changed, 32 insertions(+), 30 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 162841693..17ba07af1 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -112,7 +112,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("PlayerHandler::handleMessage") } -void PlayerHandler::attack(int id, bool keep) +void PlayerHandler::attack(const int id, const bool keep) const { MessageOut outMsg(CMSG_PLAYER_ATTACK); outMsg.writeInt32(id); @@ -122,18 +122,18 @@ void PlayerHandler::attack(int id, bool keep) outMsg.writeInt8(0); } -void PlayerHandler::stopAttack() +void PlayerHandler::stopAttack() const { MessageOut outMsg(CMSG_PLAYER_STOP_ATTACK); } -void PlayerHandler::emote(uint8_t emoteId) +void PlayerHandler::emote(const uint8_t emoteId) const { MessageOut outMsg(CMSG_PLAYER_EMOTE); outMsg.writeInt8(emoteId); } -void PlayerHandler::increaseAttribute(int attr) +void PlayerHandler::increaseAttribute(const int attr) const { if (attr >= STR && attr <= LUK) { @@ -143,7 +143,7 @@ void PlayerHandler::increaseAttribute(int attr) } } -void PlayerHandler::increaseSkill(unsigned short skillId) +void PlayerHandler::increaseSkill(const unsigned short skillId) const { if (PlayerInfo::getAttribute(PlayerInfo::SKILL_POINTS) <= 0) return; @@ -152,7 +152,7 @@ void PlayerHandler::increaseSkill(unsigned short skillId) outMsg.writeInt16(skillId); } -void PlayerHandler::pickUp(const FloorItem *floorItem) +void PlayerHandler::pickUp(const FloorItem *const floorItem) const { if (!floorItem) return; @@ -165,14 +165,15 @@ void PlayerHandler::pickUp(const FloorItem *floorItem) handler->pushPickup(floorItem->getId()); } -void PlayerHandler::setDirection(unsigned char direction) +void PlayerHandler::setDirection(const unsigned char direction) const { MessageOut outMsg(CMSG_PLAYER_CHANGE_DIR); outMsg.writeInt16(0); outMsg.writeInt8(direction); } -void PlayerHandler::setDestination(int x, int y, int direction) +void PlayerHandler::setDestination(const int x, const int y, + const int direction) const { MessageOut outMsg(CMSG_PLAYER_CHANGE_DEST); outMsg.writeCoordinates(static_cast(x), @@ -180,7 +181,7 @@ void PlayerHandler::setDestination(int x, int y, int direction) static_cast(direction)); } -void PlayerHandler::changeAction(Being::Action action) +void PlayerHandler::changeAction(const Being::Action action) const { char type; switch (action) @@ -205,18 +206,18 @@ void PlayerHandler::changeAction(Being::Action action) outMsg.writeInt8(type); } -void PlayerHandler::respawn() +void PlayerHandler::respawn() const { MessageOut outMsg(CMSG_PLAYER_RESTART); outMsg.writeInt8(0); } -void PlayerHandler::requestOnlineList() +void PlayerHandler::requestOnlineList() const { MessageOut outMsg(CMSG_ONLINE_LIST); } -void PlayerHandler::processOnlineList(Net::MessageIn &msg) +void PlayerHandler::processOnlineList(Net::MessageIn &msg) const { if (!whoIsOnline) return; @@ -231,11 +232,11 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) return; } - char *start = reinterpret_cast(msg.readBytes(size)); + char *const start = reinterpret_cast(msg.readBytes(size)); if (!start) return; - char *buf = start; + const char *buf = start; int addVal = 1; if (serverVersion >= 4) @@ -269,7 +270,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) gender = GENDER_FEMALE; } } - arr.push_back(new OnlinePlayer(static_cast(buf), + arr.push_back(new OnlinePlayer(static_cast(buf), status, level, gender, ver)); buf += strlen(buf) + 1; } @@ -279,7 +280,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) delete [] start; } -void PlayerHandler::updateStatus(uint8_t status) +void PlayerHandler::updateStatus(const uint8_t status) const { MessageOut outMsg(CMSG_SET_STATUS); outMsg.writeInt8(status); diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index 8aab78738..8307d7d05 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -40,24 +40,25 @@ class PlayerHandler final : public MessageHandler, public Ea::PlayerHandler A_DELETE_COPY(PlayerHandler) - void handleMessage(Net::MessageIn &msg); + void handleMessage(Net::MessageIn &msg) override; - void attack(int id, bool keep); - void stopAttack(); - void emote(uint8_t emoteId); + void attack(const int id, const bool keep) const override; + void stopAttack() const override; + void emote(const uint8_t emoteId) const override; - void increaseAttribute(int attr); - void increaseSkill(unsigned short skillId); + void increaseAttribute(const int attr) const override; + void increaseSkill(const unsigned short skillId) const override; - void pickUp(const FloorItem *floorItem); - void setDirection(unsigned char direction); - void setDestination(int x, int y, int direction); - void changeAction(Being::Action action); - void processOnlineList(Net::MessageIn &msg); - void requestOnlineList(); - void updateStatus(uint8_t status); + void pickUp(const FloorItem *const floorItem) const override; + void setDirection(const unsigned char direction) const override; + void setDestination(const int x, const int y, + const int direction) const override; + void changeAction(const Being::Action action) const override; + void processOnlineList(Net::MessageIn &msg) const; + void requestOnlineList() const override; + void updateStatus(const uint8_t status) const override; - void respawn(); + void respawn() const override; }; } // namespace TmwAthena -- cgit v1.2.3-70-g09d2