summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/game-server/monster.cpp11
-rw-r--r--src/game-server/monster.hpp15
-rw-r--r--src/game-server/monstermanager.cpp28
4 files changed, 54 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index d68b4159..d2ebd345 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-02-05 Philipp Sehmisch <tmw@crushnet.org>
+
+ * src/game-server/monster.cpp, src/game-server/monster.hpp,
+ src/game-server/monstermanager.cpp: Monster base attributes are now read
+ from monsters.xml.
+
2008-01-28 Philipp Sehmisch <tmw@crushnet.org>
* src/account-server/accounthandler.cpp, src/account-server/character.cpp,
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;
}