diff options
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/being.cpp | 26 | ||||
-rw-r--r-- | src/game-server/being.hpp | 2 | ||||
-rw-r--r-- | src/game-server/character.cpp | 13 | ||||
-rw-r--r-- | src/game-server/character.hpp | 4 |
4 files changed, 38 insertions, 7 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()) diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp index 44857dc1..27da220a 100644 --- a/src/game-server/being.hpp +++ b/src/game-server/being.hpp @@ -213,6 +213,7 @@ class Being : public MovingObject virtual void modifiedAttribute(int) {} protected: + static const int TICKS_PER_HP_REGENERATION = 100; Action mAction; std::vector< Attribute > 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; |