From 2dbb62e760853f88a19e6e783870de156d52f8c6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 27 Aug 2015 19:58:59 +0300 Subject: Move receive code from mercenaryhandler into separate file. --- src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/net/eathena/chatrecv.cpp | 4 +- src/net/eathena/mercenaryhandler.cpp | 109 +------------------------- src/net/eathena/mercenaryhandler.h | 9 --- src/net/eathena/mercenaryrecv.cpp | 146 +++++++++++++++++++++++++++++++++++ src/net/eathena/mercenaryrecv.h | 40 ++++++++++ src/net/mercenaryhandler.h | 2 - src/net/tmwa/mercenaryhandler.cpp | 4 - src/net/tmwa/mercenaryhandler.h | 2 - 10 files changed, 196 insertions(+), 124 deletions(-) create mode 100644 src/net/eathena/mercenaryrecv.cpp create mode 100644 src/net/eathena/mercenaryrecv.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f6f2df89..b1a74e79a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1652,6 +1652,8 @@ SET(SRCS_EATHENA net/eathena/menutype.h net/eathena/mercenaryhandler.cpp net/eathena/mercenaryhandler.h + net/eathena/mercenaryrecv.cpp + net/eathena/mercenaryrecv.h net/eathena/messagehandler.cpp net/eathena/messagehandler.h net/eathena/messagein.cpp diff --git a/src/Makefile.am b/src/Makefile.am index a4a46f68a..440e257aa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1498,6 +1498,8 @@ manaplus_SOURCES += gui/windows/bankwindow.cpp \ net/eathena/menutype.h \ net/eathena/mercenaryhandler.cpp \ net/eathena/mercenaryhandler.h \ + net/eathena/mercenaryrecv.cpp \ + net/eathena/mercenaryrecv.h \ net/eathena/messagehandler.cpp \ net/eathena/messagehandler.h \ net/eathena/messagein.cpp \ diff --git a/src/net/eathena/chatrecv.cpp b/src/net/eathena/chatrecv.cpp index 69785731b..f058593c9 100644 --- a/src/net/eathena/chatrecv.cpp +++ b/src/net/eathena/chatrecv.cpp @@ -38,11 +38,11 @@ #include "gui/widgets/tabs/chat/chattab.h" -#include "net/mercenaryhandler.h" #include "net/serverfeatures.h" #include "net/ea/chatrecv.h" +#include "net/eathena/mercenaryrecv.h" #include "net/eathena/messageout.h" #include "net/eathena/protocol.h" @@ -130,7 +130,7 @@ void ChatRecv::processFormatMessage(Net::MessageIn &msg) std::string chatMsg; if (msgId >= 1266 && msgId <= 1269) { - mercenaryHandler->handleMercenaryMessage(msgId - 1266); + MercenaryRecv::handleMercenaryMessage(msgId - 1266); return; } switch (msgId) diff --git a/src/net/eathena/mercenaryhandler.cpp b/src/net/eathena/mercenaryhandler.cpp index 3d5f0a72c..c4c6741a7 100644 --- a/src/net/eathena/mercenaryhandler.cpp +++ b/src/net/eathena/mercenaryhandler.cpp @@ -33,6 +33,7 @@ #include "net/serverfeatures.h" +#include "net/eathena/mercenaryrecv.h" #include "net/eathena/messageout.h" #include "net/eathena/protocol.h" @@ -62,15 +63,15 @@ void MercenaryHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_MERCENARY_UPDATE: - processMercenaryUpdate(msg); + MercenaryRecv::processMercenaryUpdate(msg); break; case SMSG_MERCENARY_INFO: - processMercenaryInfo(msg); + MercenaryRecv::processMercenaryInfo(msg); break; case SMSG_MERCENARY_SKILLS: - processMercenarySkills(msg); + MercenaryRecv::processMercenarySkills(msg); break; default: @@ -78,108 +79,6 @@ void MercenaryHandler::handleMessage(Net::MessageIn &msg) } } -void MercenaryHandler::processMercenaryUpdate(Net::MessageIn &msg) -{ - UNIMPLIMENTEDPACKET; - // +++ need create if need mercenary being and update stats - msg.readInt16("type"); - msg.readInt32("value"); -} - -void MercenaryHandler::processMercenaryInfo(Net::MessageIn &msg) -{ - // +++ need create if need mercenary being and update stats - Being *const dstBeing = actorManager->findBeing( - msg.readBeingId("being id")); - msg.readInt16("atk"); - msg.readInt16("matk"); - msg.readInt16("hit"); - msg.readInt16("crit/10"); - msg.readInt16("def"); - msg.readInt16("mdef"); - msg.readInt16("flee"); - msg.readInt16("attack speed"); - const std::string name = msg.readString(24, "name"); - const int level = msg.readInt16("level"); - msg.readInt32("hp"); - msg.readInt32("max hp"); - msg.readInt32("sp"); - msg.readInt32("max sp"); - msg.readInt32("expire time"); - msg.readInt16("faith"); - msg.readInt32("calls"); - msg.readInt32("kills"); - const int range = msg.readInt16("attack range"); - if (dstBeing && localPlayer) - { - MercenaryInfo *const mercenary = new MercenaryInfo; - mercenary->id = dstBeing->getId(); - mercenary->name = name; - mercenary->level = level; - mercenary->range = range; - PlayerInfo::setMercenary(mercenary); - PlayerInfo::setMercenaryBeing(dstBeing); - } -} - -void MercenaryHandler::processMercenarySkills(Net::MessageIn &msg) -{ - if (skillDialog) - skillDialog->hideSkills(SkillOwner::Mercenary); - const int count = (msg.readInt16("len") - 4) / 37; - for (int f = 0; f < count; f ++) - { - const int skillId = msg.readInt16("skill id"); - const SkillType::SkillType inf = static_cast( - msg.readInt32("inf")); - const int level = msg.readInt16("skill level"); - const int sp = msg.readInt16("sp"); - const int range = msg.readInt16("range"); - const std::string name = msg.readString(24, "skill name"); - const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable); - PlayerInfo::setSkillLevel(skillId, level); - if (skillDialog) - { - if (!skillDialog->updateSkill(skillId, range, up, inf, sp)) - { - skillDialog->addSkill(SkillOwner::Mercenary, - skillId, name, level, range, up, inf, sp); - } - } - } - if (skillDialog) - skillDialog->updateModels(); -} - -void MercenaryHandler::handleMercenaryMessage(const int cmd) -{ - PlayerInfo::setMercenary(nullptr); - if (skillDialog) - { - skillDialog->hideSkills(SkillOwner::Mercenary); - skillDialog->updateModels(); - } - - switch (cmd) - { - case 0: - NotifyManager::notify(NotifyTypes::MERCENARY_EXPIRED); - break; - case 1: - NotifyManager::notify(NotifyTypes::MERCENARY_KILLED); - break; - case 2: - NotifyManager::notify(NotifyTypes::MERCENARY_FIRED); - break; - case 3: - NotifyManager::notify(NotifyTypes::MERCENARY_RUN); - break; - default: - NotifyManager::notify(NotifyTypes::MERCENARY_UNKNOWN); - break; - } -} - void MercenaryHandler::fire() { createOutPacket(CMSG_MERCENARY_ACTION); diff --git a/src/net/eathena/mercenaryhandler.h b/src/net/eathena/mercenaryhandler.h index 643f4ec74..9c41e15d3 100644 --- a/src/net/eathena/mercenaryhandler.h +++ b/src/net/eathena/mercenaryhandler.h @@ -37,8 +37,6 @@ class MercenaryHandler final : public MessageHandler, void handleMessage(Net::MessageIn &msg) override final; - void handleMercenaryMessage(const int cmd) override final; - void fire() override final; void moveToMaster() const override final; @@ -53,13 +51,6 @@ class MercenaryHandler final : public MessageHandler, void emote(const uint8_t emoteId) const override final; void setDirection(const unsigned char type) const override final; - - protected: - static void processMercenaryUpdate(Net::MessageIn &msg); - - static void processMercenaryInfo(Net::MessageIn &msg); - - static void processMercenarySkills(Net::MessageIn &msg); }; } // namespace EAthena diff --git a/src/net/eathena/mercenaryrecv.cpp b/src/net/eathena/mercenaryrecv.cpp new file mode 100644 index 000000000..c96340703 --- /dev/null +++ b/src/net/eathena/mercenaryrecv.cpp @@ -0,0 +1,146 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "net/eathena/mercenaryrecv.h" + +#include "actormanager.h" +#include "notifymanager.h" + +#include "being/localplayer.h" +#include "being/mercenaryinfo.h" +#include "being/playerinfo.h" + +#include "enums/resources/notifytypes.h" + +#include "gui/windows/skilldialog.h" + +#include "net/serverfeatures.h" + +#include "net/eathena/messageout.h" +#include "net/eathena/protocol.h" + +#include "debug.h" + +namespace EAthena +{ + +void MercenaryRecv::processMercenaryUpdate(Net::MessageIn &msg) +{ + UNIMPLIMENTEDPACKET; + // +++ need create if need mercenary being and update stats + msg.readInt16("type"); + msg.readInt32("value"); +} + +void MercenaryRecv::processMercenaryInfo(Net::MessageIn &msg) +{ + // +++ need create if need mercenary being and update stats + Being *const dstBeing = actorManager->findBeing( + msg.readBeingId("being id")); + msg.readInt16("atk"); + msg.readInt16("matk"); + msg.readInt16("hit"); + msg.readInt16("crit/10"); + msg.readInt16("def"); + msg.readInt16("mdef"); + msg.readInt16("flee"); + msg.readInt16("attack speed"); + const std::string name = msg.readString(24, "name"); + const int level = msg.readInt16("level"); + msg.readInt32("hp"); + msg.readInt32("max hp"); + msg.readInt32("sp"); + msg.readInt32("max sp"); + msg.readInt32("expire time"); + msg.readInt16("faith"); + msg.readInt32("calls"); + msg.readInt32("kills"); + const int range = msg.readInt16("attack range"); + if (dstBeing && localPlayer) + { + MercenaryInfo *const mercenary = new MercenaryInfo; + mercenary->id = dstBeing->getId(); + mercenary->name = name; + mercenary->level = level; + mercenary->range = range; + PlayerInfo::setMercenary(mercenary); + PlayerInfo::setMercenaryBeing(dstBeing); + } +} + +void MercenaryRecv::processMercenarySkills(Net::MessageIn &msg) +{ + if (skillDialog) + skillDialog->hideSkills(SkillOwner::Mercenary); + const int count = (msg.readInt16("len") - 4) / 37; + for (int f = 0; f < count; f ++) + { + const int skillId = msg.readInt16("skill id"); + const SkillType::SkillType inf = static_cast( + msg.readInt32("inf")); + const int level = msg.readInt16("skill level"); + const int sp = msg.readInt16("sp"); + const int range = msg.readInt16("range"); + const std::string name = msg.readString(24, "skill name"); + const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable); + PlayerInfo::setSkillLevel(skillId, level); + if (skillDialog) + { + if (!skillDialog->updateSkill(skillId, range, up, inf, sp)) + { + skillDialog->addSkill(SkillOwner::Mercenary, + skillId, name, level, range, up, inf, sp); + } + } + } + if (skillDialog) + skillDialog->updateModels(); +} + +void MercenaryRecv::handleMercenaryMessage(const int cmd) +{ + PlayerInfo::setMercenary(nullptr); + if (skillDialog) + { + skillDialog->hideSkills(SkillOwner::Mercenary); + skillDialog->updateModels(); + } + + switch (cmd) + { + case 0: + NotifyManager::notify(NotifyTypes::MERCENARY_EXPIRED); + break; + case 1: + NotifyManager::notify(NotifyTypes::MERCENARY_KILLED); + break; + case 2: + NotifyManager::notify(NotifyTypes::MERCENARY_FIRED); + break; + case 3: + NotifyManager::notify(NotifyTypes::MERCENARY_RUN); + break; + default: + NotifyManager::notify(NotifyTypes::MERCENARY_UNKNOWN); + break; + } +} + +} // namespace EAthena diff --git a/src/net/eathena/mercenaryrecv.h b/src/net/eathena/mercenaryrecv.h new file mode 100644 index 000000000..18fed7069 --- /dev/null +++ b/src/net/eathena/mercenaryrecv.h @@ -0,0 +1,40 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NET_EATHENA_MERCENARYRECV_H +#define NET_EATHENA_MERCENARYRECV_H + +#include "net/mercenaryhandler.h" + +#include "net/eathena/messagehandler.h" + +namespace EAthena +{ + namespace MercenaryRecv + { + void handleMercenaryMessage(const int cmd); + void processMercenaryUpdate(Net::MessageIn &msg); + void processMercenaryInfo(Net::MessageIn &msg); + void processMercenarySkills(Net::MessageIn &msg); +}; + +} // namespace EAthena + +#endif // NET_EATHENA_MERCENARYRECV_H diff --git a/src/net/mercenaryhandler.h b/src/net/mercenaryhandler.h index d39267c5f..c2937b437 100644 --- a/src/net/mercenaryhandler.h +++ b/src/net/mercenaryhandler.h @@ -39,8 +39,6 @@ class MercenaryHandler notfinal virtual ~MercenaryHandler() { } - virtual void handleMercenaryMessage(const int cmd) = 0; - virtual void fire() = 0; virtual void moveToMaster() const = 0; diff --git a/src/net/tmwa/mercenaryhandler.cpp b/src/net/tmwa/mercenaryhandler.cpp index 7b39823f3..2bbdc0a31 100644 --- a/src/net/tmwa/mercenaryhandler.cpp +++ b/src/net/tmwa/mercenaryhandler.cpp @@ -42,10 +42,6 @@ void MercenaryHandler::handleMessage(Net::MessageIn &msg A_UNUSED) { } -void MercenaryHandler::handleMercenaryMessage(const int cmd A_UNUSED) -{ -} - void MercenaryHandler::fire() { } diff --git a/src/net/tmwa/mercenaryhandler.h b/src/net/tmwa/mercenaryhandler.h index eea2a19a2..17489b7fd 100644 --- a/src/net/tmwa/mercenaryhandler.h +++ b/src/net/tmwa/mercenaryhandler.h @@ -40,8 +40,6 @@ class MercenaryHandler final : public MessageHandler, void handleMessage(Net::MessageIn &msg) override final; - void handleMercenaryMessage(const int cmd) override final; - void fire() override final; void moveToMaster() const override final; -- cgit v1.2.3-70-g09d2