diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-02-20 20:55:37 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-02-20 20:55:37 +0000 |
commit | e99b6aaeb119feabfa2f7c3c49908625981e9708 (patch) | |
tree | 00f599c90443be884b9b8b51618552c2f8834f2d /src | |
parent | eadbe0cb009b8c8fec622946f0b0109a2f07b1f1 (diff) | |
download | mana-client-e99b6aaeb119feabfa2f7c3c49908625981e9708.tar.gz mana-client-e99b6aaeb119feabfa2f7c3c49908625981e9708.tar.bz2 mana-client-e99b6aaeb119feabfa2f7c3c49908625981e9708.tar.xz mana-client-e99b6aaeb119feabfa2f7c3c49908625981e9708.zip |
Now different sounds can play when a monster misses the player.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 10 | ||||
-rw-r--r-- | src/being.h | 19 | ||||
-rw-r--r-- | src/localplayer.h | 17 | ||||
-rw-r--r-- | src/monster.cpp | 18 | ||||
-rw-r--r-- | src/monster.h | 18 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 31 |
6 files changed, 87 insertions, 26 deletions
diff --git a/src/being.cpp b/src/being.cpp index bfed2d51..03129c61 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -152,13 +152,21 @@ Being::setSpeech(const std::string &text, Uint32 time) } void -Being::setDamage(Sint16 amount, Uint32 time) +Being::takeDamage(int amount) { mDamage = amount ? toString(amount) : "miss"; mDamageTime = 300; } void +Being::handleAttack(Being *victim, int damage) +{ + setAction(Being::ATTACK); + mFrame = 0; + mWalkTime = tick_time; +} + +void Being::setMap(Map *map) { // Remove sprite from potential previous map diff --git a/src/being.h b/src/being.h index 91913385..9dda42a7 100644 --- a/src/being.h +++ b/src/being.h @@ -141,13 +141,22 @@ class Being : public Sprite void setSpeech(const std::string &text, Uint32 time); /** - * Puts a damage bubble above this being for the specified amount - * of time. + * Puts a damage bubble above this being for the specified amount of + * time. * - * @param text The text that should appear. - * @param time The amount of time the text should stay in milliseconds. + * @param amount The amount of damage. */ - void setDamage(Sint16 amount, Uint32 time); + virtual void + takeDamage(int amount); + + /** + * Handles an attack of another being by this being. + * + * @param victim The attacked being. + * @param damage The amount of damage dealt (0 means miss). + */ + virtual void + handleAttack(Being *victim, int damage); /** * Returns the name of the being. diff --git a/src/localplayer.h b/src/localplayer.h index b120969e..f4ba3747 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -36,6 +36,9 @@ class Inventory; class Item; class Network; +/** + * The local player character. + */ class LocalPlayer : public Player { public: @@ -112,11 +115,23 @@ class LocalPlayer : public Player */ void setTrading(bool trading) { mTrading = trading; } - void attack(Being *target=NULL, bool keep=false); + void attack(Being *target = NULL, bool keep = false); + void stopAttack(); + Being* getTarget() const; /** + * Overridden to do nothing. The attacks of the local player are + * 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). + */ + virtual void handleAttack(Being *victim, int damage) {} + + /** * Sets the target being of the player. */ void setTarget(Being* target) { mTarget = target; } diff --git a/src/monster.cpp b/src/monster.cpp index 68e9d6ba..c20e12d0 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -73,11 +73,10 @@ Monster::setAction(Uint8 action) break; case DEAD: currentAction = ACTION_DEAD; - sound.playSfx(MonsterDB::get(mJob - 1002).getSound(EVENT_DIE)); + sound.playSfx(getInfo().getSound(EVENT_DIE)); break; case ATTACK: currentAction = ACTION_ATTACK; - sound.playSfx(MonsterDB::get(mJob - 1002).getSound(EVENT_HIT)); mSprites[BASE_SPRITE]->reset(); break; case STAND: @@ -94,3 +93,18 @@ Monster::setAction(Uint8 action) mAction = action; } } + +void +Monster::handleAttack(Being *victim, int damage) +{ + Being::handleAttack(victim, damage); + + const MonsterInfo &mi = getInfo(); + sound.playSfx(mi.getSound((damage > 0) ? EVENT_HIT : EVENT_MISS)); +} + +const MonsterInfo& +Monster::getInfo() const +{ + return MonsterDB::get(mJob - 1002); +} diff --git a/src/monster.h b/src/monster.h index 3d3cd546..1b666db4 100644 --- a/src/monster.h +++ b/src/monster.h @@ -26,6 +26,8 @@ #include "being.h" +class MonsterInfo; + class Monster : public Being { public: @@ -36,6 +38,22 @@ class Monster : public Being virtual void setAction(Uint8 action); virtual Type getType() const; + + /** + * 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). + */ + virtual void handleAttack(Being *victim, int damage); + + protected: + /** + * Returns the MonsterInfo, with static data about this monster. + */ + const MonsterInfo& + getInfo() const; }; #endif diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 46c44664..4734a710 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -187,35 +187,32 @@ void BeingHandler::handleMessage(MessageIn *msg) switch (type) { case 0: // Damage - if (dstBeing == NULL) break; - - dstBeing->setDamage(param1, SPEECH_TIME); - - if (srcBeing != NULL && - srcBeing != player_node) - { - srcBeing->setAction(Being::ATTACK); - srcBeing->mFrame = 0; - srcBeing->mWalkTime = tick_time; + if (dstBeing) { + dstBeing->takeDamage(param1); + } + if (srcBeing) { + srcBeing->handleAttack(dstBeing, param1); } break; case 2: // Sit - if (srcBeing == NULL) break; - srcBeing->mFrame = 0; - srcBeing->setAction(Being::SIT); + if (srcBeing) { + srcBeing->mFrame = 0; + srcBeing->setAction(Being::SIT); + } break; case 3: // Stand up - if (srcBeing == NULL) break; - srcBeing->mFrame = 0; - srcBeing->setAction(Being::STAND); + if (srcBeing) { + srcBeing->mFrame = 0; + srcBeing->setAction(Being::STAND); + } break; } break; case SMSG_BEING_LEVELUP: - if ((Uint32)msg->readInt32() == player_node->getId()) { + if ((Uint32) msg->readInt32() == player_node->getId()) { logger->log("Level up"); sound.playSfx("sfx/levelup.ogg"); } else { |