From 983a8587fedec18e08a1d032a76784d8f9a18085 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Wed, 6 Feb 2008 16:36:57 +0000 Subject: Monster base attributes are now read from monsters.xml. --- src/game-server/monster.cpp | 11 ++++++----- src/game-server/monster.hpp | 15 ++++++++++++++- src/game-server/monstermanager.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) (limited to 'src') 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. @@ -63,6 +63,18 @@ class MonsterClass void setDrops(MonsterDrops const &v) { 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 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 #"<setDrops(drops); + if (!attributesSet) LOG_WARN(monsterReferenceFile<<": No attributes defined for monster #"<