From 84bea0b72c36a27e3b39a0713aaf7b12d4df5a2a Mon Sep 17 00:00:00 2001 From: Chuck Miller Date: Sat, 3 Oct 2009 10:23:59 -0400 Subject: Adds the changeAnger method to monsters --- src/game-server/monster.cpp | 30 ++++++++++++++++++++---------- src/game-server/monster.hpp | 5 +++++ 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src') 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::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 @@ -261,6 +261,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 */ -- cgit v1.2.3-70-g09d2