summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-10-03 10:23:59 -0400
committerChuck Miller <shadowmil@gmail.com>2009-10-03 10:23:59 -0400
commit84bea0b72c36a27e3b39a0713aaf7b12d4df5a2a (patch)
tree2f26a9fb77d48ba2170ea8f388c1b8295638eabe /src
parent80b8174acb340a36194c1ebe4905ab6cca8fdb8f (diff)
downloadmanaserv-84bea0b72c36a27e3b39a0713aaf7b12d4df5a2a.tar.gz
manaserv-84bea0b72c36a27e3b39a0713aaf7b12d4df5a2a.tar.bz2
manaserv-84bea0b72c36a27e3b39a0713aaf7b12d4df5a2a.tar.xz
manaserv-84bea0b72c36a27e3b39a0713aaf7b12d4df5a2a.zip
Adds the changeAnger method to monsters
Diffstat (limited to 'src')
-rw-r--r--src/game-server/monster.cpp30
-rw-r--r--src/game-server/monster.hpp5
2 files changed, 25 insertions, 10 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 68cfa88e..3caaac2e 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -379,23 +379,33 @@ void Monster::forgetTarget(Thing *t)
}
}
-int Monster::damage(Actor *source, const Damage &damage)
+void Monster::changeAnger(Actor *target, int amount)
{
- int HPLoss = Being::damage(source, damage);
- if (HPLoss && source && source->getType() == OBJECT_CHARACTER)
+ if (target && (target->getType() == OBJECT_MONSTER || target->getType() == OBJECT_CHARACTER))
{
- Character *s = static_cast< Character * >(source);
- std::pair< std::map< Being *, int >::iterator, bool > ib =
- mAnger.insert(std::make_pair(s, HPLoss));
-
- if (ib.second)
+ Being *t = static_cast< Being * >(target);
+ if (mAnger.find(t) != mAnger.end())
{
- s->addListener(&mTargetListener);
+ mAnger[t] = amount;
}
else
{
- ib.first->second += HPLoss;
+ mAnger[t] = amount;
+ t->addListener(&mTargetListener);
}
+ }
+}
+
+int Monster::damage(Actor *source, const Damage &damage)
+{
+ int HPLoss = Being::damage(source, damage);
+ if (source)
+ {
+ changeAnger(source, HPLoss);
+ }
+ if (HPLoss && source && source->getType() == OBJECT_CHARACTER)
+ {
+ Character *s = static_cast< Character * >(source);
std::list<size_t>::const_iterator iSkill;
for (iSkill = damage.usedSkills.begin(); iSkill != damage.usedSkills.end(); ++iSkill)
diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp
index 2278e8fd..79b8c69b 100644
--- a/src/game-server/monster.hpp
+++ b/src/game-server/monster.hpp
@@ -262,6 +262,11 @@ class Monster : public Being
void died();
/**
+ * Alters hate for the monster
+ */
+ void changeAnger(Actor *target, int amount);
+
+ /**
* Calls the damage function in Being and updates the aggro list
*/
virtual int damage(Actor *source, const Damage &damage);