diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-29 01:21:45 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-05-01 23:45:51 +0300 |
commit | 6ff97aad8bf4af8e1a69665b3ad414042efada02 (patch) | |
tree | ed0f186c524146d0b68c082373b1053d84f51c16 /src | |
parent | bba99b414167d9adb40622d8fc8c1e9dc814e956 (diff) | |
download | manaverse-6ff97aad8bf4af8e1a69665b3ad414042efada02.tar.gz manaverse-6ff97aad8bf4af8e1a69665b3ad414042efada02.tar.bz2 manaverse-6ff97aad8bf4af8e1a69665b3ad414042efada02.tar.xz manaverse-6ff97aad8bf4af8e1a69665b3ad414042efada02.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
Conflicts:
src/being.cpp
src/resources/itemdb.cpp
src/resources/iteminfo.h
ManaPlus: adding missing checks.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 23 | ||||
-rw-r--r-- | src/being.h | 3 | ||||
-rw-r--r-- | src/defaults.cpp | 2 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 8 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 26 |
5 files changed, 54 insertions, 8 deletions
diff --git a/src/being.cpp b/src/being.cpp index 3a7f08dda..eae4ebd66 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -606,10 +606,25 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) if (effectManager) { - 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); } } } @@ -624,7 +639,7 @@ void Being::handleAttack(Being *victim, int damage, setAction(Being::ATTACK, 1); if (getType() == PLAYER && mEquippedWeapon) - fireMissile(victim, mEquippedWeapon->getMissileParticle()); + fireMissile(victim, mEquippedWeapon->getMissileParticleFile()); else if (mInfo->getAttack(mAttackType)) fireMissile(victim, mInfo->getAttack(mAttackType)->missileParticle); diff --git a/src/being.h b/src/being.h index 96c547e89..c83d0fb48 100644 --- a/src/being.h +++ b/src/being.h @@ -236,6 +236,9 @@ class Being : public ActorSprite, public ConfigListener */ 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 5249addd2..622740f61 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -244,6 +244,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 59d7e951c..ab38e282e 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -226,6 +226,10 @@ void ItemDB::load() int attackRange = XML::getProperty(node, "attack-range", 0); std::string missileParticle = 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")); SpriteDisplay display; display.image = image; @@ -283,7 +287,9 @@ void ItemDB::load() itemInfo->setWeight(weight); itemInfo->setAttackAction(attackAction); itemInfo->setAttackRange(attackRange); - itemInfo->setMissileParticle(missileParticle); + itemInfo->setMissileParticleFile(missileParticle); + itemInfo->setHitEffectId(hitEffectId); + itemInfo->setCriticalHitEffectId(criticalEffectId); itemInfo->setDrawBefore(parseSpriteName(drawBefore)); itemInfo->setDrawAfter(parseSpriteName(drawAfter)); itemInfo->setDrawPriority(drawPriority); diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 8b276601c..01a4b5b9e 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -183,11 +183,25 @@ class ItemInfo void setAttackAction(std::string attackAction); // 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 @@ -232,6 +246,9 @@ class ItemInfo bool isRemoveItemId(int id) const; + /** Effects to be shown when weapon attacks - see also effects.xml */ + std::string mMissileParticleFile; + int getReplaceToSpriteId(int id) const; std::map<int, int> &addReplaceSprite(int sprite); @@ -251,6 +268,9 @@ class ItemInfo const std::string replaceColors(std::string str, unsigned char color) const; + int mHitEffectId; + int mCriticalHitEffectId; + protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ std::string mName; |