From 51975cd8624fff3b20aa3b7b1932555e32786561 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 3 Apr 2011 20:10:33 +0300 Subject: Add spawn animation to mobs. Also impliment sound events: SOUND_EVENT_MOVE, SOUND_EVENT_SIT, SOUND_EVENT_SPAWN --- src/animatedsprite.cpp | 5 +++++ src/being.cpp | 11 +++++++++++ src/being.h | 3 ++- src/net/tmwa/beinghandler.cpp | 19 +++++++++++++++---- src/net/tmwa/beinghandler.h | 1 + src/resources/animation.cpp | 8 +++++++- src/resources/animation.h | 4 ++++ src/resources/beinginfo.h | 5 ++++- src/resources/monsterdb.cpp | 12 ++++++++++++ src/resources/spritedef.cpp | 5 +++++ src/resources/spritedef.h | 1 + 11 files changed, 67 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 5e33b65d2..10bb05cf8 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -159,6 +159,11 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time) mFrame = 0; return false; } + if (!mFrame->nextAction.empty()) + { + play(mFrame->nextAction); + return true; + } } return true; diff --git a/src/being.cpp b/src/being.cpp index 2e2c68283..a18f28ae3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -865,6 +865,8 @@ void Being::setAction(Action action, int attackType _UNUSED_) switch (action) { case MOVE: + if (mInfo) + sound.playSfx(mInfo->getSound(SOUND_EVENT_MOVE), mX, mY); currentAction = SpriteAction::MOVE; // Note: When adding a run action, // Differentiate walk and run with action name, @@ -872,6 +874,8 @@ void Being::setAction(Action action, int attackType _UNUSED_) break; case SIT: currentAction = SpriteAction::SIT; + if (mInfo) + sound.playSfx(mInfo->getSound(SOUND_EVENT_SIT), mX, mY); break; case ATTACK: if (mEquippedWeapon) @@ -919,6 +923,8 @@ void Being::setAction(Action action, int attackType _UNUSED_) break; case HURT: + if (mInfo) + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT), mX, mY); //currentAction = SpriteAction::HURT;// Buggy: makes the player stop // attacking and unable to attack // again until he moves. @@ -932,6 +938,11 @@ void Being::setAction(Action action, int attackType _UNUSED_) case STAND: currentAction = SpriteAction::STAND; break; + case SPAWN: + if (mInfo) + sound.playSfx(mInfo->getSound(SOUND_EVENT_SPAWN), mX, mY); + currentAction = SpriteAction::SPAWN; + break; default: logger->log("Being::setAction unknown action: " + toString(static_cast(action))); diff --git a/src/being.h b/src/being.h index 7d4883ba6..1faec9560 100644 --- a/src/being.h +++ b/src/being.h @@ -88,7 +88,8 @@ class Being : public ActorSprite, public ConfigListener ATTACK, SIT, DEAD, - HURT + HURT, + SPAWN, }; enum Speech diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 05f10854a..9e3cdefb8 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -61,7 +61,8 @@ const int EMOTION_TIME = 500; /**< Duration of emotion icon */ Being *createBeing(int id, short job); BeingHandler::BeingHandler(bool enableSync): - mSync(enableSync) + mSync(enableSync), + mSpawnId(0) { static const Uint16 _messages[] = { @@ -169,6 +170,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) int hp, maxHP, oldHP; unsigned char colors[9]; Uint8 dir; + int spawnId; switch (msg.getId()) { @@ -176,6 +178,11 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) case SMSG_BEING_MOVE: // Information about a being in range id = msg.readInt32(); + if (id == mSpawnId) + spawnId = mSpawnId; + else + spawnId = 0; + mSpawnId = 0; speed = msg.readInt16(); stunMode = msg.readInt16(); // opt1 statusEffects = msg.readInt16(); // opt2 @@ -208,6 +215,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) if (!dstBeing) break; + if (job == 1022 && killStats) killStats->jackoAlive(dstBeing->getId()); } @@ -223,14 +231,17 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) if (dstBeing->getType() == Being::PLAYER) dstBeing->setMoveTime(); - if (msg.getId() == SMSG_BEING_VISIBLE) + if (spawnId) + { + dstBeing->setAction(Being::SPAWN); + } + else if (msg.getId() == SMSG_BEING_VISIBLE) { dstBeing->clearPath(); dstBeing->setActionTime(tick_time); dstBeing->setAction(Being::STAND); } - // Prevent division by 0 when calculating frame if (speed == 0) speed = 150; @@ -401,7 +412,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) case SMSG_BEING_SPAWN: // skipping this packet - msg.readInt32(); // id + mSpawnId = msg.readInt32(); // id msg.readInt16(); // speed msg.readInt16(); // opt1 msg.readInt16(); // opt2 diff --git a/src/net/tmwa/beinghandler.h b/src/net/tmwa/beinghandler.h index 1484567fd..aa278b1d6 100644 --- a/src/net/tmwa/beinghandler.h +++ b/src/net/tmwa/beinghandler.h @@ -45,6 +45,7 @@ class BeingHandler : public MessageHandler, public Net::BeingHandler private: // Should we honor server "Stop Walking" packets bool mSync; + int mSpawnId; }; } // namespace TmwAthena diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index 328824827..fe5822f7b 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -31,7 +31,7 @@ Animation::Animation(): void Animation::addFrame(Image *image, int delay, int offsetX, int offsetY) { - Frame frame = { image, delay, offsetX, offsetY }; + Frame frame = { image, delay, offsetX, offsetY, "" }; mFrames.push_back(frame); mDuration += delay; } @@ -45,3 +45,9 @@ bool Animation::isTerminator(const Frame &candidate) { return (candidate.image == NULL); } + +void Animation::addJump(std::string name) +{ + Frame frame = { 0, 0, 0, 0, name }; + mFrames.push_back(frame); +} diff --git a/src/resources/animation.h b/src/resources/animation.h index a78850b3a..9ec8396af 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -26,6 +26,7 @@ #include #include +#include class Image; @@ -38,6 +39,7 @@ struct Frame int delay; int offsetX; int offsetY; + std::string nextAction; }; /** @@ -78,6 +80,8 @@ class Animation int getDuration() const { return mDuration; } + void addJump(std::string name); + /** * Determines whether the given animation frame is a terminator. */ diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index d5c0c6b28..192a4c3b5 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -54,7 +54,10 @@ enum SoundEvent SOUND_EVENT_HIT = 0, SOUND_EVENT_MISS, SOUND_EVENT_HURT, - SOUND_EVENT_DIE + SOUND_EVENT_DIE, + SOUND_EVENT_MOVE, + SOUND_EVENT_SIT, + SOUND_EVENT_SPAWN }; typedef std::map* > SoundEvents; diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 8990d679a..9fce60306 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -134,6 +134,18 @@ void MonsterDB::load() { currentInfo->addSound(SOUND_EVENT_DIE, filename); } + else if (event == "move") + { + currentInfo->addSound(SOUND_EVENT_MOVE, filename); + } + else if (event == "sit") + { + currentInfo->addSound(SOUND_EVENT_SIT, filename); + } + else if (event == "spawn") + { + currentInfo->addSound(SOUND_EVENT_SPAWN, filename); + } else { logger->log("MonsterDB: Warning, sound effect %s for " diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index ceefac845..b3b473cd7 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -102,6 +102,7 @@ void SpriteDef::substituteActions() substituteAction(SpriteAction::SLEEP, SpriteAction::SIT); substituteAction(SpriteAction::HURT, SpriteAction::STAND); substituteAction(SpriteAction::DEAD, SpriteAction::HURT); + substituteAction(SpriteAction::SPAWN, SpriteAction::STAND); } void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, @@ -287,6 +288,10 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, { animation->addTerminator(); } + else if (xmlStrEqual(frameNode->name, BAD_CAST "jump")) + { + animation->addJump(XML::getProperty(frameNode, "action", "")); + } } // for frameNode } diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 1ad74d744..424d88869 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -84,6 +84,7 @@ namespace SpriteAction static const std::string USE_SPECIAL = "special"; static const std::string CAST_MAGIC = "magic"; static const std::string USE_ITEM = "item"; + static const std::string SPAWN = "spawn"; static const std::string INVALID = ""; } -- cgit v1.2.3-60-g2f50