From 5dcba0dec84d73a02b08bde21388535a80e94c56 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 19 Aug 2024 15:29:15 +0200 Subject: Renamed specials to abilities To match mana/manaserv@9ff69160ea1c3c64ea7012cd70a3b50ff4373264. --- data/graphics/gui/button-icon-abilities.png | Bin 0 -> 766 bytes data/graphics/gui/button-icon-specials.png | Bin 766 -> 0 bytes src/CMakeLists.txt | 18 +-- src/game.cpp | 8 +- src/gui/abilitieswindow.cpp | 213 +++++++++++++++++++++++++ src/gui/abilitieswindow.h | 58 +++++++ src/gui/specialswindow.cpp | 213 ------------------------- src/gui/specialswindow.h | 57 ------- src/gui/windowmenu.cpp | 10 +- src/net/abilityhandler.h | 42 +++++ src/net/manaserv/abilityhandler.cpp | 75 +++++++++ src/net/manaserv/abilityhandler.h | 46 ++++++ src/net/manaserv/generalhandler.cpp | 4 +- src/net/manaserv/generalhandler.h | 2 +- src/net/manaserv/manaserv_protocol.h | 8 +- src/net/manaserv/playerhandler.cpp | 10 +- src/net/manaserv/specialhandler.cpp | 75 --------- src/net/manaserv/specialhandler.h | 46 ------ src/net/net.cpp | 8 +- src/net/net.h | 4 +- src/net/specialhandler.h | 42 ----- src/net/tmwa/abilityhandler.cpp | 238 ++++++++++++++++++++++++++++ src/net/tmwa/abilityhandler.h | 47 ++++++ src/net/tmwa/generalhandler.cpp | 6 +- src/net/tmwa/generalhandler.h | 2 +- src/net/tmwa/specialhandler.cpp | 238 ---------------------------- src/net/tmwa/specialhandler.h | 47 ------ src/playerinfo.cpp | 36 ++--- src/playerinfo.h | 20 ++- src/resources/abilitydb.cpp | 115 ++++++++++++++ src/resources/abilitydb.h | 64 ++++++++ src/resources/settingsmanager.cpp | 21 +-- src/resources/specialdb.cpp | 115 -------------- src/resources/specialdb.h | 64 -------- src/resources/spritedef.h | 4 +- 35 files changed, 973 insertions(+), 983 deletions(-) create mode 100644 data/graphics/gui/button-icon-abilities.png delete mode 100644 data/graphics/gui/button-icon-specials.png create mode 100644 src/gui/abilitieswindow.cpp create mode 100644 src/gui/abilitieswindow.h delete mode 100644 src/gui/specialswindow.cpp delete mode 100644 src/gui/specialswindow.h create mode 100644 src/net/abilityhandler.h create mode 100644 src/net/manaserv/abilityhandler.cpp create mode 100644 src/net/manaserv/abilityhandler.h delete mode 100644 src/net/manaserv/specialhandler.cpp delete mode 100644 src/net/manaserv/specialhandler.h delete mode 100644 src/net/specialhandler.h create mode 100644 src/net/tmwa/abilityhandler.cpp create mode 100644 src/net/tmwa/abilityhandler.h delete mode 100644 src/net/tmwa/specialhandler.cpp delete mode 100644 src/net/tmwa/specialhandler.h create mode 100644 src/resources/abilitydb.cpp create mode 100644 src/resources/abilitydb.h delete mode 100644 src/resources/specialdb.cpp delete mode 100644 src/resources/specialdb.h diff --git a/data/graphics/gui/button-icon-abilities.png b/data/graphics/gui/button-icon-abilities.png new file mode 100644 index 00000000..31c66e81 Binary files /dev/null and b/data/graphics/gui/button-icon-abilities.png differ diff --git a/data/graphics/gui/button-icon-specials.png b/data/graphics/gui/button-icon-specials.png deleted file mode 100644 index 31c66e81..00000000 Binary files a/data/graphics/gui/button-icon-specials.png and /dev/null differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b7cfe091..23505dcd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -266,8 +266,8 @@ set(SRCS gui/socialwindow.h gui/speechbubble.cpp gui/speechbubble.h - gui/specialswindow.cpp - gui/specialswindow.h + gui/abilitieswindow.cpp + gui/abilitieswindow.h gui/statuswindow.cpp gui/statuswindow.h gui/textdialog.cpp @@ -307,7 +307,7 @@ set(SRCS net/partyhandler.h net/playerhandler.h net/serverinfo.h - net/specialhandler.h + net/abilityhandler.h net/tradehandler.h net/worldinfo.h resources/action.cpp @@ -354,8 +354,8 @@ set(SRCS resources/settingsmanager.h resources/soundeffect.h resources/soundeffect.cpp - resources/specialdb.cpp - resources/specialdb.h + resources/abilitydb.cpp + resources/abilitydb.h resources/spritedef.h resources/spritedef.cpp resources/statuseffectdb.cpp @@ -547,8 +547,8 @@ set(SRCS_TMWA net/tmwa/playerhandler.cpp net/tmwa/playerhandler.h net/tmwa/protocol.h - net/tmwa/specialhandler.cpp - net/tmwa/specialhandler.h + net/tmwa/abilityhandler.cpp + net/tmwa/abilityhandler.h net/tmwa/token.h net/tmwa/tradehandler.cpp net/tmwa/tradehandler.h) @@ -598,8 +598,8 @@ set(SRCS_MANA net/manaserv/playerhandler.cpp net/manaserv/playerhandler.h net/manaserv/manaserv_protocol.h - net/manaserv/specialhandler.cpp - net/manaserv/specialhandler.h + net/manaserv/abilityhandler.cpp + net/manaserv/abilityhandler.h net/manaserv/tradehandler.cpp net/manaserv/tradehandler.h) diff --git a/src/game.cpp b/src/game.cpp index 0607bcc2..9657bee7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -57,7 +57,7 @@ #include "gui/sdlinput.h" #include "gui/setup.h" #include "gui/socialwindow.h" -#include "gui/specialswindow.h" +#include "gui/abilitieswindow.h" #include "gui/skilldialog.h" #include "gui/statuswindow.h" #include "gui/textdialog.h" @@ -104,7 +104,7 @@ DebugWindow *debugWindow; ShortcutWindow *itemShortcutWindow; ShortcutWindow *emoteShortcutWindow; OutfitWindow *outfitWindow; -SpecialsWindow *specialsWindow; +AbilitiesWindow *abilitiesWindow; SocialWindow *socialWindow; ActorSpriteManager *actorSpriteManager; @@ -159,7 +159,7 @@ static void createGuiWindows() emoteShortcutWindow = new ShortcutWindow("EmoteShortcut", new EmoteShortcutContainer); outfitWindow = new OutfitWindow(); - specialsWindow = new SpecialsWindow(); + abilitiesWindow = new AbilitiesWindow(); socialWindow = new SocialWindow(); localChatTab = new ChatTab(_("General")); @@ -192,7 +192,7 @@ static void destroyGuiWindows() del_0(itemShortcutWindow) del_0(emoteShortcutWindow) del_0(outfitWindow) - del_0(specialsWindow) + del_0(abilitiesWindow) del_0(socialWindow) Event::trigger(Event::NpcChannel, Event::CloseAll); // Cleanup remaining NPC dialogs diff --git a/src/gui/abilitieswindow.cpp b/src/gui/abilitieswindow.cpp new file mode 100644 index 00000000..c6aefb32 --- /dev/null +++ b/src/gui/abilitieswindow.cpp @@ -0,0 +1,213 @@ +/* + * The Mana Client + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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/abilitieswindow.h" + +#include "log.h" + +#include "gui/setup.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/container.h" +#include "gui/widgets/icon.h" +#include "gui/widgets/label.h" +#include "gui/widgets/progressbar.h" +#include "gui/widgets/windowcontainer.h" + +#include "net/net.h" +#include "net/abilityhandler.h" + +#include "resources/abilitydb.h" +#include "resources/theme.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include "localplayer.h" + +#include + +#define ABILITIES_WIDTH 200 +#define ABILITIES_HEIGHT 32 + +class AbilityEntry : public Container +{ + public: + AbilityEntry(AbilityInfo *info); + + void update(int current, int needed); + + protected: + friend class AbilitiesWindow; + AbilityInfo *mInfo; + + private: + Icon *mIcon = nullptr; // icon to display + Label *mNameLabel = nullptr; // name to display + Button *mUse = nullptr; // use button (only shown when applicable) + ProgressBar *mRechargeBar = nullptr; // recharge bar (only shown when applicable) +}; + +AbilitiesWindow::AbilitiesWindow(): + Window(_("Abilities")) +{ + setWindowName("Abilities"); + setCloseButton(true); + setResizable(true); + setSaveVisible(true); + setDefaultSize(windowContainer->getWidth() - 280, 40, ABILITIES_WIDTH + 20, 225); + setupWindow->registerWindowForReset(this); + + center(); + loadWindowState(); +} + +AbilitiesWindow::~AbilitiesWindow() +{ + // Clear gui +} + +void AbilitiesWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "use") + { + auto *disp = dynamic_cast(event.getSource()->getParent()); + + if (disp) + { + if (disp->mInfo->targetMode == AbilityInfo::TARGET_BEING) + { + Being *target = local_player->getTarget(); + + if (target) + Net::getAbilityHandler()->use(disp->mInfo->id, 1, target->getId()); + else + Net::getAbilityHandler()->use(disp->mInfo->id); + } + else + { + // TODO: Allow the player to aim at a position on the map and + // Use abilities on the map position. + } + } + } + else if (event.getId() == "close") + { + setVisible(false); + } +} + +void AbilitiesWindow::draw(gcn::Graphics *graphics) +{ + // update the progress bars + const std::map &abilityData = PlayerInfo::getAbilityStatus(); + bool foundNew = false; + unsigned int found = 0; // number of entries in abilityData which match mEntries + + for (auto &[id, ability] : abilityData) + { + auto e = mEntries.find(id); + if (e == mEntries.end()) + { + // found a new ability - abort update and rebuild from scratch + foundNew = true; + break; + } + + // update progress bar of ability + e->second->update(ability.currentMana, ability.neededMana); + found++; + } + // a rebuild is needed when a) the number of abilities changed or b) an existing entry isn't found anymore + if (foundNew || found != mEntries.size()) + rebuild(abilityData); + + Window::draw(graphics); +} + +void AbilitiesWindow::rebuild(const std::map &abilityData) +{ + delete_all(mEntries); + + mEntries.clear(); + int vPos = 0; //vertical position of next placed element + + for (auto &[id, ability] : abilityData) + { + logger->log("Updating ability GUI for %d", id); + + AbilityInfo *info = AbilityDB::get(id); + if (info) + { + info->rechargeCurrent = ability.currentMana; + info->rechargeNeeded = ability.neededMana; + auto *entry = new AbilityEntry(info); + entry->setPosition(0, vPos); + vPos += entry->getHeight() + 3; + add(entry); + mEntries[id] = entry; + } + else + { + logger->log("Warning: No info available of ability %d", id); + } + } +} + + +AbilityEntry::AbilityEntry(AbilityInfo *info) : + mInfo(info) +{ + setSize(ABILITIES_WIDTH, ABILITIES_HEIGHT); + + if (!info->icon.empty()) + mIcon = new Icon(info->icon); + else + mIcon = new Icon(Theme::resolveThemePath("unknown-item.png")); + + mIcon->setPosition(1, 0); + add(mIcon); + + mNameLabel = new Label(info->name); + mNameLabel->setPosition(35, 0); + add(mNameLabel); + + mUse = new Button("Use", "use", abilitiesWindow); + mUse->setPosition(getWidth() - mUse->getWidth(), 5); + add(mUse); + + if (info->rechargeable) + { + float progress = (float)info->rechargeCurrent / (float)info->rechargeNeeded; + mRechargeBar = new ProgressBar(progress, 100, 10, Theme::PROG_MP); + mRechargeBar->setSmoothProgress(false); + mRechargeBar->setPosition(mNameLabel->getX(), 18); + add(mRechargeBar); + } +} + +void AbilityEntry::update(int current, int needed) +{ + if (mRechargeBar) + { + float progress = (float)current / (float)needed; + mRechargeBar->setProgress(progress); + } +} diff --git a/src/gui/abilitieswindow.h b/src/gui/abilitieswindow.h new file mode 100644 index 00000000..aa84ed79 --- /dev/null +++ b/src/gui/abilitieswindow.h @@ -0,0 +1,58 @@ +/* + * The Mana Client + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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 . + */ + +#pragma once + +#include "playerinfo.h" + +#include "gui/widgets/window.h" + +#include + +#include + +class AbilityEntry; + +class AbilitiesWindow : public Window, public gcn::ActionListener +{ + public: + AbilitiesWindow(); + + ~AbilitiesWindow() override; + + /** + * Called when receiving actions from widget. + */ + void action(const gcn::ActionEvent &actionEvent) override; + + void draw(gcn::Graphics *graphics) override; + + bool hasAbilities() const + { return !mEntries.empty(); } + + private: + // (re)constructs the list of abilities + void rebuild(const std::map &abilityData); + + std::map mEntries; +}; + +extern AbilitiesWindow *abilitiesWindow; + diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp deleted file mode 100644 index 340a1e41..00000000 --- a/src/gui/specialswindow.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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/specialswindow.h" - -#include "log.h" - -#include "gui/setup.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/container.h" -#include "gui/widgets/icon.h" -#include "gui/widgets/label.h" -#include "gui/widgets/progressbar.h" -#include "gui/widgets/windowcontainer.h" - -#include "net/net.h" -#include "net/specialhandler.h" - -#include "resources/specialdb.h" -#include "resources/theme.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - -#include "localplayer.h" - -#include - -#define SPECIALS_WIDTH 200 -#define SPECIALS_HEIGHT 32 - -class SpecialEntry : public Container -{ - public: - SpecialEntry(SpecialInfo *info); - - void update(int current, int needed); - - protected: - friend class SpecialsWindow; - SpecialInfo *mInfo; - - private: - Icon *mIcon = nullptr; // icon to display - Label *mNameLabel = nullptr; // name to display - Button *mUse = nullptr; // use button (only shown when applicable) - ProgressBar *mRechargeBar = nullptr; // recharge bar (only shown when applicable) -}; - -SpecialsWindow::SpecialsWindow(): - Window(_("Specials")) -{ - setWindowName("Specials"); - setCloseButton(true); - setResizable(true); - setSaveVisible(true); - setDefaultSize(windowContainer->getWidth() - 280, 40, SPECIALS_WIDTH + 20, 225); - setupWindow->registerWindowForReset(this); - - center(); - loadWindowState(); -} - -SpecialsWindow::~SpecialsWindow() -{ - // Clear gui -} - -void SpecialsWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "use") - { - auto *disp = dynamic_cast(event.getSource()->getParent()); - - if (disp) - { - if (disp->mInfo->targetMode == SpecialInfo::TARGET_BEING) - { - Being *target = local_player->getTarget(); - - if (target) - Net::getSpecialHandler()->use(disp->mInfo->id, 1, target->getId()); - else - Net::getSpecialHandler()->use(disp->mInfo->id); - } - else - { - // TODO: Allow the player to aim at a position on the map and - // Use special on the map position. - } - } - } - else if (event.getId() == "close") - { - setVisible(false); - } -} - -void SpecialsWindow::draw(gcn::Graphics *graphics) -{ - // update the progress bars - std::map specialData = PlayerInfo::getSpecialStatus(); - bool foundNew = false; - unsigned int found = 0; // number of entries in specialData which match mEntries - - for (auto &special : specialData) - { - auto e = mEntries.find(special.first); - if (e == mEntries.end()) - { - // found a new special - abort update and rebuild from scratch - foundNew = true; - break; - } - - // update progress bar of special - e->second->update(special.second.currentMana, special.second.neededMana); - found++; - } - // a rebuild is needed when a) the number of specials changed or b) an existing entry isn't found anymore - if (foundNew || found != mEntries.size()) - rebuild(specialData); - - Window::draw(graphics); -} - -void SpecialsWindow::rebuild(const std::map &specialData) -{ - delete_all(mEntries); - - mEntries.clear(); - int vPos = 0; //vertical position of next placed element - - for (auto special : specialData) - { - logger->log("Updating special GUI for %d", special.first); - - SpecialInfo *info = SpecialDB::get(special.first); - if (info) - { - info->rechargeCurrent = special.second.currentMana; - info->rechargeNeeded = special.second.neededMana; - auto* entry = new SpecialEntry(info); - entry->setPosition(0, vPos); - vPos += entry->getHeight() + 3; - add(entry); - mEntries[special.first] = entry; - } - else - { - logger->log("Warning: No info available of special %d", special.first); - } - } -} - - -SpecialEntry::SpecialEntry(SpecialInfo *info) : - mInfo(info) -{ - setSize(SPECIALS_WIDTH, SPECIALS_HEIGHT); - - if (!info->icon.empty()) - mIcon = new Icon(info->icon); - else - mIcon = new Icon(Theme::resolveThemePath("unknown-item.png")); - - mIcon->setPosition(1, 0); - add(mIcon); - - mNameLabel = new Label(info->name); - mNameLabel->setPosition(35, 0); - add(mNameLabel); - - mUse = new Button("Use", "use", specialsWindow); - mUse->setPosition(getWidth() - mUse->getWidth(), 5); - add(mUse); - - if (info->rechargeable) - { - float progress = (float)info->rechargeCurrent / (float)info->rechargeNeeded; - mRechargeBar = new ProgressBar(progress, 100, 10, Theme::PROG_MP); - mRechargeBar->setSmoothProgress(false); - mRechargeBar->setPosition(mNameLabel->getX(), 18); - add(mRechargeBar); - } -} - -void SpecialEntry::update(int current, int needed) -{ - if (mRechargeBar) - { - float progress = (float)current / (float)needed; - mRechargeBar->setProgress(progress); - } -} diff --git a/src/gui/specialswindow.h b/src/gui/specialswindow.h deleted file mode 100644 index fd2bb120..00000000 --- a/src/gui/specialswindow.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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 . - */ - -#pragma once - -#include "playerinfo.h" - -#include "gui/widgets/window.h" - -#include - -#include - -class SpecialEntry; - -class SpecialsWindow : public Window, public gcn::ActionListener -{ - public: - SpecialsWindow(); - - ~SpecialsWindow() override; - - /** - * Called when receiving actions from widget. - */ - void action(const gcn::ActionEvent &actionEvent) override; - - void draw(gcn::Graphics *graphics) override; - - bool hasSpecials() const - { return !mEntries.empty(); } - - private: - // (re)constructs the list of specials - void rebuild(const std::map &specialData); - - std::map mEntries; -}; - -extern SpecialsWindow *specialsWindow; diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index c6e52ee7..0b2d126f 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -25,7 +25,7 @@ #include "gui/emotepopup.h" #include "gui/skilldialog.h" -#include "gui/specialswindow.h" +#include "gui/abilitieswindow.h" #include "gui/widgets/button.h" #include "gui/widgets/window.h" @@ -61,8 +61,8 @@ WindowMenu::WindowMenu() addButton(N_("Skills"), x, h, "button-icon-skills.png", KeyboardConfig::KEY_WINDOW_SKILL); - if (specialsWindow->hasSpecials()) - addButton(N_("Specials"), x, h, "button-icon-specials.png"); + if (abilitiesWindow->hasAbilities()) + addButton(N_("Abilities"), x, h, "button-icon-abilities.png"); addButton(N_("Social"), x, h, "button-icon-social.png", KeyboardConfig::KEY_WINDOW_SOCIAL); @@ -122,9 +122,9 @@ void WindowMenu::action(const gcn::ActionEvent &event) { window = skillDialog; } - else if (event.getId() == "Specials") + else if (event.getId() == "Abilities") { - window = specialsWindow; + window = abilitiesWindow; } else if (event.getId() == "Social") { diff --git a/src/net/abilityhandler.h b/src/net/abilityhandler.h new file mode 100644 index 00000000..6e3526bb --- /dev/null +++ b/src/net/abilityhandler.h @@ -0,0 +1,42 @@ +/* + * The Mana Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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 . + */ + +#pragma once + +#include + +namespace Net { + +class AbilityHandler +{ + public: + virtual ~AbilityHandler () {} + + virtual void use(int id) = 0; + + virtual void use(int id, int level, int beingId) = 0; + + virtual void use(int id, int level, int x, int y) = 0; + + virtual void use(int id, const std::string &map) = 0; +}; + +} // namespace Net diff --git a/src/net/manaserv/abilityhandler.cpp b/src/net/manaserv/abilityhandler.cpp new file mode 100644 index 00000000..b5ce9d2e --- /dev/null +++ b/src/net/manaserv/abilityhandler.cpp @@ -0,0 +1,75 @@ +/* + * The Mana Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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/manaserv/abilityhandler.h" + +#include "net/manaserv/connection.h" +#include "net/manaserv/messagein.h" +#include "net/manaserv/messageout.h" +#include "net/manaserv/manaserv_protocol.h" + +extern Net::AbilityHandler *abilityHandler; + +namespace ManaServ { + +extern Connection *gameServerConnection; + +AbilityHandler::AbilityHandler() +{ + abilityHandler = this; +} + +void AbilityHandler::handleMessage(MessageIn &msg) +{ + // TODO +} + +void AbilityHandler::use(int id) +{ + MessageOut msg(PGMSG_USE_ABILITY_ON_BEING); + msg.writeInt8(id); + msg.writeInt16(0); + gameServerConnection->send(msg); +} + +void AbilityHandler::use(int id, int level, int beingId) +{ + MessageOut msg(PGMSG_USE_ABILITY_ON_BEING); + msg.writeInt8(id); + msg.writeInt16(beingId); + gameServerConnection->send(msg); +} + +void AbilityHandler::use(int id, int level, int x, int y) +{ + MessageOut msg(PGMSG_USE_ABILITY_ON_POINT); + msg.writeInt8(id); + msg.writeInt16(x); + msg.writeInt16(y); + gameServerConnection->send(msg); +} + +void AbilityHandler::use(int id, const std::string &map) +{ + // TODO +} + +} // namespace ManaServ diff --git a/src/net/manaserv/abilityhandler.h b/src/net/manaserv/abilityhandler.h new file mode 100644 index 00000000..69ab9c2b --- /dev/null +++ b/src/net/manaserv/abilityhandler.h @@ -0,0 +1,46 @@ +/* + * The Mana Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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 . + */ + +#pragma once + +#include "net/abilityhandler.h" + +#include "net/manaserv/messagehandler.h" + +namespace ManaServ { + +class AbilityHandler final : public MessageHandler, public Net::AbilityHandler +{ + public: + AbilityHandler(); + + void handleMessage(MessageIn &msg) override; + + void use(int id) override; + + void use(int id, int level, int beingId) override; + + void use(int id, int level, int x, int y) override; + + void use(int id, const std::string &map) override; +}; + +} // namespace ManaServ diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 0692ee82..1e443c66 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -42,7 +42,7 @@ #include "net/manaserv/npchandler.h" #include "net/manaserv/partyhandler.h" #include "net/manaserv/playerhandler.h" -#include "net/manaserv/specialhandler.h" +#include "net/manaserv/abilityhandler.h" #include "net/manaserv/tradehandler.h" #include "resources/attributes.h" @@ -76,7 +76,7 @@ GeneralHandler::GeneralHandler(): mPartyHandler(new PartyHandler), mPlayerHandler(new PlayerHandler), mTradeHandler(new TradeHandler), - mSpecialHandler(new SpecialHandler) + mAbilityHandler(new AbilityHandler) { initialize(); diff --git a/src/net/manaserv/generalhandler.h b/src/net/manaserv/generalhandler.h index b9eb9df0..865bbd0d 100644 --- a/src/net/manaserv/generalhandler.h +++ b/src/net/manaserv/generalhandler.h @@ -63,7 +63,7 @@ class GeneralHandler : public Net::GeneralHandler, public EventListener MessageHandlerPtr mPartyHandler; MessageHandlerPtr mPlayerHandler; MessageHandlerPtr mTradeHandler; - MessageHandlerPtr mSpecialHandler; + MessageHandlerPtr mAbilityHandler; }; } // namespace ManaServ diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h index b30bf20b..01632215 100644 --- a/src/net/manaserv/manaserv_protocol.h +++ b/src/net/manaserv/manaserv_protocol.h @@ -25,7 +25,7 @@ namespace ManaServ { enum { PROTOCOL_VERSION = 3, - SUPPORTED_DB_VERSION = 21 + SUPPORTED_DB_VERSION = 22 }; /** @@ -138,9 +138,9 @@ enum { GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* PGMSG_ATTACK = 0x0290, // W being id GPMSG_BEING_ATTACK = 0x0291, // W being id, B direction, B attack Id - PGMSG_USE_SPECIAL_ON_BEING = 0x0292, // B specialID, W being id - GPMSG_SPECIAL_STATUS = 0x0293, // { B specialID, D current, D max, D recharge } - PGMSG_USE_SPECIAL_ON_POINT = 0x0294, // B specialID, W*2 position + PGMSG_USE_ABILITY_ON_BEING = 0x0292, // B abilityID, W being id + GPMSG_ABILITY_STATUS = 0x0293, // { B abilityID, D current, D max, D recharge } + PGMSG_USE_ABILITY_ON_POINT = 0x0294, // B abilityID, W*2 position PGMSG_SAY = 0x02A0, // S text GPMSG_SAY = 0x02A1, // W being id, S text GPMSG_NPC_CHOICE = 0x02B0, // W being id, { S text }* diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index bf5694c6..335546be 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -75,7 +75,7 @@ PlayerHandler::PlayerHandler() GPMSG_LEVEL_PROGRESS, GPMSG_RAISE_ATTRIBUTE_RESPONSE, GPMSG_LOWER_ATTRIBUTE_RESPONSE, - GPMSG_SPECIAL_STATUS, + GPMSG_ABILITY_STATUS, 0 }; handledMessages = _messages; @@ -243,17 +243,17 @@ void PlayerHandler::handleMessage(MessageIn &msg) } break; - case GPMSG_SPECIAL_STATUS : + case GPMSG_ABILITY_STATUS: { - PlayerInfo::clearSpecialStatus(); + PlayerInfo::clearAbilityStatus(); while (msg.getUnreadLength()) { - // { B specialID, L current, L max, L recharge } + // { B abilityID, L current, L max, L recharge } int id = msg.readInt8(); int current = msg.readInt32(); int max = msg.readInt32(); int recharge = msg.readInt32(); - PlayerInfo::setSpecialStatus(id, current, max, recharge); + PlayerInfo::setAbilityStatus(id, current, max, recharge); } } break; /* diff --git a/src/net/manaserv/specialhandler.cpp b/src/net/manaserv/specialhandler.cpp deleted file mode 100644 index 0a477ff8..00000000 --- a/src/net/manaserv/specialhandler.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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/manaserv/specialhandler.h" - -#include "net/manaserv/connection.h" -#include "net/manaserv/messagein.h" -#include "net/manaserv/messageout.h" -#include "net/manaserv/manaserv_protocol.h" - -extern Net::SpecialHandler *specialHandler; - -namespace ManaServ { - -extern Connection *gameServerConnection; - -SpecialHandler::SpecialHandler() -{ - specialHandler = this; -} - -void SpecialHandler::handleMessage(MessageIn &msg) -{ - // TODO -} - -void SpecialHandler::use(int id) -{ - MessageOut msg(PGMSG_USE_SPECIAL_ON_BEING); - msg.writeInt8(id); - msg.writeInt16(0); - gameServerConnection->send(msg); -} - -void SpecialHandler::use(int id, int level, int beingId) -{ - MessageOut msg(PGMSG_USE_SPECIAL_ON_BEING); - msg.writeInt8(id); - msg.writeInt16(beingId); - gameServerConnection->send(msg); -} - -void SpecialHandler::use(int id, int level, int x, int y) -{ - MessageOut msg(PGMSG_USE_SPECIAL_ON_POINT); - msg.writeInt8(id); - msg.writeInt16(x); - msg.writeInt16(y); - gameServerConnection->send(msg); -} - -void SpecialHandler::use(int id, const std::string &map) -{ - // TODO -} - -} // namespace ManaServ diff --git a/src/net/manaserv/specialhandler.h b/src/net/manaserv/specialhandler.h deleted file mode 100644 index 45793b62..00000000 --- a/src/net/manaserv/specialhandler.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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 . - */ - -#pragma once - -#include "net/specialhandler.h" - -#include "net/manaserv/messagehandler.h" - -namespace ManaServ { - -class SpecialHandler final : public MessageHandler, public Net::SpecialHandler -{ - public: - SpecialHandler(); - - void handleMessage(MessageIn &msg) override; - - void use(int id) override; - - void use(int id, int level, int beingId) override; - - void use(int id, int level, int x, int y) override; - - void use(int id, const std::string &map) override; -}; - -} // namespace ManaServ diff --git a/src/net/net.cpp b/src/net/net.cpp index 3a389db2..93003280 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -34,7 +34,7 @@ #include "net/npchandler.h" #include "net/partyhandler.h" #include "net/playerhandler.h" -#include "net/specialhandler.h" +#include "net/abilityhandler.h" #include "net/tradehandler.h" #include "net/tmwa/generalhandler.h" @@ -54,7 +54,7 @@ Net::GuildHandler *guildHandler = nullptr; Net::NpcHandler *npcHandler = nullptr; Net::PartyHandler *partyHandler = nullptr; Net::PlayerHandler *playerHandler = nullptr; -Net::SpecialHandler *specialHandler = nullptr; +Net::AbilityHandler *abilityHandler = nullptr; Net::TradeHandler *tradeHandler = nullptr; Net::AdminHandler *Net::getAdminHandler() @@ -112,9 +112,9 @@ Net::PlayerHandler *Net::getPlayerHandler() return playerHandler; } -Net::SpecialHandler *Net::getSpecialHandler() +Net::AbilityHandler *Net::getAbilityHandler() { - return specialHandler; + return abilityHandler; } Net::TradeHandler *Net::getTradeHandler() diff --git a/src/net/net.h b/src/net/net.h index 216c2048..ced0f7ba 100644 --- a/src/net/net.h +++ b/src/net/net.h @@ -44,7 +44,7 @@ class LoginHandler; class NpcHandler; class PartyHandler; class PlayerHandler; -class SpecialHandler; +class AbilityHandler; class TradeHandler; AdminHandler *getAdminHandler(); @@ -58,7 +58,7 @@ LoginHandler *getLoginHandler(); NpcHandler *getNpcHandler(); PartyHandler *getPartyHandler(); PlayerHandler *getPlayerHandler(); -SpecialHandler *getSpecialHandler(); +AbilityHandler *getAbilityHandler(); TradeHandler *getTradeHandler(); ServerType getNetworkType(); diff --git a/src/net/specialhandler.h b/src/net/specialhandler.h deleted file mode 100644 index df09087d..00000000 --- a/src/net/specialhandler.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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 . - */ - -#pragma once - -#include - -namespace Net { - -class SpecialHandler -{ - public: - virtual ~SpecialHandler () {} - - virtual void use(int id) = 0; - - virtual void use(int id, int level, int beingId) = 0; - - virtual void use(int id, int level, int x, int y) = 0; - - virtual void use(int id, const std::string &map) = 0; -}; - -} // namespace Net diff --git a/src/net/tmwa/abilityhandler.cpp b/src/net/tmwa/abilityhandler.cpp new file mode 100644 index 00000000..e221039c --- /dev/null +++ b/src/net/tmwa/abilityhandler.cpp @@ -0,0 +1,238 @@ +/* + * The Mana Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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/abilityhandler.h" + +#include "event.h" +#include "log.h" +#include "playerinfo.h" + +#include "gui/skilldialog.h" + +#include "net/tmwa/messagein.h" +#include "net/tmwa/protocol.h" + +#include "utils/gettext.h" + +/** job dependend identifiers (?) */ +#define SKILL_BASIC 0x0001 +#define SKILL_WARP 0x001b +#define SKILL_STEAL 0x0032 +#define SKILL_ENVENOM 0x0034 + +/** basic skills identifiers */ +#define BSKILL_TRADE 0x0000 +#define BSKILL_EMOTE 0x0001 +#define BSKILL_SIT 0x0002 +#define BSKILL_CREATECHAT 0x0003 +#define BSKILL_JOINPARTY 0x0004 +#define BSKILL_SHOUT 0x0005 +#define BSKILL_PK 0x0006 // ?? +#define BSKILL_SETALLIGN 0x0007 // ?? + +/** reasons why action failed */ +#define RFAIL_SKILLDEP 0x00 +#define RFAIL_INSUFSP 0x01 +#define RFAIL_INSUFHP 0x02 +#define RFAIL_NOMEMO 0x03 +#define RFAIL_SKILLDELAY 0x04 +#define RFAIL_ZENY 0x05 +#define RFAIL_WEAPON 0x06 +#define RFAIL_REDGEM 0x07 +#define RFAIL_BLUEGEM 0x08 +#define RFAIL_OVERWEIGHT 0x09 +#define RFAIL_GENERIC 0x0a + +/** should always be zero if failed */ +#define SKILL_FAILED 0x00 + +extern Net::AbilityHandler *abilityHandler; + +namespace TmwAthena { + +AbilityHandler::AbilityHandler() +{ + static const Uint16 _messages[] = { + SMSG_PLAYER_SKILLS, + SMSG_SKILL_FAILED, + SMSG_PLAYER_SKILL_UP, + 0 + }; + handledMessages = _messages; + abilityHandler = this; +} + +void AbilityHandler::handleMessage(MessageIn &msg) +{ + int skillCount; + int skillId; + + switch (msg.getId()) + { + case SMSG_PLAYER_SKILLS: + msg.readInt16(); // length + skillCount = (msg.getLength() - 4) / 37; + + for (int k = 0; k < skillCount; k++) + { + skillId = msg.readInt16(); + msg.readInt16(); // target type + msg.skip(2); // unused + int level = msg.readInt16(); + msg.readInt16(); // sp + msg.readInt16(); // range + msg.skip(24); // unused + int up = msg.readInt8(); + + PlayerInfo::setStatBase(skillId, level); + if (skillDialog) + skillDialog->setModifiable(skillId, up); + } + break; + + case SMSG_PLAYER_SKILL_UP: + { + skillId = msg.readInt16(); + int level = msg.readInt16(); + msg.readInt16(); // sp + msg.readInt16(); // range + int up = msg.readInt8(); + + PlayerInfo::setStatBase(skillId, level); + skillDialog->setModifiable(skillId, up); + } + break; + + case SMSG_SKILL_FAILED: + // Action failed (ex. sit because you have not reached the + // right level) + skillId = msg.readInt16(); + short bskill = msg.readInt16(); + msg.readInt16(); // unknown + char success = msg.readInt8(); + char reason = msg.readInt8(); + if (success != SKILL_FAILED && bskill == BSKILL_EMOTE) + { + logger->log("Action: %d/%d", bskill, success); + } + + std::string msg; + if (success == SKILL_FAILED && skillId == SKILL_BASIC) + { + switch (bskill) + { + case BSKILL_TRADE: + msg = _("Trade failed!"); + break; + case BSKILL_EMOTE: + msg = _("Emote failed!"); + break; + case BSKILL_SIT: + msg = _("Sit failed!"); + break; + case BSKILL_CREATECHAT: + msg = _("Chat creating failed!"); + break; + case BSKILL_JOINPARTY: + msg = _("Could not join party!"); + break; + case BSKILL_SHOUT: + msg = _("Cannot shout!"); + break; + } + + msg += " "; + + switch (reason) + { + case RFAIL_SKILLDEP: + msg += _("You have not yet reached a high enough lvl!"); + break; + case RFAIL_INSUFHP: + msg += _("Insufficient HP!"); + break; + case RFAIL_INSUFSP: + msg += _("Insufficient SP!"); + break; + case RFAIL_NOMEMO: + msg += _("You have no memos!"); + break; + case RFAIL_SKILLDELAY: + msg += _("You cannot do that right now!"); + break; + case RFAIL_ZENY: + msg += _("Seems you need more money... ;-)"); + break; + case RFAIL_WEAPON: + msg += _("You cannot use this skill with that kind of weapon!"); + break; + case RFAIL_REDGEM: + msg += _("You need another red gem!"); + break; + case RFAIL_BLUEGEM: + msg += _("You need another blue gem!"); + break; + case RFAIL_OVERWEIGHT: + msg += _("You're carrying to much to do this!"); + break; + default: + msg += _("Huh? What's that?"); + break; + } + } + else + { + switch (skillId) + { + case SKILL_WARP: + msg = _("Warp failed..."); + break; + case SKILL_STEAL: + msg = _("Could not steal anything..."); + break; + case SKILL_ENVENOM: + msg = _("Poison had no effect..."); + break; + } + } + + serverNotice(msg); + break; + } +} + +void AbilityHandler::use(int id) +{ +} + +void AbilityHandler::use(int id, int level, int beingId) +{ +} + +void AbilityHandler::use(int id, int level, int x, int y) +{ +} + +void AbilityHandler::use(int id, const std::string &map) +{ +} + +} // namespace TmwAthena diff --git a/src/net/tmwa/abilityhandler.h b/src/net/tmwa/abilityhandler.h new file mode 100644 index 00000000..822ed737 --- /dev/null +++ b/src/net/tmwa/abilityhandler.h @@ -0,0 +1,47 @@ +/* + * The Mana Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2012 The Mana Developers + * + * This file is part of The Mana 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 . + */ + +#pragma once + +#include "net/net.h" +#include "net/abilityhandler.h" + +#include "net/tmwa/messagehandler.h" + +namespace TmwAthena { + +class AbilityHandler final : public MessageHandler, public Net::AbilityHandler +{ + public: + AbilityHandler(); + + void handleMessage(MessageIn &msg) override; + + void use(int id) override; + + void use(int id, int level, int beingId) override; + + void use(int id, int level, int x, int y) override; + + void use(int id, const std::string &map) override; +}; + +} // namespace TmwAthena diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index e1b1a9ea..2a8afb4e 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -49,7 +49,7 @@ #include "net/tmwa/playerhandler.h" #include "net/tmwa/protocol.h" #include "net/tmwa/tradehandler.h" -#include "net/tmwa/specialhandler.h" +#include "net/tmwa/abilityhandler.h" #include "net/tmwa/gui/guildtab.h" #include "net/tmwa/gui/partytab.h" @@ -84,7 +84,7 @@ GeneralHandler::GeneralHandler(): mNpcHandler(new NpcHandler), mPartyHandler(new PartyHandler), mPlayerHandler(new PlayerHandler), - mSpecialHandler(new SpecialHandler), + mAbilityHandler(new AbilityHandler), mTradeHandler(new TradeHandler) { static const Uint16 _messages[] = { @@ -169,7 +169,7 @@ void GeneralHandler::load() mNetwork->registerHandler(mLoginHandler.get()); mNetwork->registerHandler(mNpcHandler.get()); mNetwork->registerHandler(mPlayerHandler.get()); - mNetwork->registerHandler(mSpecialHandler.get()); + mNetwork->registerHandler(mAbilityHandler.get()); mNetwork->registerHandler(mTradeHandler.get()); mNetwork->registerHandler(mPartyHandler.get()); } diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index 26c6fe27..529c1661 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -66,7 +66,7 @@ class GeneralHandler final : public MessageHandler, public Net::GeneralHandler, MessageHandlerPtr mNpcHandler; MessageHandlerPtr mPartyHandler; MessageHandlerPtr mPlayerHandler; - MessageHandlerPtr mSpecialHandler; + MessageHandlerPtr mAbilityHandler; MessageHandlerPtr mTradeHandler; }; diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp deleted file mode 100644 index 2e22b00a..00000000 --- a/src/net/tmwa/specialhandler.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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/specialhandler.h" - -#include "event.h" -#include "log.h" -#include "playerinfo.h" - -#include "gui/skilldialog.h" - -#include "net/tmwa/messagein.h" -#include "net/tmwa/protocol.h" - -#include "utils/gettext.h" - -/** job dependend identifiers (?) */ -#define SKILL_BASIC 0x0001 -#define SKILL_WARP 0x001b -#define SKILL_STEAL 0x0032 -#define SKILL_ENVENOM 0x0034 - -/** basic skills identifiers */ -#define BSKILL_TRADE 0x0000 -#define BSKILL_EMOTE 0x0001 -#define BSKILL_SIT 0x0002 -#define BSKILL_CREATECHAT 0x0003 -#define BSKILL_JOINPARTY 0x0004 -#define BSKILL_SHOUT 0x0005 -#define BSKILL_PK 0x0006 // ?? -#define BSKILL_SETALLIGN 0x0007 // ?? - -/** reasons why action failed */ -#define RFAIL_SKILLDEP 0x00 -#define RFAIL_INSUFSP 0x01 -#define RFAIL_INSUFHP 0x02 -#define RFAIL_NOMEMO 0x03 -#define RFAIL_SKILLDELAY 0x04 -#define RFAIL_ZENY 0x05 -#define RFAIL_WEAPON 0x06 -#define RFAIL_REDGEM 0x07 -#define RFAIL_BLUEGEM 0x08 -#define RFAIL_OVERWEIGHT 0x09 -#define RFAIL_GENERIC 0x0a - -/** should always be zero if failed */ -#define SKILL_FAILED 0x00 - -extern Net::SpecialHandler *specialHandler; - -namespace TmwAthena { - -SpecialHandler::SpecialHandler() -{ - static const Uint16 _messages[] = { - SMSG_PLAYER_SKILLS, - SMSG_SKILL_FAILED, - SMSG_PLAYER_SKILL_UP, - 0 - }; - handledMessages = _messages; - specialHandler = this; -} - -void SpecialHandler::handleMessage(MessageIn &msg) -{ - int skillCount; - int skillId; - - switch (msg.getId()) - { - case SMSG_PLAYER_SKILLS: - msg.readInt16(); // length - skillCount = (msg.getLength() - 4) / 37; - - for (int k = 0; k < skillCount; k++) - { - skillId = msg.readInt16(); - msg.readInt16(); // target type - msg.skip(2); // unused - int level = msg.readInt16(); - msg.readInt16(); // sp - msg.readInt16(); // range - msg.skip(24); // unused - int up = msg.readInt8(); - - PlayerInfo::setStatBase(skillId, level); - if (skillDialog) - skillDialog->setModifiable(skillId, up); - } - break; - - case SMSG_PLAYER_SKILL_UP: - { - skillId = msg.readInt16(); - int level = msg.readInt16(); - msg.readInt16(); // sp - msg.readInt16(); // range - int up = msg.readInt8(); - - PlayerInfo::setStatBase(skillId, level); - skillDialog->setModifiable(skillId, up); - } - break; - - case SMSG_SKILL_FAILED: - // Action failed (ex. sit because you have not reached the - // right level) - skillId = msg.readInt16(); - short bskill = msg.readInt16(); - msg.readInt16(); // unknown - char success = msg.readInt8(); - char reason = msg.readInt8(); - if (success != SKILL_FAILED && bskill == BSKILL_EMOTE) - { - logger->log("Action: %d/%d", bskill, success); - } - - std::string msg; - if (success == SKILL_FAILED && skillId == SKILL_BASIC) - { - switch (bskill) - { - case BSKILL_TRADE: - msg = _("Trade failed!"); - break; - case BSKILL_EMOTE: - msg = _("Emote failed!"); - break; - case BSKILL_SIT: - msg = _("Sit failed!"); - break; - case BSKILL_CREATECHAT: - msg = _("Chat creating failed!"); - break; - case BSKILL_JOINPARTY: - msg = _("Could not join party!"); - break; - case BSKILL_SHOUT: - msg = _("Cannot shout!"); - break; - } - - msg += " "; - - switch (reason) - { - case RFAIL_SKILLDEP: - msg += _("You have not yet reached a high enough lvl!"); - break; - case RFAIL_INSUFHP: - msg += _("Insufficient HP!"); - break; - case RFAIL_INSUFSP: - msg += _("Insufficient SP!"); - break; - case RFAIL_NOMEMO: - msg += _("You have no memos!"); - break; - case RFAIL_SKILLDELAY: - msg += _("You cannot do that right now!"); - break; - case RFAIL_ZENY: - msg += _("Seems you need more money... ;-)"); - break; - case RFAIL_WEAPON: - msg += _("You cannot use this skill with that kind of weapon!"); - break; - case RFAIL_REDGEM: - msg += _("You need another red gem!"); - break; - case RFAIL_BLUEGEM: - msg += _("You need another blue gem!"); - break; - case RFAIL_OVERWEIGHT: - msg += _("You're carrying to much to do this!"); - break; - default: - msg += _("Huh? What's that?"); - break; - } - } - else - { - switch (skillId) - { - case SKILL_WARP: - msg = _("Warp failed..."); - break; - case SKILL_STEAL: - msg = _("Could not steal anything..."); - break; - case SKILL_ENVENOM: - msg = _("Poison had no effect..."); - break; - } - } - - serverNotice(msg); - break; - } -} - -void SpecialHandler::use(int id) -{ -} - -void SpecialHandler::use(int id, int level, int beingId) -{ -} - -void SpecialHandler::use(int id, int level, int x, int y) -{ -} - -void SpecialHandler::use(int id, const std::string &map) -{ -} - -} // namespace TmwAthena diff --git a/src/net/tmwa/specialhandler.h b/src/net/tmwa/specialhandler.h deleted file mode 100644 index 2448b7e0..00000000 --- a/src/net/tmwa/specialhandler.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana 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 . - */ - -#pragma once - -#include "net/net.h" -#include "net/specialhandler.h" - -#include "net/tmwa/messagehandler.h" - -namespace TmwAthena { - -class SpecialHandler final : public MessageHandler, public Net::SpecialHandler -{ - public: - SpecialHandler(); - - void handleMessage(MessageIn &msg) override; - - void use(int id) override; - - void use(int id, int level, int beingId) override; - - void use(int id, int level, int x, int y) override; - - void use(int id, const std::string &map) override; -}; - -} // namespace TmwAthena diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index aacff3a1..6eaa20b7 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -50,8 +50,8 @@ static bool mNPCPostCount = false; static BuySellState mBuySellState = BUYSELL_NONE; -static std::map mSpecials; -static Timer mSpecialRechargeUpdateTimer; +static std::map mAbilities; +static Timer mAbilityRechargeUpdateTimer; // --- Triggers --------------------------------------------------------------- @@ -278,25 +278,25 @@ void setBuySellState(BuySellState buySellState) } } -// --- Specials --------------------------------------------------------------- +// --- Abilities -------------------------------------------------------------- -void clearSpecialStatus() +void clearAbilityStatus() { - mSpecials.clear(); + mAbilities.clear(); } -void setSpecialStatus(int id, int current, int max, int recharge) +void setAbilityStatus(int id, int current, int max, int recharge) { - logger->log("SpecialUpdate Skill #%d -- (%d/%d) -> %d", id, current, max, + logger->log("AbilityUpdate Skill #%d -- (%d/%d) -> %d", id, current, max, recharge); - mSpecials[id].currentMana = current; - mSpecials[id].neededMana = max; - mSpecials[id].recharge = recharge; + mAbilities[id].currentMana = current; + mAbilities[id].neededMana = max; + mAbilities[id].recharge = recharge; } -const SpecialsMap &getSpecialStatus() +const std::map &getAbilityStatus() { - return mSpecials; + return mAbilities; } // --- Misc ------------------------------------------------------------------- @@ -314,16 +314,16 @@ bool isTalking() void logic() { - if (mSpecialRechargeUpdateTimer.passed()) + if (mAbilityRechargeUpdateTimer.passed()) { - mSpecialRechargeUpdateTimer.set(100); + mAbilityRechargeUpdateTimer.set(100); - for (auto &special : mSpecials) + for (auto &[id, ability] : mAbilities) { - special.second.currentMana += special.second.recharge; - if (special.second.currentMana > special.second.neededMana) + ability.currentMana += ability.recharge; + if (ability.currentMana > ability.neededMana) { - special.second.currentMana = special.second.neededMana; + ability.currentMana = ability.neededMana; } } } diff --git a/src/playerinfo.h b/src/playerinfo.h index dd7d98fe..8ac82463 100644 --- a/src/playerinfo.h +++ b/src/playerinfo.h @@ -70,17 +70,15 @@ enum BuySellState }; /** - * Special information storage structure. + * Ability information storage structure. */ -struct Special +struct Ability { int currentMana; int neededMana; int recharge; }; -using SpecialsMap = std::map; - /** * A database like namespace which holds global info about the localplayer * @@ -217,22 +215,22 @@ namespace PlayerInfo */ void setBuySellState(BuySellState buySellState); -// --- Specials --------------------------------------------------------------- +// --- Abilities -------------------------------------------------------------- /** - * Removes all specials. + * Removes all abilities. */ - void clearSpecialStatus(); + void clearAbilityStatus(); /** - * Changes the status of the given special. + * Changes the status of the given ability. */ - void setSpecialStatus(int id, int current, int max, int recharge); + void setAbilityStatus(int id, int current, int max, int recharge); /** - * Returns the status of the given special. + * Returns the status of the given ability. */ - const SpecialsMap &getSpecialStatus(); + const std::map &getAbilityStatus(); // --- Misc ------------------------------------------------------------------- diff --git a/src/resources/abilitydb.cpp b/src/resources/abilitydb.cpp new file mode 100644 index 00000000..115f120e --- /dev/null +++ b/src/resources/abilitydb.cpp @@ -0,0 +1,115 @@ +/* + * The Mana Client + * Copyright (C) 2010-2013 The Mana Developers + * + * This file is part of The Mana 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 "resources/abilitydb.h" + +#include "log.h" + +#include "utils/dtor.h" + +#include + +namespace +{ + std::map mAbilityInfos; + bool mLoaded = false; +} + +AbilityInfo::TargetMode AbilityDB::targetModeFromString(const std::string& str) +{ + if (str == "being") + return AbilityInfo::TARGET_BEING; + if (str == "point") + return AbilityInfo::TARGET_POINT; + + logger->log("AbilityDB: Warning, unknown target mode \"%s\"", str.c_str() ); + return AbilityInfo::TARGET_BEING; +} + + +void AbilityDB::init() +{ + if (mLoaded) + unload(); +} + +void AbilityDB::readAbilitySetNode(XML::Node node, const std::string &filename) +{ + std::string setName = node.getProperty("name", "Actions"); + + for (auto ability : node.children()) + { + if (ability.name() == "ability") + { + auto *info = new AbilityInfo(); + int id = ability.getProperty("id", 0); + info->id = id; + info->set = setName; + info->name = ability.getProperty("name", ""); + info->icon = ability.getProperty("icon", ""); + + info->targetMode = targetModeFromString(ability.getProperty("target", "being")); + + info->rechargeable = ability.getBoolProperty("rechargeable", true); + info->rechargeNeeded = 0; + info->rechargeCurrent = 0; + + if (mAbilityInfos.find(id) != mAbilityInfos.end()) + { + logger->log("AbilityDB: Duplicate ability ID %d in %s, ignoring", id, filename.c_str()); + } else { + mAbilityInfos[id] = info; + } + } + } + +} + +void AbilityDB::checkStatus() +{ + mLoaded = true; +} + + +void AbilityDB::unload() +{ + + delete_all(mAbilityInfos); + mAbilityInfos.clear(); + + mLoaded = false; +} + + +AbilityInfo *AbilityDB::get(int id) +{ + + auto i = mAbilityInfos.find(id); + + if (i == mAbilityInfos.end()) + { + return nullptr; + } + else + { + return i->second; + } + return nullptr; +} diff --git a/src/resources/abilitydb.h b/src/resources/abilitydb.h new file mode 100644 index 00000000..e03a7992 --- /dev/null +++ b/src/resources/abilitydb.h @@ -0,0 +1,64 @@ +/* + * The Mana Client + * Copyright (C) 2010-2013 The Mana Developers + * + * This file is part of The Mana 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 . + */ + +#pragma once + +#include +#include "utils/xml.h" + +struct AbilityInfo +{ + enum TargetMode + { + TARGET_BEING, // target any being + TARGET_POINT // target map location + }; + int id; + std::string set; // tab on which the ability is shown + std::string name; // displayed name of ability + std::string icon; // filename of graphical icon + + TargetMode targetMode; // target mode + + bool rechargeable; // true when the ability has a recharge bar + int rechargeNeeded; // maximum recharge when applicable + int rechargeCurrent; // current recharge when applicable +}; + +/** + * Ability information database. + */ +namespace AbilityDB +{ + void init(); + + void readAbilitySetNode(XML::Node node, const std::string &filename); + + void checkStatus(); + + void unload(); + + /** gets the ability info for ID. Will return 0 when it is + * a server-specific ability. + */ + AbilityInfo *get(int id); + + AbilityInfo::TargetMode targetModeFromString(const std::string& str); +} diff --git a/src/resources/settingsmanager.cpp b/src/resources/settingsmanager.cpp index 789b8b75..b5add444 100644 --- a/src/resources/settingsmanager.cpp +++ b/src/resources/settingsmanager.cpp @@ -26,7 +26,7 @@ #include "resources/itemdb.h" #include "resources/monsterdb.h" #include "resources/npcdb.h" -#include "resources/specialdb.h" +#include "resources/abilitydb.h" #include "resources/statuseffectdb.h" #include "net/net.h" @@ -53,7 +53,7 @@ namespace SettingsManager hairDB.init(); itemDb->init(); MonsterDB::init(); - SpecialDB::init(); + AbilityDB::init(); NPCDB::init(); EmoteDB::init(); StatusEffectDB::init(); @@ -77,7 +77,7 @@ namespace SettingsManager hairDB.checkStatus(); itemDb->checkStatus(); MonsterDB::checkStatus(); - SpecialDB::checkStatus(); + AbilityDB::checkStatus(); NPCDB::checkStatus(); EmoteDB::checkStatus(); StatusEffectDB::checkStatus(); @@ -94,7 +94,7 @@ namespace SettingsManager StatusEffectDB::unload(); EmoteDB::unload(); NPCDB::unload(); - SpecialDB::unload(); + AbilityDB::unload(); MonsterDB::unload(); if (itemDb) itemDb->unload(); @@ -214,9 +214,9 @@ namespace SettingsManager { MonsterDB::readMonsterNode(childNode, filename); } - else if (childNode.name() == "special-set") + else if (childNode.name() == "ability-set") { - SpecialDB::readSpecialSetNode(childNode, filename); + AbilityDB::readAbilitySetNode(childNode, filename); } else if (childNode.name() == "npc") { @@ -234,15 +234,6 @@ namespace SettingsManager { Units::readUnitNode(childNode, filename); } - else - { - // compatibility stuff with older configs/games - if (node.name() == "specials" && childNode.name() == "set") - { - // specials.xml:/specials/set - SpecialDB::readSpecialSetNode(childNode, filename); - } - } } mIncludedFiles.erase(filename); diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp deleted file mode 100644 index ec0b3f2f..00000000 --- a/src/resources/specialdb.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2010-2013 The Mana Developers - * - * This file is part of The Mana 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 "resources/specialdb.h" - -#include "log.h" - -#include "utils/dtor.h" - -#include - -namespace -{ - std::map mSpecialInfos; - bool mLoaded = false; -} - -SpecialInfo::TargetMode SpecialDB::targetModeFromString(const std::string& str) -{ - if (str == "being") - return SpecialInfo::TARGET_BEING; - if (str == "point") - return SpecialInfo::TARGET_POINT; - - logger->log("SpecialDB: Warning, unknown target mode \"%s\"", str.c_str() ); - return SpecialInfo::TARGET_BEING; -} - - -void SpecialDB::init() -{ - if (mLoaded) - unload(); -} - -void SpecialDB::readSpecialSetNode(XML::Node node, const std::string &filename) -{ - std::string setName = node.getProperty("name", "Actions"); - - for (auto special : node.children()) - { - if (special.name() == "special") - { - auto *info = new SpecialInfo(); - int id = special.getProperty("id", 0); - info->id = id; - info->set = setName; - info->name = special.getProperty("name", ""); - info->icon = special.getProperty("icon", ""); - - info->targetMode = targetModeFromString(special.getProperty("target", "being")); - - info->rechargeable = special.getBoolProperty("rechargeable", true); - info->rechargeNeeded = 0; - info->rechargeCurrent = 0; - - if (mSpecialInfos.find(id) != mSpecialInfos.end()) - { - logger->log("SpecialDB: Duplicate special ID %d in %s, ignoring", id, filename.c_str()); - } else { - mSpecialInfos[id] = info; - } - } - } - -} - -void SpecialDB::checkStatus() -{ - mLoaded = true; -} - - -void SpecialDB::unload() -{ - - delete_all(mSpecialInfos); - mSpecialInfos.clear(); - - mLoaded = false; -} - - -SpecialInfo *SpecialDB::get(int id) -{ - - auto i = mSpecialInfos.find(id); - - if (i == mSpecialInfos.end()) - { - return nullptr; - } - else - { - return i->second; - } - return nullptr; -} diff --git a/src/resources/specialdb.h b/src/resources/specialdb.h deleted file mode 100644 index c8158a27..00000000 --- a/src/resources/specialdb.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2010-2013 The Mana Developers - * - * This file is part of The Mana 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 . - */ - -#pragma once - -#include -#include "utils/xml.h" - -struct SpecialInfo -{ - enum TargetMode - { - TARGET_BEING, // target any being - TARGET_POINT // target map location - }; - int id; - std::string set; // tab on which the special is shown - std::string name; // displayed name of special - std::string icon; // filename of graphical icon - - TargetMode targetMode; // target mode - - bool rechargeable; // true when the special has a recharge bar - int rechargeNeeded; // maximum recharge when applicable - int rechargeCurrent; // current recharge when applicable -}; - -/** - * Special information database. - */ -namespace SpecialDB -{ - void init(); - - void readSpecialSetNode(XML::Node node, const std::string &filename); - - void checkStatus(); - - void unload(); - - /** gets the special info for ID. Will return 0 when it is - * a server-specific special. - */ - SpecialInfo *get(int id); - - SpecialInfo::TargetMode targetModeFromString(const std::string& str); -} diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 83bd9598..0d48d145 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -49,7 +49,7 @@ struct SpriteDisplay * Remember those are the main action. * Action subtypes, e.g.: "attack_bow" are to be passed by items.xml after * an ACTION_ATTACK call. - * Which special to be use to to be passed with the USE_SPECIAL call. + * Which ability to be use to to be passed with the USE_ABILITY call. * Running, walking, ... is a sub-type of moving. * ... * Please don't add hard-coded subtypes here! @@ -64,7 +64,7 @@ namespace SpriteAction static const std::string MOVE = "walk"; static const std::string ATTACK = "attack"; static const std::string HURT = "hurt"; - static const std::string USE_SPECIAL = "special"; + static const std::string USE_ABILITY = "ability"; static const std::string CAST_MAGIC = "magic"; static const std::string USE_ITEM = "item"; static const std::string INVALID; -- cgit v1.2.3-70-g09d2