Skip to content

Commit

Permalink
[9037] Cleanups in spellmode apply code.
Browse files Browse the repository at this point in the history
* Add constructores for spellmode creating instead explcit fields init
* Use uint32 for family mask 2 instead unneded uint64

Also drop one from manual applies for uno-existed now spell.
  • Loading branch information
VladimirMangos committed Dec 20, 2009
1 parent 9729773 commit b02ec8a
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 127 deletions.
4 changes: 4 additions & 0 deletions src/game/DBCStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,10 @@ struct SpellEntry

// helpers
int32 CalculateSimpleValue(uint8 eff) const { return EffectBasePoints[eff]+int32(EffectBaseDice[eff]); }
uint32 const* GetEffectSpellClassMask(uint8 effect) const
{
return EffectSpellClassMaskA + effect * 3;
}

private:
// prevent creating custom entries (copy data from original in fact)
Expand Down
34 changes: 31 additions & 3 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,33 @@ std::ostringstream& operator<< (std::ostringstream& ss, PlayerTaxi const& taxi)
return ss;
}

SpellModifier::SpellModifier( SpellModOp _op, SpellModType _type, int32 _value, SpellEntry const* spellEntry, uint8 eff, int16 _charges /*= 0*/ ) : op(_op), type(_type), charges(_charges), value(_value), spellId(spellEntry->Id), lastAffected(NULL)
{
uint32 const* ptr = spellEntry->GetEffectSpellClassMask(eff);
mask = uint64(ptr[0]) | (uint64(ptr[1]) << 32);
mask2= ptr[2];
}

SpellModifier::SpellModifier( SpellModOp _op, SpellModType _type, int32 _value, Aura const* aura, int16 _charges /*= 0*/ ) : op(_op), type(_type), charges(_charges), value(_value), spellId(aura->GetId()), lastAffected(NULL)
{
uint32 const* ptr = aura->getAuraSpellClassMask();
mask = uint64(ptr[0]) | (uint64(ptr[1]) << 32);
mask2= ptr[2];
}

bool SpellModifier::isAffectedOnSpell( SpellEntry const *spell ) const
{
SpellEntry const *affect_spell = sSpellStore.LookupEntry(spellId);
// False if affect_spell == NULL or spellFamily not equal
if (!affect_spell || affect_spell->SpellFamilyName != spell->SpellFamilyName)
return false;
if (mask & spell->SpellFamilyFlags)
return true;
if (mask2 & spell->SpellFamilyFlags2)
return true;
return false;
}

//== Player ====================================================

UpdateMask Player::updateVisualBits;
Expand Down Expand Up @@ -17173,7 +17200,7 @@ bool Player::IsAffectedBySpellmod(SpellEntry const *spellInfo, SpellModifier *mo
return false;
}

return sSpellMgr.IsAffectedByMod(spellInfo, mod);
return mod->isAffectedOnSpell(spellInfo);
}

void Player::AddSpellMod(SpellModifier* mod, bool apply)
Expand All @@ -17183,9 +17210,9 @@ void Player::AddSpellMod(SpellModifier* mod, bool apply)
for(int eff=0;eff<96;++eff)
{
uint64 _mask = 0;
uint64 _mask2= 0;
uint32 _mask2= 0;
if (eff<64) _mask = uint64(1) << (eff- 0);
else _mask2= uint64(1) << (eff-64);
else _mask2= uint32(1) << (eff-64);
if ( mod->mask & _mask || mod->mask2 & _mask2)
{
int32 val = 0;
Expand Down Expand Up @@ -21288,3 +21315,4 @@ void Player::SetHomebindToCurrentPos()
CharacterDatabase.PExecute("UPDATE character_homebind SET map = '%u', zone = '%u', position_x = '%f', position_y = '%f', position_z = '%f' WHERE guid = '%u'",
m_homebindMapId, m_homebindZoneId, m_homebindX, m_homebindY, m_homebindZ, GetGUIDLow());
}

13 changes: 12 additions & 1 deletion src/game/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,23 @@ struct PlayerSpell
struct SpellModifier
{
SpellModifier() : charges(0), lastAffected(NULL) {}

SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, uint32 _spellId, uint64 _mask, uint32 _mask2 = 0, int16 _charges = 0)
: op(_op), type(_type), charges(_charges), value(_value), mask(_mask), mask2(_mask2), spellId(_spellId), lastAffected(NULL)
{}

SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, SpellEntry const* spellEntry, uint8 eff, int16 _charges = 0);

SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, Aura const* aura, int16 _charges = 0);

bool isAffectedOnSpell(SpellEntry const *spell) const;

SpellModOp op : 8;
SpellModType type : 8;
int16 charges : 16;
int32 value;
uint64 mask;
uint64 mask2;
uint32 mask2;
uint32 spellId;
Spell const* lastAffected;
};
Expand Down
5 changes: 4 additions & 1 deletion src/game/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5772,7 +5772,10 @@ void Spell::UpdatePointers()

bool Spell::IsAffectedByAura(Aura *aura) const
{
return sSpellMgr.IsAffectedByMod(m_spellInfo, aura->getAuraSpellMod());
if(SpellModifier* mod = aura->getAuraSpellMod())
return mod->isAffectedOnSpell(m_spellInfo);
else
return false;
}

bool Spell::CheckTargetCreatureType(Unit* target) const
Expand Down
99 changes: 14 additions & 85 deletions src/game/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,30 +1395,14 @@ void Aura::HandleAddModifier(bool apply, bool Real)
break;
}

SpellModifier *mod = new SpellModifier;
mod->op = SpellModOp(m_modifier.m_miscvalue);
mod->value = m_modifier.m_amount;
mod->type = SpellModType(m_modifier.m_auraname); // SpellModType value == spell aura types
mod->spellId = GetId();

uint32 const *ptr;
switch (m_effIndex)
{
case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
default:
return;
}

mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
mod->mask2= (uint64)ptr[2];

// prevent expire spell mods with (charges > 0 && m_stackAmount > 1)
// all this spell expected expire not at use but at spell proc event check
mod->charges = m_spellProto->StackAmount > 1 ? 0 : m_procCharges;

m_spellmod = mod;
m_spellmod = new SpellModifier(
SpellModOp(m_modifier.m_miscvalue),
SpellModType(m_modifier.m_auraname), // SpellModType value == spell aura types
m_modifier.m_amount,
this,
// prevent expire spell mods with (charges > 0 && m_stackAmount > 1)
// all this spell expected expire not at use but at spell proc event check
m_spellProto->StackAmount > 1 ? 0 : m_procCharges);
}

((Player*)m_target)->AddSpellMod(m_spellmod, apply);
Expand Down Expand Up @@ -1454,18 +1438,10 @@ void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
SpellModifier *mod = new SpellModifier;
mod->spellId = GetId();

uint32 const *ptr;
switch (m_effIndex)
{
case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
default:
return;
}
uint32 const *ptr = m_spellProto->GetEffectSpellClassMask(m_effIndex);

mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
mod->mask2= (uint64)ptr[2];
mod->mask2= ptr[2];
m_spellmod = mod;
}
else
Expand Down Expand Up @@ -2611,14 +2587,8 @@ void Aura::HandleAuraDummy(bool apply, bool Real)
if(apply)
{
// Reduce backfire damage (dot damage) from Shadow Word: Death
SpellModifier *mod = new SpellModifier;
mod->op = SPELLMOD_DOT;
mod->value = m_modifier.m_amount;
mod->type = SPELLMOD_PCT;
mod->spellId = GetId();
mod->mask = UI64LIT(0x0000200000000000);
mod->mask2= UI64LIT(0x0);
m_spellmod = mod;
// aura have wrong effectclassmask, so use hardcoded value
m_spellmod = new SpellModifier(SPELLMOD_DOT,SPELLMOD_PCT,m_modifier.m_amount,GetId(),0x0000200000000000);
}
((Player*)m_target)->AddSpellMod(m_spellmod, apply);
return;
Expand All @@ -2636,17 +2606,8 @@ void Aura::HandleAuraDummy(bool apply, bool Real)
return;

if(apply)
{
SpellModifier *mod = new SpellModifier;
mod->op = SPELLMOD_DOT;
mod->value = m_modifier.m_amount/7;
mod->type = SPELLMOD_FLAT;
mod->spellId = GetId();
mod->mask = UI64LIT(0x001000000000);
mod->mask2= UI64LIT(0x0);

m_spellmod = mod;
}
// dummy not have proper effectclassmask
m_spellmod = new SpellModifier(SPELLMOD_DOT,SPELLMOD_FLAT,m_modifier.m_amount/7,GetId(),UI64LIT(0x001000000000));

((Player*)m_target)->AddSpellMod(m_spellmod, apply);
return;
Expand Down Expand Up @@ -2770,39 +2731,7 @@ void Aura::HandleAuraDummy(bool apply, bool Real)
}
break;
case SPELLFAMILY_SHAMAN:
{
// Improved Weapon Totems
if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
{
if(apply)
{
SpellModifier *mod = new SpellModifier;
mod->op = SPELLMOD_EFFECT1;
mod->value = m_modifier.m_amount;
mod->type = SPELLMOD_PCT;
mod->spellId = GetId();
switch (m_effIndex)
{
case 0:
// Windfury Totem
mod->mask = UI64LIT(0x00200000000);
mod->mask2= UI64LIT(0x0);
break;
case 1:
// Flametongue Totem
mod->mask = UI64LIT(0x00400000000);
mod->mask2= UI64LIT(0x0);
break;
}

m_spellmod = mod;
}

((Player*)m_target)->AddSpellMod(m_spellmod, apply);
return;
}
break;
}
}

// pet auras
Expand Down
2 changes: 1 addition & 1 deletion src/game/SpellAuras.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class MANGOS_DLL_SPEC Aura
void TriggerSpell();
void TriggerSpellWithValue();

uint32 const *getAuraSpellClassMask() const { return m_spellProto->EffectSpellClassMaskA + m_effIndex * 3; }
uint32 const *getAuraSpellClassMask() const { return m_spellProto->GetEffectSpellClassMask(m_effIndex); }
bool isAffectedOnSpell(SpellEntry const *spell) const;
protected:
Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
Expand Down
19 changes: 0 additions & 19 deletions src/game/SpellMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,25 +862,6 @@ void SpellMgr::LoadSpellTargetPositions()
sLog.outString( ">> Loaded %u spell teleport coordinates", count );
}

bool SpellMgr::IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const
{
// false for spellInfo == NULL
if (!spellInfo || !mod)
return false;

SpellEntry const *affect_spell = sSpellStore.LookupEntry(mod->spellId);
// False if affect_spell == NULL or spellFamily not equal
if (!affect_spell || affect_spell->SpellFamilyName != spellInfo->SpellFamilyName)
return false;

// true
if (mod->mask & spellInfo->SpellFamilyFlags ||
mod->mask2 & spellInfo->SpellFamilyFlags2)
return true;

return false;
}

struct DoSpellProcEvent
{
DoSpellProcEvent(SpellProcEventEntry const& _spe) : spe(_spe) {}
Expand Down
2 changes: 0 additions & 2 deletions src/game/SpellMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ class SpellMgr
// Accessors (const or static functions)
public:

bool IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const;

SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }

uint32 GetSpellElixirMask(uint32 spellid) const
Expand Down
17 changes: 3 additions & 14 deletions src/game/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6548,13 +6548,8 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura* triggeredByAu
}
// No thread generated mod
// TODO: exist special flag in spell attributes for this, need found and use!
SpellModifier *mod = new SpellModifier;
mod->op = SPELLMOD_THREAT;
mod->value = -100;
mod->type = SPELLMOD_PCT;
mod->spellId = dummySpell->Id;
mod->mask = UI64LIT(0x0000000000000003);
mod->mask2= UI64LIT(0x0);
SpellModifier *mod = new SpellModifier(SPELLMOD_THREAT,SPELLMOD_PCT,-100,triggeredByAura);

((Player*)this)->AddSpellMod(mod, true);

// Remove cooldown (Chain Lightning - have Category Recovery time)
Expand Down Expand Up @@ -12809,13 +12804,7 @@ bool Unit::HandleMendingAuraProc( Aura* triggeredByAura )
if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius))
{
// aura will applied from caster, but spell casted from current aura holder
SpellModifier *mod = new SpellModifier;
mod->op = SPELLMOD_CHARGES;
mod->value = jumps-5; // negative
mod->type = SPELLMOD_FLAT;
mod->spellId = spellProto->Id;
mod->mask = spellProto->SpellFamilyFlags;
mod->mask2 = spellProto->SpellFamilyFlags2;
SpellModifier *mod = new SpellModifier(SPELLMOD_CHARGES,SPELLMOD_FLAT,jumps-5,spellProto->Id,spellProto->SpellFamilyFlags,spellProto->SpellFamilyFlags2);

// remove before apply next (locked against deleted)
triggeredByAura->SetInUse(true);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9036"
#define REVISION_NR "9037"
#endif // __REVISION_NR_H__

3 comments on commit b02ec8a

@filo
Copy link

@filo filo commented on b02ec8a Dec 20, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This revision coused this compile error (I think):
../../../src/game/SpellAuras.cpp:2591: error: integer constant is too large for ‘long’ type

@SkyFire
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a clean compile in windows vs2008 Compiled fine.

@filo
Copy link

@filo filo commented on b02ec8a Dec 20, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xeross: yes, i have debian

Please sign in to comment.