diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 60 | ||||
-rw-r--r-- | src/being.h | 17 | ||||
-rw-r--r-- | src/beingmanager.cpp | 5 | ||||
-rw-r--r-- | src/monster.cpp | 36 | ||||
-rw-r--r-- | src/monster.h | 2 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 51 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 6 | ||||
-rw-r--r-- | src/player.cpp | 22 | ||||
-rw-r--r-- | src/resources/monsterinfo.cpp | 8 | ||||
-rw-r--r-- | src/resources/monsterinfo.h | 2 |
10 files changed, 113 insertions, 96 deletions
diff --git a/src/being.cpp b/src/being.cpp index c47ce90f..e6077d35 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -166,7 +166,7 @@ Being::setMap(Map *map) void Being::setAction(Uint8 action) { - SpriteAction currentAction = ACTION_STAND; + SpriteAction currentAction = ACTION_INVALID; switch (action) { case WALK: @@ -176,50 +176,56 @@ Being::setAction(Uint8 action) currentAction = ACTION_SIT; break; case ATTACK: - if (getType() == MONSTER) + switch (getWeapon()) { - currentAction = ACTION_DEAD; + case 3: + currentAction = ACTION_ATTACK; + break; + case 2: + currentAction = ACTION_ATTACK_BOW; + break; + case 1: + currentAction = ACTION_ATTACK_STAB; + break; + case 0: + currentAction = ACTION_ATTACK; + break; } - else { - switch (getWeapon()) + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i]) { - case 3: - currentAction = ACTION_ATTACK; - break; - case 2: - currentAction = ACTION_ATTACK_BOW; - break; - case 1: - currentAction = ACTION_ATTACK_STAB; - break; - case 0: - currentAction = ACTION_ATTACK; - break; + mSprites[i]->reset(); } - }; + } break; - case MONSTER_ATTACK: - currentAction = ACTION_ATTACK; + case HURT: + //currentAction = ACTION_HURT; // Buggy: makes the player stop + // attacking and unable to attack + // again until he moves break; case DEAD: currentAction = ACTION_DEAD; break; - default: + case STAND: currentAction = ACTION_STAND; break; } - for (int i = 0; i < VECTOREND_SPRITE; i++) + if (currentAction != ACTION_INVALID) { - if (mSprites[i]) + for (int i = 0; i < VECTOREND_SPRITE; i++) { - mSprites[i]->play(currentAction); + if (mSprites[i]) + { + mSprites[i]->play(currentAction); + } } + mAction = action; } - - mAction = action; } + void Being::setDirection(Uint8 direction) { @@ -366,7 +372,7 @@ Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) } // Draw damage above this being - if (mShowDamage) + if (mShowDamage && get_elapsed_time(mDamageTime) > 250) { // Selecting the right color if (mDamage == "miss") diff --git a/src/being.h b/src/being.h index 81f7bc07..80b07e87 100644 --- a/src/being.h +++ b/src/being.h @@ -68,14 +68,12 @@ class Being : public Sprite }; enum Action { - STAND = 0, - WALK = 1, - MONSTER_ATTACK = 5, - SIT = 7, - DEAD = 8, - ATTACK = 9, - MONSTER_DEAD = 9, - HIT = 17 + STAND, + WALK, + ATTACK, + SIT, + DEAD, + HURT }; enum Sprite { @@ -290,7 +288,8 @@ class Being : public Sprite /** * Sets the current action. */ - void setAction(Uint8 action); + virtual void + setAction(Uint8 action); /** * Returns the current direction. diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 027e08d3..eea8c419 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -41,7 +41,7 @@ class FindBeingFunctor Uint16 other_y = y + ((being->getType() == Being::NPC) ? 1 : 0); return (being->mX == x && (being->mY == y || being->mY == other_y) && - being->mAction != Being::MONSTER_DEAD && + being->mAction != Being::DEAD && (type == Being::UNKNOWN || being->getType() == type)); } @@ -133,7 +133,7 @@ void BeingManager::logic() being->logic(); - if (being->mAction == Being::MONSTER_DEAD && being->mFrame >= 20) + if (being->mAction == Being::DEAD && being->mFrame >= 20) { delete being; i = mBeings.erase(i); @@ -174,7 +174,6 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer && being->mAction != Being::DEAD // no dead beings - && being->mAction != Being::MONSTER_DEAD ) { dist = d; diff --git a/src/monster.cpp b/src/monster.cpp index 017c088e..f624ff07 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -25,6 +25,7 @@ #include "animatedsprite.h" #include "game.h" +#include "sound.h" #include "resources/monsterdb.h" @@ -45,7 +46,7 @@ Monster::logic() { mFrame = (get_elapsed_time(mWalkTime) * 4) / mWalkSpeed; - if (mFrame >= 4 && mAction != MONSTER_DEAD) + if (mFrame >= 4 && mAction != DEAD) { nextStep(); } @@ -60,3 +61,36 @@ Monster::getType() const return MONSTER; } +void +Monster::setAction(Uint8 action) +{ + SpriteAction currentAction = ACTION_INVALID; + + switch (action) + { + case WALK: + currentAction = ACTION_WALK; + break; + case DEAD: + currentAction = ACTION_DEAD; + sound.playSfx(MonsterDB::get(mJob-1002).getSound(EVENT_DIE).c_str()); + break; + case ATTACK: + currentAction = ACTION_ATTACK; + sound.playSfx(MonsterDB::get(mJob-1002).getSound(EVENT_HIT).c_str()); + mSprites[BASE_SPRITE]->reset(); + break; + case STAND: + currentAction = ACTION_STAND; + break; + case HURT: + // Not implemented yet + break; + } + + if (currentAction != ACTION_INVALID) + { + mSprites[BASE_SPRITE]->play(currentAction); + mAction = action; + } +} diff --git a/src/monster.h b/src/monster.h index 4a82a461..3d3cd546 100644 --- a/src/monster.h +++ b/src/monster.h @@ -33,6 +33,8 @@ class Monster : public Being virtual void logic(); + virtual void setAction(Uint8 action); + virtual Type getType() const; }; diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 67d04ee4..5a1ed1e5 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -107,7 +107,7 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->mJob = job; dstBeing->setHairStyle(msg->readInt16()); dstBeing->setWeapon(msg->readInt16()); - dstBeing->setVisibleEquipment(3, msg->readInt16()); // head bottom + dstBeing->setVisibleEquipment(Being::BOTTOMCLOTHES_SPRITE, msg->readInt16()); // head bottom if (msg->getId() == SMSG_BEING_MOVE) { @@ -115,8 +115,8 @@ void BeingHandler::handleMessage(MessageIn *msg) } msg->readInt16(); // shield - dstBeing->setVisibleEquipment(4, msg->readInt16()); // head top - dstBeing->setVisibleEquipment(5, msg->readInt16()); // head mid + dstBeing->setVisibleEquipment(Being::HAT_SPRITE, msg->readInt16()); // head top + dstBeing->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, msg->readInt16()); // head mid dstBeing->setHairColor(msg->readInt16()); msg->readInt16(); // unknown msg->readInt16(); // head dir @@ -158,19 +158,7 @@ void BeingHandler::handleMessage(MessageIn *msg) if (msg->readInt8() == 1) { - // Death - switch (dstBeing->getType()) - { - case Being::MONSTER: - dstBeing->setAction(Being::MONSTER_DEAD); - dstBeing->mFrame = 0; - dstBeing->mWalkTime = tick_time; - break; - - default: - dstBeing->setAction(Being::DEAD); - break; - } + dstBeing->setAction(Being::DEAD); } else { @@ -204,15 +192,7 @@ void BeingHandler::handleMessage(MessageIn *msg) if (srcBeing != NULL && srcBeing != player_node) { - // buggy - if (srcBeing->getType() == Being::MONSTER) - { - srcBeing->setAction(Being::MONSTER_ATTACK); - } - else - { - srcBeing->setAction(Being::ATTACK); - } + srcBeing->setAction(Being::ATTACK); srcBeing->mFrame = 0; srcBeing->mWalkTime = tick_time; } @@ -272,9 +252,18 @@ void BeingHandler::handleMessage(MessageIn *msg) case 4: case 5: // Equip/unequip head 3. Bottom 4. Top 5. Middle - dstBeing->setVisibleEquipment(type, msg->readInt8()); - // First 3 slots of mVisibleEquipments are reserved for - // later use, probably accessories. + switch (msg->readInt8()) + { + case 3: + dstBeing->setVisibleEquipment(Being::BOTTOMCLOTHES_SPRITE, msg->readInt8()); + break; + case 4: + dstBeing->setVisibleEquipment(Being::HAT_SPRITE, msg->readInt8()); + break; + case 5: + dstBeing->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, msg->readInt8()); + break; + } break; case 6: dstBeing->setHairColor(msg->readInt8()); @@ -333,9 +322,9 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt16(); // manner msg->readInt8(); // karma dstBeing->setSex(1 - msg->readInt8()); // sex - dstBeing->setVisibleEquipment(3, headBottom); - dstBeing->setVisibleEquipment(4, headTop); - dstBeing->setVisibleEquipment(5, headMid); + dstBeing->setVisibleEquipment(Being::BOTTOMCLOTHES_SPRITE, headBottom); + dstBeing->setVisibleEquipment(Being::HAT_SPRITE, headTop); + dstBeing->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, headMid); if (msg->getId() == SMSG_PLAYER_MOVE) { diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 06ec78c1..64b7f8cd 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -191,10 +191,10 @@ LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot) tempPlayer->setWeapon(weapon); tempPlayer->mLevel = msg->readInt16(); msg->readInt16(); // skill point - tempPlayer->setVisibleEquipment(3, msg->readInt16()); // head bottom + tempPlayer->setVisibleEquipment(Being::BOTTOMCLOTHES_SPRITE, msg->readInt16()); // head bottom msg->readInt16(); // shield - tempPlayer->setVisibleEquipment(4, msg->readInt16()); // head option top - tempPlayer->setVisibleEquipment(5, msg->readInt16()); // head option mid + tempPlayer->setVisibleEquipment(Being::HAT_SPRITE, msg->readInt16()); // head option top + tempPlayer->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, msg->readInt16()); // head option mid tempPlayer->setHairColor(msg->readInt16()); msg->readInt16(); // unknown tempPlayer->setName(msg->readString(24)); diff --git a/src/player.cpp b/src/player.cpp index 533d88fa..a543b345 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -197,25 +197,11 @@ Player::setHairStyle(Uint16 style) void Player::setVisibleEquipment(Uint8 slot, int id) { - // Translate eAthena specific slot - Uint8 position = 0; - switch (slot) { - case 3: - position = BOTTOMCLOTHES_SPRITE; - break; - case 4: - position = HAT_SPRITE; - break; - case 5: - position = TOPCLOTHES_SPRITE; - break; - } - // id = 0 means unequip if (id == 0) { - delete mSprites[position]; - mSprites[position] = NULL; + delete mSprites[slot]; + mSprites[slot] = NULL; } else { @@ -233,8 +219,8 @@ Player::setVisibleEquipment(Uint8 slot, int id) equipmentSprite->setDirection(getSpriteDirection()); - delete mSprites[position]; - mSprites[position] = equipmentSprite; + delete mSprites[slot]; + mSprites[slot] = equipmentSprite; setAction(mAction); } diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index 1808d1c8..43aac32a 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -48,14 +48,16 @@ MonsterInfo::addSound (SoundEvent event, std::string filename) mSounds[event] = new std::vector<std::string>;
}
- mSounds[event]->push_back(filename);
+ mSounds[event]->push_back("sfx/" + filename);
}
std::string
-MonsterInfo::getSound (SoundEvent event)
+MonsterInfo::getSound (SoundEvent event) const
{
- std::map<SoundEvent, std::vector<std::string>* >::iterator i = mSounds.find(event);
+ std::map<SoundEvent, std::vector<std::string>* >::const_iterator i;
+
+ i = mSounds.find(event);
if (i == mSounds.end())
{
diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index c5ded375..413dafa0 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -61,7 +61,7 @@ class MonsterInfo getSprite () const { return mSprite; };
std::string
- getSound (SoundEvent event);
+ getSound (SoundEvent event) const;
private:
|