summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-12-28 00:47:49 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-12-28 00:47:49 +0100
commit61420bdc4aa951e6b57a1b6bec37729e1cb1824e (patch)
treec95a5becf48280c215b1f1c98b53e617709d637d /src
parentedcc60717dd6d3765e9c48ca469df0fa91c259d3 (diff)
downloadmanaserv-61420bdc4aa951e6b57a1b6bec37729e1cb1824e.tar.gz
manaserv-61420bdc4aa951e6b57a1b6bec37729e1cb1824e.tar.bz2
manaserv-61420bdc4aa951e6b57a1b6bec37729e1cb1824e.tar.xz
manaserv-61420bdc4aa951e6b57a1b6bec37729e1cb1824e.zip
Added support for skill names as weapon types in items.xml (still hardcoded)
Diffstat (limited to 'src')
-rw-r--r--src/game-server/itemmanager.cpp8
-rw-r--r--src/game-server/main-game.cpp3
-rw-r--r--src/game-server/skillmanager.cpp61
-rw-r--r--src/game-server/skillmanager.hpp48
4 files changed, 118 insertions, 2 deletions
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 #"<<id<<" - treating it as generic item");
+ } else {
+ weaponType = SkillManager::getIdFromString(strWeaponType);
}
modifiers.setValue(MOD_WEAPON_TYPE, weaponType);
modifiers.setValue(MOD_WEAPON_RANGE, XML::getProperty(node, "range", 0));
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 0f898f7f..5e132fc5 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -38,6 +38,7 @@
#include "common/configuration.hpp"
#include "game-server/accountconnection.hpp"
#include "game-server/gamehandler.hpp"
+#include "game-server/skillmanager.hpp"
#include "game-server/itemmanager.hpp"
#include "game-server/mapmanager.hpp"
#include "game-server/monstermanager.hpp"
@@ -60,6 +61,7 @@ using utils::Logger;
#define DEFAULT_LOG_FILE "manaserv-game.log"
#define DEFAULT_CONFIG_FILE "manaserv.xml"
#define DEFAULT_ITEMSDB_FILE "items.xml"
+#define DEFAULT_SKILLSDB_FILE "mana-skills.xml"
#define DEFAULT_MAPSDB_FILE "maps.xml"
#define DEFAULT_MONSTERSDB_FILE "monsters.xml"
#define DEFAULT_STATUSDB_FILE "mana-status-effect.xml"
@@ -161,6 +163,7 @@ void initialize()
LOG_FATAL("The Game Server can't find any valid/available maps.");
exit(2);
}
+ SkillManager::initialize(DEFAULT_SKILLSDB_FILE);
ItemManager::initialize(DEFAULT_ITEMSDB_FILE);
MonsterManager::initialize(DEFAULT_MONSTERSDB_FILE);
StatusManager::initialize(DEFAULT_STATUSDB_FILE);
diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp
new file mode 100644
index 00000000..8cf88e55
--- /dev/null
+++ b/src/game-server/skillmanager.cpp
@@ -0,0 +1,61 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "game-server/skillmanager.hpp"
+
+#include "utils/string.hpp" // for the toupper function
+
+#include <map>
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef SKILLMANAGER_H
+#define SKILLMANAGER_H
+
+#include <string>
+
+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