diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-11-23 04:40:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-11-24 03:32:57 +0300 |
commit | 8e5861c3cfd41574351547a1a518efcf9007666a (patch) | |
tree | 8d941791c1bbd296b7125475fa0abb9581df632f /src/being.cpp | |
parent | 004aa3358c6efeb469045785baa891a449dde5a4 (diff) | |
download | plus-8e5861c3cfd41574351547a1a518efcf9007666a.tar.gz plus-8e5861c3cfd41574351547a1a518efcf9007666a.tar.bz2 plus-8e5861c3cfd41574351547a1a518efcf9007666a.tar.xz plus-8e5861c3cfd41574351547a1a518efcf9007666a.zip |
Add ability to play different animation depend on monster hp.
Disabled for legacy servers because monster hp unknown and
compilated hp can be wrong (version <= 0).
For usage need add to action tag attribute hp="xx"
Example:
<action name="stand" hp="50" imageset="base">
...
</action>
Here 50 mean 50% of health or less.
Default action tag mean hp=100
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/being.cpp b/src/being.cpp index 9d731d2c9..3ed7ba587 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -253,7 +253,8 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): mAdvanced(false), mShop(false), mAway(false), - mInactive(false) + mInactive(false), + mNumber(100) { mSpriteRemap = new int[20]; mSpriteHide = new int[20]; @@ -287,6 +288,7 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): updateColors(); resetCounters(); + updatePercentHP(); } Being::~Being() @@ -660,7 +662,10 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) } if (mType == MONSTER) + { + updatePercentHP(); updateName(); + } else if (mType == PLAYER && socialWindow && getName() != "") socialWindow->updateAvatar(getName()); @@ -1036,6 +1041,7 @@ void Being::setAction(Action action, int attackType A_UNUSED) if (currentAction != SpriteAction::INVALID) { + //set mNumber play(currentAction); mAction = action; } @@ -2102,6 +2108,8 @@ void Being::setHP(int hp) mHP = hp; if (mMaxHP < mHP) mMaxHP = mHP; + if (mType == MONSTER) + updatePercentHP(); } void Being::setMaxHP(int hp) @@ -2521,6 +2529,23 @@ void Being::setEmote(Uint8 emotion, int emote_time) } } +void Being::updatePercentHP() +{ + if (!mMaxHP || !serverVersion) + return; + unsigned num = 0; + if (mHP) + { + num = mHP * 100 / mMaxHP; + if (num != mNumber) + { + mNumber = num; + if (updateNumber(mNumber)) + setAction(mAction); + } + } +} + BeingEquipBackend::BeingEquipBackend(Being *being): mBeing(being) { |