diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-10 14:57:39 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-10 14:57:39 +0300 |
commit | 3efda43abd11979adfd048fc62fe4f09e702f772 (patch) | |
tree | 80f8d0f65bf7648ae78e12badc11f13b4481b87a /src/net/tmwa/npchandler.cpp | |
parent | a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73 (diff) | |
download | manaverse-3efda43abd11979adfd048fc62fe4f09e702f772.tar.gz manaverse-3efda43abd11979adfd048fc62fe4f09e702f772.tar.bz2 manaverse-3efda43abd11979adfd048fc62fe4f09e702f772.tar.xz manaverse-3efda43abd11979adfd048fc62fe4f09e702f772.zip |
improve npchandler class.
Diffstat (limited to 'src/net/tmwa/npchandler.cpp')
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 9166c5b84..0c55d8d7e 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -111,20 +111,20 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("NpcHandler::handleMessage") } -void NpcHandler::talk(int npcId) +void NpcHandler::talk(const int npcId) const { MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeInt32(npcId); outMsg.writeInt8(0); // Unused } -void NpcHandler::nextDialog(int npcId) +void NpcHandler::nextDialog(const int npcId) const { MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(npcId); } -void NpcHandler::closeDialog(int npcId) +void NpcHandler::closeDialog(const int npcId) { MessageOut outMsg(CMSG_NPC_CLOSE); outMsg.writeInt32(npcId); @@ -132,29 +132,30 @@ void NpcHandler::closeDialog(int npcId) const NpcDialogs::iterator it = mNpcDialogs.find(npcId); if (it != mNpcDialogs.end()) { - if ((*it).second.dialog) - (*it).second.dialog->close(); - if ((*it).second.dialog == mDialog) + NpcDialog *const dialog = (*it).second.dialog; + if (dialog) + dialog->close(); + if (dialog == mDialog) mDialog = nullptr; mNpcDialogs.erase(it); } } -void NpcHandler::listInput(int npcId, unsigned char value) +void NpcHandler::listInput(const int npcId, const unsigned char value) const { MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(npcId); outMsg.writeInt8(value); } -void NpcHandler::integerInput(int npcId, int value) +void NpcHandler::integerInput(const int npcId, const int value) const { MessageOut outMsg(CMSG_NPC_INT_RESPONSE); outMsg.writeInt32(npcId); outMsg.writeInt32(value); } -void NpcHandler::stringInput(int npcId, const std::string &value) +void NpcHandler::stringInput(const int npcId, const std::string &value) const { MessageOut outMsg(CMSG_NPC_STR_RESPONSE); outMsg.writeInt16(static_cast<int16_t>(value.length() + 9)); @@ -163,22 +164,22 @@ void NpcHandler::stringInput(int npcId, const std::string &value) outMsg.writeInt8(0); // Prevent problems with string reading } -void NpcHandler::buy(int beingId) +void NpcHandler::buy(const int beingId) const { MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeInt32(beingId); outMsg.writeInt8(0); // Buy } -void NpcHandler::sell(int beingId) +void NpcHandler::sell(const int beingId) const { MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeInt32(beingId); outMsg.writeInt8(1); // Sell } -void NpcHandler::buyItem(int beingId A_UNUSED, int itemId, - unsigned char color, int amount) +void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, + const unsigned char color, const int amount) const { MessageOut outMsg(CMSG_NPC_BUY_REQUEST); if (serverVersion > 0) @@ -197,7 +198,8 @@ void NpcHandler::buyItem(int beingId A_UNUSED, int itemId, } } -void NpcHandler::sellItem(int beingId A_UNUSED, int itemId, int amount) +void NpcHandler::sellItem(const int beingId A_UNUSED, + const int itemId, const int amount) const { MessageOut outMsg(CMSG_NPC_SELL_REQUEST); outMsg.writeInt16(8); // One item (length of packet) @@ -205,7 +207,7 @@ void NpcHandler::sellItem(int beingId A_UNUSED, int itemId, int amount) outMsg.writeInt16(static_cast<int16_t>(amount)); } -int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength) +int NpcHandler::getNpc(Net::MessageIn &msg, const bool haveLength) { if (haveLength) msg.readInt16(); // length @@ -241,16 +243,17 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength) } else { - if (mDialog && mDialog != diag->second.dialog) + NpcDialog *const dialog = diag->second.dialog; + if (mDialog && mDialog != dialog) mDialog->restoreCamera(); - mDialog = diag->second.dialog; + mDialog = dialog; if (mDialog) mDialog->saveCamera(); } return npcId; } -void NpcHandler::processNpcCommand(Net::MessageIn &msg, int npcId) +void NpcHandler::processNpcCommand(Net::MessageIn &msg, const int npcId) { const int cmd = msg.readInt16(); switch (cmd) @@ -324,7 +327,8 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg, int npcId) } } -void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED, int npcId) +void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED, + const int npcId) { mRequestLang = false; stringInput(npcId, getLangSimple()); |