2012-05-29 13:13:44 +00:00
# ifndef MWMECHANICS_SPELLSUCCESS_H
# define MWMECHANICS_SPELLSUCCESS_H
2017-06-30 12:27:18 +00:00
# include <components/esm/effectlist.hpp>
2014-02-23 19:11:05 +00:00
# include <components/esm/loadskil.hpp>
2016-06-17 14:07:16 +00:00
# include "../mwworld/ptr.hpp"
2014-02-23 19:11:05 +00:00
namespace ESM
{
struct Spell ;
struct Ingredient ;
struct Potion ;
struct EffectList ;
}
2012-05-29 13:13:44 +00:00
namespace MWMechanics
{
2015-03-06 08:36:42 +00:00
struct EffectKey ;
2014-06-17 20:24:56 +00:00
class MagicEffects ;
2015-07-18 18:39:45 +00:00
class CreatureStats ;
2014-01-18 09:52:16 +00:00
ESM : : Skill : : SkillEnum spellSchoolToSkill ( int school ) ;
2012-05-29 16:33:01 +00:00
2017-06-30 12:27:18 +00:00
float calcEffectCost ( const ESM : : ENAMstruct & effect ) ;
2015-01-22 03:12:08 +00:00
bool isSummoningEffect ( int effectId ) ;
2012-05-29 16:33:01 +00:00
/**
2012-10-23 09:42:38 +00:00
* @ param spell spell to cast
2012-05-29 16:33:01 +00:00
* @ param actor calculate spell success chance for this actor ( depends on actor ' s skills )
2013-11-14 18:19:32 +00:00
* @ param effectiveSchool the spell ' s effective school ( relevant for skill progress ) will be written here
2014-07-30 23:14:44 +00:00
* @ param cap cap the result to 100 % ?
* @ note actor can be an NPC or a creature
* @ return success chance from 0 to 100 ( in percent ) , if cap = false then chance above 100 may be returned .
2012-05-29 16:33:01 +00:00
*/
2014-07-30 23:14:44 +00:00
float getSpellSuccessChance ( const ESM : : Spell * spell , const MWWorld : : Ptr & actor , int * effectiveSchool = NULL , bool cap = true ) ;
float getSpellSuccessChance ( const std : : string & spellId , const MWWorld : : Ptr & actor , int * effectiveSchool = NULL , bool cap = true ) ;
2013-11-14 18:19:32 +00:00
2014-01-18 09:52:16 +00:00
int getSpellSchool ( const std : : string & spellId , const MWWorld : : Ptr & actor ) ;
int getSpellSchool ( const ESM : : Spell * spell , const MWWorld : : Ptr & actor ) ;
2013-11-14 18:19:32 +00:00
2014-08-24 18:36:31 +00:00
/// Get whether or not the given spell contributes to skill progress.
bool spellIncreasesSkill ( const ESM : : Spell * spell ) ;
bool spellIncreasesSkill ( const std : : string & spellId ) ;
2014-07-15 20:06:46 +00:00
/// Get the resistance attribute against an effect for a given actor. This will add together
/// ResistX and Weakness to X effects relevant against the given effect.
float getEffectResistanceAttribute ( short effectId , const MagicEffects * actorEffects ) ;
/// Get the effective resistance against an effect casted by the given actor in the given spell (optional).
2013-11-16 01:34:43 +00:00
/// @return >=100 for fully resisted. can also return negative value for damage amplification.
2014-06-17 20:24:56 +00:00
/// @param effects Override the actor's current magicEffects. Useful if there are effects currently
/// being applied (but not applied yet) that should also be considered.
float getEffectResistance ( short effectId , const MWWorld : : Ptr & actor , const MWWorld : : Ptr & caster ,
const ESM : : Spell * spell = NULL , const MagicEffects * effects = NULL ) ;
2013-11-16 01:34:43 +00:00
2014-10-07 02:56:41 +00:00
/// Get an effect multiplier for applying an effect cast by the given actor in the given spell (optional).
/// @return effect multiplier from 0 to 2. (100% net resistance to 100% net weakness)
/// @param effects Override the actor's current magicEffects. Useful if there are effects currently
/// being applied (but not applied yet) that should also be considered.
2014-06-17 20:24:56 +00:00
float getEffectMultiplier ( short effectId , const MWWorld : : Ptr & actor , const MWWorld : : Ptr & caster ,
const ESM : : Spell * spell = NULL , const MagicEffects * effects = NULL ) ;
2013-11-17 22:15:57 +00:00
2016-11-14 15:20:17 +00:00
bool checkEffectTarget ( int effectId , const MWWorld : : Ptr & target , const MWWorld : : Ptr & caster , bool castByPlayer ) ;
2015-01-07 03:28:56 +00:00
int getEffectiveEnchantmentCastCost ( float castCost , const MWWorld : : Ptr & actor ) ;
2017-06-30 12:27:18 +00:00
float calcSpellBaseSuccessChance ( const ESM : : Spell * spell , const MWWorld : : Ptr & actor , int * effectiveSchool ) ;
2015-01-07 03:28:56 +00:00
2016-12-05 11:12:13 +00:00
/// Apply a magic effect that is applied in tick intervals until its remaining time ends or it is removed
/// @return Was the effect a tickable effect with a magnitude?
bool effectTick ( CreatureStats & creatureStats , const MWWorld : : Ptr & actor , const MWMechanics : : EffectKey & effectKey , float magnitude ) ;
2015-07-18 18:39:45 +00:00
2017-02-20 18:58:00 +00:00
std : : string getSummonedCreature ( int effectId ) ;
2013-11-17 22:15:57 +00:00
class CastSpell
{
private :
2014-06-17 23:41:07 +00:00
MWWorld : : Ptr mCaster ; // May be empty
MWWorld : : Ptr mTarget ; // May be empty
2013-11-28 16:31:17 +00:00
public :
2013-11-17 22:15:57 +00:00
bool mStack ;
std : : string mId ; // ID of spell, potion, item etc
std : : string mSourceName ; // Display name for spell, potion, etc
2015-06-01 19:41:13 +00:00
osg : : Vec3f mHitPosition ; // Used for spawning area orb
2014-10-08 23:39:35 +00:00
bool mAlwaysSucceed ; // Always succeed spells casted by NPCs/creatures regardless of their chance (default: false)
2016-12-19 09:15:19 +00:00
bool mFromProjectile ; // True if spell is cast by enchantment of some projectile (arrow, bolt or thrown weapon)
2013-11-17 22:15:57 +00:00
public :
2016-12-19 09:15:19 +00:00
CastSpell ( const MWWorld : : Ptr & caster , const MWWorld : : Ptr & target , const bool fromProjectile = false ) ;
2013-11-17 22:15:57 +00:00
bool cast ( const ESM : : Spell * spell ) ;
2014-06-17 23:41:07 +00:00
/// @note mCaster must be an actor
2016-02-22 18:37:19 +00:00
/// @param launchProjectile If set to false, "on target" effects are directly applied instead of being launched as projectile originating from the caster.
bool cast ( const MWWorld : : Ptr & item , bool launchProjectile = true ) ;
2014-06-17 23:41:07 +00:00
/// @note mCaster must be an NPC
2013-11-17 22:15:57 +00:00
bool cast ( const ESM : : Ingredient * ingredient ) ;
2014-06-17 23:41:07 +00:00
2013-11-17 22:15:57 +00:00
bool cast ( const ESM : : Potion * potion ) ;
/// @note Auto detects if spell, ingredient or potion
bool cast ( const std : : string & id ) ;
2016-07-16 13:47:33 +00:00
void playSpellCastingEffects ( const std : : string & spellid ) ;
2016-09-04 19:22:57 +00:00
/// Launch a bolt with the given effects.
void launchMagicBolt ( const ESM : : EffectList & effects ) ;
2016-08-31 10:03:28 +00:00
2014-05-14 03:33:18 +00:00
/// @note \a target can be any type of object, not just actors.
2014-05-15 00:37:20 +00:00
/// @note \a caster can be any type of object, or even an empty object.
2013-11-17 22:15:57 +00:00
void inflict ( const MWWorld : : Ptr & target , const MWWorld : : Ptr & caster ,
2014-01-20 14:48:06 +00:00
const ESM : : EffectList & effects , ESM : : RangeType range , bool reflected = false , bool exploded = false ) ;
2013-11-17 22:15:57 +00:00
2014-05-15 00:37:20 +00:00
/// @note \a caster can be any type of object, or even an empty object.
2015-08-04 15:55:38 +00:00
/// @return was the target suitable for the effect?
bool applyInstantEffect ( const MWWorld : : Ptr & target , const MWWorld : : Ptr & caster , const MWMechanics : : EffectKey & effect , float magnitude ) ;
2013-11-17 22:15:57 +00:00
} ;
2012-05-29 13:13:44 +00:00
}
# endif