Skip to content

Commit

Permalink
Move ApplySpellMod definition to cpp file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Dec 27, 2024
1 parent d3d816e commit e08f128
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
52 changes: 52 additions & 0 deletions src/game/Objects/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22734,6 +22734,58 @@ void Player::CastHighestStealthRank()
CastSpell(nullptr, stealthSpellEntry, true);
}

template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell* spell)
{
SpellEntry const* spellInfo = sSpellMgr.GetSpellEntry(spellId);
if (!spellInfo || spellInfo->HasAttribute(SPELL_ATTR_EX3_IGNORE_CASTER_MODIFIERS)) return 0;
float totalpct = 0;
float totalflat = 0;
for (const auto mod : m_spellMods[op])
{
if (!IsAffectedBySpellmod(spellInfo,mod,spell))
continue;

if (mod->type == SPELLMOD_FLAT)
totalflat += mod->value;
else if (mod->type == SPELLMOD_PCT)
{
// skip percent mods for null basevalue (most important for spell mods with charges)
if (basevalue == T(0))
continue;

// special case (skip >10sec spell casts for instant cast setting)
if (mod->op==SPELLMOD_CASTING_TIME && basevalue >= T(10*IN_MILLISECONDS) && mod->value <= -100)
continue;

totalpct += mod->value;
}

#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_10_2
// World of Warcraft Client Patch 1.11.0 (2006-06-20)
// - Nature's Grace: You will no longer consume this effect when casting a
// spell which was made instant by Nature's Swiftness.
if (!((mod->op == SPELLMOD_CASTING_TIME) && (mod->type == SPELLMOD_FLAT) && HasInstantCastingSpellMod(spellInfo)))
#endif
DropModCharge(mod, spell);

// Nostalrius : fix ecorce (22812 - +1sec incant) + rapidite nature (17116 - sorts instant) = 0sec de cast
if (mod->op == SPELLMOD_CASTING_TIME && mod->type == SPELLMOD_PCT && mod->value == -100)
{
totalpct = -100;
totalflat = 0;
break;
}
}

float diff = float(basevalue) * totalpct/100.0f + totalflat;
basevalue = T(float(basevalue) + diff);
return T(diff);
}

template int32 Player::ApplySpellMod(uint32 spellId, SpellModOp op, int32& basevalue, Spell* spell);
template uint32 Player::ApplySpellMod(uint32 spellId, SpellModOp op, uint32& basevalue, Spell* spell);
template float Player::ApplySpellMod(uint32 spellId, SpellModOp op, float& basevalue, Spell* spell);

static char const* type_strings[] =
{
"Basic",
Expand Down
49 changes: 0 additions & 49 deletions src/game/Objects/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2711,53 +2711,4 @@ inline Player const* ToPlayer(Object const* object)
void AddItemsSetItem(Player*player,Item* item);
void RemoveItemsSetItem(Player*player,ItemPrototype const* proto);

// "the bodies of template functions must be made available in a header file"
template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell* spell)
{
SpellEntry const* spellInfo = sSpellMgr.GetSpellEntry(spellId);
if (!spellInfo || spellInfo->HasAttribute(SPELL_ATTR_EX3_IGNORE_CASTER_MODIFIERS)) return 0;
float totalpct = 0;
float totalflat = 0;
for (const auto mod : m_spellMods[op])
{
if (!IsAffectedBySpellmod(spellInfo,mod,spell))
continue;

if (mod->type == SPELLMOD_FLAT)
totalflat += mod->value;
else if (mod->type == SPELLMOD_PCT)
{
// skip percent mods for null basevalue (most important for spell mods with charges)
if (basevalue == T(0))
continue;

// special case (skip >10sec spell casts for instant cast setting)
if (mod->op==SPELLMOD_CASTING_TIME && basevalue >= T(10*IN_MILLISECONDS) && mod->value <= -100)
continue;

totalpct += mod->value;
}

#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_10_2
// World of Warcraft Client Patch 1.11.0 (2006-06-20)
// - Nature's Grace: You will no longer consume this effect when casting a
// spell which was made instant by Nature's Swiftness.
if (!((mod->op == SPELLMOD_CASTING_TIME) && (mod->type == SPELLMOD_FLAT) && HasInstantCastingSpellMod(spellInfo)))
#endif
DropModCharge(mod, spell);

// Nostalrius : fix ecorce (22812 - +1sec incant) + rapidite nature (17116 - sorts instant) = 0sec de cast
if (mod->op == SPELLMOD_CASTING_TIME && mod->type == SPELLMOD_PCT && mod->value == -100)
{
totalpct = -100;
totalflat = 0;
break;
}
}

float diff = (float)basevalue*(float)totalpct/100.0f + (float)totalflat;
basevalue = T((float)basevalue + diff);
return T(diff);
}

#endif

0 comments on commit e08f128

Please sign in to comment.