Guest User

Untitled

a guest
Dec 12th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // "the bodies of template functions must be made available in a header file"
  2. template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell)
  3. {
  4. SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
  5. if (!spellInfo) return 0;
  6. int32 totalpct = 0;
  7. int32 totalflat = 0;
  8. for (SpellModList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr)
  9. {
  10. SpellModifier *mod = *itr;
  11.  
  12. if (!IsAffectedBySpellmod(spellInfo, mod, spell))
  13. continue;
  14. if (mod->type == SPELLMOD_FLAT)
  15. totalflat += mod->value;
  16. else if (mod->type == SPELLMOD_PCT)
  17. {
  18. // skip percent mods for null basevalue (most important for spell mods with charges)
  19. if (basevalue == T(0))
  20. continue;
  21.  
  22. // special case (skip >10sec spell casts for instant cast setting)
  23. if (mod->op == SPELLMOD_CASTING_TIME && basevalue >= T(10*IN_MILLISECONDS) && mod->value <= -100)
  24. continue;
  25.  
  26. totalpct += mod->value;
  27. }
  28.  
  29. if (mod->charges > 0)
  30. {
  31. if (!(spellInfo->SpellFamilyName == 8 && spellInfo->SpellFamilyFlags & 0x200000000LL))
  32. --mod->charges;
  33. if (mod->charges == 0)
  34. {
  35. mod->charges = -1;
  36. mod->lastAffected = spell;
  37. if (!mod->lastAffected)
  38. mod->lastAffected = FindCurrentSpellBySpellId(spellId);
  39. ++m_SpellModRemoveCount;
  40. }
  41. }
  42. }
  43.  
  44. float diff = (float)basevalue*(float)totalpct/100.0f + (float)totalflat;
  45. basevalue = T((float)basevalue + diff);
  46. return T(diff);
  47. }
Add Comment
Please, Sign In to add comment