summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-10 18:53:53 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-10 18:53:53 +0300
commit919d790980be710ec991af3654521225e97b5f79 (patch)
tree0d09d6d430502488fde4bd0841d8d5767af7d4f4
parenta3635c94a9f1074736f243b0f7de7ab1c8aa14d0 (diff)
downloadplus-919d790980be710ec991af3654521225e97b5f79.tar.gz
plus-919d790980be710ec991af3654521225e97b5f79.tar.bz2
plus-919d790980be710ec991af3654521225e97b5f79.tar.xz
plus-919d790980be710ec991af3654521225e97b5f79.zip
improve playerhandler class.
-rw-r--r--src/net/ea/playerhandler.cpp44
-rw-r--r--src/net/ea/playerhandler.h35
-rw-r--r--src/net/eathena/playerhandler.cpp29
-rw-r--r--src/net/eathena/playerhandler.h31
-rw-r--r--src/net/playerhandler.h32
-rw-r--r--src/net/tmwa/playerhandler.cpp33
-rw-r--r--src/net/tmwa/playerhandler.h29
7 files changed, 118 insertions, 115 deletions
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index 655d6be60..72de30304 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -54,7 +54,7 @@ namespace
/**
* Listener used for handling the overweigth message.
*/
- struct WeightListener : public gcn::ActionListener
+ struct WeightListener final : public gcn::ActionListener
{
void action(const gcn::ActionEvent &event A_UNUSED)
{
@@ -65,7 +65,7 @@ namespace
/**
* Listener used for handling death message.
*/
- struct DeathListener : public gcn::ActionListener
+ struct DeathListener final : public gcn::ActionListener
{
void action(const gcn::ActionEvent &event A_UNUSED)
{
@@ -144,20 +144,17 @@ PlayerHandler::PlayerHandler()
{
}
-void PlayerHandler::decreaseAttribute(int attr A_UNUSED)
+void PlayerHandler::decreaseAttribute(const int attr A_UNUSED) const
{
- // Supported by eA?
}
void PlayerHandler::ignorePlayer(const std::string &player A_UNUSED,
- bool ignore A_UNUSED)
+ const bool ignore A_UNUSED) const
{
- // TODO
}
-void PlayerHandler::ignoreAll(bool ignore A_UNUSED)
+void PlayerHandler::ignoreAll(const bool ignore A_UNUSED) const
{
- // TODO
}
bool PlayerHandler::canCorrectAttributes() const
@@ -172,7 +169,7 @@ Vector PlayerHandler::getDefaultWalkSpeed() const
return Vector(150, 150, 0);
}
-void PlayerHandler::processWalkResponse(Net::MessageIn &msg)
+void PlayerHandler::processWalkResponse(Net::MessageIn &msg) const
{
/*
* This client assumes that all walk messages succeed,
@@ -186,7 +183,7 @@ void PlayerHandler::processWalkResponse(Net::MessageIn &msg)
player_node->setRealPos(dstX, dstY);
}
-void PlayerHandler::processPlayerWarp(Net::MessageIn &msg)
+void PlayerHandler::processPlayerWarp(Net::MessageIn &msg) const
{
std::string mapPath = msg.readString(16);
int x = msg.readInt16();
@@ -241,11 +238,11 @@ void PlayerHandler::processPlayerWarp(Net::MessageIn &msg)
scrollOffsetY = (y - player_node->getTileY())
* map->getTileHeight();
}
+ scrollOffsetX = (x - player_node->getTileX())
+ * map->getTileWidth();
+ scrollOffsetY = (y - player_node->getTileY())
+ * map->getTileHeight();
}
-
- player_node->setAction(Being::STAND);
- player_node->setTileCoords(x, y);
- player_node->navigateClean();
}
logger->log("Adjust scrolling by %d:%d", scrollOffsetX, scrollOffsetY);
@@ -259,7 +256,7 @@ void PlayerHandler::processPlayerWarp(Net::MessageIn &msg)
}
}
-void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg)
+void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) const
{
const int type = msg.readInt16();
const int value = msg.readInt32();
@@ -437,7 +434,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg)
}
}
-void PlayerHandler::processPlayerStatUpdate2(Net::MessageIn &msg)
+void PlayerHandler::processPlayerStatUpdate2(Net::MessageIn &msg) const
{
const int type = msg.readInt16();
switch (type)
@@ -480,7 +477,7 @@ void PlayerHandler::processPlayerStatUpdate2(Net::MessageIn &msg)
}
}
-void PlayerHandler::processPlayerStatUpdate3(Net::MessageIn &msg)
+void PlayerHandler::processPlayerStatUpdate3(Net::MessageIn &msg) const
{
const int type = msg.readInt32();
const int base = msg.readInt32();
@@ -492,7 +489,7 @@ void PlayerHandler::processPlayerStatUpdate3(Net::MessageIn &msg)
PlayerInfo::updateAttrs();
}
-void PlayerHandler::processPlayerStatUpdate4(Net::MessageIn &msg)
+void PlayerHandler::processPlayerStatUpdate4(Net::MessageIn &msg) const
{
const int type = msg.readInt16();
const int ok = msg.readInt8();
@@ -501,8 +498,8 @@ void PlayerHandler::processPlayerStatUpdate4(Net::MessageIn &msg)
if (ok != 1)
{
const int oldValue = PlayerInfo::getStatBase(type);
- int points = PlayerInfo::getAttribute(PlayerInfo::CHAR_POINTS);
- points += oldValue - value;
+ const int points = PlayerInfo::getAttribute(PlayerInfo::CHAR_POINTS)
+ + oldValue - value;
PlayerInfo::setAttribute(PlayerInfo::CHAR_POINTS, points);
NotifyManager::notify(NotifyManager::SKILL_RAISE_ERROR);
}
@@ -510,7 +507,7 @@ void PlayerHandler::processPlayerStatUpdate4(Net::MessageIn &msg)
PlayerInfo::setStatBase(type, value);
}
-void PlayerHandler::processPlayerStatUpdate5(Net::MessageIn &msg)
+void PlayerHandler::processPlayerStatUpdate5(Net::MessageIn &msg) const
{
PlayerInfo::setAttribute(PlayerInfo::CHAR_POINTS, msg.readInt16());
@@ -582,7 +579,7 @@ void PlayerHandler::processPlayerStatUpdate5(Net::MessageIn &msg)
msg.readInt16(); // manner
}
-void PlayerHandler::processPlayerStatUpdate6(Net::MessageIn &msg)
+void PlayerHandler::processPlayerStatUpdate6(Net::MessageIn &msg) const
{
const int type = msg.readInt16();
if (statusWindow)
@@ -615,10 +612,9 @@ void PlayerHandler::processPlayerStatUpdate6(Net::MessageIn &msg)
}
}
-void PlayerHandler::processPlayerArrowMessage(Net::MessageIn &msg)
+void PlayerHandler::processPlayerArrowMessage(Net::MessageIn &msg) const
{
const int type = msg.readInt16();
-
switch (type)
{
case 0:
diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h
index 016b29782..57ff3b6af 100644
--- a/src/net/ea/playerhandler.h
+++ b/src/net/ea/playerhandler.h
@@ -37,39 +37,40 @@ class PlayerHandler : public Net::PlayerHandler
A_DELETE_COPY(PlayerHandler)
- void decreaseAttribute(int attr);
+ void decreaseAttribute(const int attr) const override;
- void ignorePlayer(const std::string &player, bool ignore);
+ void ignorePlayer(const std::string &player,
+ const bool ignore) const override;
- void ignoreAll(bool ignore);
+ void ignoreAll(const bool ignore) const override;
- bool canUseMagic() const;
+ bool canUseMagic() const override;
- bool canCorrectAttributes() const;
+ bool canCorrectAttributes() const override;
- Vector getDefaultWalkSpeed() const A_WARN_UNUSED;
+ Vector getDefaultWalkSpeed() const override A_WARN_UNUSED;
- int getJobLocation() const A_WARN_UNUSED;
+ int getJobLocation() const override A_WARN_UNUSED;
- int getAttackLocation() const A_WARN_UNUSED;
+ int getAttackLocation() const override A_WARN_UNUSED;
- void processWalkResponse(Net::MessageIn &msg);
+ void processWalkResponse(Net::MessageIn &msg) const;
- void processPlayerWarp(Net::MessageIn &msg);
+ void processPlayerWarp(Net::MessageIn &msg) const;
- void processPlayerStatUpdate1(Net::MessageIn &msg);
+ void processPlayerStatUpdate1(Net::MessageIn &msg) const;
- void processPlayerStatUpdate2(Net::MessageIn &msg);
+ void processPlayerStatUpdate2(Net::MessageIn &msg) const;
- void processPlayerStatUpdate3(Net::MessageIn &msg);
+ void processPlayerStatUpdate3(Net::MessageIn &msg) const;
- void processPlayerStatUpdate4(Net::MessageIn &msg);
+ void processPlayerStatUpdate4(Net::MessageIn &msg) const;
- void processPlayerStatUpdate5(Net::MessageIn &msg);
+ void processPlayerStatUpdate5(Net::MessageIn &msg) const;
- void processPlayerStatUpdate6(Net::MessageIn &msg);
+ void processPlayerStatUpdate6(Net::MessageIn &msg) const;
- void processPlayerArrowMessage(Net::MessageIn &msg);
+ void processPlayerArrowMessage(Net::MessageIn &msg) const;
};
} // namespace Ea
diff --git a/src/net/eathena/playerhandler.cpp b/src/net/eathena/playerhandler.cpp
index 7a7bdff4f..3d80c2e1e 100644
--- a/src/net/eathena/playerhandler.cpp
+++ b/src/net/eathena/playerhandler.cpp
@@ -115,7 +115,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
}
}
-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);
@@ -125,18 +125,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)
{
@@ -146,7 +146,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;
@@ -155,7 +155,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;
@@ -168,14 +168,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<short unsigned int>(x),
@@ -183,7 +184,7 @@ void PlayerHandler::setDestination(int x, int y, int direction)
static_cast<unsigned char>(direction));
}
-void PlayerHandler::changeAction(Being::Action action)
+void PlayerHandler::changeAction(const Being::Action action) const
{
unsigned char type;
switch (action)
@@ -208,24 +209,24 @@ 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
{
}
-void PlayerHandler::updateStatus(uint8_t status)
+void PlayerHandler::updateStatus(const uint8_t status) const
{
MessageOut outMsg(CMSG_SET_STATUS);
outMsg.writeInt8(status);
outMsg.writeInt8(0);
}
-void PlayerHandler::processPlayerShortcuts(Net::MessageIn &msg)
+void PlayerHandler::processPlayerShortcuts(Net::MessageIn &msg) const
{
for (int f = 0; f < 27; f ++)
{
@@ -235,7 +236,7 @@ void PlayerHandler::processPlayerShortcuts(Net::MessageIn &msg)
}
}
-void PlayerHandler::processPlayerShowEquip(Net::MessageIn &msg)
+void PlayerHandler::processPlayerShowEquip(Net::MessageIn &msg) const
{
msg.readInt8(); // show equip
}
diff --git a/src/net/eathena/playerhandler.h b/src/net/eathena/playerhandler.h
index 87bd2a7c6..ec8fcd5cb 100644
--- a/src/net/eathena/playerhandler.h
+++ b/src/net/eathena/playerhandler.h
@@ -40,26 +40,27 @@ 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 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 updateStatus(const uint8_t status) const override;
- void processPlayerShortcuts(Net::MessageIn &msg);
- void processPlayerShowEquip(Net::MessageIn &msg);
+ void processPlayerShortcuts(Net::MessageIn &msg) const;
+ void processPlayerShowEquip(Net::MessageIn &msg) const;
- void requestOnlineList();
- void respawn();
+ void requestOnlineList() const override;
+ void respawn() const override;
};
} // namespace EAthena
diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h
index d0a9fb512..a536bbf18 100644
--- a/src/net/playerhandler.h
+++ b/src/net/playerhandler.h
@@ -36,31 +36,33 @@ class PlayerHandler
virtual ~PlayerHandler()
{ }
- virtual void attack(int id, bool keep) = 0;
+ virtual void attack(const int id, const bool keep) const = 0;
- virtual void stopAttack() = 0;
+ virtual void stopAttack() const = 0;
- virtual void emote(uint8_t emoteId) = 0;
+ virtual void emote(const uint8_t emoteId) const = 0;
- virtual void increaseAttribute(int attr) = 0;
+ virtual void increaseAttribute(const int attr) const = 0;
- virtual void decreaseAttribute(int attr) = 0;
+ virtual void decreaseAttribute(const int attr) const = 0;
- virtual void increaseSkill(unsigned short skillId) = 0;
+ virtual void increaseSkill(const unsigned short skillId) const = 0;
- virtual void pickUp(const FloorItem *floorItem) = 0;
+ virtual void pickUp(const FloorItem *const floorItem) const = 0;
- virtual void setDirection(unsigned char direction) = 0;
+ virtual void setDirection(const unsigned char direction) const = 0;
- virtual void setDestination(int x, int y, int direction) = 0;
+ virtual void setDestination(const int x, const int y,
+ const int direction) const = 0;
- virtual void changeAction(Being::Action action) = 0;
+ virtual void changeAction(const Being::Action action) const = 0;
- virtual void respawn() = 0;
+ virtual void respawn() const = 0;
- virtual void ignorePlayer(const std::string &player, bool ignore) = 0;
+ virtual void ignorePlayer(const std::string &player,
+ const bool ignore) const = 0;
- virtual void ignoreAll(bool ignore) = 0;
+ virtual void ignoreAll(const bool ignore) const = 0;
virtual bool canUseMagic() const = 0;
@@ -72,9 +74,9 @@ class PlayerHandler
virtual Vector getDefaultWalkSpeed() const A_WARN_UNUSED = 0;
- virtual void requestOnlineList() = 0;
+ virtual void requestOnlineList() const = 0;
- virtual void updateStatus(uint8_t status) = 0;
+ virtual void updateStatus(const uint8_t status) const = 0;
};
} // namespace Net
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<short unsigned int>(x),
@@ -180,7 +181,7 @@ void PlayerHandler::setDestination(int x, int y, int direction)
static_cast<unsigned char>(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<char*>(msg.readBytes(size));
+ char *const start = reinterpret_cast<char*>(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<char*>(buf),
+ arr.push_back(new OnlinePlayer(static_cast<const char*>(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