From 41079fd0e69cde97fcb44d2e6fe03ad198764fea Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 4 Mar 2008 06:08:39 +0000 Subject: Added natural HP regeneration, capped HP at maximum and set HP to 1 after respawn. --- src/defines.h | 1 + src/game-server/being.cpp | 26 +++++++++++++++++++++++++- src/game-server/being.hpp | 2 ++ src/game-server/character.cpp | 13 +++++++++---- src/game-server/character.hpp | 4 ++-- 5 files changed, 39 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/defines.h b/src/defines.h index f8ee5ea1..539b72a2 100644 --- a/src/defines.h +++ b/src/defines.h @@ -369,6 +369,7 @@ enum BASE_ATTR_EVADE, /**< Ability to avoid hits. */ BASE_ATTR_HIT, /**< Ability to hit stuff. */ BASE_ATTR_HP, /**< Hit Points (Base value: maximum, Modded value: current) */ + BASE_ATTR_HP_REGEN,/**< number of HP regenerated every 10 game ticks */ BASE_ATTR_END, BASE_ATTR_NB = BASE_ATTR_END - BASE_ATTR_BEGIN, 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:"< mAttributes; @@ -222,6 +223,7 @@ class Being : public MovingObject Hits mHitsTaken; /**< List of punches taken since last update */ AttributeModifiers mModifiers; /**< Currently modified attributes. */ + int mHpRegenTimer; /**< timer for hp regeneration*/ }; #endif // _TMWSERV_BEING_H_ diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index c13f3805..7318f712 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -125,11 +125,10 @@ void Character::respawn() static const int spawnY = 1024; GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY); - //restore hit points - mAttributes[BASE_ATTR_HP].mod = 0; - //make alive again setAction(STAND); + mAttributes[BASE_ATTR_HP].mod = -mAttributes[BASE_ATTR_HP].base + 1; + modifiedAttribute(BASE_ATTR_HP); } int Character::getMapId() const @@ -244,7 +243,13 @@ void Character::modifiedAttribute(int attr) { int newValue = getAttribute(i); - if (i == BASE_ATTR_HP){ + if (i == BASE_ATTR_HP_REGEN){ + newValue = (getModifiedAttribute(CHAR_ATTR_VITALITY) + 10) + * (getModifiedAttribute(CHAR_ATTR_VITALITY) + 10) + / (600 / TICKS_PER_HP_REGENERATION); + // formula is in HP per minute. 600 game ticks = 1 minute. + } + else if (i == BASE_ATTR_HP){ newValue = (getModifiedAttribute(CHAR_ATTR_VITALITY) + 10) * (mLevel + 10); } diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index 05834f7d..b90d2b3c 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -275,8 +275,8 @@ class Character : public Being Character(Character const &); Character &operator=(Character const &); - static const float EXPCURVE_EXPONENT = 5.0f; // should maybe be obtained - static const float EXPCURVE_FACTOR = 3.0f; // from the config file + static const float EXPCURVE_EXPONENT = 3.0f; // should maybe be obtained + static const float EXPCURVE_FACTOR = 10.0f; // from the config file static const float LEVEL_SKILL_PRECEDENCE_FACTOR = 0.75f; // I am taking suggestions for a better name static const int CHARPOINTS_PER_LEVELUP = 5; static const int CORRECTIONPOINTS_PER_LEVELUP = 2; -- cgit v1.2.3-60-g2f50