Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
SpellCalculations.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "SpellCalculations.h"
7
8#include "SpellAuraDefines.h"
9#include "Util.h"
10
11namespace Skyfire
12{
13namespace Spells
14{
15 int32 CalculateBaseCastTime(uint8 level, int32 castTimeMin, int32 castTimeMax, int32 castTimeMaxLevel, int32 fallbackCastTime)
16 {
17 if (!level || castTimeMax <= 0)
18 return fallbackCastTime;
19
20 if (castTimeMaxLevel > level)
21 return castTimeMin + int32(level - 1) * (castTimeMax - castTimeMin) / (castTimeMaxLevel - 1);
22
23 return castTimeMax;
24 }
25
26 uint32 FinalizeCastTime(int32 castTime, bool addRangedAmmoDelay)
27 {
28 if (addRangedAmmoDelay)
29 castTime += 500;
30
31 return castTime > 0 ? uint32(castTime) : 0;
32 }
33
35 {
36 if (duration == -1)
37 return -1;
38
39 return duration < 0 ? -duration : duration;
40 }
41
42 int32 CalculateDuration(bool hasDurationEntry, int32 duration)
43 {
44 return hasDurationEntry ? NormalizeDurationValue(duration) : 0;
45 }
46
47 namespace
48 {
49 bool IsCountedPeriodicAura(uint32 auraName)
50 {
51 switch (auraName)
52 {
56 return true;
57 default:
58 return false;
59 }
60 }
61 }
62
63 uint32 CalculateMaxTicks(int32 duration, SpellTickEffectInfo const* effects, uint32 effectCount)
64 {
65 if (duration == 0)
66 return 1;
67
68 int32 tickDuration = duration;
69 if (tickDuration > 30000)
70 tickDuration = 30000;
71
72 for (uint32 i = 0; i < effectCount; ++i)
73 {
74 if (effects[i].Effect == SPELL_EFFECT_APPLY_AURA &&
75 IsCountedPeriodicAura(effects[i].ApplyAuraName) &&
76 effects[i].ApplyAuraTickCount != 0)
77 return tickDuration / effects[i].ApplyAuraTickCount;
78 }
79
80 return 6;
81 }
82
84 {
85 return dieSides == 0 ? value : value - 1;
86 }
87
89 {
90 if (!data.HasRadius)
91 return data.HasMaxRadius ? data.MaxRadiusMin : 0.0f;
92
93 float radius = data.RadiusMin;
94 if (data.HasCaster)
95 {
96 radius += data.RadiusPerLevel * data.CasterLevel;
97 if (radius > data.RadiusMax)
98 radius = data.RadiusMax;
99 }
100
101 return radius;
102 }
103
104 float SelectSpellRange(bool hasRangeEntry, float friendRange, float hostileRange, bool positive)
105 {
106 if (!hasRangeEntry)
107 return 0.0f;
108
109 return positive ? friendRange : hostileRange;
110 }
111
112 uint32 CalculateRecoveryTime(uint32 recoveryTime, uint32 categoryRecoveryTime)
113 {
114 return recoveryTime > categoryRecoveryTime ? recoveryTime : categoryRecoveryTime;
115 }
116
118 {
120 {
121 data.BasePowerCost,
124 };
125
126 if (data.ChannelCostPercentage)
128
129 if (!data.PowerCostPercentage)
130 return result;
131
132 switch (data.PowerType)
133 {
134 case POWER_HEALTH:
136 break;
137 case POWER_MANA:
140 break;
143 break;
144 default:
145 result.PowerCost = 0;
147 break;
148 }
149
150 return result;
151 }
152}
153}
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
@ POWER_DEMONIC_FURY
@ POWER_HEALTH
@ POWER_RUNIC_POWER
@ POWER_MANA
@ SPELL_EFFECT_APPLY_AURA
@ SPELL_AURA_PERIODIC_DAMAGE
@ SPELL_AURA_PERIODIC_HEAL
@ SPELL_AURA_PERIODIC_LEECH
T CalculatePct(T base, U pct)
Definition Util.h:103
uint32 CalculateMaxTicks(int32 duration, SpellTickEffectInfo const *effects, uint32 effectCount)
@ SPELL_POWER_COST_UNSUPPORTED_POWER_TYPE
int32 CalculateBaseCastTime(uint8 level, int32 castTimeMin, int32 castTimeMax, int32 castTimeMaxLevel, int32 fallbackCastTime)
uint32 CalculateRecoveryTime(uint32 recoveryTime, uint32 categoryRecoveryTime)
int32 CalculateDuration(bool hasDurationEntry, int32 duration)
SpellPowerCostCalculationResult CalculateSpellPowerCosts(SpellPowerCostCalculationData const &data)
float SelectSpellRange(bool hasRangeEntry, float friendRange, float hostileRange, bool positive)
float CalculateRadius(SpellRadiusCalculationData const &data)
uint32 FinalizeCastTime(int32 castTime, bool addRangedAmmoDelay)
int32 CalculateEffectBaseValue(int32 value, int32 dieSides)
int32 NormalizeDurationValue(int32 duration)