diff options
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/accountconnection.cpp | 11 | ||||
-rw-r--r-- | src/game-server/accountconnection.h | 10 | ||||
-rw-r--r-- | src/game-server/being.cpp | 1 | ||||
-rw-r--r-- | src/game-server/character.cpp | 162 | ||||
-rw-r--r-- | src/game-server/character.h | 115 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 49 | ||||
-rw-r--r-- | src/game-server/itemmanager.cpp | 1 | ||||
-rw-r--r-- | src/game-server/main-game.cpp | 2 | ||||
-rw-r--r-- | src/game-server/monster.h | 14 | ||||
-rw-r--r-- | src/game-server/monstermanager.cpp | 13 | ||||
-rw-r--r-- | src/game-server/settingsmanager.cpp | 9 | ||||
-rw-r--r-- | src/game-server/skillmanager.cpp | 201 | ||||
-rw-r--r-- | src/game-server/skillmanager.h | 103 |
13 files changed, 1 insertions, 690 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index e52393bd..06674780 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -476,17 +476,6 @@ void AccountConnection::updateAttributes(int charId, int attrId, double base, syncChanges(); } -void AccountConnection::updateExperience(int charId, int skillId, - int skillValue) -{ - ++mSyncMessages; - mSyncBuffer->writeInt8(SYNC_CHARACTER_SKILL); - mSyncBuffer->writeInt32(charId); - mSyncBuffer->writeInt8(skillId); - mSyncBuffer->writeInt32(skillValue); - syncChanges(); -} - void AccountConnection::updateOnlineStatus(int charId, bool online) { ++mSyncMessages; diff --git a/src/game-server/accountconnection.h b/src/game-server/accountconnection.h index 2ad79dd2..f6ef8678 100644 --- a/src/game-server/accountconnection.h +++ b/src/game-server/accountconnection.h @@ -141,16 +141,6 @@ class AccountConnection : public Connection double mod); /** - * Write a modification message about character skills to the sync - * buffer. - * - * @param charId ID of the character - * @param skillId ID of the skill - * @param skillValue new skill points - */ - void updateExperience(int charId, int skillId, int skillValue); - - /** * Update the status of a character to online (true) or offline * (false). * diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index b4feda9c..b49e3cba 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -29,7 +29,6 @@ #include "game-server/collisiondetection.h" #include "game-server/mapcomposite.h" #include "game-server/effect.h" -#include "game-server/skillmanager.h" #include "game-server/statuseffect.h" #include "game-server/statusmanager.h" #include "utils/logger.h" diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index a8d29625..e4a30a2f 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -31,7 +31,6 @@ #include "game-server/map.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" -#include "game-server/skillmanager.h" #include "game-server/state.h" #include "game-server/trade.h" #include "scripting/scriptmanager.h" @@ -46,12 +45,6 @@ #include <cmath> #include <limits.h> -// Experience curve related values -const float CharacterComponent::EXPCURVE_EXPONENT = 3.0f; -const float CharacterComponent::EXPCURVE_FACTOR = 10.0f; -const float CharacterComponent::LEVEL_SKILL_PRECEDENCE_FACTOR = 0.75f; -const float CharacterComponent::EXP_LEVEL_FLEXIBILITY = 1.0f; - Script::Ref CharacterComponent::mDeathCallback; Script::Ref CharacterComponent::mDeathAcceptedCallback; Script::Ref CharacterComponent::mLoginCallback; @@ -76,10 +69,6 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mDatabaseID(-1), mHairStyle(0), mHairColor(0), - mLevel(1), - mLevelProgress(0), - mUpdateLevelProgress(false), - mRecalculateLevel(true), mSendAbilityCooldown(false), mParty(0), mTransaction(TRANS_NONE), @@ -133,13 +122,6 @@ CharacterComponent::~CharacterComponent() void CharacterComponent::update(Entity &entity) { - // Update character level if needed. - if (mRecalculateLevel) - { - mRecalculateLevel = false; - recalculateLevel(entity); - } - // Dead character: don't regenerate anything else if (entity.getComponent<BeingComponent>()->getAction() == DEAD) return; @@ -304,27 +286,6 @@ void CharacterComponent::sendStatus(Entity &entity) } if (attribMsg.getLength() > 2) gameHandler->sendTo(mClient, attribMsg); mModifiedAttributes.clear(); - - MessageOut expMsg(GPMSG_PLAYER_EXP_CHANGE); - for (std::set<size_t>::const_iterator i = mModifiedExperience.begin(), - i_end = mModifiedExperience.end(); i != i_end; ++i) - { - int skill = *i; - expMsg.writeInt16(skill); - expMsg.writeInt32(getExpGot(skill)); - expMsg.writeInt32(getExpNeeded(skill)); - expMsg.writeInt16(levelForExp(getExperience(skill))); - } - if (expMsg.getLength() > 2) gameHandler->sendTo(mClient, expMsg); - mModifiedExperience.clear(); - - if (mUpdateLevelProgress) - { - mUpdateLevelProgress = false; - MessageOut progressMessage(GPMSG_LEVEL_PROGRESS); - progressMessage.writeInt8(mLevelProgress); - gameHandler->sendTo(mClient, progressMessage); - } } void CharacterComponent::modifiedAllAttributes(Entity &entity) @@ -350,55 +311,6 @@ void CharacterComponent::attributeChanged(Entity *entity, unsigned attr) mModifiedAttributes.insert(attr); } -int CharacterComponent::expForLevel(int level) -{ - return int(pow(level, EXPCURVE_EXPONENT) * EXPCURVE_FACTOR); -} - -int CharacterComponent::levelForExp(int exp) -{ - return int(pow(float(exp) / EXPCURVE_FACTOR, 1.0f / EXPCURVE_EXPONENT)); -} - -void CharacterComponent::receiveExperience(int skill, int experience, int optimalLevel) -{ - // reduce experience when skill is over optimal level - int levelOverOptimum = levelForExp(getExperience(skill)) - optimalLevel; - if (optimalLevel && levelOverOptimum > 0) - { - experience *= EXP_LEVEL_FLEXIBILITY - / (levelOverOptimum + EXP_LEVEL_FLEXIBILITY); - } - - // Add exp - int oldExp = mExperience[skill]; - long int newExp = mExperience[skill] + experience; - if (newExp < 0) - newExp = 0; // Avoid integer underflow/negative exp. - - // Check the skill cap - long int maxSkillCap = Configuration::getValue("game_maxSkillCap", INT_MAX); - assert(maxSkillCap <= INT_MAX); // Avoid integer overflow. - if (newExp > maxSkillCap) - { - newExp = maxSkillCap; - if (oldExp != maxSkillCap) - { - LOG_INFO("Player hit the skill cap"); - // TODO: Send a message to player letting them know they hit the cap - // or not? - } - } - mExperience[skill] = newExp; - mModifiedExperience.insert(skill); - - // Inform account server - if (newExp != oldExp) - accountHandler->updateExperience(getDatabaseID(), skill, newExp); - - mRecalculateLevel = true; -} - void CharacterComponent::incrementKillCount(int monsterType) { std::map<int, int>::iterator i = mKillCount.find(monsterType); @@ -422,80 +334,6 @@ int CharacterComponent::getKillCount(int monsterType) const return 0; } - -void CharacterComponent::recalculateLevel(Entity &entity) -{ - std::list<float> levels; - std::map<int, int>::const_iterator a; - for (a = getSkillBegin(); a != getSkillEnd(); a++) - { - // Only use the first 1000 skill levels in calculation - if (a->first < 1000) - { - float expGot = getExpGot(a->first); - float expNeed = getExpNeeded(a->first); - levels.push_back(levelForExp(a->first) + expGot / expNeed); - } - } - levels.sort(); - - std::list<float>::iterator i = levels.end(); - float level = 0.0f; - float factor = 1.0f; - float factorSum = 0.0f; - while (i != levels.begin()) - { - i--; - level += *i * factor; - factorSum += factor; - factor *= LEVEL_SKILL_PRECEDENCE_FACTOR; - } - level /= factorSum; - level += 1.0f; // + 1.0f because the lowest level is 1 and not 0 - - while (mLevel < level) - { - levelup(entity); - } - - int levelProgress = int((level - floor(level)) * 100); - if (levelProgress != mLevelProgress) - { - mLevelProgress = levelProgress; - mUpdateLevelProgress = true; - } -} - -int CharacterComponent::getExpNeeded(size_t skill) const -{ - int level = levelForExp(getExperience(skill)); - return CharacterComponent::expForLevel(level + 1) - expForLevel(level); -} - -int CharacterComponent::getExpGot(size_t skill) const -{ - int level = levelForExp(getExperience(skill)); - return mExperience.at(skill) - CharacterComponent::expForLevel(level); -} - -void CharacterComponent::levelup(Entity &entity) -{ - mLevel++; - - mCharacterPoints += CHARPOINTS_PER_LEVELUP; - mCorrectionPoints += CORRECTIONPOINTS_PER_LEVELUP; - if (mCorrectionPoints > CORRECTIONPOINTS_MAX) - mCorrectionPoints = CORRECTIONPOINTS_MAX; - - MessageOut levelupMsg(GPMSG_LEVELUP); - levelupMsg.writeInt16(mLevel); - levelupMsg.writeInt16(mCharacterPoints); - levelupMsg.writeInt16(mCorrectionPoints); - gameHandler->sendTo(mClient, levelupMsg); - LOG_INFO(entity.getComponent<BeingComponent>()->getName() - << " reached level " << mLevel); -} - AttribmodResponseCode CharacterComponent::useCharacterPoint(Entity &entity, int attribute) { diff --git a/src/game-server/character.h b/src/game-server/character.h index b5d923e6..162235ad 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -69,10 +69,6 @@ public: void setCorrectionPoints(int correctionPoints); int getCorrectionPoints() const; - void setExperience(int skill, int level); - void setLevel(int level) const; - int getLevel() const; - int getAccountLevel() const; void setHairStyle(int style); @@ -82,10 +78,6 @@ public: void setAccountLevel(int level); - int getSkillSize() const; - const std::map<int, int>::const_iterator getSkillBegin() const; - const std::map<int, int>::const_iterator getSkillEnd() const; - void applyStatusEffect(int status, int time); int getStatusEffectSize() const; const std::map<int, Status>::const_iterator getStatusEffectBegin() const; @@ -127,7 +119,7 @@ class CharacterComponent : public Component ~CharacterComponent(); /** - * recalculates the level when necessary and calls Being::update + * calls Being::update and handles special recharges and status effects */ void update(Entity &entity); @@ -213,9 +205,6 @@ class CharacterComponent : public Component int getHairColor() const { return mHairColor; } void setHairColor(int color) { mHairColor = color; } - int getLevel() const { return mLevel; } - void setLevel(int level) { mLevel = level; } - int getAccountLevel() const { return mAccountLevel; } void setAccountLevel(int l) { mAccountLevel = l; } @@ -258,21 +247,6 @@ class CharacterComponent : public Component std::map< std::string, std::string > questCache; /** - * Gives a skill a specific amount of exp and checks if a levelup - * occured. - */ - void receiveExperience(int skill, int experience, int optimalLevel); - - int getSkillSize() const - { return mExperience.size(); } - - const std::map<int, int>::const_iterator getSkillBegin() const - { return mExperience.begin(); } - - const std::map<int, int>::const_iterator getSkillEnd() const - { return mExperience.end(); } - - /** * Used to serialize kill count. */ int getKillCountSize() const @@ -288,18 +262,6 @@ class CharacterComponent : public Component { mKillCount[monsterId] = kills; } /** - * Gets total accumulated exp for skill. - */ - int getExperience(int skill) const - { return mExperience.find(skill)->second; } - - /** - * Sets total accumulated exp for skill. - */ - void setExperience(int skill, int value) - { mExperience[skill] = 0; receiveExperience(skill, value, 0); } - - /** * Adds one kill of the monster type to the characters kill count. */ void incrementKillCount(int monsterType); @@ -310,16 +272,6 @@ class CharacterComponent : public Component int getKillCount(int monsterType) const; /** - * Returns the exp needed to reach a specific skill level - */ - static int expForLevel(int level); - - /** - * Returns the level for a given exp - */ - static int levelForExp(int exp); - - /** * Tries to use a character point to increase a * basic attribute */ @@ -395,34 +347,6 @@ class CharacterComponent : public Component CharacterComponent(const CharacterComponent &); CharacterComponent &operator=(const CharacterComponent &); - static const float EXPCURVE_EXPONENT; - static const float EXPCURVE_FACTOR; - static const float LEVEL_SKILL_PRECEDENCE_FACTOR; // I am taking suggestions for a better name - static const float EXP_LEVEL_FLEXIBILITY; - static const int CHARPOINTS_PER_LEVELUP = 5; - static const int CORRECTIONPOINTS_PER_LEVELUP = 2; - static const int CORRECTIONPOINTS_MAX = 10; - - /** - * Advances the character by one level; - */ - void levelup(Entity &entity); - - /** - * Returns the exp needed for next skill levelup - */ - int getExpNeeded(size_t skill) const; - - /** - * Returns the exp collected on this skill level - */ - int getExpGot(size_t skill) const; - - /** - * Recalculates the character level - */ - void recalculateLevel(Entity &entity); - void abilityStatusChanged(int id); void abilityCooldownActivated(); @@ -451,21 +375,14 @@ class CharacterComponent : public Component /** Attributes modified since last update. */ std::set<size_t> mModifiedAttributes; - std::set<size_t> mModifiedExperience; - - std::map<int, int> mExperience; /**< experience collected for each skill.*/ std::set<unsigned> mModifiedAbilities; int mDatabaseID; /**< Character's database ID. */ unsigned char mHairStyle; /**< Hair Style of the character. */ unsigned char mHairColor; /**< Hair Color of the character. */ - int mLevel; /**< Level of the character. */ - int mLevelProgress; /**< progress to next level in percent */ int mCharacterPoints; /**< Unused attribute points that can be distributed */ int mCorrectionPoints; /**< Unused attribute correction points */ - bool mUpdateLevelProgress; /**< Flag raised when percent to next level changed */ - bool mRecalculateLevel; /**< Flag raised when the character level might have increased */ bool mSendAbilityCooldown; unsigned char mAccountLevel; /**< Account level of the user. */ int mParty; /**< Party id of the character */ @@ -562,21 +479,6 @@ inline int CharacterData::getCorrectionPoints() const return mCharacterComponent->getCorrectionPoints(); } -inline void CharacterData::setExperience(int skill, int level) -{ - mCharacterComponent->setExperience(skill, level); -} - -inline void CharacterData::setLevel(int level) const -{ - mCharacterComponent->setLevel(level); -} - -inline int CharacterData::getLevel() const -{ - return mCharacterComponent->getLevel(); -} - inline int CharacterData::getAccountLevel() const { return mCharacterComponent->getAccountLevel(); @@ -607,21 +509,6 @@ inline void CharacterData::setAccountLevel(int level) mCharacterComponent->setAccountLevel(level); } -inline int CharacterData::getSkillSize() const -{ - return mCharacterComponent->getSkillSize(); -} - -inline const std::map<int, int>::const_iterator CharacterData::getSkillBegin() const -{ - return mCharacterComponent->getSkillBegin(); -} - -inline const std::map<int, int>::const_iterator CharacterData::getSkillEnd() const -{ - return mCharacterComponent->getSkillEnd(); -} - inline void CharacterData::applyStatusEffect(int status, int time) { mEntity->getComponent<BeingComponent>()->applyStatusEffect(status, time); diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index e54b9eaf..3cdb2f43 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -80,7 +80,6 @@ static void handleLogsay(Entity*, std::string&); static void handleKillMonsters(Entity*, std::string&); 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 handleGiveAbility(Entity*, std::string&); static void handleTakeAbility(Entity*, std::string&); @@ -147,8 +146,6 @@ static CmdRef const cmdRef[] = "Crafts something.", &handleCraft}, {"getpos", "<character>", "Gets the position of a character.", &handleGetPos}, - {"skills", "<character>", - "Lists all skills and their values of a character", &handleSkills}, {"effect", "<effectid> <x> <y> / <effectid> <being> / <effectid>", "Shows an effect at the given position or on the given being. " "The player's character is targeted if neither of them is provided.", @@ -1516,52 +1513,6 @@ static void handleGetPos(Entity *player, std::string &args) say(str.str(), player); } -static void handleSkills(Entity *player, std::string &args) -{ - std::string character = getArgument(args); - if (character.empty()) - { - say("Invalid amount of arguments given.", player); - say("Usage: @skills <character>", player); - return; - } - Entity *other; - if (character == "#") - other = player; - else - other = gameHandler->getCharacterByNameSlow(character); - if (!other) - { - say("Invalid character, or player is offline.", player); - return; - } - - - auto *characterComponent = - player->getComponent<CharacterComponent>(); - - say("List of skills of player '" + - other->getComponent<BeingComponent>()->getName() + "':", player); - std::map<int, int>::const_iterator it = - characterComponent->getSkillBegin(); - std::map<int, int>::const_iterator it_end = - characterComponent->getSkillEnd(); - - if (it == it_end) - { - say("No skills available.", player); - return; - } - - while (it != it_end) - { - std::stringstream str; - str << "Id: " << it->first << " value: " << it->second; - say(str.str(), player); - ++it; - } -} - static void handleEffect(Entity *player, std::string &args) { std::vector<std::string> arguments; diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 0362c5d9..bcb64072 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -24,7 +24,6 @@ #include "common/resourcemanager.h" #include "game-server/attributemanager.h" #include "game-server/item.h" -#include "game-server/skillmanager.h" #include "scripting/script.h" #include "scripting/scriptmanager.h" #include "utils/logger.h" diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index 7d053bf9..7b78bc21 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -30,7 +30,6 @@ #include "game-server/itemmanager.h" #include "game-server/mapmanager.h" #include "game-server/monstermanager.h" -#include "game-server/skillmanager.h" #include "game-server/abilitymanager.h" #include "game-server/statusmanager.h" #include "game-server/postman.h" @@ -82,7 +81,6 @@ AbilityManager *abilityManager = new AbilityManager(); AttributeManager *attributeManager = new AttributeManager(); ItemManager *itemManager = new ItemManager(); MonsterManager *monsterManager = new MonsterManager(); -SkillManager *skillManager = new SkillManager(); EmoteManager *emoteManager = new EmoteManager(); SettingsManager *settingsManager = new SettingsManager(DEFAULT_SETTINGS_FILE); diff --git a/src/game-server/monster.h b/src/game-server/monster.h index ae798efc..e50f7451 100644 --- a/src/game-server/monster.h +++ b/src/game-server/monster.h @@ -67,7 +67,6 @@ class MonsterClass mGender(GENDER_UNSPECIFIED), mSpeed(1), mSize(16), - mExp(-1), mMutation(0), mOptimalLevel(0) {} @@ -118,18 +117,6 @@ class MonsterClass /** Returns collision circle radius. */ int getSize() const { return mSize; } - /** Sets experience reward for killing the monster. */ - void setExp(int exp) { mExp = exp; } - - /** Returns experience reward for killing the monster. */ - int getExp() const { return mExp; } - - /** Gets maximum skill level after which exp reward is reduced */ - void setOptimalLevel(int level) { mOptimalLevel = level; } - - /** Sets maximum skill level after which exp reward is reduced. */ - int getOptimalLevel() const { return mOptimalLevel; } - /** Sets mutation factor in percent. */ void setMutation(unsigned factor) { mMutation = factor; } @@ -155,7 +142,6 @@ class MonsterClass std::set<AbilityManager::AbilityInfo *> mAbilities; float mSpeed; /**< The monster class speed in tiles per second */ int mSize; - int mExp; int mMutation; int mOptimalLevel; diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index 0043cdb4..327c5c10 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -216,22 +216,9 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam monster->addAbility(info); } - else if (xmlStrEqual(subnode->name, BAD_CAST "exp")) - { - xmlChar *exp = subnode->xmlChildrenNode->content; - monster->setExp(atoi((const char*)exp)); - monster->setOptimalLevel(XML::getProperty(subnode, "level", 0)); - } } monster->setDrops(drops); - if (monster->getExp() == -1) - { - LOG_WARN(filename - << ": No experience defined for monster Id:" << monsterId - << " (" << name << ")"); - monster->setExp(0); - } } /** diff --git a/src/game-server/settingsmanager.cpp b/src/game-server/settingsmanager.cpp index 75aea3ce..29c4f214 100644 --- a/src/game-server/settingsmanager.cpp +++ b/src/game-server/settingsmanager.cpp @@ -27,7 +27,6 @@ #include "game-server/abilitymanager.h" #include "game-server/attributemanager.h" -#include "game-server/skillmanager.h" #include "game-server/itemmanager.h" #include "game-server/mapmanager.h" #include "game-server/monstermanager.h" @@ -44,7 +43,6 @@ void SettingsManager::initialize() // initialize all managers in correct order MapManager::initialize(); attributeManager->initialize(); - skillManager->initialize(); abilityManager->initialize(); itemManager->initialize(); monsterManager->initialize(); @@ -65,7 +63,6 @@ void SettingsManager::reload() { MapManager::reload(); attributeManager->reload(); - skillManager->reload(); abilityManager->reload(); itemManager->reload(); monsterManager->reload(); @@ -138,11 +135,6 @@ void SettingsManager::loadFile(const std::string &filename) // attribute config attributeManager->readAttributeNode(childNode); } - else if (xmlStrEqual(childNode->name, BAD_CAST "skill-set")) - { - // skills config - skillManager->readSkillSetNode(childNode, filename); - } else if (xmlStrEqual(childNode->name, BAD_CAST "ability-category")) { // ability config @@ -191,7 +183,6 @@ void SettingsManager::checkStatus() { MapManager::checkStatus(); attributeManager->checkStatus(); - skillManager->checkStatus(); abilityManager->checkStatus(); itemManager->checkStatus(); monsterManager->checkStatus(); diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp deleted file mode 100644 index 8ebe18f2..00000000 --- a/src/game-server/skillmanager.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * 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 "game-server/skillmanager.h" - -#include "utils/logger.h" - -#include <map> - -void SkillManager::clear() -{ - for (SkillsInfo::iterator it = mSkillsInfo.begin(), - it_end = mSkillsInfo.end(); it != it_end; ++it) - { - delete it->second; - } - - mSkillsInfo.clear(); - mNamedSkillsInfo.clear(); - mDefaultSkillId = 0; -} - -void SkillManager::initialize() -{ - clear(); -} - -void SkillManager::reload() -{ - initialize(); -} - -/** - * Read a <skill-set> element from settings. - * Used by SettingsManager. - */ -void SkillManager::readSkillSetNode(xmlNodePtr node, const std::string& filename) -{ - std::string setName = XML::getProperty(node, "name", std::string()); - if (setName.empty()) - { - LOG_WARN("The " << filename << " file is containing unamed <skill-set> " - "tags and will be ignored."); - return; - } - - setName = utils::toLower(setName); - - for_each_xml_child_node(skillNode, node) - { - if (xmlStrEqual(skillNode->name, BAD_CAST "skill")) { - readSkillNode(skillNode, setName); - } - } -} - -/** - * Check the status of recently loaded configuration. - */ -void SkillManager::checkStatus() -{ - printDebugSkillTable(); - - if (!mDefaultSkillId) - LOG_WARN("SkillManager: No default weapon-type id was given during " - "Skill map loading. " - "Players won't be able to earn XP when unarmed."); - - LOG_INFO("Loaded " << mSkillsInfo.size() << " skills"); -} - -void SkillManager::readSkillNode(xmlNodePtr skillNode, - const std::string& setName) -{ - if (!xmlStrEqual(skillNode->name, BAD_CAST "skill")) - return; - - SkillInfo *skillInfo = new SkillInfo; - skillInfo->setName = setName; - skillInfo->skillName = utils::toLower( - XML::getProperty(skillNode, "name", std::string())); - int id = XML::getProperty(skillNode, "id", 0); - - if (id <= 0 || skillInfo->skillName.empty()) - { - LOG_WARN("Invalid skill (empty name or id <= 0) in set: " << setName); - return; - } - skillInfo->id = (unsigned)id; - - SkillsInfo::iterator it = mSkillsInfo.find(skillInfo->id); - if (it != mSkillsInfo.end()) - { - LOG_WARN("SkillManager: The same id: " << skillInfo->id - << " is given for skill names: " << it->first - << " and " << skillInfo->skillName); - LOG_WARN("The skill reference: " << skillInfo->id - << ": '" << skillInfo->skillName << "' will be ignored."); - return; - } - - if (XML::getBoolProperty(skillNode, "default", false)) - { - if (mDefaultSkillId) - { - LOG_WARN("SkillManager: " - "Default Skill id already defined as " - << mDefaultSkillId - << ". Redefinit it as: " << skillInfo->id); - } - else - { - LOG_INFO("SkillManager: Defining skill id: " << skillInfo->id - << " as default weapon-type id."); - } - mDefaultSkillId = skillInfo->id; - } - - mSkillsInfo.insert(std::make_pair(skillInfo->id, skillInfo)); - - std::string keyName = setName + "_" + skillInfo->skillName; - mNamedSkillsInfo.insert(keyName, skillInfo); -} - -void SkillManager::printDebugSkillTable() -{ - if (::utils::Logger::mVerbosity >= ::utils::Logger::Debug) - { - std::string lastSet; - LOG_DEBUG("Skill map:" - << std::endl << "-----"); - for (SkillsInfo::iterator it = mSkillsInfo.begin(); - it != mSkillsInfo.end(); ++it) - { - if (!lastSet.compare(it->second->setName)) - { - lastSet = it->second->setName; - LOG_DEBUG("Skill set: " << lastSet); - } - - if (it->first == mDefaultSkillId) - { - LOG_DEBUG("'" << it->first << "': " << it->second->skillName - << " (Default)"); - } - else - { - LOG_DEBUG("'" << it->first << "': " << it->second->skillName); - } - } - LOG_DEBUG("-----"); - } -} - -unsigned SkillManager::getId(const std::string &set, - const std::string &name) const -{ - std::string key = utils::toLower(set) + "_" + utils::toLower(name); - return getId(key); -} - -unsigned SkillManager::getId(const std::string &skillName) const -{ - SkillInfo *skillInfo = mNamedSkillsInfo.value(skillName); - return skillInfo ? skillInfo->id : 0; -} - -const std::string SkillManager::getSkillName(unsigned id) const -{ - SkillsInfo::const_iterator it = mSkillsInfo.find(id); - return it != mSkillsInfo.end() ? it->second->skillName : ""; -} - -const std::string SkillManager::getSetName(unsigned id) const -{ - SkillsInfo::const_iterator it = mSkillsInfo.find(id); - return it != mSkillsInfo.end() ? it->second->setName : ""; -} - -bool SkillManager::exists(unsigned id) const -{ - SkillsInfo::const_iterator it = mSkillsInfo.find(id); - return it != mSkillsInfo.end(); -} diff --git a/src/game-server/skillmanager.h b/src/game-server/skillmanager.h deleted file mode 100644 index 12828fe4..00000000 --- a/src/game-server/skillmanager.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * 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/>. - */ - - -#ifndef SKILLMANAGER_H -#define SKILLMANAGER_H - -#include "utils/string.h" -#include "utils/xml.h" - -class SkillManager -{ - public: - SkillManager(): - mDefaultSkillId(0) - {} - - ~SkillManager() - { clear(); } - - /** - * Loads skill reference file. - */ - void initialize(); - - /** - * Reloads skill reference file. - */ - void reload(); - - /** - * Gets the skill Id from a set and a skill string. - */ - unsigned getId(const std::string &set, const std::string &name) const; - - /** - * Gets the skill Id from a string formatted in this way: - * "setname_skillname" - */ - unsigned getId(const std::string &skillName) const; - - const std::string getSkillName(unsigned id) const; - const std::string getSetName(unsigned id) const; - - bool exists(unsigned id) const; - - unsigned getDefaultSkillId() const - { return mDefaultSkillId; } - - void readSkillSetNode(xmlNodePtr node, const std::string &filename); - - void checkStatus(); - - private: - struct SkillInfo { - SkillInfo(): - id(0) - {} - - unsigned id; - std::string setName; - std::string skillName; - }; - - /* - * Clears up the skill maps. - */ - void clear(); - - void printDebugSkillTable(); - - void readSkillNode(xmlNodePtr skillNode, const std::string& setName); - - // The skill map - typedef std::map<unsigned, SkillInfo*> SkillsInfo; - SkillsInfo mSkillsInfo; - // A map used to get skills per name. - utils::NameMap<SkillInfo*> mNamedSkillsInfo; - - // The default skill id - unsigned mDefaultSkillId; -}; - -extern SkillManager *skillManager; - -#endif // SKILLMANAGER_H |