diff options
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/abilitymanager.cpp | 182 | ||||
-rw-r--r-- | src/game-server/abilitymanager.h (renamed from src/game-server/specialmanager.h) | 52 | ||||
-rw-r--r-- | src/game-server/character.cpp | 149 | ||||
-rw-r--r-- | src/game-server/character.h | 112 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 128 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 24 | ||||
-rw-r--r-- | src/game-server/gamehandler.h | 4 | ||||
-rw-r--r-- | src/game-server/main-game.cpp | 6 | ||||
-rw-r--r-- | src/game-server/settingsmanager.cpp | 16 | ||||
-rw-r--r-- | src/game-server/specialmanager.cpp | 179 |
10 files changed, 428 insertions, 424 deletions
diff --git a/src/game-server/abilitymanager.cpp b/src/game-server/abilitymanager.cpp new file mode 100644 index 0000000..91669f1 --- /dev/null +++ b/src/game-server/abilitymanager.cpp @@ -0,0 +1,182 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2010-2012 The Mana Developers + * + * This file is part of The Mana Server. + * + * The Mana Server 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. + * + * The Mana Server 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 The Mana Server. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "abilitymanager.h" + +#include "utils/xml.h" +#include "utils/logger.h" + +static AbilityManager::TargetMode getTargetByString(const std::string &str) +{ + std::string strLower = utils::toLower(str); + if (strLower == "being") + return AbilityManager::TARGET_BEING; + else if (strLower == "point") + return AbilityManager::TARGET_POINT; + + LOG_WARN("Unknown targetmode " << str << " assuming being."); + return AbilityManager::TARGET_BEING; +} + + +/** + * Read a <special> element from settings. + * Used by SettingsManager. + */ +void AbilityManager::readAbilitySetNode(xmlNodePtr node, + const std::string &filename) +{ + std::string setName = XML::getProperty(node, "name", std::string()); + if (setName.empty()) + { + LOG_WARN("The " << filename << " file contains unamed " + << "<ability-set> tags and will be ignored."); + return; + } + + setName = utils::toLower(setName); + + for_each_xml_child_node(specialNode, node) + { + if (xmlStrEqual(specialNode->name, BAD_CAST "ability")) { + readAbilityNode(specialNode, setName); + } + } + +} + +/** + * Check the status of recently loaded configuration. + */ +void AbilityManager::checkStatus() +{ + LOG_INFO("Loaded " << mAbilitiesInfo.size() << " abilities"); +} + + +void AbilityManager::readAbilityNode(xmlNodePtr abilityNode, + const std::string &setName) +{ + std::string name = utils::toLower( + XML::getProperty(abilityNode, "name", std::string())); + int id = XML::getProperty(abilityNode, "id", 0); + + if (id <= 0 || name.empty()) + { + LOG_WARN("Invalid ability (empty name or id <= 0) in set: " << setName); + return; + } + + AbilitiesInfo::iterator it = mAbilitiesInfo.find(id); + if (it != mAbilitiesInfo.end()) + { + LOG_WARN("AbilityManager: The same id: " << id + << " is given for ability names: " << it->first + << " and " << name); + LOG_WARN("The ability reference: " << id + << ": '" << name << "' will be ignored."); + return; + } + + bool rechargeable = XML::getBoolProperty(abilityNode, "rechargeable", true); + int neededMana = XML::getProperty(abilityNode, "needed", 0); + int defaultRechargeSpeed = XML::getProperty(abilityNode, + "rechargespeed", 0); + + if (rechargeable && neededMana <= 0) + { + LOG_WARN("Invalid ability '" << name + << "' (rechargable but no needed attribute) in set: " + << setName); + return; + } + + + AbilityInfo *newInfo = new AbilityManager::AbilityInfo; + newInfo->setName = setName; + newInfo->name = name; + newInfo->id = id; + newInfo->rechargeable = rechargeable; + newInfo->neededPoints = neededMana; + newInfo->defaultRechargeSpeed = defaultRechargeSpeed; + + newInfo->target = getTargetByString(XML::getProperty(abilityNode, "target", + std::string())); + + mAbilitiesInfo[newInfo->id] = newInfo; + + std::string keyName = setName + "_" + newInfo->name; + mNamedAbilitiesInfo[keyName] = newInfo; +} + +void AbilityManager::initialize() +{ + clear(); +} + +void AbilityManager::reload() +{ + clear(); +} + +void AbilityManager::clear() +{ + for (AbilitiesInfo::iterator it = mAbilitiesInfo.begin(), + it_end = mAbilitiesInfo.end(); it != it_end; ++it) + { + delete it->second; + } + mAbilitiesInfo.clear(); + mNamedAbilitiesInfo.clear(); +} + +unsigned AbilityManager::getId(const std::string &set, + const std::string &name) const +{ + std::string key = utils::toLower(set) + "_" + utils::toLower(name); + return getId(key); +} + +unsigned AbilityManager::getId(const std::string &abilityName) const +{ + if (mNamedAbilitiesInfo.contains(abilityName)) + return mNamedAbilitiesInfo.value(abilityName)->id; + else + return 0; +} + +const std::string AbilityManager::getAbilityName(int id) const +{ + AbilitiesInfo::const_iterator it = mAbilitiesInfo.find(id); + return it != mAbilitiesInfo.end() ? it->second->name : ""; +} + +const std::string AbilityManager::getSetName(int id) const +{ + AbilitiesInfo::const_iterator it = mAbilitiesInfo.find(id); + return it != mAbilitiesInfo.end() ? it->second->setName : ""; +} + +AbilityManager::AbilityInfo *AbilityManager::getAbilityInfo(int id) +{ + AbilitiesInfo::const_iterator it = mAbilitiesInfo.find(id); + return it != mAbilitiesInfo.end() ? it->second : 0; +} diff --git a/src/game-server/specialmanager.h b/src/game-server/abilitymanager.h index b5ac874..969cd70 100644 --- a/src/game-server/specialmanager.h +++ b/src/game-server/abilitymanager.h @@ -19,8 +19,8 @@ */ -#ifndef SPECIALMANAGER_H -#define SPECIALMANAGER_H +#ifndef ABILITYMANAGER_H +#define ABILITYMANAGER_H #include "utils/string.h" #include "utils/xml.h" @@ -29,7 +29,7 @@ -class SpecialManager +class AbilityManager { public: enum TargetMode @@ -38,13 +38,13 @@ public: TARGET_POINT }; - struct SpecialInfo + struct AbilityInfo { - SpecialInfo() : + AbilityInfo() : id(0), rechargeable(false), defaultRechargeSpeed(0), - neededMana(0), + neededPoints(0), target(TARGET_BEING) {} @@ -53,65 +53,65 @@ public: std::string setName; bool rechargeable; int defaultRechargeSpeed; - unsigned neededMana; + unsigned neededPoints; TargetMode target; Script::Ref rechargedCallback; Script::Ref useCallback; }; - SpecialManager() + AbilityManager() { } - ~SpecialManager() + ~AbilityManager() { clear(); } /** - * Loads special reference file. + * Loads ability reference file. */ void initialize(); /** - * Reloads special reference file. + * Reloads ability reference file. */ void reload(); /** - * Gets the specials Id from a set and a special string. + * Gets the abilities Id from a set and a ability string. */ unsigned getId(const std::string &set, const std::string &name) const; /** - * Gets the specials Id from a string formatted in this way: - * "setname_skillname" + * Gets the abilities Id from a string formatted in this way: + * "setname_abilityname" */ - unsigned getId(const std::string &specialName) const; + unsigned getId(const std::string &abilityName) const; - const std::string getSpecialName(int id) const; + const std::string getAbilityName(int id) const; const std::string getSetName(int id) const; - SpecialInfo *getSpecialInfo(int id); + AbilityInfo *getAbilityInfo(int id); - void readSpecialSetNode(xmlNodePtr node, const std::string &filename); + void readAbilitySetNode(xmlNodePtr node, const std::string &filename); void checkStatus(); private: /** - * Clears up the special maps. + * Clears up the ability maps. */ void clear(); - void readSpecialNode(xmlNodePtr skillNode, + void readAbilityNode(xmlNodePtr skillNode, const std::string &setName); - typedef std::map<unsigned, SpecialInfo*> SpecialsInfo; - SpecialsInfo mSpecialsInfo; - typedef utils::NameMap<SpecialInfo*> NamedSpecialsInfo; - NamedSpecialsInfo mNamedSpecialsInfo; + typedef std::map<unsigned, AbilityInfo*> AbilitiesInfo; + AbilitiesInfo mAbilitiesInfo; + typedef utils::NameMap<AbilityInfo*> NamedAbilitiesInfo; + NamedAbilitiesInfo mNamedAbilitiesInfo; }; -extern SpecialManager *specialManager; +extern AbilityManager *abilityManager; -#endif // SPECIALMANAGER_H +#endif // ABILITYMANAGER_H diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 52cc73f..ce8c6ca 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -75,7 +75,7 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mClient(nullptr), mConnected(true), mTransactionHandler(nullptr), - mSpecialUpdateNeeded(false), + mAbilitiesUpdateNeeded(false), mDatabaseID(-1), mHairStyle(0), mHairColor(0), @@ -161,30 +161,30 @@ void CharacterComponent::update(Entity &entity) if (entity.getComponent<BeingComponent>()->getAction() == DEAD) return; - // Update special recharge - for (SpecialMap::iterator it = mSpecials.begin(), it_end = mSpecials.end(); - it != it_end; it++) + // Update ability recharge + for (auto &it : mAbilities) { - SpecialValue &s = it->second; - if (s.specialInfo->rechargeable && s.currentMana < s.specialInfo->neededMana) + AbilityValue &s = it.second; + if (s.abilityInfo->rechargeable && + s.currentPoints < s.abilityInfo->neededPoints) { - s.currentMana += s.rechargeSpeed; - if (s.currentMana >= s.specialInfo->neededMana && - s.specialInfo->rechargedCallback.isValid()) + s.currentPoints += s.rechargeSpeed; + if (s.currentPoints >= s.abilityInfo->neededPoints && + s.abilityInfo->rechargedCallback.isValid()) { Script *script = ScriptManager::currentState(); - script->prepare(s.specialInfo->rechargedCallback); + script->prepare(s.abilityInfo->rechargedCallback); script->push(&entity); - script->push(s.specialInfo->id); + script->push(s.abilityInfo->id); script->execute(entity.getMap()); } } } - if (mSpecialUpdateNeeded) + if (mAbilitiesUpdateNeeded) { - sendSpecialUpdate(); - mSpecialUpdateNeeded = false; + sendAbilityUpdate(); + mAbilitiesUpdateNeeded = false; } } @@ -225,130 +225,131 @@ void CharacterComponent::respawn(Entity &entity) Point(spawnX, spawnY)); } -bool CharacterComponent::specialUseCheck(SpecialMap::iterator it) +bool CharacterComponent::abilityUseCheck(AbilityMap::iterator it) { - if (it == mSpecials.end()) + if (it == mAbilities.end()) { - LOG_INFO("Character uses special " << it->first + LOG_INFO("Character uses ability " << it->first << " without authorization."); return false; } - //check if the special is currently recharged - SpecialValue &special = it->second; - if (special.specialInfo->rechargeable && - special.currentMana < special.specialInfo->neededMana) + //check if the ability is currently recharged + AbilityValue &ability = it->second; + if (ability.abilityInfo->rechargeable && + ability.currentPoints < ability.abilityInfo->neededPoints) { - LOG_INFO("Character uses special " << it->first << " which is not recharged. (" - << special.currentMana << "/" - << special.specialInfo->neededMana << ")"); + LOG_INFO("Character uses ability " << it->first + << " which is not recharged. (" + << ability.currentPoints << "/" + << ability.abilityInfo->neededPoints << ")"); return false; } - if (!special.specialInfo->useCallback.isValid()) + if (!ability.abilityInfo->useCallback.isValid()) { - LOG_WARN("No callback for use of special " - << special.specialInfo->setName << "/" - << special.specialInfo->name << ". Ignoring special."); + LOG_WARN("No callback for use of ability " + << ability.abilityInfo->setName << "/" + << ability.abilityInfo->name << ". Ignoring ability."); return false; } return true; } -void CharacterComponent::useSpecialOnBeing(Entity &user, int id, Entity *b) +void CharacterComponent::useAbilityOnBeing(Entity &user, int id, Entity *b) { - SpecialMap::iterator it = mSpecials.find(id); - if (!specialUseCheck(it)) + AbilityMap::iterator it = mAbilities.find(id); + if (!abilityUseCheck(it)) return; - SpecialValue &special = it->second; + AbilityValue &ability = it->second; - if (special.specialInfo->target != SpecialManager::TARGET_BEING) + if (ability.abilityInfo->target != AbilityManager::TARGET_BEING) return; //tell script engine to cast the spell Script *script = ScriptManager::currentState(); - script->prepare(special.specialInfo->useCallback); + script->prepare(ability.abilityInfo->useCallback); script->push(&user); script->push(b); - script->push(special.specialInfo->id); + script->push(ability.abilityInfo->id); script->execute(user.getMap()); } -void CharacterComponent::useSpecialOnPoint(Entity &user, int id, int x, int y) +void CharacterComponent::useAbilityOnPoint(Entity &user, int id, int x, int y) { - SpecialMap::iterator it = mSpecials.find(id); - if (!specialUseCheck(it)) + AbilityMap::iterator it = mAbilities.find(id); + if (!abilityUseCheck(it)) return; - SpecialValue &special = it->second; + AbilityValue &ability = it->second; - if (special.specialInfo->target != SpecialManager::TARGET_POINT) + if (ability.abilityInfo->target != AbilityManager::TARGET_POINT) return; //tell script engine to cast the spell Script *script = ScriptManager::currentState(); - script->prepare(special.specialInfo->useCallback); + script->prepare(ability.abilityInfo->useCallback); script->push(&user); script->push(x); script->push(y); - script->push(special.specialInfo->id); + script->push(ability.abilityInfo->id); script->execute(user.getMap()); } -bool CharacterComponent::giveSpecial(int id, int currentMana) +bool CharacterComponent::giveAbility(int id, int currentPoints) { - if (mSpecials.find(id) == mSpecials.end()) + if (mAbilities.find(id) == mAbilities.end()) { - const SpecialManager::SpecialInfo *specialInfo = - specialManager->getSpecialInfo(id); - if (!specialInfo) + const AbilityManager::AbilityInfo *abilityInfo = + abilityManager->getAbilityInfo(id); + if (!abilityInfo) { - LOG_ERROR("Tried to give not existing special id " << id << "."); + LOG_ERROR("Tried to give not existing ability id " << id << "."); return false; } - mSpecials.insert(std::pair<int, SpecialValue>( - id, SpecialValue(currentMana, specialInfo))); - mSpecialUpdateNeeded = true; + mAbilities.insert(std::pair<int, AbilityValue>( + id, AbilityValue(currentPoints, abilityInfo))); + mAbilitiesUpdateNeeded = true; return true; } return false; } -bool CharacterComponent::setSpecialMana(int id, int mana) +bool CharacterComponent::setAbilityMana(int id, int mana) { - SpecialMap::iterator it = mSpecials.find(id); - if (it != mSpecials.end()) + AbilityMap::iterator it = mAbilities.find(id); + if (it != mAbilities.end()) { - it->second.currentMana = mana; - mSpecialUpdateNeeded = true; + it->second.currentPoints = mana; + mAbilitiesUpdateNeeded = true; return true; } return false; } -bool CharacterComponent::setSpecialRechargeSpeed(int id, int speed) +bool CharacterComponent::setAbilityRechargeSpeed(int id, int speed) { - SpecialMap::iterator it = mSpecials.find(id); - if (it != mSpecials.end()) + AbilityMap::iterator it = mAbilities.find(id); + if (it != mAbilities.end()) { it->second.rechargeSpeed = speed; - mSpecialUpdateNeeded = true; + mAbilitiesUpdateNeeded = true; return true; } return false; } -void CharacterComponent::sendSpecialUpdate() +void CharacterComponent::sendAbilityUpdate() { - //GPMSG_SPECIAL_STATUS = 0x0293, - // { B specialID, L current, L max, L recharge } + //GPMSG_ABILITY_STATUS = 0x0293, + // { B abilityID, L current, L max, L recharge } - MessageOut msg(GPMSG_SPECIAL_STATUS); - for (SpecialMap::iterator it = mSpecials.begin(), it_end = mSpecials.end(); + MessageOut msg(GPMSG_ABILITY_STATUS); + for (AbilityMap::iterator it = mAbilities.begin(), it_end = mAbilities.end(); it != it_end; ++it) { msg.writeInt8(it->first); - msg.writeInt32(it->second.currentMana); - msg.writeInt32(it->second.specialInfo->neededMana); + msg.writeInt32(it->second.currentPoints); + msg.writeInt32(it->second.abilityInfo->neededPoints); msg.writeInt32(it->second.rechargeSpeed); } gameHandler->sendTo(mClient, msg); @@ -724,21 +725,21 @@ void CharacterComponent::disconnected(Entity &entity) signal_disconnected.emit(entity); } -bool CharacterComponent::takeSpecial(int id) +bool CharacterComponent::takeAbility(int id) { - SpecialMap::iterator i = mSpecials.find(id); - if (i != mSpecials.end()) + AbilityMap::iterator i = mAbilities.find(id); + if (i != mAbilities.end()) { - mSpecials.erase(i); - mSpecialUpdateNeeded = true; + mAbilities.erase(i); + mAbilitiesUpdateNeeded = true; return true; } return false; } -void CharacterComponent::clearSpecials() +void CharacterComponent::clearAbilities() { - mSpecials.clear(); + mAbilities.clear(); } void CharacterComponent::triggerLoginCallback(Entity &entity) diff --git a/src/game-server/character.h b/src/game-server/character.h index 704122d..d4dd0fd 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -28,7 +28,7 @@ #include "game-server/being.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" -#include "game-server/specialmanager.h" +#include "game-server/abilitymanager.h" #include "scripting/script.h" @@ -46,24 +46,24 @@ class MessageOut; class Point; class Trade; -struct SpecialValue +struct AbilityValue { - SpecialValue(unsigned currentMana, - const SpecialManager::SpecialInfo *specialInfo) - : currentMana(currentMana) - , rechargeSpeed(specialInfo->defaultRechargeSpeed) - , specialInfo(specialInfo) + AbilityValue(unsigned currentMana, + const AbilityManager::AbilityInfo *abilityInfo) + : currentPoints(currentMana) + , rechargeSpeed(abilityInfo->defaultRechargeSpeed) + , abilityInfo(abilityInfo) {} - unsigned currentMana; + unsigned currentPoints; unsigned rechargeSpeed; - const SpecialManager::SpecialInfo *specialInfo; + const AbilityManager::AbilityInfo *abilityInfo; }; /** - * Stores specials by their id. + * Stores abilities by their id. */ -typedef std::map<unsigned, SpecialValue> SpecialMap; +typedef std::map<unsigned, AbilityValue> AbilityMap; class CharacterData @@ -114,11 +114,11 @@ public: const std::map<int, int>::const_iterator getKillCountEnd() const; void setKillCount(int monsterId, int kills); - void clearSpecials(); - void giveSpecial(int id, int mana); - int getSpecialSize() const; - SpecialMap::const_iterator getSpecialBegin() const; - SpecialMap::const_iterator getSpecialEnd() const; + void clearAbilities(); + void giveAbility(int id, int mana); + int getAbilitySize() const; + AbilityMap::const_iterator getAbilityBegin() const; + AbilityMap::const_iterator getAbilityEnd() const; Possessions &getPossessions() const; @@ -162,52 +162,52 @@ class CharacterComponent : public Component void respawn(Entity &entity); /** - * makes the character perform a special action on a being + * makes the character perform a ability on a being * when it is allowed to do so */ - void useSpecialOnBeing(Entity &user, int id, Entity *b); + void useAbilityOnBeing(Entity &user, int id, Entity *b); /** - * makes the character perform a special action on a map point + * makes the character perform a ability on a map point * when it is allowed to do so */ - void useSpecialOnPoint(Entity &user, int id, int x, int y); + void useAbilityOnPoint(Entity &user, int id, int x, int y); /** - * Allows a character to perform a special action + * Allows a character to perform a ability */ - bool giveSpecial(int id, int currentMana = 0); + bool giveAbility(int id, int currentMana = 0); /** * Sets new current mana + makes sure that the client will get informed. */ - bool setSpecialMana(int id, int mana); + bool setAbilityMana(int id, int mana); /** - * Gets the special value by id + * Gets the ability value by id */ - SpecialMap::iterator findSpecial(int id) - { return mSpecials.find(id); } + AbilityMap::iterator findAbility(int id) + { return mAbilities.find(id); } /** - * Sets recharge speed of a special + * Sets recharge speed of a ability */ - bool setSpecialRechargeSpeed(int id, int speed); + bool setAbilityRechargeSpeed(int id, int speed); /** - * Removes all specials from character + * Removes all abilities from character */ - void clearSpecials(); + void clearAbilities(); /** - * Checks if a character knows a special action + * Checks if a character knows a ability action */ - bool hasSpecial(int id) { return mSpecials.find(id) != mSpecials.end(); } + bool hasAbility(int id) { return mAbilities.find(id) != mAbilities.end(); } /** - * Removes an available special action + * Removes an available ability action */ - bool takeSpecial(int id); + bool takeAbility(int id); /** * Gets client computer. @@ -356,16 +356,16 @@ class CharacterComponent : public Component { mKillCount[monsterId] = kills; } /** - * Used to serialize specials. + * Used to serialize abilities. */ - int getSpecialSize() const - { return mSpecials.size(); } + int getAbilitiesSize() const + { return mAbilities.size(); } - const SpecialMap::const_iterator getSpecialBegin() const - { return mSpecials.begin(); } + const AbilityMap::const_iterator getAbilitiesBegin() const + { return mAbilities.begin(); } - const SpecialMap::const_iterator getSpecialEnd() const - { return mSpecials.end(); } + const AbilityMap::const_iterator getAbilitiesEnd() const + { return mAbilities.end(); } /** * Gets total accumulated exp for skill. @@ -470,7 +470,7 @@ class CharacterComponent : public Component sigc::signal<void, Entity &> signal_disconnected; private: - bool specialUseCheck(SpecialMap::iterator it); + bool abilityUseCheck(AbilityMap::iterator it); double getAttrBase(AttributeMap::const_iterator it) const { return it->second.getBase(); } @@ -509,9 +509,9 @@ class CharacterComponent : public Component void recalculateLevel(Entity &entity); /** - * Informs the client about his characters special charge status + * Informs the client about his characters abilities charge status */ - void sendSpecialUpdate(); + void sendAbilityUpdate(); enum TransactionType { TRANS_NONE, TRANS_TRADE, TRANS_BUYSELL }; @@ -535,8 +535,8 @@ class CharacterComponent : public Component std::map<int, int> mExperience; /**< experience collected for each skill.*/ - SpecialMap mSpecials; - bool mSpecialUpdateNeeded; + AbilityMap mAbilities; + bool mAbilitiesUpdateNeeded; int mDatabaseID; /**< Character's database ID. */ unsigned char mHairStyle; /**< Hair Style of the character. */ @@ -744,29 +744,29 @@ inline void CharacterData::setKillCount(int monsterId, int kills) mCharacterComponent->setKillCount(monsterId, kills); } -inline void CharacterData::clearSpecials() +inline void CharacterData::clearAbilities() { - mCharacterComponent->clearSpecials(); + mCharacterComponent->clearAbilities(); } -inline void CharacterData::giveSpecial(int id, int mana) +inline void CharacterData::giveAbility(int id, int mana) { - mCharacterComponent->giveSpecial(id, mana); + mCharacterComponent->giveAbility(id, mana); } -inline int CharacterData::getSpecialSize() const +inline int CharacterData::getAbilitySize() const { - return mCharacterComponent->getSpecialSize(); + return mCharacterComponent->getAbilitiesSize(); } -inline SpecialMap::const_iterator CharacterData::getSpecialBegin() const +inline AbilityMap::const_iterator CharacterData::getAbilityBegin() const { - return mCharacterComponent->getSpecialBegin(); + return mCharacterComponent->getAbilitiesBegin(); } -inline SpecialMap::const_iterator CharacterData::getSpecialEnd() const +inline AbilityMap::const_iterator CharacterData::getAbilityEnd() const { - return mCharacterComponent->getSpecialEnd(); + return mCharacterComponent->getAbilitiesEnd(); } inline Possessions &CharacterData::getPossessions() const diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 4c210bf..c93aeee 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -32,7 +32,7 @@ #include "game-server/mapmanager.h" #include "game-server/monster.h" #include "game-server/monstermanager.h" -#include "game-server/specialmanager.h" +#include "game-server/abilitymanager.h" #include "game-server/state.h" #include "scripting/scriptmanager.h" @@ -82,10 +82,10 @@ static void handleCraft(Entity*, std::string&); static void handleGetPos(Entity*, std::string&); static void handleSkills(Entity*, std::string&); static void handleEffect(Entity*, std::string&); -static void handleGiveSpecial(Entity*, std::string&); -static void handleTakeSpecial(Entity*, std::string&); -static void handleRechargeSpecial(Entity*, std::string&); -static void handleListSpecials(Entity*, std::string&); +static void handleGiveAbility(Entity*, std::string&); +static void handleTakeAbility(Entity*, std::string&); +static void handleRechargeAbility(Entity*, std::string&); +static void handleListAbility(Entity*, std::string&); static CmdRef const cmdRef[] = { @@ -153,20 +153,20 @@ static CmdRef const cmdRef[] = "Shows an effect at the given position or on the given being. " "The player's character is targeted if neither of them is provided.", &handleEffect}, - {"givespecial", "<character> <special>", - "Gives the character the special. " - "The special can get passed as specialid or in the format " - "<setname>_<specialname>", &handleGiveSpecial}, - {"takespecial", "<character> <special>", - "Takes the special aways from the character. " - "The special can get passed as specialid or in the format " - "<setname>_<specialname>", &handleTakeSpecial}, - {"rechargespecial", "<character> <special>", - "Recharges the special of the character. " - "The special can get passed as specialid or in the format " - "<setname>_<specialname>", &handleRechargeSpecial}, - {"listspecials", "<character>", - "Lists the specials of the character.", &handleListSpecials}, + {"giveability", "<character> <ability>", + "Gives the character the ability. " + "The ability can get passed as abilityid or in the format " + "<setname>_<abilityname>", &handleGiveAbility}, + {"takeability", "<character> <ability>", + "Takes the ability aways from the character. " + "The ability can get passed as abilityid or in the format " + "<setname>_<abilityname>", &handleTakeAbility}, + {"rechargeability", "<character> <ability>", + "Recharges the ability of the character. " + "The ability can get passed as abilityid or in the format " + "<setname>_<abilityname>", &handleRechargeAbility}, + {"listabilities", "<character>", + "Lists the abilitys of the character.", &handleListAbility}, {nullptr, nullptr, nullptr, nullptr} }; @@ -1602,14 +1602,14 @@ static void handleEffect(Entity *player, std::string &args) } } -static void handleGiveSpecial(Entity *player, std::string &args) +static void handleGiveAbility(Entity *player, std::string &args) { std::string character = getArgument(args); - std::string special = getArgument(args); - if (character.empty() || special.empty()) + std::string ability = getArgument(args); + if (character.empty() || ability.empty()) { say("Invalid amount of arguments given.", player); - say("Usage: @givespecial <character> <special>", player); + say("Usage: @giveability <character> <ability>", player); return; } @@ -1625,28 +1625,28 @@ static void handleGiveSpecial(Entity *player, std::string &args) return; } - int specialId; - if (utils::isNumeric(special)) - specialId = utils::stringToInt(special); + int abilityId; + if (utils::isNumeric(ability)) + abilityId = utils::stringToInt(ability); else - specialId = specialManager->getId(special); + abilityId = abilityManager->getId(ability); - if (specialId <= 0 || - !other->getComponent<CharacterComponent>()->giveSpecial(specialId)) + if (abilityId <= 0 || + !other->getComponent<CharacterComponent>()->giveAbility(abilityId)) { - say("Invalid special.", player); + say("Invalid ability.", player); return; } } -static void handleTakeSpecial(Entity *player, std::string &args) +static void handleTakeAbility(Entity *player, std::string &args) { std::string character = getArgument(args); - std::string special = getArgument(args); - if (character.empty() || special.empty()) + std::string ability = getArgument(args); + if (character.empty() || ability.empty()) { say("Invalid amount of arguments given.", player); - say("Usage: @takespecial <character> <special>", player); + say("Usage: @takeability <character> <ability>", player); return; } @@ -1662,33 +1662,33 @@ static void handleTakeSpecial(Entity *player, std::string &args) return; } - int specialId; - if (utils::isNumeric(special)) - specialId = utils::stringToInt(special); + int abilityId; + if (utils::isNumeric(ability)) + abilityId = utils::stringToInt(ability); else - specialId = specialManager->getId(special); + abilityId = abilityManager->getId(ability); - if (specialId <= 0) + if (abilityId <= 0) { - say("Invalid special.", player); + say("Invalid ability.", player); return; } - if (!other->getComponent<CharacterComponent>()->takeSpecial(specialId)) + if (!other->getComponent<CharacterComponent>()->takeAbility(abilityId)) { - say("Character does not have special.", player); + say("Character does not have ability.", player); return; } } -static void handleRechargeSpecial(Entity *player, std::string &args) +static void handleRechargeAbility(Entity *player, std::string &args) { std::string character = getArgument(args); - std::string special = getArgument(args); + std::string ability = getArgument(args); std::string newMana = getArgument(args); - if (character.empty() || special.empty()) + if (character.empty() || ability.empty()) { say("Invalid amount of arguments given.", player); - say("Usage: @rechargespecial <character> <special> [<mana>]", player); + say("Usage: @rechargeability <character> <ability> [<mana>]", player); return; } @@ -1704,24 +1704,24 @@ static void handleRechargeSpecial(Entity *player, std::string &args) return; } - int specialId; - if (utils::isNumeric(special)) - specialId = utils::stringToInt(special); + int abilityId; + if (utils::isNumeric(ability)) + abilityId = utils::stringToInt(ability); else - specialId = specialManager->getId(special); + abilityId = abilityManager->getId(ability); - SpecialManager::SpecialInfo *info = - specialManager->getSpecialInfo(specialId); + AbilityManager::AbilityInfo *info = + abilityManager->getAbilityInfo(abilityId); if (!info) { - say("Invalid special.", player); + say("Invalid ability.", player); return; } int mana; if (newMana.empty()) { - mana = info->neededMana; + mana = info->neededPoints; } else { @@ -1733,20 +1733,20 @@ static void handleRechargeSpecial(Entity *player, std::string &args) mana = utils::stringToInt(newMana); } if (!other->getComponent<CharacterComponent>() - ->setSpecialMana(specialId, mana)) + ->setAbilityMana(abilityId, mana)) { - say("Character does not have special.", player); + say("Character does not have ability.", player); return; } } -static void handleListSpecials(Entity *player, std::string &args) +static void handleListAbility(Entity *player, std::string &args) { std::string character = getArgument(args); if (character.empty()) { say("Invalid amount of arguments given.", player); - say("Usage: @listspecials <character>", player); + say("Usage: @listabilitys <character>", player); return; } @@ -1765,15 +1765,15 @@ static void handleListSpecials(Entity *player, std::string &args) auto *characterComponent = other->getComponent<CharacterComponent>(); - say("Specials of character " + + say("Abilityies of character " + other->getComponent<BeingComponent>()->getName() + ":", player); - for (SpecialMap::const_iterator it = characterComponent->getSpecialBegin(), - it_end = characterComponent->getSpecialEnd(); it != it_end; ++it) + for (AbilityMap::const_iterator it = characterComponent->getAbilitiesBegin(), + it_end = characterComponent->getAbilitiesEnd(); it != it_end; ++it) { - const SpecialValue &info = it->second; + const AbilityValue &info = it->second; std::stringstream str; - str << info.specialInfo->id << ": " << info.specialInfo->setName << "/" - << info.specialInfo->name << " charge: " << info.currentMana; + str << info.abilityInfo->id << ": " << info.abilityInfo->setName << "/" + << info.abilityInfo->name << " charge: " << info.currentPoints; say(str.str(), player); } } diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 79a14c6..2740284 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -258,12 +258,12 @@ void GameHandler::processMessage(NetComputer *computer, MessageIn &message) handleAttack(client, message); break; - case PGMSG_USE_SPECIAL_ON_BEING: - handleUseSpecialOnBeing(client, message); + case PGMSG_USE_ABILITY_ON_BEING: + handleUseAbilityOnBeing(client, message); break; - case PGMSG_USE_SPECIAL_ON_POINT: - handleUseSpecialOnPoint(client, message); + case PGMSG_USE_ABILITY_ON_POINT: + handleUseAbilityOnPoint(client, message); break; case PGMSG_ACTION_CHANGE: @@ -687,12 +687,12 @@ void GameHandler::handleAttack(GameClient &client, MessageIn &message) } } -void GameHandler::handleUseSpecialOnBeing(GameClient &client, MessageIn &message) +void GameHandler::handleUseAbilityOnBeing(GameClient &client, MessageIn &message) { if (client.character->getComponent<BeingComponent>()->getAction() == DEAD) return; - const int specialID = message.readInt8(); + const int abilityID = message.readInt8(); const int targetID = message.readInt16(); // 0 when no target is selected Entity *being = 0; if (targetID != 0) @@ -701,28 +701,28 @@ void GameHandler::handleUseSpecialOnBeing(GameClient &client, MessageIn &message const int publicId = client.character->getComponent<ActorComponent>()->getPublicID(); LOG_DEBUG("Character " << publicId - << " tries to use his special attack " << specialID); + << " tries to use his ability " << abilityID); auto *characterComponent = client.character ->getComponent<CharacterComponent>(); - characterComponent->useSpecialOnBeing(*client.character, specialID, being); + characterComponent->useAbilityOnBeing(*client.character, abilityID, being); } -void GameHandler::handleUseSpecialOnPoint(GameClient &client, MessageIn &message) +void GameHandler::handleUseAbilityOnPoint(GameClient &client, MessageIn &message) { if (client.character->getComponent<BeingComponent>()->getAction() == DEAD) return; - const int specialID = message.readInt8(); + const int abilityID = message.readInt8(); const int x = message.readInt16(); const int y = message.readInt16(); const int publicId = client.character->getComponent<ActorComponent>()->getPublicID(); LOG_DEBUG("Character " << publicId - << " tries to use his special attack " << specialID); + << " tries to use his ability attack " << abilityID); auto *characterComponent = client.character ->getComponent<CharacterComponent>(); - characterComponent->useSpecialOnPoint(*client.character, specialID, x, y); + characterComponent->useAbilityOnPoint(*client.character, abilityID, x, y); } void GameHandler::handleActionChange(GameClient &client, MessageIn &message) diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h index d66caf5..0abc287 100644 --- a/src/game-server/gamehandler.h +++ b/src/game-server/gamehandler.h @@ -135,8 +135,8 @@ class GameHandler: public ConnectionHandler void handleMoveItem(GameClient &client, MessageIn &message); void handleAttack(GameClient &client, MessageIn &message); - void handleUseSpecialOnBeing(GameClient &client, MessageIn &message); - void handleUseSpecialOnPoint(GameClient &client, MessageIn &message); + void handleUseAbilityOnBeing(GameClient &client, MessageIn &message); + void handleUseAbilityOnPoint(GameClient &client, MessageIn &message); void handleActionChange(GameClient &client, MessageIn &message); void handleDirectionChange(GameClient &client, MessageIn &message); diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index 894af5f..1a9f0af 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -31,7 +31,7 @@ #include "game-server/mapmanager.h" #include "game-server/monstermanager.h" #include "game-server/skillmanager.h" -#include "game-server/specialmanager.h" +#include "game-server/abilitymanager.h" #include "game-server/statusmanager.h" #include "game-server/postman.h" #include "game-server/state.h" @@ -78,11 +78,11 @@ static bool running = true; /**< Whether the server keeps running */ utils::StringFilter *stringFilter; /**< Slang's Filter */ +AbilityManager *abilityManager = new AbilityManager(); AttributeManager *attributeManager = new AttributeManager(); ItemManager *itemManager = new ItemManager(); MonsterManager *monsterManager = new MonsterManager(); SkillManager *skillManager = new SkillManager(); -SpecialManager *specialManager = new SpecialManager(); EmoteManager *emoteManager = new EmoteManager(); SettingsManager *settingsManager = new SettingsManager(DEFAULT_SETTINGS_FILE); @@ -185,7 +185,7 @@ static void deinitializeServer() // Destroy Managers delete stringFilter; stringFilter = 0; delete monsterManager; monsterManager = 0; - delete skillManager; skillManager = 0; + delete abilityManager; abilityManager = 0; delete itemManager; itemManager = 0; delete emoteManager; emoteManager = 0; delete settingsManager; settingsManager = 0; diff --git a/src/game-server/settingsmanager.cpp b/src/game-server/settingsmanager.cpp index b45ef93..b909fb6 100644 --- a/src/game-server/settingsmanager.cpp +++ b/src/game-server/settingsmanager.cpp @@ -25,11 +25,11 @@ #include "common/resourcemanager.h" -#include "game-server/mapmanager.h" +#include "game-server/abilitymanager.h" #include "game-server/attributemanager.h" #include "game-server/skillmanager.h" -#include "game-server/specialmanager.h" #include "game-server/itemmanager.h" +#include "game-server/mapmanager.h" #include "game-server/monstermanager.h" #include "game-server/emotemanager.h" #include "game-server/statusmanager.h" @@ -45,7 +45,7 @@ void SettingsManager::initialize() MapManager::initialize(); attributeManager->initialize(); skillManager->initialize(); - specialManager->initialize(); + abilityManager->initialize(); itemManager->initialize(); monsterManager->initialize(); emoteManager->initialize(); @@ -66,7 +66,7 @@ void SettingsManager::reload() MapManager::reload(); attributeManager->reload(); skillManager->reload(); - specialManager->reload(); + abilityManager->reload(); itemManager->reload(); monsterManager->reload(); emoteManager->reload(); @@ -143,10 +143,10 @@ void SettingsManager::loadFile(const std::string &filename) // skills config skillManager->readSkillSetNode(childNode, filename); } - else if (xmlStrEqual(childNode->name, BAD_CAST "special-set")) + else if (xmlStrEqual(childNode->name, BAD_CAST "ability-set")) { - // special config - specialManager->readSpecialSetNode(childNode, filename); + // ability config + abilityManager->readAbilitySetNode(childNode, filename); } else if (xmlStrEqual(childNode->name, BAD_CAST "slot")) { @@ -192,7 +192,7 @@ void SettingsManager::checkStatus() MapManager::checkStatus(); attributeManager->checkStatus(); skillManager->checkStatus(); - specialManager->checkStatus(); + abilityManager->checkStatus(); itemManager->checkStatus(); monsterManager->checkStatus(); emoteManager->checkStatus(); diff --git a/src/game-server/specialmanager.cpp b/src/game-server/specialmanager.cpp deleted file mode 100644 index 0840d25..0000000 --- a/src/game-server/specialmanager.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * Copyright (C) 2010-2012 The Mana Developers - * - * This file is part of The Mana Server. - * - * The Mana Server 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. - * - * The Mana Server 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 The Mana Server. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "specialmanager.h" - -#include "utils/xml.h" -#include "utils/logger.h" - -static SpecialManager::TargetMode getTargetByString(const std::string &str) -{ - std::string strLower = utils::toLower(str); - if (strLower == "being") - return SpecialManager::TARGET_BEING; - else if (strLower == "point") - return SpecialManager::TARGET_POINT; - - LOG_WARN("Unknown targetmode " << str << " assuming being."); - return SpecialManager::TARGET_BEING; -} - - -/** - * Read a <special> element from settings. - * Used by SettingsManager. - */ -void SpecialManager::readSpecialSetNode(xmlNodePtr node, const std::string &filename) -{ - std::string setName = XML::getProperty(node, "name", std::string()); - if (setName.empty()) - { - LOG_WARN("The " << filename << " file contains unamed <set> tags and will be ignored."); - return; - } - - setName = utils::toLower(setName); - - for_each_xml_child_node(specialNode, node) - { - if (xmlStrEqual(specialNode->name, BAD_CAST "special")) { - readSpecialNode(specialNode, setName); - } - } - -} - -/** - * Check the status of recently loaded configuration. - */ -void SpecialManager::checkStatus() -{ - LOG_INFO("Loaded " << mSpecialsInfo.size() << " specials"); -} - -void SpecialManager::readSpecialNode(xmlNodePtr specialNode, - const std::string &setName) -{ - std::string name = utils::toLower( - XML::getProperty(specialNode, "name", std::string())); - int id = XML::getProperty(specialNode, "id", 0); - - if (id <= 0 || name.empty()) - { - LOG_WARN("Invalid special (empty name or id <= 0) in set: " << setName); - return; - } - - SpecialsInfo::iterator it = mSpecialsInfo.find(id); - if (it != mSpecialsInfo.end()) - { - LOG_WARN("SpecialManager: The same id: " << id - << " is given for special names: " << it->first - << " and " << name); - LOG_WARN("The special reference: " << id - << ": '" << name << "' will be ignored."); - return; - } - - bool rechargeable = XML::getBoolProperty(specialNode, "rechargeable", true); - int neededMana = XML::getProperty(specialNode, "needed", 0); - int defaultRechargeSpeed = XML::getProperty(specialNode, - "rechargespeed", 0); - - if (rechargeable && neededMana <= 0) - { - LOG_WARN("Invalid special '" << name - << "' (rechargable but no needed attribute) in set: " - << setName); - return; - } - - - SpecialInfo *newInfo = new SpecialManager::SpecialInfo; - newInfo->setName = setName; - newInfo->name = name; - newInfo->id = id; - newInfo->rechargeable = rechargeable; - newInfo->neededMana = neededMana; - newInfo->defaultRechargeSpeed = defaultRechargeSpeed; - - newInfo->target = getTargetByString(XML::getProperty(specialNode, "target", - std::string())); - - mSpecialsInfo[newInfo->id] = newInfo; - - std::string keyName = setName + "_" + newInfo->name; - mNamedSpecialsInfo[keyName] = newInfo; -} - -void SpecialManager::initialize() -{ - clear(); -} - -void SpecialManager::reload() -{ - clear(); -} - -void SpecialManager::clear() -{ - for (SpecialsInfo::iterator it = mSpecialsInfo.begin(), - it_end = mSpecialsInfo.end(); it != it_end; ++it) - { - delete it->second; - } - mSpecialsInfo.clear(); - mNamedSpecialsInfo.clear(); -} - -unsigned SpecialManager::getId(const std::string &set, - const std::string &name) const -{ - std::string key = utils::toLower(set) + "_" + utils::toLower(name); - return getId(key); -} - -unsigned SpecialManager::getId(const std::string &specialName) const -{ - if (mNamedSpecialsInfo.contains(specialName)) - return mNamedSpecialsInfo.value(specialName)->id; - else - return 0; -} - -const std::string SpecialManager::getSpecialName(int id) const -{ - SpecialsInfo::const_iterator it = mSpecialsInfo.find(id); - return it != mSpecialsInfo.end() ? it->second->name : ""; -} - -const std::string SpecialManager::getSetName(int id) const -{ - SpecialsInfo::const_iterator it = mSpecialsInfo.find(id); - return it != mSpecialsInfo.end() ? it->second->setName : ""; -} - -SpecialManager::SpecialInfo *SpecialManager::getSpecialInfo(int id) -{ - SpecialsInfo::const_iterator it = mSpecialsInfo.find(id); - return it != mSpecialsInfo.end() ? it->second : 0; -} |