1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00
OpenMW/apps/openmw/mwmechanics/activespells.hpp

111 lines
3.4 KiB
C++
Raw Normal View History

#ifndef GAME_MWMECHANICS_ACTIVESPELLS_H
#define GAME_MWMECHANICS_ACTIVESPELLS_H
#include <map>
#include <vector>
#include <string>
2016-06-17 23:07:16 +09:00
#include <components/esm/activespells.hpp>
#include "../mwworld/timestamp.hpp"
#include "magiceffects.hpp"
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:
2014-05-14 22:16:39 +02:00
typedef ESM::ActiveEffect ActiveEffect;
struct ActiveSpellParams
{
2014-05-14 22:16:39 +02:00
std::vector<ActiveEffect> mEffects;
MWWorld::TimeStamp mTimeStamp;
std::string mDisplayName;
2013-11-19 18:43:21 +01:00
2014-05-14 07:14:08 +02:00
// The caster that inflicted this spell on us
int mCasterActorId;
};
typedef std::multimap<std::string, ActiveSpellParams > TContainer;
typedef TContainer::const_iterator TIterator;
2014-05-14 22:16:39 +02:00
void readState (const ESM::ActiveSpells& state);
void writeState (ESM::ActiveSpells& state) const;
TIterator begin() const;
TIterator end() const;
void update(float duration) const;
private:
mutable TContainer mSpells;
mutable MagicEffects mEffects;
mutable bool mSpellsChanged;
void rebuildEffects() const;
/// Add any effects that are in "from" and not in "addTo" to "addTo"
void mergeEffects(std::vector<ActiveEffect>& addTo, const std::vector<ActiveEffect>& from);
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;
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.
///
2021-06-23 23:13:59 +02:00
void addSpell (const std::string& id, bool stack, const std::vector<ActiveEffect>& effects,
2014-05-14 07:14:08 +02:00
const std::string& displayName, int casterActorId);
/// 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 with this effect id and source id
void purgeEffect (short effectId, const std::string& sourceId, int effectIndex=-1);
/// Remove all active effects, if roll succeeds (for each effect)
void purgeAll(float chance, bool spellOnly = false);
2014-05-14 07:14:08 +02:00
/// Remove all effects with CASTER_LINKED flag that were cast by \a casterActorId
void purge (int casterActorId);
2014-01-12 10:21:49 +01:00
2014-05-14 22:16:39 +02:00
/// Remove all spells
void clear();
2015-12-07 22:49:15 +01:00
bool isSpellActive (const std::string& id) const;
2012-11-25 01:26:29 +01:00
///< case insensitive
void purgeCorprusDisease();
const MagicEffects& getMagicEffects() const;
void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor) const;
};
}
#endif