diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-29 01:21:45 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-30 15:59:52 +0200 |
commit | 8a67e721880959b431d220e2d1fd5b60a4f11ad7 (patch) | |
tree | e8383591a0cd3d4849309a6ab0fa1d67823f371c | |
parent | fe87acd14acd2aa33c9b8a03a77d80d6a7648f1b (diff) | |
download | mana-8a67e721880959b431d220e2d1fd5b60a4f11ad7.tar.gz mana-8a67e721880959b431d220e2d1fd5b60a4f11ad7.tar.bz2 mana-8a67e721880959b431d220e2d1fd5b60a4f11ad7.tar.xz mana-8a67e721880959b431d220e2d1fd5b60a4f11ad7.zip |
Added customizable on-hit effects for characters.
This patch adds support for the following two parameters
in weapon items:
hit-effect-id: Effect triggered on the victim on normal hit.
critical-hit-effect-id: Triggered on the victim on critical hit.
(Specified in effects.xml)
The patch also permits the use of custom defaults set in paths.xml
by setting the following keys:
(Paths are relative to the 'particles' key value, here.)
hitEffectId: defaulted to effect id 26.
criticalHitEffectId: defaulted to effect id 28.
Resolves: Mana-mantis #337.
Reviewed-by: bcs86
-rw-r--r-- | src/being.cpp | 22 | ||||
-rw-r--r-- | src/being.h | 3 | ||||
-rw-r--r-- | src/defaults.cpp | 2 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 12 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 28 |
5 files changed, 54 insertions, 13 deletions
diff --git a/src/being.cpp b/src/being.cpp index 5911b03c..94ece475 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -389,10 +389,24 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) updateName(); } - if (type != CRITICAL) - effectManager->trigger(26, this); + // Init the particle effect path based on current weapon or default. + int hitEffectId = 0; + const ItemInfo *attackerWeapon = attacker->getEquippedWeapon(); + if (attacker->getType() == PLAYER && attackerWeapon) + { + if (type != CRITICAL) + hitEffectId = attackerWeapon->getHitEffectId(); + else + hitEffectId = attackerWeapon->getCriticalHitEffectId(); + } else - effectManager->trigger(28, this); + { + if (type != CRITICAL) + hitEffectId = paths.getIntValue("hitEffectId"); + else + hitEffectId = paths.getIntValue("criticalHitEffectId"); + } + effectManager->trigger(hitEffectId, this); } } @@ -405,7 +419,7 @@ void Being::handleAttack(Being *victim, int damage, AttackType type) lookAt(victim->getPosition()); if (getType() == PLAYER && victim && mEquippedWeapon) - fireMissile(victim, mEquippedWeapon->getMissileParticle()); + fireMissile(victim, mEquippedWeapon->getMissileParticleFile()); else fireMissile(victim, mInfo->getAttack(mAttackType)->missileParticle); diff --git a/src/being.h b/src/being.h index a4e2e443..bc749a3a 100644 --- a/src/being.h +++ b/src/being.h @@ -176,6 +176,9 @@ class Being : public ActorSprite, public EventListener */ virtual void handleAttack(Being *victim, int damage, AttackType type); + const ItemInfo *getEquippedWeapon() const + { return mEquippedWeapon; } + /** * Returns the name of the being. */ diff --git a/src/defaults.cpp b/src/defaults.cpp index 54e39c1f..87f7953e 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -160,6 +160,8 @@ DefaultsData* getPathsDefaults() AddDEF(pathsData, "particles", "graphics/particles/"); AddDEF(pathsData, "levelUpEffectFile", "levelup.particle.xml"); AddDEF(pathsData, "portalEffectFile", "warparea.particle.xml"); + AddDEF(pathsData, "hitEffectId", 26); + AddDEF(pathsData, "criticalHitEffectId", 28); AddDEF(pathsData, "minimaps", "graphics/minimaps/"); AddDEF(pathsData, "maps", "maps/"); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 5e1b2a2f..1457b6dd 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -199,7 +199,13 @@ void ItemDB::loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node) std::string attackAction = XML::getProperty(node, "attack-action", SpriteAction::INVALID); int attackRange = XML::getProperty(node, "attack-range", 0); - std::string missileParticle = XML::getProperty(node, "missile-particle", ""); + std::string missileParticleFile = XML::getProperty(node, + "missile-particle", + ""); + int hitEffectId = XML::getProperty(node, "hit-effect-id", + paths.getIntValue("hitEffectId")); + int criticalEffectId = XML::getProperty(node, "critical-hit-effect-id", + paths.getIntValue("criticalHitEffectId")); // Load Ta Item Type std::string typeStr = XML::getProperty(node, "type", "other"); @@ -218,7 +224,9 @@ void ItemDB::loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node) itemInfo->mWeight = weight; itemInfo->mAttackAction = attackAction; itemInfo->mAttackRange = attackRange; - itemInfo->setMissileParticle(missileParticle); + itemInfo->setMissileParticleFile(missileParticleFile); + itemInfo->setHitEffectId(hitEffectId); + itemInfo->setCriticalHitEffectId(criticalEffectId); // Load <sprite>, <sound>, and <floor> for_each_xml_child_node(itemChild, node) diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 16bc4392..4ab66597 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -109,13 +109,25 @@ class ItemInfo const std::string &getSprite(Gender gender) const; // Handlers for seting and getting the string used for particles when attacking - void setMissileParticle(std::string s) - { mMissileParticle = s; } + void setMissileParticleFile(const std::string &s) + { mMissileParticleFile = s; } - std::string getMissileParticle() const - { return mMissileParticle; } + const std::string &getMissileParticleFile() const + { return mMissileParticleFile; } - std::string getAttackAction() const + void setHitEffectId(int s) + { mHitEffectId = s; } + + int getHitEffectId() const + { return mHitEffectId; } + + void setCriticalHitEffectId(int s) + { mCriticalHitEffectId = s; } + + int getCriticalHitEffectId() const + { return mCriticalHitEffectId; } + + const std::string &getAttackAction() const { return mAttackAction; } int getAttackRange() const @@ -162,8 +174,10 @@ class ItemInfo /** Attack range, will be equal to ATTACK_RANGE_NOT_SET if no weapon. */ int mAttackRange; - // Particle to be shown when weapon attacks - std::string mMissileParticle; + /** Effects to be shown when weapon attacks - see also effects.xml */ + std::string mMissileParticleFile; + int mHitEffectId; + int mCriticalHitEffectId; /** Maps gender to sprite filenames. */ std::map<int, std::string> mAnimationFiles; |