diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-19 08:05:45 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-19 08:05:45 +0000 |
commit | 31232e3a5702a7618fe40dc74f5d987a662cb081 (patch) | |
tree | 170b799b14dc950201eb7eec63c957e542e4c96d /src/game-server/being.cpp | |
parent | 2ae3f3a3ef5caee193138a3e5c1613403302089c (diff) | |
download | manaserv-31232e3a5702a7618fe40dc74f5d987a662cb081.tar.gz manaserv-31232e3a5702a7618fe40dc74f5d987a662cb081.tar.bz2 manaserv-31232e3a5702a7618fe40dc74f5d987a662cb081.tar.xz manaserv-31232e3a5702a7618fe40dc74f5d987a662cb081.zip |
Added support for protective equipment.
Diffstat (limited to 'src/game-server/being.cpp')
-rw-r--r-- | src/game-server/being.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 0fd03af1..aafb076a 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -36,6 +36,11 @@ Being::Being(int type, int id): { Attribute attr = { 0, 0 }; mAttributes.resize(NB_BEING_ATTRIBUTES, attr); + // Initialize element resistance to 100 (normal damage). + for (int i = BASE_ELEM_BEGIN; i < BASE_ELEM_END; ++i) + { + mAttributes[i].base = 100; + } } Being::~Being() @@ -81,7 +86,6 @@ int Being::damage(Object *, Damage const &damage) if (avoidChance > 50) avoidChance = 50; } int chance = rand() / (RAND_MAX / 100); - LOG_INFO("Chance: " << chance << " (" << avoidChance << ", " << 100 - criticalChance << "); Damage: " << HPloss); if (chance <= avoidChance) { mHitsTaken.push_back(0); @@ -89,9 +93,9 @@ int Being::damage(Object *, Damage const &damage) } if (chance >= 100 - criticalChance) HPloss *= 2; - /* Elemental modifier at 0 means normal damage. At -100, it means immune. - And at 100, it means vulnerable (double damage). */ - int mod1 = 100 + getModifiedAttribute(BASE_ELEM_BEGIN + damage.element); + /* Elemental modifier at 100 means normal damage. At 0, it means immune. + And at 200, it means vulnerable (double damage). */ + int mod1 = getModifiedAttribute(BASE_ELEM_BEGIN + damage.element); /* Resistance to damage at 0 gives normal damage. At 100, it gives halved damage. At 200, it divides damage by 3. And so on. */ @@ -245,15 +249,17 @@ void Being::removeEquipmentModifier(int attr, int value) void Being::dispellModifiers(int level) { - for (AttributeModifiers::iterator i = mModifiers.begin(); - i != mModifiers.end(); ++i) + AttributeModifiers::iterator i = mModifiers.begin(); + while (i != mModifiers.end()) { if (i->level && i->level <= level) { mAttributes[i->attr].mod -= i->value; modifiedAttribute(i->attr); i = mModifiers.erase(i); + continue; } + ++i; } } @@ -262,3 +268,22 @@ int Being::getModifiedAttribute(int attr) const int res = mAttributes[attr].base + mAttributes[attr].mod; return res <= 0 ? 0 : res; } + +void Being::update() +{ + // Update lifetime of effects. + AttributeModifiers::iterator i = mModifiers.begin(); + while (i != mModifiers.end()) + { + if (i->duration) + { + --i->duration; + if (!i->duration) + { + i = mModifiers.erase(i); + continue; + } + } + ++i; + } +} |