#ifndef GAME_MWMECHANICS_ACTIVESPELLS_H #define GAME_MWMECHANICS_ACTIVESPELLS_H #include #include #include #include "../mwworld/timestamp.hpp" #include "magiceffects.hpp" #include namespace MWMechanics { /// \brief Lasting spell effects /// /// \note The name of this class is slightly misleading, since it also handels lasting potion /// effects. class ActiveSpells { public: // Parameters of an effect concerning lasting effects. // Note we are not using ENAMstruct since the magnitude may be modified by magic resistance, etc. // It could also be a negative magnitude, in case of inversing an effect, e.g. Absorb spell causes damage on target, but heals the caster. struct Effect { float mMagnitude; EffectKey mKey; float mDuration; }; struct ActiveSpellParams { std::vector mEffects; MWWorld::TimeStamp mTimeStamp; std::string mDisplayName; // Handle to the caster that that inflicted this spell on us std::string mCasterHandle; }; typedef std::multimap TContainer; typedef TContainer::const_iterator TIterator; private: mutable TContainer mSpells; mutable MagicEffects mEffects; mutable bool mSpellsChanged; mutable MWWorld::TimeStamp mLastUpdate; void update() const; void rebuildEffects() const; double timeToExpire (const TIterator& iterator) const; ///< Returns time (in in-game hours) until the spell pointed to by \a iterator /// expires. const TContainer& getActiveSpells() const; TIterator begin() const; TIterator end() const; public: ActiveSpells(); /// Add lasting effects /// /// \brief addSpell /// \param id ID for stacking purposes. /// \param stack If false, the spell is not added if one with the same ID exists already. /// \param effects /// \param displayName Name for display in magic menu. /// \param casterHandle /// void addSpell (const std::string& id, bool stack, std::vector effects, const std::string& displayName, const std::string& casterHandle); /// Removes the active effects from this spell/potion/.. with \a id void removeEffects (const std::string& id); /// Remove all active effects with this effect id void purgeEffect (short effectId); /// Remove all active effects, if roll succeeds (for each effect) void purgeAll (float chance); bool isSpellActive (std::string id) const; ///< case insensitive const MagicEffects& getMagicEffects() const; void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor) const; }; } #endif