diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-05 21:33:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-05 21:33:44 +0300 |
commit | e6d7fca349c28eaf98d643325dc99dd9d3a53568 (patch) | |
tree | 84ac779d45a0094dde45d9a05039db41d568adbf | |
parent | a48638c5e9bfc04876661ea938eed4a3ab9e5c42 (diff) | |
download | mv-e6d7fca349c28eaf98d643325dc99dd9d3a53568.tar.gz mv-e6d7fca349c28eaf98d643325dc99dd9d3a53568.tar.bz2 mv-e6d7fca349c28eaf98d643325dc99dd9d3a53568.tar.xz mv-e6d7fca349c28eaf98d643325dc99dd9d3a53568.zip |
first part for adding mobs particle effects.
Based on mana commit b35aef2d924f03d85eb44a2465be5a745444eafd
by Yohann Ferreira
-rw-r--r-- | src/being.cpp | 71 | ||||
-rw-r--r-- | src/being.h | 3 | ||||
-rw-r--r-- | src/effectmanager.cpp | 10 | ||||
-rw-r--r-- | src/effectmanager.h | 5 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 11 | ||||
-rw-r--r-- | src/resources/beinginfo.h | 22 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 12 |
7 files changed, 66 insertions, 68 deletions
diff --git a/src/being.cpp b/src/being.cpp index 1f637ef06..0df07870f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -198,7 +198,6 @@ Being::Being(const int id, const Type type, const uint16_t subtype, mEmotion(0), mEmotionTime(0), mSpeechTime(0), - mAttackType(1), mAttackSpeed(350), mAction(STAND), mSubType(0xFFFF), @@ -645,9 +644,8 @@ void Being::takeDamage(Being *const attacker, const int amount, int hitEffectId = 0; if (type != SKILL) { - const ItemInfo *const attackerWeapon - = attacker->getEquippedWeapon(); - if (attacker->mType == PLAYER && attackerWeapon) + const ItemInfo *attackerWeapon = attacker->getEquippedWeapon(); + if (attackerWeapon && attacker->getType() == PLAYER) { if (type != CRITICAL) hitEffectId = attackerWeapon->getHitEffectId(); @@ -673,18 +671,18 @@ void Being::takeDamage(Being *const attacker, const int amount, } void Being::handleAttack(Being *const victim, const int damage, - const AttackType type A_UNUSED) + const int attackId) { if (!victim || !mInfo) return; if (this != player_node) - setAction(Being::ATTACK, 1); + setAction(Being::ATTACK, attackId); if (mType == PLAYER && mEquippedWeapon) fireMissile(victim, mEquippedWeapon->getMissileParticleFile()); - else if (mInfo->getAttack(mAttackType)) - fireMissile(victim, mInfo->getAttack(mAttackType)->missileParticle); + else if (mInfo->getAttack(attackId)) + fireMissile(victim, mInfo->getAttack(attackId)->mMissileParticle); #ifdef MANASERV_SUPPORT if (Net::getNetworkType() != ServerInfo::MANASERV) @@ -978,7 +976,7 @@ std::string Being::getSitAction() const } } -void Being::setAction(const Action &action, const int attackType A_UNUSED) +void Being::setAction(const Action &action, const int attackId) { std::string currentAction = SpriteAction::INVALID; @@ -1005,6 +1003,7 @@ void Being::setAction(const Action &action, const int attackType A_UNUSED) } break; case ATTACK: +// mAttackId = attackId; if (mEquippedWeapon) { currentAction = mEquippedWeapon->getAttackAction(); @@ -1012,43 +1011,39 @@ void Being::setAction(const Action &action, const int attackType A_UNUSED) } else { - mAttackType = attackType; - if (!mInfo || !mInfo->getAttack(attackType)) + if (!mInfo || !mInfo->getAttack(attackId)) break; - currentAction = mInfo->getAttack(attackType)->action; + currentAction = mInfo->getAttack(attackId)->mAction; reset(); -#ifdef MANASERV_SUPPORT - if (Net::getNetworkType() == ServerInfo::MANASERV - && mInfo->getAttack(attackType)) + //attack particle effect + if (Particle::enabled) { - //attack particle effect - std::string particleEffect = mInfo->getAttack(attackType) - ->particleEffect; - if (!particleEffect.empty() && Particle::enabled) + int effectId = mInfo->getAttack(attackId)->mEffectId; + + int rotation = 0; + switch (mSpriteDirection) { - int rotation = 0; - switch (mSpriteDirection) - { - case DIRECTION_DOWN: rotation = 0; break; - case DIRECTION_LEFT: rotation = 90; break; - case DIRECTION_UP: rotation = 180; break; - case DIRECTION_RIGHT: rotation = 270; break; - default: break; - } - if (particleEngine) - { - Particle *p = particleEngine->addEffect( - particleEffect, 0, 0, rotation); - if (p) - controlParticle(p); - } + case DIRECTION_DOWN: + rotation = 0; + break; + case DIRECTION_LEFT: + rotation = 90; + break; + case DIRECTION_UP: + rotation = 180; + break; + case DIRECTION_RIGHT: + rotation = 270; + break; + default: + break; } + if (effectManager) + effectManager->trigger(effectId, this, rotation); } -#endif } - break; case HURT: if (mInfo) @@ -1327,6 +1322,7 @@ void Being::logic() / mAttackSpeed; } +/* //attack particle effect if (mEquippedWeapon) { @@ -1363,6 +1359,7 @@ void Being::logic() particleEffect, 0, 0, rotation); controlParticle(p); } +*/ if (this == player_node && curFrame >= frameCount) nextTile(); diff --git a/src/being.h b/src/being.h index c1a9d8dbd..95fff8b51 100644 --- a/src/being.h +++ b/src/being.h @@ -268,7 +268,7 @@ class Being : public ActorSprite, public ConfigListener * @param type the attack type */ virtual void handleAttack(Being *const victim, const int damage, - const AttackType type); + const int attackId = 1); virtual void handleSkill(Being *const victim, const int damage, const int skillId); @@ -860,7 +860,6 @@ class Being : public ActorSprite, public ConfigListener /** Time until the last speech sentence disappears */ int mSpeechTime; - int mAttackType; int mAttackSpeed; /**< Attack speed */ Action mAction; /**< Action the being is performing */ diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index 42c6d471d..f80a16972 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -61,7 +61,8 @@ EffectManager::~EffectManager() { } -bool EffectManager::trigger(const int id, Being *const being) +bool EffectManager::trigger(const int id, Being *const being, + const int rotation) { if (!being || !particleEngine) return false; @@ -76,7 +77,7 @@ bool EffectManager::trigger(const int id, Being *const being) if (!(*i).GFX.empty()) { Particle *const selfFX = particleEngine->addEffect( - (*i).GFX, 0, 0); + (*i).GFX, 0, 0, rotation); being->controlParticle(selfFX); } if (!(*i).SFX.empty()) @@ -87,7 +88,8 @@ bool EffectManager::trigger(const int id, Being *const being) return rValue; } -bool EffectManager::trigger(const int id, const int x, const int y) +bool EffectManager::trigger(const int id, const int x, const int y, + const int rotation) { if (!particleEngine) return false; @@ -100,7 +102,7 @@ bool EffectManager::trigger(const int id, const int x, const int y) { rValue = true; if (!(*i).GFX.empty() && particleEngine) - particleEngine->addEffect((*i).GFX, x, y); + particleEngine->addEffect((*i).GFX, x, y, rotation); if (!(*i).SFX.empty()) sound.playSfx((*i).SFX); break; diff --git a/src/effectmanager.h b/src/effectmanager.h index 190f1d0ce..b877b2cf1 100644 --- a/src/effectmanager.h +++ b/src/effectmanager.h @@ -48,13 +48,14 @@ class EffectManager final * Triggers a effect with the id, at * the specified being. */ - bool trigger(const int id, Being *const being); + bool trigger(const int id, Being *const being, const int rotation = 0); /** * Triggers a effect with the id, at * the specified x and y coordinate. */ - bool trigger(const int id, const int x, const int y); + bool trigger(const int id, const int x, const int y, + const int rotation = 0); private: std::vector<EffectDescription> mEffects; diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 5ffdb887d..992a43b5b 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -30,7 +30,7 @@ #include "debug.h" BeingInfo *BeingInfo::unknown = nullptr; -Attack *BeingInfo::empty = new Attack(SpriteAction::ATTACK, "", ""); +Attack *BeingInfo::empty = new Attack(SpriteAction::ATTACK, -1, std::string()); BeingInfo::BeingInfo() : mName(_("unnamed")), @@ -106,21 +106,20 @@ const std::string &BeingInfo::getSound(const SoundEvent event) const i->second->at(rand() % i->second->size()); } -const Attack *BeingInfo::getAttack(const int type) const +const Attack *BeingInfo::getAttack(const int id) const { - const Attacks::const_iterator i = mAttacks.find(type); + const Attacks::const_iterator i = mAttacks.find(id); return (i == mAttacks.end()) ? empty : (*i).second; } -void BeingInfo::addAttack(const int id, std::string action, - const std::string &particleEffect, +void BeingInfo::addAttack(const int id, std::string action, const int effectId, const std::string &missileParticle) { if (mAttacks[id]) delete mAttacks[id]; - mAttacks[id] = new Attack(action, particleEffect, missileParticle); + mAttacks[id] = new Attack(action, effectId, missileParticle); } void BeingInfo::clear() diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index ccd9ccf21..ceaed6c40 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -30,15 +30,15 @@ struct Attack final { - std::string action; - std::string particleEffect; - std::string missileParticle; - - Attack(std::string action0, std::string particleEffect0, - std::string missileParticle0) : - action(action0), - particleEffect(particleEffect0), - missileParticle(missileParticle0) + std::string mAction; + int mEffectId; + std::string mMissileParticle; + + Attack(const std::string &action, const int effectId, + const std::string &missileParticle) : + mAction(action), + mEffectId(effectId), + mMissileParticle(missileParticle) { } }; @@ -101,10 +101,10 @@ class BeingInfo final const std::string &getSound(const SoundEvent event) const; void addAttack(const int id, std::string action, - const std::string &particleEffect, + const int effectId, const std::string &missileParticle); - const Attack *getAttack(const int type) const; + const Attack *getAttack(const int id) const; void setWalkMask(const unsigned char mask) { mWalkMask = mask; } diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index a7976b97d..f6352d8ec 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -190,15 +190,15 @@ void MonsterDB::load() else if (xmlNameEqual(spriteNode, "attack")) { const int id = XML::getProperty(spriteNode, "id", 0); - const std::string particleEffect = XML::getProperty( - spriteNode, "particle-effect", ""); - const std::string spriteAction = XML::getProperty(spriteNode, - "action", - "attack"); + const int effectId = XML::getProperty( + spriteNode, "effect-id", -1); + const std::string spriteAction = XML::getProperty( + spriteNode, "action", "attack"); + const std::string missileParticle = XML::getProperty( spriteNode, "missile-particle", ""); currentInfo->addAttack(id, spriteAction, - particleEffect, missileParticle); + effectId, missileParticle); } else if (xmlNameEqual(spriteNode, "particlefx")) { |