OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spellcasting.hpp
Go to the documentation of this file.
1 #ifndef MWMECHANICS_SPELLSUCCESS_H
2 #define MWMECHANICS_SPELLSUCCESS_H
3 
7 
8 #include "../mwworld/ptr.hpp"
9 
10 #include "magiceffects.hpp"
11 
12 namespace ESM
13 {
14  struct Spell;
15  struct Ingredient;
16  struct Potion;
17  struct EffectList;
18 }
19 
20 namespace MWMechanics
21 {
22  struct EffectKey;
23  class MagicEffects;
24  class CreatureStats;
25 
27 
28  float calcEffectCost(const ESM::ENAMstruct& effect);
29  float calcEffectCost(const ESM::ENAMstruct& effect, const ESM::MagicEffect* magicEffect);
30 
31  bool isSummoningEffect(int effectId);
32 
42  float getSpellSuccessChance (const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool = NULL, bool cap=true, bool checkMagicka=false);
43  float getSpellSuccessChance (const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool = NULL, bool cap=true, bool checkMagicka=false);
44 
45  int getSpellSchool(const std::string& spellId, const MWWorld::Ptr& actor);
46  int getSpellSchool(const ESM::Spell* spell, const MWWorld::Ptr& actor);
47 
49  bool spellIncreasesSkill(const ESM::Spell* spell);
50  bool spellIncreasesSkill(const std::string& spellId);
51 
54  float getEffectResistanceAttribute (short effectId, const MagicEffects* actorEffects);
55 
60  float getEffectResistance (short effectId, const MWWorld::Ptr& actor, const MWWorld::Ptr& caster,
61  const ESM::Spell* spell = NULL, const MagicEffects* effects = NULL);
62 
67  float getEffectMultiplier(short effectId, const MWWorld::Ptr& actor, const MWWorld::Ptr& caster,
68  const ESM::Spell* spell = NULL, const MagicEffects* effects = NULL);
69 
70  bool checkEffectTarget (int effectId, const MWWorld::Ptr& target, const MWWorld::Ptr& caster, bool castByPlayer);
71 
72  int getEffectiveEnchantmentCastCost (float castCost, const MWWorld::Ptr& actor);
73  float calcSpellBaseSuccessChance (const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool);
74 
77  bool effectTick(CreatureStats& creatureStats, const MWWorld::Ptr& actor, const MWMechanics::EffectKey& effectKey, float magnitude);
78 
79  std::string getSummonedCreature(int effectId);
80 
81  class CastSpell
82  {
83  private:
84  MWWorld::Ptr mCaster; // May be empty
85  MWWorld::Ptr mTarget; // May be empty
86  public:
87  bool mStack;
88  std::string mId; // ID of spell, potion, item etc
89  std::string mSourceName; // Display name for spell, potion, etc
90  osg::Vec3f mHitPosition; // Used for spawning area orb
91  bool mAlwaysSucceed; // Always succeed spells casted by NPCs/creatures regardless of their chance (default: false)
92  bool mFromProjectile; // True if spell is cast by enchantment of some projectile (arrow, bolt or thrown weapon)
93  bool mManualSpell; // True if spell is casted from script and ignores some checks (mana level, success chance, etc.)
94 
95  public:
96  CastSpell(const MWWorld::Ptr& caster, const MWWorld::Ptr& target, const bool fromProjectile=false, const bool manualSpell=false);
97 
98  bool cast (const ESM::Spell* spell);
99 
102  bool cast (const MWWorld::Ptr& item, bool launchProjectile=true);
103 
105  bool cast (const ESM::Ingredient* ingredient);
106 
107  bool cast (const ESM::Potion* potion);
108 
110  bool cast (const std::string& id);
111 
112  void playSpellCastingEffects(const std::string &spellid);
113 
114  bool spellIncreasesSkill();
115 
117  void launchMagicBolt ();
118 
121  void inflict (const MWWorld::Ptr& target, const MWWorld::Ptr& caster,
122  const ESM::EffectList& effects, ESM::RangeType range, bool reflected=false, bool exploded=false);
123 
126  bool applyInstantEffect (const MWWorld::Ptr& target, const MWWorld::Ptr& caster, const MWMechanics::EffectKey& effect, float magnitude);
127  };
128 
130  {
131  private:
133 
134  public:
136  : mActor(actor)
137  {
138  }
139 
140  virtual void visit (MWMechanics::EffectKey key,
141  const std::string& /*sourceName*/, const std::string& /*sourceId*/, int /*casterActorId*/,
142  float /*magnitude*/, float /*remainingTime*/ = -1, float /*totalTime*/ = -1);
143  };
144 }
145 
146 #endif
Definition: magiceffects.hpp:73
MWWorld::Ptr mActor
Definition: spellcasting.hpp:132
float getEffectMultiplier(short effectId, const MWWorld::Ptr &actor, const MWWorld::Ptr &caster, const ESM::Spell *spell, const MagicEffects *effects)
Definition: spellcasting.cpp:270
float getEffectResistance(short effectId, const MWWorld::Ptr &actor, const MWWorld::Ptr &caster, const ESM::Spell *spell, const MagicEffects *effects)
Definition: spellcasting.cpp:221
ESM::Skill::SkillEnum spellSchoolToSkill(int school)
Definition: spellcasting.cpp:35
Definition: loadingr.hpp:16
bool checkEffectTarget(int effectId, const MWWorld::Ptr &target, const MWWorld::Ptr &caster, bool castByPlayer)
Check if the given effect can be applied to the target. If castByPlayer, emits a message box on failu...
Definition: spellcasting.cpp:278
bool mFromProjectile
Definition: spellcasting.hpp:92
virtual void visit(MWMechanics::EffectKey key, const std::string &, const std::string &, int, float, float=-1, float=-1)
Definition: spellcasting.cpp:1362
Definition: loadspel.hpp:14
float getSpellSuccessChance(const ESM::Spell *spell, const MWWorld::Ptr &actor, int *effectiveSchool, bool cap, bool checkMagicka)
Definition: spellcasting.cpp:127
bool mManualSpell
Definition: spellcasting.hpp:93
MWWorld::Ptr mTarget
Definition: spellcasting.hpp:85
Definition: spellcasting.hpp:81
int getSpellSchool(const std::string &spellId, const MWWorld::Ptr &actor)
Definition: spellcasting.cpp:172
bool applyInstantEffect(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, const MWMechanics::EffectKey &effect, float magnitude)
Definition: spellcasting.cpp:657
Definition: effectlist.hpp:17
std::string mSourceName
Definition: spellcasting.hpp:89
RangeType
Definition: defs.hpp:27
std::string getSummonedCreature(int effectId)
Definition: spellcasting.cpp:1326
ApplyLoopingParticlesVisitor(const MWWorld::Ptr &actor)
Definition: spellcasting.hpp:135
float calcSpellBaseSuccessChance(const ESM::Spell *spell, const MWWorld::Ptr &actor, int *effectiveSchool)
Definition: spellcasting.cpp:83
bool mAlwaysSucceed
Definition: spellcasting.hpp:91
MWWorld::Ptr mCaster
Definition: spellcasting.hpp:84
Definition: magiceffects.hpp:17
bool mStack
Definition: spellcasting.hpp:87
int getEffectiveEnchantmentCastCost(float castCost, const MWWorld::Ptr &actor)
Definition: spellcasting.cpp:1106
bool isSummoningEffect(int effectId)
Definition: spellcasting.cpp:1118
Definition: spellcasting.hpp:129
Definition: loadmgef.hpp:13
bool spellIncreasesSkill()
Definition: spellcasting.cpp:1098
std::string mId
Definition: spellcasting.hpp:88
bool spellIncreasesSkill(const ESM::Spell *spell)
Get whether or not the given spell contributes to skill progress.
Definition: spellcasting.cpp:186
void playSpellCastingEffects(const std::string &spellid)
Definition: spellcasting.cpp:1014
float calcEffectCost(const ESM::ENAMstruct &effect)
Definition: spellcasting.cpp:52
bool effectTick(CreatureStats &creatureStats, const MWWorld::Ptr &actor, const EffectKey &effectKey, float magnitude)
Definition: spellcasting.cpp:1175
void launchMagicBolt()
Launch a bolt with the given effects.
Definition: spellcasting.cpp:338
float getEffectResistanceAttribute(short effectId, const MagicEffects *actorEffects)
Definition: spellcasting.cpp:200
osg::Vec3f mHitPosition
Definition: spellcasting.hpp:90
bool cast(const ESM::Spell *spell)
Definition: spellcasting.cpp:873
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
CastSpell(const MWWorld::Ptr &caster, const MWWorld::Ptr &target, const bool fromProjectile=false, const bool manualSpell=false)
Definition: spellcasting.cpp:327
Definition: loadalch.hpp:18
SkillEnum
Definition: loadskil.hpp:45
EffectList, ENAM subrecord.
Definition: effectlist.hpp:33
void inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, const ESM::EffectList &effects, ESM::RangeType range, bool reflected=false, bool exploded=false)
Definition: spellcasting.cpp:355