Skip to content

Commit

Permalink
[11789] Remove ApplySpellMod body from header. We can explicitly inst…
Browse files Browse the repository at this point in the history
…antiate possible variants.

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
  • Loading branch information
Vinolentus authored and Schmoozerd committed Sep 5, 2011
1 parent 9243e5b commit 71df210
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
44 changes: 44 additions & 0 deletions src/game/Player.cpp
Expand Up @@ -60,6 +60,7 @@
#include "SocialMgr.h"
#include "AchievementMgr.h"
#include "Mail.h"
#include "SpellAuras.h"

#include <cmath>

Expand Down Expand Up @@ -18620,6 +18621,49 @@ void Player::AddSpellMod(Aura* aura, bool apply)
m_spellMods[mod->m_miscvalue].remove(aura);
}

template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell)
{
SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo)
return 0;

int32 totalpct = 0;
int32 totalflat = 0;
for (AuraList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr)
{
Aura *aura = *itr;

Modifier const* mod = aura->GetModifier();

if (!aura->isAffectedOnSpell(spellInfo))
continue;

if (mod->m_auraname == SPELL_AURA_ADD_FLAT_MODIFIER)
totalflat += mod->m_amount;
else
{
// 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->m_miscvalue == SPELLMOD_CASTING_TIME
&& basevalue >= T(10*IN_MILLISECONDS) && mod->m_amount <= -100)
continue;

totalpct += mod->m_amount;
}
}

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

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

// send Proficiency
void Player::SendProficiency(ItemClass itemClass, uint32 itemSubclassMask)
{
Expand Down
38 changes: 0 additions & 38 deletions src/game/Player.h
Expand Up @@ -38,7 +38,6 @@
#include "BattleGround.h"
#include "DBCStores.h"
#include "SharedDefines.h"
#include "SpellAuras.h"

#include<string>
#include<vector>
Expand Down Expand Up @@ -2632,41 +2631,4 @@ class MANGOS_DLL_SPEC Player : public Unit
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 const* spell)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo) return 0;
int32 totalpct = 0;
int32 totalflat = 0;
for (AuraList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr)
{
Aura *aura = *itr;

Modifier const* mod = aura->GetModifier();

if (!aura->isAffectedOnSpell(spellInfo))
continue;

if (mod->m_auraname == SPELL_AURA_ADD_FLAT_MODIFIER)
totalflat += mod->m_amount;
else
{
// 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->m_miscvalue == SPELLMOD_CASTING_TIME && basevalue >= T(10*IN_MILLISECONDS) && mod->m_amount <= -100)
continue;

totalpct += mod->m_amount;
}
}

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

#endif
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11788"
#define REVISION_NR "11789"
#endif // __REVISION_NR_H__

0 comments on commit 71df210

Please sign in to comment.