diff options
author | sniper <sniper@livecd.janhome.net> | 2009-03-10 14:28:31 +0100 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-03-10 09:02:53 -0600 |
commit | 2353f11b75e347c9662c7224f5b3abcd9189a6bb (patch) | |
tree | bf4c6b7dca4cab6b6bacf5e32c51518cbd327ae5 /src | |
parent | 1570fb33d5909786ef2997246ada7c46dd6de9e4 (diff) | |
download | mana-2353f11b75e347c9662c7224f5b3abcd9189a6bb.tar.gz mana-2353f11b75e347c9662c7224f5b3abcd9189a6bb.tar.bz2 mana-2353f11b75e347c9662c7224f5b3abcd9189a6bb.tar.xz mana-2353f11b75e347c9662c7224f5b3abcd9189a6bb.zip |
Extended hit type handling
The client can now differentiate between the following hit types:
- hit (normal)
- critical (full attack)
- multi (more than one hit at once, currently not used)
- reflect (reflected damage, currently not used)
- flee (dodging criticals)
The Being's showCrit method is now merged into takeDamage.
Being's takeDamage and handleAttack now both get the opponent, the amount of
damage and the attack type as parameter.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 55 | ||||
-rw-r--r-- | src/being.h | 27 | ||||
-rw-r--r-- | src/localplayer.h | 8 | ||||
-rw-r--r-- | src/monster.cpp | 8 | ||||
-rw-r--r-- | src/monster.h | 13 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 15 |
6 files changed, 66 insertions, 60 deletions
diff --git a/src/being.cpp b/src/being.cpp index c31dae6d..ad6b2dea 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -219,26 +219,29 @@ void Being::setSpeech(const std::string &text, int time) mSpeechTime = time <= SPEECH_MAX_TIME ? time : SPEECH_MAX_TIME; } -void Being::takeDamage(int amount) +void Being::takeDamage(Being *attacker, int amount, AttackType type) { gcn::Font *font; - std::string damage = amount ? toString(amount) : "miss"; + std::string damage = amount ? toString(amount) : type == FLEE ? + "dodge" : "miss"; int red, green, blue; font = gui->getInfoParticleFont(); // Selecting the right color - if (damage == "miss") + if (type == CRITICAL || type == FLEE) { red = 255; - green = 255; + green = 128; blue = 0; } - else - { - if (getType() == MONSTER) + else if (!amount) + { + if (attacker == player_node) { + // This is intended to be the wrong direction to visually + // differentiate between hits and misses red = 0; green = 100; blue = 255; @@ -246,27 +249,11 @@ void Being::takeDamage(int amount) else { red = 255; - green = 50; - blue = 50; - } - } - - // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); -} - -void Being::showCrit() -{ - gcn::Font *font; - std::string text = "crit!"; - - int red, green, blue; - - font = gui->getInfoParticleFont(); - - // Selecting the right color - if (getType() == MONSTER) + green = 255; + blue = 0; + } + } + else if (getType() == MONSTER) { red = 0; green = 100; @@ -279,12 +266,18 @@ void Being::showCrit() blue = 50; } - // Show crit notice - particleEngine->addTextSplashEffect(text, red, green, blue, font, + if (amount > 0 && type == CRITICAL) + { + particleEngine->addTextSplashEffect("crit!", red, green, blue, font, + mPx + 16, mPy + 16, true); + } + + // Show damage number + particleEngine->addTextSplashEffect(damage, red, green, blue, font, mPx + 16, mPy + 16, true); } -void Being::handleAttack(Being *victim, int damage) +void Being::handleAttack(Being *victim, int damage, AttackType type) { setAction(Being::ATTACK); mFrame = 0; diff --git a/src/being.h b/src/being.h index 9b3bbde4..63e5e07f 100644 --- a/src/being.h +++ b/src/being.h @@ -123,6 +123,15 @@ class Being : public Sprite NUM_SPEECH }; + enum AttackType + { + HIT = 0x00, + CRITICAL = 0x0a, + MULTI = 0x08, + REFLECT = 0x04, + FLEE = 0x0b + }; + /** * Directions, to be used as bitmask values */ @@ -171,22 +180,20 @@ class Being : public Sprite /** * Puts a damage bubble above this being. * - * @param amount The amount of damage. - */ - virtual void takeDamage(int amount); - - /** - * Puts a crit notification bubble above this being. + * @param attacker the attacking being + * @param damage the amount of damage recieved (0 means miss) + * @param type the attack type */ - virtual void showCrit(); + virtual void takeDamage(Being *attacker, int damage, AttackType type); /** * Handles an attack of another being by this being. * - * @param victim The attacked being. - * @param damage The amount of damage dealt (0 means miss). + * @param victim the victim being + * @param damage the amount of damage dealt (0 means miss) + * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage); + virtual void handleAttack(Being *victim, int damage, AttackType type); /** * Returns the name of the being. diff --git a/src/localplayer.h b/src/localplayer.h index 85868750..16e7c124 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -143,11 +143,11 @@ class LocalPlayer : public Player * displayed as soon as the player attacks, not when the server says * the player does. * - * @param victim The attacked being. - * @param damage The amount of damage dealt (0 means miss). + * @param victim the victim being + * @param damage the amount of damage dealt (0 means miss) + * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage) {} - + virtual void handleAttack(Being *victim, int damage, AttackType type) {} /** * Returns the current target of the player. Returns 0 if no being is * currently targeted. diff --git a/src/monster.cpp b/src/monster.cpp index 61c867e9..45d2fbeb 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -161,19 +161,19 @@ void Monster::setAction(Action action) } } -void Monster::handleAttack(Being *victim, int damage) +void Monster::handleAttack(Being *victim, int damage, AttackType type) { - Being::handleAttack(victim, damage); + Being::handleAttack(victim, damage, type); const MonsterInfo &mi = getInfo(); sound.playSfx(mi.getSound((damage > 0) ? MONSTER_EVENT_HIT : MONSTER_EVENT_MISS)); } -void Monster::takeDamage(int amount) +void Monster::takeDamage(Being *attacker, int amount, AttackType type) { if (amount > 0) sound.playSfx(getInfo().getSound(MONSTER_EVENT_HURT)); - Being::takeDamage(amount); + Being::takeDamage(attacker, amount, type); } Being::TargetCursorSize Monster::getTargetCursorSize() const diff --git a/src/monster.h b/src/monster.h index 12297373..afb55769 100644 --- a/src/monster.h +++ b/src/monster.h @@ -48,17 +48,20 @@ class Monster : public Being * Handles an attack of another being by this monster. Plays a hit or * miss sound when appropriate. * - * @param victim The attacked being. - * @param damage The amount of damage dealt (0 means miss). + * @param victim the victim being + * @param damage the amount of damage dealt (0 means miss) + * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage); + virtual void handleAttack(Being *victim, int damage, AttackType type); /** * Puts a damage bubble above this monster and plays the hurt sound * - * @param amount The amount of damage. + * @param attacker the attacking being + * @param damage the amount of damage recieved (0 means miss) + * @param type the attack type */ - virtual void takeDamage(int amount); + virtual void takeDamage(Being *attacker, int amount, AttackType type); /** * Returns the MonsterInfo, with static data about this monster. diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 4ff303ab..d1810537 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -229,14 +229,17 @@ void BeingHandler::handleMessage(MessageIn *msg) switch (type) { - case 0x0a: // Critical Damage + case Being::HIT: // Damage + case Being::CRITICAL: // Critical Damage + case Being::MULTI: // Critical Damage + case Being::REFLECT: // Reflected Damage + case Being::FLEE: // Lucky Dodge if (dstBeing) - dstBeing->showCrit(); - case 0x00: // Damage - if (dstBeing) - dstBeing->takeDamage(param1); + dstBeing->takeDamage(srcBeing, param1, + (Being::AttackType)type); if (srcBeing) - srcBeing->handleAttack(dstBeing, param1); + srcBeing->handleAttack(dstBeing, param1, + (Being::AttackType)type); break; case 0x02: // Sit |