summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2006-10-19 02:43:26 +0000
committerYohann Ferreira <bertram@cegetel.net>2006-10-19 02:43:26 +0000
commitc38af49bd66095b581e7eca10a91e100391201c3 (patch)
tree9fefeb60de43b3a8be3c21be965f3045088defeb /src
parentb5857d43bfc4ac08ed99cb02a149d6cb63f13862 (diff)
downloadmanaserv-c38af49bd66095b581e7eca10a91e100391201c3.tar.gz
manaserv-c38af49bd66095b581e7eca10a91e100391201c3.tar.bz2
manaserv-c38af49bd66095b581e7eca10a91e100391201c3.tar.xz
manaserv-c38af49bd66095b581e7eca10a91e100391201c3.zip
Added a backend to get item reference information. The xml file isn't ready yet.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/being.h92
-rw-r--r--src/dalstorage.cpp26
-rw-r--r--src/item.cpp22
-rw-r--r--src/item.h102
-rw-r--r--src/itemmanager.cpp193
-rw-r--r--src/itemmanager.h89
-rw-r--r--src/main.cpp47
-rw-r--r--src/player.cpp12
9 files changed, 502 insertions, 85 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 40631398..fbd3bd8b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,8 +43,8 @@ tmwserv_SOURCES = main.cpp \
inventory.cpp \
item.h \
item.cpp \
- itemhandler.h \
- itemhandler.cpp \
+ itemmanager.h \
+ itemmanager.cpp \
map.h \
map.cpp \
mapcomposite.h \
diff --git a/src/being.h b/src/being.h
index 2782a265..fb6e837a 100644
--- a/src/being.h
+++ b/src/being.h
@@ -33,15 +33,83 @@
class Controller;
/**
+ * Element attribute for beings, actors and items.
+ */
+typedef enum {
+ ELEMENT_NEUTRAL = 0,
+ ELEMENT_FIRE,
+ ELEMENT_WATER,
+ ELEMENT_EARTH,
+ ELEMENT_AIR,
+ ELEMENT_SACRED,
+ ELEMENT_DEATH
+} Element;
+
+/**
+ * States attribute for beings, and actors.
+ * States can be multiple for the same being.
+ */
+struct BeingState {
+ bool STATE_NORMAL;
+ bool STATE_POISONED;
+ bool STATE_STONED;
+ bool STATE_STUNNED;
+ bool STATE_SLOWED;
+ bool STATE_TIRED;
+ bool STATE_MAD;
+ bool STATE_BERSERK;
+ bool STATE_HASTED;
+ bool STATE_FLOATING;
+};
+
+/**
+ * Moves enum for beings and actors for others players vision.
+ */
+typedef enum {
+ ACTION_DEFAULT = 0,
+ ACTION_STAND,
+ ACTION_WALK,
+ ACTION_RUN,
+ ACTION_JUMP,
+ ACTION_CRAWL,
+ ACTION_ATTACK,
+ ACTION_ATTACK_SWING,
+ ACTION_ATTACK_STAB,
+ ACTION_ATTACK_BOW,
+ ACTION_ATTACK_THROW,
+ ACTION_CAST_MAGIC,
+ ACTION_USE_ITEM,
+ ACTION_SIT,
+ ACTION_SLEEP,
+ ACTION_HURT,
+ ACTION_DEAD,
+ ACTION_INVALID
+} SpriteAction;
+
+/**
+ * Beings and actors directions
+ */
+typedef enum {
+ DIRECTION_NORTH,
+ DIRECTION_NORTHWEST,
+ DIRECTION_NORTHEAST,
+ DIRECTION_WEST,
+ DIRECTION_EAST,
+ DIRECTION_SOUTH,
+ DIRECTION_SOUTHWEST,
+ DIRECTION_SOUTHEAST
+} SpriteDirection;
+
+/**
* Raw statistics of a Player.
*/
enum {
- STAT_STR = 0,
- STAT_AGI,
- STAT_VIT,
- STAT_INT,
- STAT_DEX,
- STAT_LUK,
+ STAT_STRENGTH = 0,
+ STAT_AGILITY,
+ STAT_VITALITY,
+ STAT_INTELLIGENCE,
+ STAT_DEXTERITY,
+ STAT_LUCK,
NB_RSTAT
};
@@ -57,12 +125,12 @@ struct RawStatistics
* Computed statistics of a Being.
*/
enum {
- STAT_HEA = 0,
- STAT_ATT,
- STAT_DEF,
- STAT_MAG,
- STAT_ACC,
- STAT_SPD,
+ STAT_HEAT = 0,
+ STAT_ATTACK,
+ STAT_DEFENCE,
+ STAT_MAGIC,
+ STAT_ACCURACY,
+ STAT_SPEED,
NB_CSTAT
};
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 87387352..44e702ef 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -645,12 +645,12 @@ void DALStorage::flush(AccountPtr const &account)
<< (*it)->getPosition().x << ", "
<< (*it)->getPosition().y << ", "
<< (*it)->getMapId() << ", "
- << (*it)->getRawStat(STAT_STR) << ", "
- << (*it)->getRawStat(STAT_AGI) << ", "
- << (*it)->getRawStat(STAT_VIT) << ", "
- << (*it)->getRawStat(STAT_INT) << ", "
- << (*it)->getRawStat(STAT_DEX) << ", "
- << (*it)->getRawStat(STAT_LUK) << ");";
+ << (*it)->getRawStat(STAT_STRENGTH) << ", "
+ << (*it)->getRawStat(STAT_AGILITY) << ", "
+ << (*it)->getRawStat(STAT_VITALITY) << ", "
+ << (*it)->getRawStat(STAT_INTELLIGENCE) << ", "
+ << (*it)->getRawStat(STAT_DEXTERITY) << ", "
+ << (*it)->getRawStat(STAT_LUCK) << ");";
// get the character id
std::ostringstream sql2;
@@ -677,16 +677,16 @@ void DALStorage::flush(AccountPtr const &account)
<< " x = " << (*it)->getPosition().x << ", "
<< " y = " << (*it)->getPosition().y << ", "
<< " map_id = " << (*it)->getMapId() << ", "
- << " str = " << (*it)->getRawStat(STAT_STR) << ", "
- << " agi = " << (*it)->getRawStat(STAT_AGI) << ", "
- << " vit = " << (*it)->getRawStat(STAT_VIT) << ", "
+ << " str = " << (*it)->getRawStat(STAT_STRENGTH) << ", "
+ << " agi = " << (*it)->getRawStat(STAT_AGILITY) << ", "
+ << " vit = " << (*it)->getRawStat(STAT_VITALITY) << ", "
#if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT)
- << " `int` = " << (*it)->getRawStat(STAT_INT) << ", "
+ << " `int` = " << (*it)->getRawStat(STAT_INTELLIGENCE) << ", "
#else
- << " int = " << (*it)->getRawStat(STAT_INT) << ", "
+ << " int = " << (*it)->getRawStat(STAT_INTELLIGENCE) << ", "
#endif
- << " dex = " << (*it)->getRawStat(STAT_DEX) << ", "
- << " luck = " << (*it)->getRawStat(STAT_LUK)
+ << " dex = " << (*it)->getRawStat(STAT_DEXTERITY) << ", "
+ << " luck = " << (*it)->getRawStat(STAT_LUCK)
<< " where id = " << (*it)->getDatabaseID() << ";";
}
mDb->execSql(sql3.str());
diff --git a/src/item.cpp b/src/item.cpp
index b0008134..660fa7b7 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -23,12 +23,26 @@
#include "item.h"
-void Item::use(BeingPtr itemUser)
+bool Item::use(BeingPtr itemUser)
{
- //
+ bool usedSuccessfully = true;
+ // Applying Modifiers for a given lifetime
+ // TODO
+
+ // Calling a script if scriptName != ""
+ if (mScriptName != "")
+ {
+ if(runScript(itemUser) && usedSuccessfully)
+ return true;
+ else
+ return false;
+ }
+ else
+ return usedSuccessfully;
}
-void Item::useWithScript(const std::string scriptFile)
+bool Item::runScript(BeingPtr itemUser)
{
- //
+ //TODO
+ return true;
}
diff --git a/src/item.h b/src/item.h
index 302c4f6a..2015a029 100644
--- a/src/item.h
+++ b/src/item.h
@@ -29,9 +29,12 @@
/**
* Enumeration of available Item types.
*/
-enum {
- ITEM_USABLE = 0,
- ITEM_EQUIPMENT_WEAPON,
+typedef enum {
+ ITEM_USABLE = 1,
+ ITEM_EQUIPMENT_ONE_HAND_WEAPON,
+ ITEM_EQUIPMENT_TWO_HANDS_WEAPON,
+ ITEM_EQUIPMENT_ONE_HAND_RANGED_WEAPON,
+ ITEM_EQUIPMENT_TWO_HANDS_RANGED_WEAPON,
ITEM_EQUIPMENT_BREST,
ITEM_EQUIPMENT_ARMS,
ITEM_EQUIPMENT_HEAD,
@@ -39,19 +42,57 @@ enum {
ITEM_EQUIPMENT_SHIELD,
ITEM_EQUIPMENT_RING,
ITEM_EQUIPMENT_NECKLACE
+} ItemType;
+
+/**
+ * States attribute effects to beings, and actors.
+ * States can be multiple for the same being.
+ */
+struct BeingStateEffects {
+ bool STATE_NORMAL;
+ bool STATE_POISONED;
+ bool STATE_STONED;
+ bool STATE_STUNNED;
+ bool STATE_SLOWED;
+ bool STATE_TIRED;
+ bool STATE_MAD;
+ bool STATE_BERSERK;
+ bool STATE_HASTED;
+ bool STATE_FLOATING;
+
+ bool STATE_NOT_POISONED;
+ bool STATE_NOT_STONED;
+ bool STATE_NOT_STUNNED;
+ bool STATE_NOT_SLOWED;
+ bool STATE_NOT_TIRED;
+ bool STATE_NOT_MAD;
+ bool STATE_NOT_BERSERK;
+ bool STATE_NOT_HASTED;
+ bool STATE_NOT_FLOATING;
};
+
/**
* statistics modifiers.
* once for usables.
* Permanent for equipment.
*/
-struct StatisticsModifiers
+struct Modifiers
{
- short rawStatsMod[NB_RSTAT]; /**< Raw Stats modifiers */
- short compStatsMod[NB_CSTAT]; /**< Computed Stats modifiers */
+ // General
+ Element element; /** Item Element */
+ BeingStateEffects beingStateEffects; /** Being State (dis)alteration */
+ unsigned short lifetime; /** Modifiers lifetime in seconds. */
+
+ // Caracteristics Modifiers
+ short rawStats[NB_RSTAT];
+ short computedStats[NB_CSTAT];
+
int hpMod; /**< HP modifier */
int mpMod; /**< MP Modifier */
+
+ // Equipment
+ unsigned short range; /** Weapon Item Range */
/**< More to come */
};
@@ -64,15 +105,16 @@ class Item
{
public:
- Item(StatisticsModifiers statsModifiers,
- unsigned short mItemType = 0,
+ Item(Modifiers modifiers,
+ unsigned short itemType = 0,
unsigned int weight = 0,
- unsigned short slot = 0,
- unsigned int value = 0):
+ unsigned int value = 0,
+ std::string scriptName = ""):
+ mModifiers(modifiers),
+ mItemType(itemType),
mWeight(weight),
- mSlot(slot),
mValue(value),
- mStatsModifiers(statsModifiers) {}
+ mScriptName(scriptName) {}
virtual ~Item() throw() { }
@@ -80,47 +122,43 @@ class Item
* The function called to use an item applying
* only the modifiers (for simple items...)
*/
- void use(BeingPtr itemUser);
-
- /**
- * The function called to use an item
- * using a script (for complex actions)
- */
- void useWithScript(const std::string scriptFile);
+ bool use(BeingPtr itemUser);
/**
* Return item Type
*/
- unsigned short getItemType() const { return mItemType; }
+ unsigned short getItemType() const { return mItemType; };
/**
* Return Weight of item
*/
- unsigned int getWeight() const { return mWeight; }
-
- /**
- * Return usual slot of item
- */
- unsigned short getSlot() const { return mSlot; }
+ unsigned int getWeight() const { return mWeight; };
/**
* Return gold value of item
*/
- unsigned int getGoldValue() const { return mValue; }
+ unsigned int getGoldValue() const { return mValue; };
/**
* Return item's modifiers
*/
- StatisticsModifiers
- getItemStatsModifiers() const { return mStatsModifiers; }
+ Modifiers
+ getItemModifiers() const { return mModifiers; };
private:
- //Item type
+
+ /**
+ * Runs the associated script when using the item, if any.
+ */
+ bool runScript(BeingPtr itemUser);
+
+ // Item reference information
unsigned short mItemType; /**< ItemType: Usable, equipment */
unsigned int mWeight; /**< Weight of the item */
- unsigned short mSlot; /**< Current slot of the item */
unsigned int mValue; /**< Gold value of the item */
- StatisticsModifiers mStatsModifiers; /**< Stats Mod of the items */
+ std::string mScriptName; /**< item's script. None if =="" */
+
+ Modifiers mModifiers; /**< Item's Modifiers */
};
/**
diff --git a/src/itemmanager.cpp b/src/itemmanager.cpp
new file mode 100644
index 00000000..2b480397
--- /dev/null
+++ b/src/itemmanager.cpp
@@ -0,0 +1,193 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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 World 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 World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id:$
+ */
+
+#include "itemmanager.h"
+
+#include "resourcemanager.h"
+#include "utils/logger.h"
+#include <libxml/tree.h>
+
+#define READ_PROP(node, prop, name, target, cast) \
+ prop = xmlGetProp(node, BAD_CAST name); \
+ if (prop) { \
+ target = cast((const char*)prop); \
+ xmlFree(prop); \
+ }
+
+ItemManager::ItemManager(std::string itemReferenceFile)
+{
+ ResourceManager *resman = ResourceManager::getInstance();
+ int size;
+ char *data = (char*)resman->loadFile(itemReferenceFile, size);
+
+ if (!data) {
+ LOG_ERROR("Item Manager: Could not find " << itemReferenceFile << "!", 0);
+ free(data);
+ }
+ else
+ {
+ xmlDocPtr doc = xmlParseMemory(data, size);
+ free(data);
+
+ if (!doc)
+ {
+ LOG_ERROR("Item Manager: Error while parsing item database ("
+ << itemReferenceFile << ")!", 0);
+ }
+ else
+ {
+ xmlNodePtr node = xmlDocGetRootElement(doc);
+ if (!node || !xmlStrEqual(node->name, BAD_CAST "items"))
+ {
+ LOG_ERROR("Item Manager: " << itemReferenceFile
+ << " is not a valid database file!", 0);
+ }
+
+ unsigned int nbItems = 0;
+ for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ // Properties
+ unsigned int id = 0;
+ unsigned short itemType = 0;
+ unsigned int weight = 0;
+ unsigned int value = 0;
+ std::string scriptName = "";
+ Modifiers modifiers;
+
+ if (!xmlStrEqual(node->name, BAD_CAST "item")) {
+ continue;
+ }
+
+ xmlChar *prop = NULL;
+ // Properties
+ READ_PROP(node, prop, "id", id, atoi);
+ READ_PROP(node, prop, "type", itemType, atoi);
+ READ_PROP(node, prop, "weight", weight, atoi);
+ READ_PROP(node, prop, "value", value, atoi);
+ READ_PROP(node, prop, "script_name", scriptName, );
+
+ // --- Modifiers
+ // General
+ READ_PROP(node, prop, "element", modifiers.element, (Element)atoi);
+ READ_PROP(node, prop, "lifetime", modifiers.lifetime, atoi);
+ // Raw Statistics
+ READ_PROP(node, prop, "strength", modifiers.rawStats[STAT_STRENGTH], atoi);
+ READ_PROP(node, prop, "agility", modifiers.rawStats[STAT_AGILITY], atoi);
+ READ_PROP(node, prop, "vitality", modifiers.rawStats[STAT_VITALITY], atoi);
+ READ_PROP(node, prop, "intelligence", modifiers.rawStats[STAT_INTELLIGENCE], atoi);
+ READ_PROP(node, prop, "dexterity", modifiers.rawStats[STAT_DEXTERITY], atoi);
+ READ_PROP(node, prop, "luck", modifiers.rawStats[STAT_LUCK], atoi);
+ // Computed Statistics
+ READ_PROP(node, prop, "heat", modifiers.computedStats[STAT_HEAT], atoi);
+ READ_PROP(node, prop, "attack", modifiers.computedStats[STAT_ATTACK], atoi);
+ READ_PROP(node, prop, "defence", modifiers.computedStats[STAT_DEFENCE], atoi);
+ READ_PROP(node, prop, "magic", modifiers.computedStats[STAT_MAGIC], atoi);
+ READ_PROP(node, prop, "accuracy", modifiers.computedStats[STAT_ACCURACY], atoi);
+ READ_PROP(node, prop, "speed", modifiers.computedStats[STAT_SPEED], atoi);
+ // Main Values
+ READ_PROP(node, prop, "hp", modifiers.hpMod, atoi);
+ READ_PROP(node, prop, "mp", modifiers.mpMod, atoi);
+ // Equipment
+ READ_PROP(node, prop, "range", modifiers.range, atoi);
+ // Status effects addition
+ READ_PROP(node, prop, "status_normal",
+ modifiers.beingStateEffects.STATE_NORMAL, (bool)atoi);
+ READ_PROP(node, prop, "status_poisoned",
+ modifiers.beingStateEffects.STATE_POISONED, (bool)atoi);
+ READ_PROP(node, prop, "status_stoned",
+ modifiers.beingStateEffects.STATE_STONED, (bool)atoi);
+ READ_PROP(node, prop, "status_stunned",
+ modifiers.beingStateEffects.STATE_STUNNED, (bool)atoi);
+ READ_PROP(node, prop, "status_slowed",
+ modifiers.beingStateEffects.STATE_SLOWED, (bool)atoi);
+ READ_PROP(node, prop, "status_tired",
+ modifiers.beingStateEffects.STATE_TIRED, (bool)atoi);
+ READ_PROP(node, prop, "status_mad",
+ modifiers.beingStateEffects.STATE_MAD, (bool)atoi);
+ READ_PROP(node, prop, "status_berserk",
+ modifiers.beingStateEffects.STATE_BERSERK, (bool)atoi);
+ READ_PROP(node, prop, "status_hasted",
+ modifiers.beingStateEffects.STATE_HASTED, (bool)atoi);
+ READ_PROP(node, prop, "status_floating",
+ modifiers.beingStateEffects.STATE_FLOATING, (bool)atoi);
+ // Status Effects deletion
+ READ_PROP(node, prop, "status_not_poisoned",
+ modifiers.beingStateEffects.STATE_NOT_POISONED, (bool)atoi);
+ READ_PROP(node, prop, "status_not_stoned",
+ modifiers.beingStateEffects.STATE_NOT_STONED, (bool)atoi);
+ READ_PROP(node, prop, "status_not_stunned",
+ modifiers.beingStateEffects.STATE_NOT_STUNNED, (bool)atoi);
+ READ_PROP(node, prop, "status_not_slowed",
+ modifiers.beingStateEffects.STATE_NOT_SLOWED, (bool)atoi);
+ READ_PROP(node, prop, "status_not_tired",
+ modifiers.beingStateEffects.STATE_NOT_TIRED, (bool)atoi);
+ READ_PROP(node, prop, "status_not_mad",
+ modifiers.beingStateEffects.STATE_NOT_MAD, (bool)atoi);
+ READ_PROP(node, prop, "status_not_berserk",
+ modifiers.beingStateEffects.STATE_NOT_BERSERK, (bool)atoi);
+ READ_PROP(node, prop, "status_not_hasted",
+ modifiers.beingStateEffects.STATE_NOT_HASTED, (bool)atoi);
+ READ_PROP(node, prop, "status_not_floating",
+ modifiers.beingStateEffects.STATE_NOT_FLOATING, (bool)atoi);
+
+ // Checks
+ if (id != 0)
+ {
+ ItemPtr item(new Item(modifiers, itemType, weight, value, scriptName));
+ mItemReference[id] = item;
+ nbItems++;
+ }
+
+ if (id == 0)
+ {
+ LOG_WARN("Item Manager: An (ignored) item has no ID in "
+ << itemReferenceFile << "!", 0);
+ }
+ if (itemType == 0)
+ {
+ LOG_WARN("Item Manager: Missing Item Type for item: "
+ << id << " in " << itemReferenceFile << ".", 0);
+ }
+ if (weight == 0)
+ {
+ LOG_WARN("Item Manager: Missing weight for item: "
+ << id << " in " << itemReferenceFile << ".", 0);
+ }
+
+ LOG_INFO("Item: ID: " << id << ", itemType: " << itemType
+ << ", weight: " << weight << ", value: " << value <<
+ ", scriptName: " << scriptName << ".", 3);
+ //TODO: Log level 5 with everything
+ }
+
+ LOG_INFO("Loaded " << nbItems << " items from " << itemReferenceFile << ".", 0);
+
+ xmlFreeDoc(doc);
+ } // End if doc?
+ } // End if data?
+}
+
+ItemManager::~ItemManager()
+{
+ mItemReference.clear();
+}
diff --git a/src/itemmanager.h b/src/itemmanager.h
new file mode 100644
index 00000000..3a80db40
--- /dev/null
+++ b/src/itemmanager.h
@@ -0,0 +1,89 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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 World 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 World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: $
+ */
+
+#ifndef _TMW_ITEMMANAGER_H
+#define _TMW_ITEMMANAGER_H
+
+#include "item.h"
+
+#include <map>
+
+/**
+ * The Item Manager loads the item reference database
+ * and also offers an API to items information, and more.
+ * For item objects, see the WorldItem class.
+ */
+class ItemManager
+{
+ public:
+ /**
+ * Constructor (loads item reference file)
+ */
+ ItemManager(std::string itemReferenceFile);
+
+ /**
+ * Destructor
+ */
+ ~ItemManager();
+
+ /**
+ * Gives an Item having the demanded information.
+ */
+ ItemPtr getItem(const unsigned int itemId)
+ { return mItemReference[itemId]; };
+
+ bool use(BeingPtr beingPtr, const unsigned int itemId)
+ { return mItemReference[itemId].get()->use(beingPtr); };
+
+ /**
+ * Return item Type
+ */
+ unsigned short getItemType(const unsigned int itemId)
+ { return mItemReference[itemId].get()->getItemType(); };
+
+ /**
+ * Return Weight of item
+ */
+ unsigned int getWeight(const unsigned int itemId)
+ { return mItemReference[itemId].get()->getWeight(); };
+
+ /**
+ * Return gold value of item
+ */
+ unsigned int getGoldValue(const unsigned int itemId)
+ { return mItemReference[itemId].get()->getGoldValue(); };
+
+ /**
+ * Return item's modifiers
+ */
+ Modifiers
+ getItemModifiers(const unsigned int itemId)
+ { return mItemReference[itemId].get()->getItemModifiers(); };
+
+ private:
+ std::map<unsigned int, ItemPtr> mItemReference; /**< Item reference */
+};
+
+extern ItemManager *itemManager;
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
index 24bf79af..9516efbd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -42,6 +42,7 @@
#include "gamehandler.h"
#include "messageout.h"
#include "resourcemanager.h"
+#include "itemmanager.h"
#include "skill.h"
#include "state.h"
#include "storage.h"
@@ -74,8 +75,14 @@ std::string scriptLanugage = "none";
// Default options that automake should be able to override.
#define DEFAULT_LOG_FILE "tmwserv.log"
#define DEFAULT_CONFIG_FILE "tmwserv.xml"
+#define DEFAULT_ITEMSDB_FILE "items.xml"
+#define DEFAULT_MAP_FOLDER "maps"
+#define DEFAULT_DATA_FOLDER "data"
#ifndef DEFAULT_SERVER_PORT
#define DEFAULT_SERVER_PORT 9601
+// Meaning Account Handler Port is 9601
+// Chat Handler Port is 9602 (9601 + 1)
+// and Game Handler Port is 9603...
#endif
utils::Timer worldTimer(100, false); /**< Timer for world tics set to 100 ms */
@@ -95,6 +102,8 @@ AccountHandler *accountHandler;
ChatHandler *chatHandler;
/** Chat Channels Manager */
ChatChannelManager *chatChannelManager;
+/** Item Manager */
+ItemManager *itemManager;
/** Core game message handler */
GameHandler *gameHandler;
@@ -107,6 +116,13 @@ State *gameState;
*/
void initialize()
{
+
+ // Reset to default segmentation fault handling for debugging purposes
+ signal(SIGSEGV, SIG_DFL);
+
+ // Set enet to quit on exit.
+ atexit(enet_deinitialize);
+
/*
* If the path values aren't defined, we set the default
* depending on the platform.
@@ -141,7 +157,10 @@ void initialize()
#endif // defined LOG_FILE
- // initialize the logger.
+ // Initialize PhysicsFS
+ PHYSFS_init("");
+
+ // Initialize the logger.
using namespace utils;
Logger::instance().setLogFile(logPath);
@@ -152,31 +171,28 @@ void initialize()
LOG_INFO("Using Config File: " << configPath, 0);
LOG_INFO("Using Log File: " << logPath, 0);
- // Initialize the slang's filter.
+ // --- Initialize the managers
+ // Initialize the slang's and double quotes filter.
stringFilter = new StringFilter(&config);
+ // Initialize the Chat channels manager
+ chatChannelManager = new ChatChannelManager();
+ // Initialize the Item Manager
+ itemManager = new ItemManager(DEFAULT_DATA_FOLDER"/"DEFAULT_ITEMSDB_FILE);
- // Initialize the global handlers
+ // --- Initialize the global handlers
// FIXME: Make the global handlers global vars or part of a bigger
// singleton or a local variable in the event-loop
- chatChannelManager = new ChatChannelManager();
-
chatHandler = new ChatHandler();
accountHandler = new AccountHandler();
gameHandler = new GameHandler();
- // Reset to default segmentation fault handling for debugging purposes
- signal(SIGSEGV, SIG_DFL);
-
- // Set enet to quit on exit.
- atexit(enet_deinitialize);
-
- // Initialize enet.
+ // --- Initialize enet.
if (enet_initialize() != 0) {
LOG_FATAL("An error occurred while initializing ENet", 0);
exit(2);
}
- // Initialize scripting subsystem.
+ // --- Initialize scripting subsystem.
#ifdef RUBY_SUPPORT
LOG_INFO("Script Language: " << scriptLanguage, 0);
@@ -209,9 +225,6 @@ void initialize()
config.setValue("dbuser", "");
config.setValue("dbpass", "");
config.setValue("dbhost", "");
-
- // Initialize PhysicsFS
- PHYSFS_init("");
}
@@ -241,7 +254,9 @@ void deinitialize()
delete chatHandler;
delete gameHandler;
+ // Destroy Managers
delete chatChannelManager;
+ delete itemManager;
// Get rid of persistent data storage
Storage::destroy();
diff --git a/src/player.cpp b/src/player.cpp
index 70659efc..0be018d6 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -36,12 +36,12 @@ void Player::setDatabaseID(int id)
void Player::update()
{
// computed stats.
- setStat(STAT_HEA, 20 + (20 * mRawStats.stats[STAT_VIT]));
- setStat(STAT_ATT, 10 + mRawStats.stats[STAT_STR]);
- setStat(STAT_DEF, 10 + mRawStats.stats[STAT_STR]);
- setStat(STAT_MAG, 10 + mRawStats.stats[STAT_INT]);
- setStat(STAT_ACC, 50 + mRawStats.stats[STAT_DEX]);
- setStat(STAT_SPD, mRawStats.stats[STAT_DEX]);
+ setStat(STAT_HEAT, 20 + (20 * mRawStats.stats[STAT_VITALITY]));
+ setStat(STAT_ATTACK, 10 + mRawStats.stats[STAT_STRENGTH]);
+ setStat(STAT_DEFENCE, 10 + mRawStats.stats[STAT_STRENGTH]);
+ setStat(STAT_MAGIC, 10 + mRawStats.stats[STAT_INTELLIGENCE]);
+ setStat(STAT_ACCURACY, 50 + mRawStats.stats[STAT_DEXTERITY]);
+ setStat(STAT_SPEED, mRawStats.stats[STAT_DEXTERITY]);
}
void Player::setInventory(const std::vector<unsigned int> &inven)