diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-05-26 23:41:01 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-05-26 23:42:10 +0200 |
commit | b35aef2d924f03d85eb44a2465be5a745444eafd (patch) | |
tree | 5de5dc327397f9e970ce1bdfacf850a16da02241 /src/being.cpp | |
parent | b02081c00450d274c23b7198620ee7748756bd72 (diff) | |
download | mana-client-b35aef2d924f03d85eb44a2465be5a745444eafd.tar.gz mana-client-b35aef2d924f03d85eb44a2465be5a745444eafd.tar.bz2 mana-client-b35aef2d924f03d85eb44a2465be5a745444eafd.tar.xz mana-client-b35aef2d924f03d85eb44a2465be5a745444eafd.zip |
Added effects support in monsters attacks.
This is provided through the use of the 'effect-id' property
of the <attack> tag.
Note that the 'particle-effect' support has been removed
as it was redundant, but can be kept for backward compatibility.
Now, on both Manaserv and tA, only the attack id 1 is supported,
i.e:
<monster>
...
<attack id="1" effect-id="11" action="attack" />
</monster>
More to come with re-enabling of the attack type support.
I had to fix a crash in the Being::takeDamage() function
when there were no attacker (in Manaserv), and add rotation
support to the effectManager to achieve this.
Reviwed-by: Jaxad0127.
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/being.cpp b/src/being.cpp index 40479236..d6c5fd55 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -76,7 +76,6 @@ Being::Being(int id, Type type, int subtype, Map *map): mInfo(BeingInfo::Unknown), mActionTime(0), mSpeechTime(0), - mAttackType(1), mAttackSpeed(350), mAction(STAND), mSubType(0xFFFF), @@ -391,8 +390,10 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) // Init the particle effect path based on current weapon or default. int hitEffectId = 0; - const ItemInfo *attackerWeapon = attacker->getEquippedWeapon(); - if (attacker->getType() == PLAYER && attackerWeapon) + const ItemInfo *attackerWeapon = attacker ? + attacker->getEquippedWeapon() : 0; + + if (attackerWeapon && attacker->getType() == PLAYER) { if (type != CRITICAL) hitEffectId = attackerWeapon->getHitEffectId(); @@ -410,10 +411,16 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) } } -void Being::handleAttack(Being *victim, int damage, AttackType type) +void Being::handleAttack(Being *victim, int damage, int attackId) { + // Monsters, NPCs and remote players handle the first attack (id="1") + // per default. + // TODO: Fix this for Manaserv by sending the attack id. + // TODO: Add attack type handling, see Attack struct and AttackType + // and make use of it by grouping attacks per attack type and add random + // attack use on tA, based on normal and critical attack types. if (this != player_node) - setAction(Being::ATTACK, 1); + setAction(Being::ATTACK, attackId); if (victim) lookAt(victim->getPosition()); @@ -421,7 +428,8 @@ void Being::handleAttack(Being *victim, int damage, AttackType type) if (getType() == PLAYER && victim && mEquippedWeapon) fireMissile(victim, mEquippedWeapon->getMissileParticleFile()); else - fireMissile(victim, mInfo->getAttack(mAttackType)->missileParticle); + fireMissile(victim, + mInfo->getAttack(attackId)->mMissileParticleFilename); sound.playSfx(mInfo->getSound((damage > 0) ? SOUND_EVENT_HIT : SOUND_EVENT_MISS), @@ -585,7 +593,7 @@ void Being::fireMissile(Being *victim, const std::string &particle) } -void Being::setAction(Action action, int attackType) +void Being::setAction(Action action, int attackId) { std::string currentAction = SpriteAction::INVALID; @@ -608,16 +616,14 @@ void Being::setAction(Action action, int attackType) } else { - mAttackType = attackType; - currentAction = mInfo->getAttack(attackType)->action; + currentAction = mInfo->getAttack(attackId)->mAction; reset(); - int rotation = 0; - //attack particle effect - std::string particleEffect = mInfo->getAttack(attackType) - ->particleEffect; - if (!particleEffect.empty() && Particle::enabled) + // Attack particle effect + if (Particle::enabled) { + int effectId = mInfo->getAttack(attackId)->mEffectId; + int rotation = 0; switch (mSpriteDirection) { case DIRECTION_DOWN: rotation = 0; break; @@ -626,10 +632,7 @@ void Being::setAction(Action action, int attackType) case DIRECTION_RIGHT: rotation = 270; break; default: break; } - Particle *p; - p = particleEngine->addEffect(particleEffect, 0, 0, - rotation); - controlParticle(p); + effectManager->trigger(effectId, this, rotation); } } |