summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-04 06:08:39 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-04 06:08:39 +0000
commit41079fd0e69cde97fcb44d2e6fe03ad198764fea (patch)
treef773ef2f7084250501414b51eb7f6ec8f00eef0d /src
parent3cf2198e2485c80633f8d80d1a4c12843db86fde (diff)
downloadmanaserv-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')
-rw-r--r--src/defines.h1
-rw-r--r--src/game-server/being.cpp26
-rw-r--r--src/game-server/being.hpp2
-rw-r--r--src/game-server/character.cpp13
-rw-r--r--src/game-server/character.hpp4
5 files changed, 39 insertions, 7 deletions
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:"<<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;