From 9234bf25b145995d5395f98a1f5dd030783d25d6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 24 Jul 2012 21:37:03 +0300 Subject: Add quests netcode and quests window. --- src/CMakeLists.txt | 6 + src/Makefile.am | 6 + src/actionmanager.cpp | 9 ++ src/actionmanager.h | 2 +- src/game.cpp | 10 +- src/gui/questswindow.cpp | 254 +++++++++++++++++++++++++++++++++ src/gui/questswindow.h | 81 +++++++++++ src/gui/setupactiondata.h | 5 + src/gui/widgets/extendednamesmodel.cpp | 70 +++++++++ src/gui/widgets/extendednamesmodel.h | 59 ++++++++ src/gui/widgets/namesmodel.h | 3 + src/keyboarddata.h | 7 + src/keydata.h | 1 + src/net/tmwa/generalhandler.cpp | 5 +- src/net/tmwa/generalhandler.h | 1 + src/net/tmwa/network.cpp | 2 +- src/net/tmwa/network.h | 2 +- src/net/tmwa/protocol.h | 2 + src/net/tmwa/questhandler.cpp | 97 +++++++++++++ src/net/tmwa/questhandler.h | 50 +++++++ src/utils/xml.h | 1 + 21 files changed, 666 insertions(+), 7 deletions(-) create mode 100644 src/gui/questswindow.cpp create mode 100644 src/gui/questswindow.h create mode 100644 src/gui/widgets/extendednamesmodel.cpp create mode 100644 src/gui/widgets/extendednamesmodel.h create mode 100644 src/net/tmwa/questhandler.cpp create mode 100644 src/net/tmwa/questhandler.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c55c9632..e5556fccb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,6 +130,8 @@ SET(SRCS gui/widgets/extendedlistbox.cpp gui/widgets/extendedlistbox.h gui/widgets/extendedlistmodel.h + gui/widgets/extendednamesmodel.cpp + gui/widgets/extendednamesmodel.h gui/widgets/flowcontainer.cpp gui/widgets/flowcontainer.h gui/widgets/guildchattab.cpp @@ -294,6 +296,8 @@ SET(SRCS gui/palette.h gui/popupmenu.cpp gui/popupmenu.h + gui/questswindow.cpp + gui/questswindow.h gui/quitdialog.cpp gui/quitdialog.h gui/registerdialog.cpp @@ -809,6 +813,8 @@ SET(SRCS_TMWA net/tmwa/playerhandler.cpp net/tmwa/playerhandler.h net/tmwa/protocol.h + net/tmwa/questhandler.cpp + net/tmwa/questhandler.h net/tmwa/specialhandler.cpp net/tmwa/specialhandler.h net/tmwa/tradehandler.cpp diff --git a/src/Makefile.am b/src/Makefile.am index bfb0718cb..ada4d657b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -139,6 +139,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/extendedlistbox.cpp \ gui/widgets/extendedlistbox.h \ gui/widgets/extendedlistmodel.h \ + gui/widgets/extendednamesmodel.cpp \ + gui/widgets/extendednamesmodel.h \ gui/widgets/flowcontainer.cpp \ gui/widgets/flowcontainer.h \ gui/widgets/guildchattab.cpp \ @@ -303,6 +305,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/palette.h \ gui/popupmenu.cpp \ gui/popupmenu.h \ + gui/questswindow.cpp \ + gui/questswindow.h \ gui/quitdialog.cpp \ gui/quitdialog.h \ gui/registerdialog.cpp \ @@ -726,6 +730,8 @@ manaplus_SOURCES += \ net/tmwa/playerhandler.cpp \ net/tmwa/playerhandler.h \ net/tmwa/protocol.h \ + net/tmwa/questhandler.cpp \ + net/tmwa/questhandler.h \ net/tmwa/specialhandler.cpp \ net/tmwa/specialhandler.h \ net/tmwa/tradehandler.cpp \ diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 28e5b9fc3..a1303773a 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -53,6 +53,7 @@ #include "gui/socialwindow.h" #include "gui/statuswindow.h" #include "gui/viewport.h" +#include "gui/questswindow.h" #include "gui/quitdialog.h" #include "gui/whoisonline.h" @@ -659,6 +660,8 @@ impHandler0(hideWindows) botCheckerWindow->setVisible(false); if (socialWindow) socialWindow->setVisible(false); + if (questsWindow) + questsWindow->setVisible(false); return true; } @@ -802,6 +805,12 @@ impHandler0(didYouKnowWindowShow) return true; } +impHandler0(questsWindowShow) +{ + showHideWindow(questsWindow); + return true; +} + impHandler0(changeMapMode) { if (viewport) diff --git a/src/actionmanager.h b/src/actionmanager.h index e415928bb..ebbfc65ad 100644 --- a/src/actionmanager.h +++ b/src/actionmanager.h @@ -1,6 +1,5 @@ /* * The ManaPlus Client - * Copyright (C) 2010 The Mana Developers * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. @@ -117,6 +116,7 @@ namespace ActionManager decHandler(botcheckerWindowShow); decHandler(whoIsOnlineWindowShow); decHandler(didYouKnowWindowShow); + decHandler(questsWindowShow); } #endif diff --git a/src/game.cpp b/src/game.cpp index 63ea0d55d..c7da8bea4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -64,6 +64,7 @@ #include "gui/textdialog.h" #include "gui/tradewindow.h" #include "gui/viewport.h" +#include "gui/questswindow.h" #include "gui/windowmenu.h" #include "gui/whoisonline.h" @@ -137,6 +138,7 @@ DidYouKnowWindow *didYouKnowWindow = nullptr; KillStats *killStats = nullptr; BotCheckerWindow *botCheckerWindow = nullptr; SocialWindow *socialWindow = nullptr; +QuestsWindow *questsWindow = nullptr; WindowMenu *windowMenu = nullptr; ActorSpriteManager *actorSpriteManager = nullptr; @@ -246,10 +248,11 @@ static void createGuiWindows() new SpellShortcutContainer(f)); } - botCheckerWindow = new BotCheckerWindow(); - whoIsOnline = new WhoIsOnline(); + botCheckerWindow = new BotCheckerWindow; + whoIsOnline = new WhoIsOnline; killStats = new KillStats; - socialWindow = new SocialWindow(); + socialWindow = new SocialWindow; + questsWindow = new QuestsWindow; localChatTab = new ChatTab(_("General")); localChatTab->setAllowHighlight(false); @@ -343,6 +346,7 @@ static void destroyGuiWindows() del_0(dropShortcutWindow); del_0(spellShortcutWindow); del_0(botCheckerWindow); + del_0(questsWindow); del_0(whoIsOnline); del_0(killStats); del_0(didYouKnowWindow); diff --git a/src/gui/questswindow.cpp b/src/gui/questswindow.cpp new file mode 100644 index 000000000..f97bac1b4 --- /dev/null +++ b/src/gui/questswindow.cpp @@ -0,0 +1,254 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 "gui/questswindow.h" + +#include "logger.h" + +#include "gui/gui.h" + +#include "gui/widgets/browserbox.h" +#include "gui/widgets/button.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/extendedlistbox.h" +#include "gui/widgets/extendednamesmodel.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/textfield.h" + +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "utils/translation/podict.h" + +#include + +#include "debug.h" + +struct QuestItemText +{ + QuestItemText(std::string text0, int type0) : + text(text0), type(type0) + { + } + + std::string text; + int type; +}; + +struct QuestItem +{ + int var; + std::string name; + std::string group; + std::set incomplete; + std::set complete; + std::vector texts; +}; + +class QuestsModel : public ExtendedNamesModel +{ + public: + QuestsModel() + { + } + + virtual ~QuestsModel() + { } +}; + +QuestsWindow::QuestsWindow() : + Window(_("Quests Window"), false, nullptr, "quest.xml") +{ + setWindowName("Quests"); + setResizable(true); + setCloseButton(true); + setStickyButtonLock(true); + + setDefaultSize(400, 350, ImageRect::RIGHT); + setMinWidth(400); + setMinHeight(350); + + mQuestsModel = new QuestsModel; + mQuestsListBox = new ExtendedListBox(mQuestsModel); + mQuestsListBox->setActionEventId("select"); + mQuestsListBox->addActionListener(this); + + mQuestScrollArea = new ScrollArea(mQuestsListBox); + mQuestScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mText = new BrowserBox; + mText->setOpaque(false); + mTextScrollArea = new ScrollArea(mText); + mTextScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mQuestsListBox->setWidth(500); + + mCloseButton = new Button(_("Close"), "close", this); + + ContainerPlacer placer; + placer = getPlacer(0, 0); + + placer(0, 0, mQuestScrollArea, 4, 3).setPadding(3); + placer(4, 0, mTextScrollArea, 4, 3).setPadding(3); + placer(7, 3, mCloseButton); + + loadWindowState(); + loadXml(); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); +} + +void QuestsWindow::loadXml() +{ + XML::Document doc("quests.xml"); + XmlNodePtr root = doc.rootNode(); + if (!root) + return; + + for_each_xml_child_node(varNode, root) + { + if (xmlNameEqual(varNode, "var")) + { + int id = XML::getProperty(varNode, "id", 0); + if (id < 0) + continue; + for_each_xml_child_node(questNode, varNode) + { + if (xmlNameEqual(questNode, "quest")) + loadQuest(id, questNode); + } + } + } +} + +void QuestsWindow::loadQuest(int var, XmlNodePtr node) +{ + QuestItem *quest = new QuestItem(); + quest->name = XML::langProperty(node, "name", _("unknown")); + quest->group = XML::getProperty(node, "group", ""); + std::string incompleteStr = XML::getProperty(node, "incomplete", ""); + std::string completeStr = XML::getProperty(node, "complete", ""); + if (incompleteStr.empty() || completeStr.empty()) + { + logger->log("complete flags incorrect"); + delete quest; + return; + } + quest->incomplete = splitToIntSet(incompleteStr, ','); + quest->complete = splitToIntSet(completeStr, ','); + if (quest->incomplete.size() + quest->complete.size() == 0) + { + logger->log("complete flags incorrect"); + delete quest; + return; + } + for_each_xml_child_node(dataNode, node) + { + if (!xmlTypeEqual(dataNode, XML_ELEMENT_NODE)) + continue; + const char *data = reinterpret_cast( + xmlNodeGetContent(dataNode)); + if (!data) + continue; + std::string str = translator->getStr(data); + + if (xmlNameEqual(dataNode, "text")) + quest->texts.push_back(QuestItemText(str, 0)); + else if (xmlNameEqual(dataNode, "name")) + quest->texts.push_back(QuestItemText(str, 1)); + } + mQuests[var].push_back(quest); +} + +void QuestsWindow::action(const gcn::ActionEvent &event) +{ + const std::string &eventId = event.getId(); + if (eventId == "select") + { + int id = mQuestsListBox->getSelected(); + if (id < 0) + return; + showQuest(mQuestLinks[id]); + } + else if (eventId == "close") + { + setVisible(false); + } +} + +void QuestsWindow::updateQuest(int var, int val) +{ + mVars[var] = val; +} + +void QuestsWindow::rebuild() +{ + mQuestsModel->clear(); + StringVect &names = mQuestsModel->getNames(); + + for (std::map::const_iterator it = mVars.begin(), + it_end = mVars.end(); it != it_end; ++ it) + { + int var = (*it).first; + int val = (*it).second; + const std::vector &quests = mQuests[var]; + for (std::vector::const_iterator it2 = quests.begin(), + it2_end = quests.end(); it2 != it2_end; ++ it2) + { + if (!*it2) + continue; + QuestItem *quest = *it2; + if (quest->complete.find(val) != quest->complete.end()) + { + names.push_back(quest->name + _("[complete]")); + mQuestLinks.push_back(quest); + } + else if (quest->incomplete.find(val) != quest->incomplete.end()) + { + names.push_back(quest->name); + mQuestLinks.push_back(quest); + } + } + } +// mQuestsListBox->adjustSize(); +} + +void QuestsWindow::showQuest(QuestItem *quest) +{ + if (!quest) + return; + + const std::vector &texts = quest->texts; + mText->clearRows(); + for (std::vector::const_iterator it = texts.begin(), + it_end = texts.end(); it != it_end; ++ it) + { + const QuestItemText &data = *it; + switch (data.type) + { + case 0: + default: + mText->addRow(translator->getStr(data.text)); + break; + case 1: + mText->addRow("[" + translator->getStr(data.text) + "]"); + break; + } + } +} diff --git a/src/gui/questswindow.h b/src/gui/questswindow.h new file mode 100644 index 000000000..c35e395bd --- /dev/null +++ b/src/gui/questswindow.h @@ -0,0 +1,81 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 QUESTS_WINDOW_H +#define QUESTS_WINDOW_H + +#include "localconsts.h" + +#include "gui/widgets/window.h" + +#include "utils/xml.h" + +#include + +#include + +class Button; +class BrowserBox; +class ExtendedListBox; +class ScrollArea; +class QuestsModel; + +struct QuestItem; + +class QuestsWindow : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + QuestsWindow(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + void updateQuest(int var, int val); + + void rebuild(); + + void showQuest(QuestItem *quest); + + private: + void loadXml(); + + void loadQuest(int var, XmlNodePtr node); + + QuestsModel *mQuestsModel; + ExtendedListBox *mQuestsListBox; + ScrollArea *mQuestScrollArea; + BrowserBox *mText; + ScrollArea *mTextScrollArea; + Button *mCloseButton; + std::map mVars; + std::map> mQuests; + std::vector mQuestLinks; +}; + +extern QuestsWindow *questsWindow; + +#endif diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index 9c516c83f..ee85f6ca5 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -402,6 +402,11 @@ static SetupActionData setupActionData2[] = Input::KEY_WINDOW_DIDYOUKNOW, "", }, + { + N_("Quests Window"), + Input::KEY_WINDOW_QUESTS, + "", + }, { N_("Previous Social Tab"), Input::KEY_PREV_SOCIAL_TAB, diff --git a/src/gui/widgets/extendednamesmodel.cpp b/src/gui/widgets/extendednamesmodel.cpp new file mode 100644 index 000000000..1cc6561dc --- /dev/null +++ b/src/gui/widgets/extendednamesmodel.cpp @@ -0,0 +1,70 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 "gui/widgets/extendednamesmodel.h" + +#include "logger.h" + +#include "utils/gettext.h" + +#include +#include + +#include "debug.h" + +ExtendedNamesModel::ExtendedNamesModel() +{ +} + +ExtendedNamesModel::~ExtendedNamesModel() +{ + clear(); +} + +int ExtendedNamesModel::getNumberOfElements() +{ + return static_cast(mNames.size()); +} + +std::string ExtendedNamesModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return _("???"); + + return mNames[i]; +} + +Image *ExtendedNamesModel::getImageAt(int i) +{ + if (i >= static_cast(mImages.size()) || i < 0) + return nullptr; + + return mImages[i]; +} + +void ExtendedNamesModel::clear() +{ + mNames.clear(); + for (std::vector::iterator it = mImages.begin(), + it_end = mImages.end(); it != it_end; ++ it) + { + (*it)->decRef(); + } +} diff --git a/src/gui/widgets/extendednamesmodel.h b/src/gui/widgets/extendednamesmodel.h new file mode 100644 index 000000000..5a15949a9 --- /dev/null +++ b/src/gui/widgets/extendednamesmodel.h @@ -0,0 +1,59 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 GUI_WIDGETS_EXTENDEDNAMESMODEL_H +#define GUI_WIDGETS_EXTENDEDNAMESMODEL_H + +#include "utils/stringvector.h" + +#include "gui/widgets/extendedlistmodel.h" + +#include "resources/image.h" + +class ExtendedNamesModel : public ExtendedListModel +{ + public: + ExtendedNamesModel(); + + virtual ~ExtendedNamesModel(); + + virtual int getNumberOfElements(); + + virtual std::string getElementAt(int i); + + virtual Image *getImageAt(int i); + + StringVect &getNames() + { return mNames; } + + std::vector &getImages() + { return mImages; } + + size_t size() + { return mNames.size(); } + + void clear(); + + protected: + StringVect mNames; + std::vector mImages; +}; + +#endif diff --git a/src/gui/widgets/namesmodel.h b/src/gui/widgets/namesmodel.h index e1dbf0a89..1064a8875 100644 --- a/src/gui/widgets/namesmodel.h +++ b/src/gui/widgets/namesmodel.h @@ -42,6 +42,9 @@ class NamesModel : public gcn::ListModel size_t size() { return mNames.size(); } + void clear() + { mNames.clear(); } + protected: StringVect mNames; }; diff --git a/src/keyboarddata.h b/src/keyboarddata.h index 6e0111ba9..31879f439 100644 --- a/src/keyboarddata.h +++ b/src/keyboarddata.h @@ -504,6 +504,13 @@ static KeyData const keyData[Input::KEY_TOTAL] = { &ActionManager::didYouKnowWindowShow, Input::KEY_NO_VALUE, 50, COND_GAME | COND_NOTARGET}, + {"keyWindowQuests", + INPUT_KEYBOARD, SDLK_LEFTBRACKET, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_DEFAULT | Input::GRP_GUI, + &ActionManager::questsWindowShow, + Input::KEY_NO_VALUE, 50, + COND_GAME | COND_NOTARGET}, {"keySocialPrevTab", INPUT_UNKNOWN, Input::KEY_NO_VALUE, INPUT_UNKNOWN, Input::KEY_NO_VALUE, diff --git a/src/keydata.h b/src/keydata.h index d0c99091a..ef1d70b88 100644 --- a/src/keydata.h +++ b/src/keydata.h @@ -134,6 +134,7 @@ namespace Input KEY_WINDOW_BOT_CHECKER, KEY_WINDOW_ONLINE, KEY_WINDOW_DIDYOUKNOW, + KEY_WINDOW_QUESTS, KEY_PREV_SOCIAL_TAB, KEY_NEXT_SOCIAL_TAB, KEY_EMOTE, diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 0006d724d..c5ca7b529 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -59,6 +59,7 @@ #include "net/tmwa/protocol.h" #include "net/tmwa/tradehandler.h" #include "net/tmwa/specialhandler.h" +#include "net/tmwa/questhandler.h" #include "net/tmwa/gui/guildtab.h" #include "net/tmwa/gui/partytab.h" @@ -94,7 +95,8 @@ GeneralHandler::GeneralHandler(): mPartyHandler(new PartyHandler), mPlayerHandler(new PlayerHandler), mSpecialHandler(new SpecialHandler), - mTradeHandler(new TradeHandler) + mTradeHandler(new TradeHandler), + mQuestHandler(new QuestHandler) { static const uint16_t _messages[] = { @@ -192,6 +194,7 @@ void GeneralHandler::load() mNetwork->registerHandler(mSpecialHandler.get()); mNetwork->registerHandler(mTradeHandler.get()); mNetwork->registerHandler(mPartyHandler.get()); + mNetwork->registerHandler(mQuestHandler.get()); } void GeneralHandler::reload() diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index f938ddd1d..88a0331d7 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -73,6 +73,7 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler, MessageHandlerPtr mPlayerHandler; MessageHandlerPtr mSpecialHandler; MessageHandlerPtr mTradeHandler; + MessageHandlerPtr mQuestHandler; }; } // namespace TmwAthena diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index c1020ebeb..c6e31af3c 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -86,7 +86,7 @@ short packet_lengths[] = -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, // #0x0200 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, - 2, -1, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, -1, 16, 0, 8, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h index 03f24839b..2c9e0de0d 100644 --- a/src/net/tmwa/network.h +++ b/src/net/tmwa/network.h @@ -39,7 +39,7 @@ * Protocol version, reported to the eAthena char and mapserver who can adjust * the protocol accordingly. */ -#define CLIENT_PROTOCOL_VERSION 6 +#define CLIENT_PROTOCOL_VERSION 7 #define CLIENT_TMW_PROTOCOL_VERSION 1 namespace TmwAthena diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h index 130268b82..72952cdd0 100644 --- a/src/net/tmwa/protocol.h +++ b/src/net/tmwa/protocol.h @@ -337,6 +337,8 @@ enum #define SMSG_ONLINE_LIST 0x0211 #define SMSG_NPC_COMMAND 0x0212 #define CMSG_SET_STATUS 0x0213 +#define CMSG_QUEST_SET_VAR 0x0214 +#define CMSG_QUEST_PLAYER_VARS 0x0215 #define CMSG_SEND_CLIENT_INFO 0x7533 #define SMSG_UPDATE_HOST2 0x7534 diff --git a/src/net/tmwa/questhandler.cpp b/src/net/tmwa/questhandler.cpp new file mode 100644 index 000000000..b3cec9fe2 --- /dev/null +++ b/src/net/tmwa/questhandler.cpp @@ -0,0 +1,97 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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/tmwa/questhandler.h" + +#include "localplayer.h" + +#include "gui/questswindow.h" + +#include "net/messagein.h" +#include "net/net.h" + +#include "net/tmwa/protocol.h" + +#include "net/ea/eaprotocol.h" + +#include "utils/langs.h" + +#include "debug.h" + +//extern Net::QuestHandler *questHandler; + +namespace TmwAthena +{ + +QuestHandler::QuestHandler() +{ + static const uint16_t _messages[] = + { + CMSG_QUEST_SET_VAR, + CMSG_QUEST_PLAYER_VARS, + 0 + }; + handledMessages = _messages; +// questHandler = this; +} + +void QuestHandler::handleMessage(Net::MessageIn &msg) +{ + switch (msg.getId()) + { + case CMSG_QUEST_SET_VAR: + processSetQuestVar(msg); + break; + + case CMSG_QUEST_PLAYER_VARS: + processPlayerQuests(msg); + break; + + default: + break; + } +} + +void QuestHandler::processSetQuestVar(Net::MessageIn &msg A_UNUSED) +{ + int var = msg.readInt16(); // variable + int val = msg.readInt32(); // value + if (questsWindow) + { + questsWindow->updateQuest(var, val); + questsWindow->rebuild(); + } +} + +void QuestHandler::processPlayerQuests(Net::MessageIn &msg A_UNUSED) +{ + int count = (msg.readInt16() - 4) / 6; + for (int f = 0; f < count; f ++) + { + int var = msg.readInt16(); // variable + int val = msg.readInt32(); // value + if (questsWindow) + questsWindow->updateQuest(var, val); + } + if (questsWindow) + questsWindow->rebuild(); +} + +} // namespace TmwAthena diff --git a/src/net/tmwa/questhandler.h b/src/net/tmwa/questhandler.h new file mode 100644 index 000000000..aa2534ddb --- /dev/null +++ b/src/net/tmwa/questhandler.h @@ -0,0 +1,50 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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_TA_QUESTHANDLER_H +#define NET_TA_QUESTHANDLER_H + +#include "net/net.h" +#include "net/npchandler.h" + +#include "net/ea/npchandler.h" + +#include "net/tmwa/messagehandler.h" + +#include + +namespace TmwAthena +{ + +class QuestHandler : public MessageHandler +{ + public: + QuestHandler(); + + void handleMessage(Net::MessageIn &msg); + + void processSetQuestVar(Net::MessageIn &msg); + + void processPlayerQuests(Net::MessageIn &msg); +}; + +} // namespace TmwAthena + +#endif // NET_TA_QUESTHANDLER_H diff --git a/src/utils/xml.h b/src/utils/xml.h index a4ff7eb2e..c5f217c78 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -32,6 +32,7 @@ #define XmlNodePtr xmlNodePtr #define xmlNameEqual(node, str) xmlStrEqual((node)->name, BAD_CAST (str)) #define XmlTextWriterPtr xmlTextWriterPtr +#define xmlTypeEqual(node, typ) ((node)->type == (typ)) /** * XML helper functions. -- cgit v1.2.3-70-g09d2