diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-03-04 06:08:39 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-03-04 06:08:39 +0000 |
commit | 41079fd0e69cde97fcb44d2e6fe03ad198764fea (patch) | |
tree | f773ef2f7084250501414b51eb7f6ec8f00eef0d /src/game-server/being.cpp | |
parent | 3cf2198e2485c80633f8d80d1a4c12843db86fde (diff) | |
download | manaserv-41079fd0e69cde97fcb44d2e6fe03ad198764fea.tar.gz manaserv-41079fd0e69cde97fcb44d2e6fe03ad198764fea.tar.bz2 manaserv-41079fd0e69cde97fcb44d2e6fe03ad198764fea.tar.xz manaserv-41079fd0e69cde97fcb44d2e6fe03ad198764fea.zip |
Added natural HP regeneration, capped HP at maximum and set HP to 1 after respawn.
Diffstat (limited to 'src/game-server/being.cpp')
-rw-r--r-- | src/game-server/being.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 6cbf4c31..a97d6097 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -32,7 +32,8 @@ Being::Being(int type, int id): MovingObject(type, id), - mAction(STAND) + mAction(STAND), + mHpRegenTimer(0) { Attribute attr = { 0, 0 }; mAttributes.resize(NB_BEING_ATTRIBUTES, attr); @@ -222,6 +223,29 @@ int Being::getModifiedAttribute(int attr) const void Being::update() { + + int oldHP = getModifiedAttribute(BASE_ATTR_HP); + int newHP = oldHP; + int maxHP = getAttribute(BASE_ATTR_HP); + + // regenerate HP + if (mAction != DEAD && mHpRegenTimer++ >= TICKS_PER_HP_REGENERATION) + { + mHpRegenTimer = 0; + newHP += getModifiedAttribute(BASE_ATTR_HP_REGEN); + } + //cap HP at maximum + if (newHP > maxHP) + { + newHP = maxHP; + } + //only update HP when it actually changed to avoid network noise + if (newHP != oldHP) + { + LOG_INFO("HP Update - newHP:"<<newHP<<", oldHP:"<<oldHP<<", maxHP:"<<maxHP); + applyModifier(BASE_ATTR_HP, newHP - oldHP); + } + // Update lifetime of effects. AttributeModifiers::iterator i = mModifiers.begin(); while (i != mModifiers.end()) |