diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-08-28 18:32:11 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-12-13 20:21:56 +0100 |
commit | 0a2fc4d340911b28b9dc6b3b23c69e9fe7729082 (patch) | |
tree | bddecd4581bb8591d0ac079a48eec3a66c411238 /src/being.cpp | |
parent | 5c4b6363d5065fb98a53b6981f5a590aaa37829b (diff) | |
download | mana-0a2fc4d340911b28b9dc6b3b23c69e9fe7729082.tar.gz mana-0a2fc4d340911b28b9dc6b3b23c69e9fe7729082.tar.bz2 mana-0a2fc4d340911b28b9dc6b3b23c69e9fe7729082.tar.xz mana-0a2fc4d340911b28b9dc6b3b23c69e9fe7729082.zip |
Added support for being effects through the eAthena levelup message, and check
whether the being exists before referencing it. Re-enabled proper MP bar
display. Improved handling of a warp to the same map.
(patch by Fate)
(cherry picked from eAthena client, the part about the levelup message
doesn't apply, and we now seem to have a second "effect manager"...)
Conflicts:
ChangeLog
src/being.cpp
src/being.h
src/engine.cpp
src/engine.h
src/gui/ministatus.cpp
src/net/beinghandler.cpp
src/net/playerhandler.cpp
src/net/protocol.h
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 103 |
1 files changed, 102 insertions, 1 deletions
diff --git a/src/being.cpp b/src/being.cpp index fbee967f..3a84ccd0 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -30,6 +30,8 @@ #include "log.h" #include "map.h" #include "particle.h" +#include "sound.h" +#include "localplayer.h" #include "resources/itemdb.h" #include "resources/resourcemanager.h" @@ -49,6 +51,10 @@ const bool debug_movement = true; #define HAIR_FILE "hair.xml" +#include "utils/xml.h" + +#define BEING_EFFECTS_FILE "effects.xml" + int Being::instances = 0; ImageSet *Being::emotionSet = NULL; @@ -525,7 +531,7 @@ void Being::logic() i != mChildParticleEffects.end();) { (*i)->setPosition(mPos.x, mPos.y); - if (!(*i)->isAlive()) + if ((*i)->isExtinct()) { (*i)->kill(); i = mChildParticleEffects.erase(i); @@ -695,3 +701,98 @@ initializeHair(void) hairInitialized = 1; } + + + +struct EffectDescription { + std::string mGFXEffect; + std::string mSFXEffect; +}; + +static EffectDescription *default_effect = NULL; +static std::map<int, EffectDescription *> effects; +static bool effects_initialized = false; + +static EffectDescription * +getEffectDescription(xmlNodePtr node, int *id) +{ + EffectDescription *ed = new EffectDescription; + + *id = atoi(XML::getProperty(node, "id", "-1").c_str()); + ed->mSFXEffect = XML::getProperty(node, "audio", ""); + ed->mGFXEffect = XML::getProperty(node, "particle", ""); + + return ed; +} + +static EffectDescription * +getEffectDescription(int effectId) +{ + if (!effects_initialized) + { + XML::Document doc(BEING_EFFECTS_FILE); + xmlNodePtr root = doc.rootNode(); + + if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects")) + { + logger->log("Error loading being effects file: " + BEING_EFFECTS_FILE); + return NULL; + } + + for_each_xml_child_node(node, root) + { + int id; + + if (xmlStrEqual(node->name, BAD_CAST "effect")) + { + EffectDescription *EffectDescription = + getEffectDescription(node, &id); + effects[id] = EffectDescription; + } else if (xmlStrEqual(node->name, BAD_CAST "default")) + { + EffectDescription *EffectDescription = + getEffectDescription(node, &id); + + if (default_effect) + delete default_effect; + + default_effect = EffectDescription; + } + } + + effects_initialized = true; + } // done initializing + + EffectDescription *ed = effects[effectId]; + + if (!ed) + return default_effect; + else + return ed; +} + +void +Being::internalTriggerEffect(int effectId, bool sfx, bool gfx) +{ + logger->log("Special effect #%d on %s", effectId, + getId() == player_node->getId() ? "self" : "other"); + + EffectDescription *ed = getEffectDescription(effectId); + + if (!ed) { + logger->log("Unknown special effect and no default recorded"); + return; + } + + if (gfx && ed->mGFXEffect != "") { + Particle *selfFX; + + selfFX = particleEngine->addEffect(ed->mGFXEffect, 0, 0); + controlParticle(selfFX); + } + + if (sfx && ed->mSFXEffect != "") { + sound.playSfx(ed->mSFXEffect); + } +} |