summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-02-06 16:36:57 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-02-06 16:36:57 +0000
commit983a8587fedec18e08a1d032a76784d8f9a18085 (patch)
tree6bf142c63b37f85cc1191c0c265cbc35274d7e54 /src
parentaa603c3ec05f6143b1c9085b56e3becf45be4bf5 (diff)
downloadmanaserv-983a8587fedec18e08a1d032a76784d8f9a18085.tar.gz
manaserv-983a8587fedec18e08a1d032a76784d8f9a18085.tar.bz2
manaserv-983a8587fedec18e08a1d032a76784d8f9a18085.tar.xz
manaserv-983a8587fedec18e08a1d032a76784d8f9a18085.zip
Monster base attributes are now read from monsters.xml.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/monster.cpp11
-rw-r--r--src/game-server/monster.hpp15
-rw-r--r--src/game-server/monstermanager.cpp28
3 files changed, 48 insertions, 6 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 018a379f..3e92e85b 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -66,6 +66,12 @@ Monster::Monster(MonsterClass *specy):
{
LOG_DEBUG("Monster spawned!");
+ // get basic attributes from monster database
+ for (int i = BASE_ATTR_BEGIN; i < BASE_ATTR_END; i++)
+ {
+ setAttribute(i, specy->getAttribute(i));
+ }
+
// Some bogus stats for testing.
// TODO: Get all this stuff from the monster database.
mAgressive = false;
@@ -76,11 +82,6 @@ Monster::Monster(MonsterClass *specy):
mAttackAngle = 10;
setSpeed(300);
setSize(8);
- setAttribute(BASE_ATTR_HP, 100);
- setAttribute(BASE_ATTR_PHY_ATK_MIN, 20);
- setAttribute(BASE_ATTR_PHY_ATK_DELTA, 2);
- setAttribute(BASE_ATTR_HIT, 10);
- setAttribute(BASE_ATTR_EVADE, 10);
mExpReward = 100;
// Set positions relative to target from which the monster can attack
diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp
index 7167e469..c6d43589 100644
--- a/src/game-server/monster.hpp
+++ b/src/game-server/monster.hpp
@@ -49,7 +49,7 @@ typedef std::vector< MonsterDrop > MonsterDrops;
class MonsterClass
{
public:
- MonsterClass(int id): mID(id) {}
+ MonsterClass(int id): mID(id), mAttributes(BASE_ATTR_NB, 0) {}
/**
* Gets monster type.
@@ -64,6 +64,18 @@ class MonsterClass
{ mDrops = v; }
/**
+ * Sets a being attribute
+ */
+ void setAttribute(size_t attribute, int value)
+ { mAttributes.at(attribute) = value ; }
+
+ /**
+ * Gets a being attribute
+ */
+ int getAttribute(size_t attribute) const
+ { return mAttributes.at(attribute); }
+
+ /**
* Randomly selects a monster drop (may return NULL).
* TODO: pass some luck modifier as an argument.
*/
@@ -72,6 +84,7 @@ class MonsterClass
private:
unsigned short mID; /**< ID of the monster class. */
MonsterDrops mDrops; /**< Items the monster drops when dying. */
+ std::vector<int> mAttributes; /**< Base attributes of the monster*/
};
/**
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index efdb4420..2d59d690 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -104,6 +104,7 @@ void MonsterManager::reload()
}
MonsterDrops drops;
+ bool attributesSet = false;
for (xmlNodePtr subnode = node->xmlChildrenNode; subnode != NULL;
subnode = subnode->next)
@@ -118,9 +119,36 @@ void MonsterManager::reload()
drops.push_back(drop);
}
}
+ else if (xmlStrEqual(subnode->name, BAD_CAST "attributes"))
+ {
+ attributesSet = true;
+ monster->setAttribute(BASE_ATTR_HP, XML::getProperty(subnode, "hp", -1));
+ monster->setAttribute(BASE_ATTR_PHY_ATK_MIN, XML::getProperty(subnode, "attack-min", -1));
+ monster->setAttribute(BASE_ATTR_PHY_ATK_DELTA, XML::getProperty(subnode, "attack-delta", -1));
+ monster->setAttribute(BASE_ATTR_MAG_ATK, XML::getProperty(subnode, "attack-magic", -1));
+ monster->setAttribute(BASE_ATTR_EVADE, XML::getProperty(subnode, "evade", -1));
+ monster->setAttribute(BASE_ATTR_HIT, XML::getProperty(subnode, "hit", -1));
+ monster->setAttribute(BASE_ATTR_PHY_RES, XML::getProperty(subnode, "physical-defence", -1));
+ monster->setAttribute(BASE_ATTR_MAG_RES, XML::getProperty(subnode, "magical-defence", -1));
+ // TODO: speed
+ // TODO: size
+
+ //check for completeness
+ bool attributesComplete = true;
+ for (int i = BASE_ATTR_BEGIN; i < BASE_ATTR_END; i++)
+ {
+ if (monster->getAttribute(i) == -1)
+ {
+ attributesComplete = false;
+ monster->setAttribute(i, 0);
+ }
+ }
+ if (!attributesComplete) LOG_WARN(monsterReferenceFile<<": Attributes incomplete for monster #"<<id);
+ }
}
monster->setDrops(drops);
+ if (!attributesSet) LOG_WARN(monsterReferenceFile<<": No attributes defined for monster #"<<id);
++nbMonsters;
}