From 61420bdc4aa951e6b57a1b6bec37729e1cb1824e Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Mon, 28 Dec 2009 00:47:49 +0100 Subject: Added support for skill names as weapon types in items.xml (still hardcoded) --- src/game-server/itemmanager.cpp | 8 ++++-- src/game-server/main-game.cpp | 3 ++ src/game-server/skillmanager.cpp | 61 ++++++++++++++++++++++++++++++++++++++++ src/game-server/skillmanager.hpp | 48 +++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/game-server/skillmanager.cpp create mode 100644 src/game-server/skillmanager.hpp (limited to 'src') diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 8abf857f..a53327eb 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -26,6 +26,7 @@ #include "defines.h" #include "game-server/item.hpp" #include "game-server/resourcemanager.hpp" +#include "game-server/skillmanager.hpp" #include "scripting/script.hpp" #include "utils/logger.h" #include "utils/xml.hpp" @@ -140,11 +141,14 @@ void ItemManager::reload() if (itemType == ITEM_EQUIPMENT_ONE_HAND_WEAPON || itemType == ITEM_EQUIPMENT_TWO_HANDS_WEAPON) { - int weaponType = XML::getProperty(node, "weapon-type", 0); - if (weaponType == 0) + int weaponType = 0; + std::string strWeaponType = XML::getProperty(node, "weapon-type", ""); + if (strWeaponType == "") { LOG_WARN(itemReferenceFile<<": Unknown weapon type \"" <<"\" for item #"<. + */ + +#include "game-server/skillmanager.hpp" + +#include "utils/string.hpp" // for the toupper function + +#include + +typedef std::map< std::string, int > SkillMap; +static SkillMap skillMap; +static std::string skillReferenceFile; + +void SkillManager::initialize(const std::string &file) +{ + skillReferenceFile = file; + reload(); +} + +void SkillManager::reload() +{ + //... + skillMap["UNARMED"] = 100; + skillMap["KNIFE"] = 101; +} + +int SkillManager::getIdFromString(std::string name) +{ + //check if already an integer, if yes just return it + int val; + val = atoi(name.c_str()); + if (val) return val; + + // convert to upper case for easier finding + name = utils::toupper(name); + // find it + SkillMap::iterator i = skillMap.find(name); + if (i == skillMap.end()) + { + return 0; + } else { + return i->second; + } +} diff --git a/src/game-server/skillmanager.hpp b/src/game-server/skillmanager.hpp new file mode 100644 index 00000000..25dd9597 --- /dev/null +++ b/src/game-server/skillmanager.hpp @@ -0,0 +1,48 @@ +/* + * The Mana Server + * Copyright (C) 2004 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 . + */ + + +#ifndef SKILLMANAGER_H +#define SKILLMANAGER_H + +#include + +namespace SkillManager +{ + /** + * Loads skill reference file. + */ + void initialize(const std::string &); + + /** + * Reloads skill reference file. + */ + void reload(); + + /** + * Gets the skill ID of a skill string + * (not case-sensitive to reduce wall-bashing) + */ + int getIdFromString(std::string name); // no, thorbjorn, I am not passing this as const reference. I need a local copy. +} + + + +#endif // SKILLMANAGER_H -- cgit v1.2.3-70-g09d2