4017{
4018
4020 if (!unitCaster)
4021 return {};
4022
4023 if (power->RequiredAuraSpellID && !unitCaster->
HasAura(power->RequiredAuraSpellID))
4024 return {};
4025
4026
4028 {
4029 if (optionalCost)
4030 return {};
4031
4032
4035
4036
4039
4040 TC_LOG_ERROR(
"spells",
"SpellInfo::CalcPowerCost: Unknown power type '{}' in spell {}", power->PowerType,
Id);
4041 return {};
4042 }
4043
4044
4045 int32 powerCost = 0;
4046 if (!optionalCost)
4047 {
4048 powerCost = power->ManaCost;
4049
4050 if (power->PowerCostPct)
4051 {
4052 switch (power->PowerType)
4053 {
4054
4056 if (G3D::fuzzyEq(power->PowerCostPct, 0.0f))
4058 else
4060 break;
4063 break;
4065 TC_LOG_ERROR(
"spells",
"SpellInfo::CalcPowerCost: Unknown power type POWER_ALTERNATE_POWER in spell {}",
Id);
4066 return {};
4067 default:
4068 {
4070 {
4071 powerCost +=
int32(
CalculatePct(powerTypeEntry->MaxBasePower, power->PowerCostPct));
4072 break;
4073 }
4074
4075 TC_LOG_ERROR(
"spells",
"SpellInfo::CalcPowerCost: Unknown power type '{}' in spell {}", power->PowerType,
Id);
4076 return {};
4077 }
4078 }
4079 }
4080 }
4081 else
4082 {
4083 powerCost =
int32(power->OptionalCost);
4084
4085 if (power->OptionalCostPct)
4086 {
4087 switch (power->PowerType)
4088 {
4089
4092 break;
4095 break;
4097 TC_LOG_ERROR(
"spells",
"SpellInfo::CalcPowerCost: Unsupported power type POWER_ALTERNATE_POWER in spell {} for optional cost percent",
Id);
4098 return {};
4099 default:
4100 {
4102 {
4103 powerCost +=
int32(
CalculatePct(powerTypeEntry->MaxBasePower, power->OptionalCostPct));
4104 break;
4105 }
4106
4107 TC_LOG_ERROR(
"spells",
"SpellInfo::CalcPowerCost: Unknown power type '{}' in spell {} for optional cost percent", power->PowerType,
Id);
4108 return {};
4109 }
4110 }
4111 }
4112
4114 {
4117 });
4118 }
4119
4120 bool initiallyNegative = powerCost < 0;
4121
4122
4124 {
4127 speed = ss->CombatRoundTime;
4128 else
4129 {
4133
4135 }
4136
4137 powerCost += speed / 100;
4138 }
4139
4141 {
4142 if (!optionalCost)
4143 {
4144
4146 {
4147 if (!(aura->GetMiscValue() & schoolMask))
4148 continue;
4149
4150 if (!(aura->GetMiscValueB() & (1 << power->PowerType)))
4151 continue;
4152
4153 powerCost += aura->GetAmount();
4154 }
4155 }
4156
4157
4159 {
4160 if (!(schoolCostPct->GetMiscValue() & schoolMask))
4161 continue;
4162
4163 if (!(schoolCostPct->GetMiscValueB() & (1 << power->PowerType)))
4164 continue;
4165
4166 powerCost +=
CalculatePct(powerCost, schoolCostPct->GetAmount());
4167 }
4168 }
4169
4170
4172 {
4174 switch (power->OrderIndex)
4175 {
4176 case 0:
4177 mod = SpellModOp::PowerCost0;
4178 break;
4179 case 1:
4180 mod = SpellModOp::PowerCost1;
4181 break;
4182 case 2:
4183 mod = SpellModOp::PowerCost2;
4184 break;
4185 default:
4186 break;
4187 }
4188
4189 if (mod)
4190 {
4191 if (!optionalCost)
4192 modOwner->ApplySpellMod(this, *mod, powerCost, spell);
4193 else
4194 {
4195
4197 float pctMod = 1.0f;
4198 modOwner->GetSpellModValues(this, *mod, spell, powerCost, &flatMod, &pctMod);
4199 powerCost =
int32(powerCost * pctMod);
4200 }
4201 }
4202 }
4203
4205 {
4207 {
4210 if (spellScaler && casterScaler)
4211 powerCost *= casterScaler->
Scaler / spellScaler->
Scaler;
4212 }
4213 }
4214
4216 powerCost = float(powerCost) * (1.0f + unitCaster->
m_unitData->ManaCostMultiplier);
4217
4218
4219 if (initiallyNegative != (powerCost < 0))
4220 powerCost = 0;
4221
4223}
DB2Storage< SpellShapeshiftFormEntry > sSpellShapeshiftFormStore("SpellShapeshiftForm.db2", &SpellShapeshiftFormLoadInfo::Instance)
std::optional< T > Optional
Optional helper class to wrap optional values within.
@ SPELL_ATTR1_USE_ALL_MANA
@ SPELL_ATTR3_REQUIRES_MAIN_HAND_WEAPON
@ SPELL_ATTR3_REQUIRES_OFF_HAND_WEAPON
@ SPELL_ATTR0_SCALES_WITH_CREATURE_LEVEL
@ SPELL_ATTR4_WEAPON_SPEED_COST_SCALING
@ SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
@ SPELL_AURA_MOD_POWER_COST_SCHOOL
@ SPELL_AURA_MOD_ADDITIONAL_POWER_COST
T CalculatePct(T base, U pct)
bool IsAffectingSpell(SpellInfo const *spell) const
int32 GetMiscValue() const
AuraEffectList const & GetAuraEffectsByType(AuraType type) const
UF::UpdateField< UF::UnitData, 0, TYPEID_UNIT > m_unitData
ShapeshiftForm GetShapeshiftForm() const
uint32 GetBaseAttackTime(WeaponAttackType att) const
uint64 GetMaxHealth() const
int32 GetTotalAuraModifier(AuraType auraType) const
int32 GetPower(Powers power) const
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
bool IsControlledByPlayer() const
uint32 GetCreateMana() const