All pastes #247626 Raw Edit

Stuff

public text v1 · immutable
#247626 ·published 2006-11-13 18:41 UTC
rendered paste body
Index: src/game/MiscHandler.cpp
===================================================================
--- src/game/MiscHandler.cpp	(revision 2641)
+++ src/game/MiscHandler.cpp	(working copy)
@@ -711,10 +711,10 @@
     GetPlayer()->SpawnCorpseBones();
 
     // set health, mana
-    GetPlayer()->ApplyStats(false);
+    GetPlayer()->RemoveStatsMods();
     GetPlayer()->SetHealth(GetPlayer()->GetMaxHealth()/2);
     GetPlayer()->SetPower(POWER_MANA,GetPlayer()->GetMaxPower(POWER_MANA)/2);
-    GetPlayer()->ApplyStats(true);
+    GetPlayer()->ApplyStatsMods();
 
     // update world right away
     MapManager::Instance().GetMap(GetPlayer()->GetMapId())->Add(GetPlayer());
Index: src/game/NPCHandler.cpp
===================================================================
--- src/game/NPCHandler.cpp	(revision 2641)
+++ src/game/NPCHandler.cpp	(working copy)
@@ -407,12 +407,12 @@
         }
     }
 
-    _player->ApplyStats(false);
+    _player->RemoveStatsMods();
     _player->SetHealth( _player->GetMaxHealth()/2 );
     _player->SetPower(POWER_MANA, _player->GetMaxPower(POWER_MANA)/2 );
     _player->SetPower(POWER_RAGE, 0 );
     _player->SetPower(POWER_ENERGY, _player->GetMaxPower(POWER_ENERGY));
-    _player->ApplyStats(true);
+    _player->ApplyStatsMods();
 
     _player->DurabilityLossAll(0.25);
     _player->SpawnCorpseBones();
Index: src/game/Player.cpp
===================================================================
--- src/game/Player.cpp	(revision 2642)
+++ src/game/Player.cpp	(working copy)
@@ -425,7 +425,8 @@
     UpdateBlockPercentage();
 
     // apply original stats mods before item equipment that call before equip _RemoveStatsMods()
-    _ApplyStatsMods();
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
 
     uint16 dest;
     uint8 msg;
@@ -499,7 +500,8 @@
     // all item positions resolved
 
     // remove applied original stats mods before item equipment
-    _RemoveStatsMods();
+    RemoveStatsMods();
+    RemovePercentStatsMods();
     return true;
 }
 
@@ -1545,7 +1547,8 @@
     // Remove item, aura, stats bonuses
     _RemoveAllItemMods();
     _RemoveAllAuraMods();
-    _RemoveStatsMods();
+    RemoveStatsMods();
+    RemovePercentStatsMods();
 
     // base stats
     float newMP  = (getClass() == WARRIOR || getClass() == ROGUE) ? 0 : GetMaxPower(POWER_MANA);
@@ -1597,7 +1600,8 @@
     UpdateBlockPercentage();
 
     // apply stats, aura, items mods
-    _ApplyStatsMods();
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
     _ApplyAllAuraMods();
     _ApplyAllItemMods();
 
@@ -4209,7 +4213,9 @@
             RemoveItemsSetItem(this,proto);
     }
 
-    _RemoveStatsMods();
+    RemoveStatsMods();
+    RemovePercentStatsMods();
+
     AuraList& mModBaseResistancePct = GetAurasByType(SPELL_AURA_MOD_BASE_RESISTANCE_PCT);
     for(AuraList::iterator i = mModBaseResistancePct.begin(); i != mModBaseResistancePct.end(); ++i)
         (*i)->ApplyModifier(false);
@@ -4218,8 +4224,11 @@
 
     for(AuraList::iterator i = mModBaseResistancePct.begin(); i != mModBaseResistancePct.end(); ++i)
         (*i)->ApplyModifier(true);
-    _ApplyStatsMods();
 
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
+    
+
     if(apply)
         CastItemEquipSpell(item);
     else
@@ -4569,7 +4578,8 @@
         }
     }
 
-    _RemoveStatsMods();
+    RemoveStatsMods();
+    RemovePercentStatsMods();
 
     AuraList& mModBaseResistancePct = GetAurasByType(SPELL_AURA_MOD_BASE_RESISTANCE_PCT);
     for(AuraList::iterator i = mModBaseResistancePct.begin(); i != mModBaseResistancePct.end(); ++i)
@@ -4591,7 +4601,8 @@
     for(AuraList::iterator i = mModBaseResistancePct.begin(); i != mModBaseResistancePct.end(); ++i)
         (*i)->ApplyModifier(true);
 
-    _ApplyStatsMods();
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
 
     sLog.outDebug("_RemoveAllItemMods complete.");
 }
@@ -4625,7 +4636,8 @@
         }
     }
 
-    _RemoveStatsMods();
+    RemoveStatsMods();
+    RemovePercentStatsMods();
 
     AuraList& mModBaseResistancePct = GetAurasByType(SPELL_AURA_MOD_BASE_RESISTANCE_PCT);
     for(AuraList::iterator i = mModBaseResistancePct.begin(); i != mModBaseResistancePct.end(); ++i)
@@ -4649,7 +4661,8 @@
     for(AuraList::iterator i = mModBaseResistancePct.begin(); i != mModBaseResistancePct.end(); ++i)
         (*i)->ApplyModifier(true);
 
-    _ApplyStatsMods();
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
 
     sLog.outDebug("_ApplyAllItemMods complete.");
 }
Index: src/game/SpellAuras.cpp
===================================================================
--- src/game/SpellAuras.cpp	(revision 2641)
+++ src/game/SpellAuras.cpp	(working copy)
@@ -576,9 +576,7 @@
     if( m_modifier.m_auraname==SPELL_AURA_MOD_REGEN || m_modifier.m_auraname==SPELL_AURA_MOD_POWER_REGEN )
         m_periodicTimer = 5000;
 
-    m_target->ApplyStats(false);
     ApplyModifier(true);
-    m_target->ApplyStats(true);
 
     sLog.outDebug("Aura %u now is in use", m_modifier.m_auraname);
 
@@ -642,10 +640,12 @@
     if(m_modifier.m_auraname == SPELL_AURA_MOD_SHAPESHIFT)  // remove the shapeshift aura's boosts
         HandleShapeshiftBoosts(false, this);
 
-    m_target->ApplyStats(false);
+    m_target->RemoveStatsMods();
+    m_target->RemovePercentStatsMods();
     sLog.outDebug("Aura %u now is remove", m_modifier.m_auraname);
     ApplyModifier(false);
-    m_target->ApplyStats(true);
+    m_target->ApplyPercentStatsMods();
+    m_target->ApplyStatsMods();
 
     Unit* caster = GetCaster();
 
@@ -904,10 +904,8 @@
                 return;
             SpellCastTargets targets;
             targets.setUnitTarget(target);
-            // prevent double stat apply for triggered auras
-            target->ApplyStats(true);
+
             spell.prepare(&targets);
-            target->ApplyStats(false);
         }
     }
 }
Index: src/game/Unit.cpp
===================================================================
--- src/game/Unit.cpp	(revision 2641)
+++ src/game/Unit.cpp	(working copy)
@@ -1673,7 +1673,14 @@
         }
     }
 
+    if(Aur->GetTarget())
+    {
+        Aur->GetTarget()->RemoveStatsMods();
+        Aur->GetTarget()->RemovePercentStatsMods();
+    }
+
     Aur->_AddAura();
+
     m_Auras.insert(AuraMap::value_type(spellEffectPair(Aur->GetId(), Aur->GetEffIndex()), Aur));
     if (Aur->GetModifier()->m_auraname < TOTAL_AURAS)
     {
@@ -1681,6 +1688,13 @@
         m_AuraModifiers[Aur->GetModifier()->m_auraname] += (Aur->GetModifier()->m_amount);
     }
 
+    if(Aur->GetTarget())
+    {
+        Aur->GetTarget()->ApplyPercentStatsMods();
+        Aur->GetTarget()->ApplyStatsMods();
+    }
+
+
     if (IsSingleTarget(Aur->GetId()) && Aur->GetTarget() && Aur->GetSpellProto())
     {
         if(Unit* caster = Aur->GetCaster())
@@ -1999,18 +2013,28 @@
     }
 }
 
-void Unit::_RemoveStatsMods()
+void Unit::RemoveStatsMods()
 {
-    ApplyStats(false);
+    _ApplyStats(false);
 }
 
-void Unit::_ApplyStatsMods()
+void Unit::ApplyStatsMods()
 {
-    ApplyStats(true);
+    _ApplyStats(true);
 }
 
-void Unit::ApplyStats(bool apply)
+void Unit::RemovePercentStatsMods()
 {
+    _ApplyPercentStats(false);
+}
+
+void Unit::ApplyPercentStatsMods()
+{
+    _ApplyPercentStats(true);
+}
+
+void Unit::_ApplyStats(bool apply)
+{
     // TODO:
     // -- add --
     // spell crit formula: 5 + INT/100
@@ -2019,54 +2043,16 @@
 
     if(GetTypeId() != TYPEID_PLAYER) return;
 
-    float val;
-    int32 val2,tem_att_power;
-    float totalstatmods[5] = {1,1,1,1,1};
-    float totalresmods[7] = {1,1,1,1,1,1,1};
-
-    AuraList& mModTotalStatPct = GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
-    for(AuraList::iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
+    if(!apply)
     {
-        if((*i)->GetModifier()->m_miscvalue != -1)
-            totalstatmods[(*i)->GetModifier()->m_miscvalue] *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f;
-        else
-            for (uint8 j = 0; j < 5; j++)
-                totalstatmods[j] *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f;
+        AuraList& mModResistancePct = GetAurasByType(SPELL_AURA_MOD_RESISTANCE_PCT);
+        for(AuraList::iterator i = mModResistancePct.begin(); i != mModResistancePct.end(); ++i)
+            (*i)->ApplyModifier(apply);
     }
-    AuraList& mModResistancePct = GetAurasByType(SPELL_AURA_MOD_RESISTANCE_PCT);
-    for(AuraList::iterator i = mModResistancePct.begin(); i != mModResistancePct.end(); ++i)
-        for(uint8 j = 0; j <= 6; j++)
-            if((*i)->GetModifier()->m_miscvalue & (1<<j))
-                totalresmods[j] *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f;
 
-    for (uint8 i = 0; i < 5; i++)
-        totalstatmods[i] = totalstatmods[i] * 100.0f - 100.0f;
-    for (uint8 i = 0; i < 7; i++)
-        totalresmods[i] = totalresmods[i] * 100.0f - 100.0f;
+    float val;
+    int32 val2,tem_att_power;
 
-    // restore percent mods
-    if (apply)
-    {
-        for (uint8 i = 0; i < 5; i++)
-        {
-            if (totalstatmods[i] != 0)
-            {
-                ApplyStatPercentMod(Stats(i),totalstatmods[i], apply );
-                ((Player*)this)->ApplyPosStatPercentMod(Stats(i),totalstatmods[i], apply );
-                ((Player*)this)->ApplyNegStatPercentMod(Stats(i),totalstatmods[i], apply );
-            }
-        }
-        for (uint8 i = 0; i < 7; i++)
-        {
-            if (totalresmods[i] != 0)
-            {
-                ApplyResistancePercentMod(SpellSchools(i), totalresmods[i], apply );
-                ((Player*)this)->ApplyResistanceBuffModsPercentMod(SpellSchools(i),true, totalresmods[i], apply);
-                ((Player*)this)->ApplyResistanceBuffModsPercentMod(SpellSchools(i),false, totalresmods[i], apply);
-            }
-        }
-    }
-
     // Armor
     val = 2*(GetStat(STAT_AGILITY) - ((Player*)this)->GetCreateStat(STAT_AGILITY));
 
@@ -2174,33 +2160,27 @@
 
     ApplyModFloatValue(PLAYER_PARRY_PERCENTAGE, val, apply);
 
-    // remove percent mods to see original stats when adding buffs/items
-    if (!apply)
+    if(apply)
     {
-        for (uint8 i = 0; i < 5; i++)
-        {
-            if (totalstatmods[i])
-            {
-                ApplyStatPercentMod(Stats(i),totalstatmods[i], apply );
-                ((Player*)this)->ApplyPosStatPercentMod(Stats(i),totalstatmods[i], apply );
-                ((Player*)this)->ApplyNegStatPercentMod(Stats(i),totalstatmods[i], apply );
-            }
-        }
-        for (uint8 i = 0; i < 7; i++)
-        {
-            if (totalresmods[i])
-            {
-                ApplyResistancePercentMod(SpellSchools(i), totalresmods[i], apply );
-                ((Player*)this)->ApplyResistanceBuffModsPercentMod(SpellSchools(i),true, totalresmods[i], apply);
-                ((Player*)this)->ApplyResistanceBuffModsPercentMod(SpellSchools(i),false, totalresmods[i], apply);
-            }
-        }
+        AuraList& mModResistancePct = GetAurasByType(SPELL_AURA_MOD_RESISTANCE_PCT);
+        for(AuraList::iterator i = mModResistancePct.begin(); i != mModResistancePct.end(); ++i)
+            (*i)->ApplyModifier(apply);
     }
 }
 
+void Unit::_ApplyPercentStats(bool apply)
+{
+    AuraList& mModTotalStatPct = GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
+    for(AuraList::iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
+        (*i)->ApplyModifier(apply);
+}
+
+
 void Unit::_RemoveAllAuraMods()
 {
-    ApplyStats(false);
+    RemoveStatsMods();
+    RemovePercentStatsMods();
+
     for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i)
     {
         switch ((*i).second->GetModifier()->m_auraname)
@@ -2213,27 +2193,14 @@
                 (*i).second->ApplyModifier(false);
         }
     }
-    ApplyStats(true);
-
-    // these must be removed after applystats
-    AuraList& mModTotalStatPct = GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
-    for(AuraList::iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
-        (*i)->ApplyModifier(false);
-    AuraList& mModResistancePct = GetAurasByType(SPELL_AURA_MOD_RESISTANCE_PCT);
-    for(AuraList::iterator i = mModResistancePct.begin(); i != mModResistancePct.end(); ++i)
-        (*i)->ApplyModifier(false);
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
 }
 
 void Unit::_ApplyAllAuraMods()
 {
-    // these must be applied before applystats
-    AuraList& mModTotalStatPct = GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
-    for(AuraList::iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
-        (*i)->ApplyModifier(true);
-    AuraList& mModResistancePct = GetAurasByType(SPELL_AURA_MOD_RESISTANCE_PCT);
-    for(AuraList::iterator i = mModResistancePct.begin(); i != mModResistancePct.end(); ++i)
-        (*i)->ApplyModifier(true);
-    ApplyStats(false);
+    RemoveStatsMods();
+    RemovePercentStatsMods();
 
     for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i)
     {
@@ -2247,7 +2214,8 @@
                 (*i).second->ApplyModifier(true);
         }
     }
-    ApplyStats(true);
+    ApplyPercentStatsMods();
+    ApplyStatsMods();
 }
 
 // TODO: FIX-ME!!!
Index: src/game/Unit.h
===================================================================
--- src/game/Unit.h	(revision 2641)
+++ src/game/Unit.h	(working copy)
@@ -629,7 +629,6 @@
         uint32 CalculateDamage(WeaponAttackType attType);
         void SetStateFlag(uint32 index, uint32 newFlag );
         void RemoveStateFlag(uint32 index, uint32 oldFlag );
-        void ApplyStats(bool apply);
         void UnsummonTotem(int8 slot = -1);
         uint32 SpellDamageBonus(Unit *pVictim, SpellEntry *spellProto, uint32 damage);
         uint32 SpellHealingBonus(SpellEntry *spellProto, uint32 healamount);
@@ -637,11 +636,15 @@
         void MeleeDamageBonus(Unit *pVictim, uint32 *damage);
         void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
 
+        void RemoveStatsMods();
+        void ApplyStatsMods();
+        void RemovePercentStatsMods();
+        void ApplyPercentStatsMods();
     protected:
         Unit ( );
 
-        void _RemoveStatsMods();
-        void _ApplyStatsMods();
+        void _ApplyStats(bool apply);
+        void _ApplyPercentStats(bool apply);
 
         void _RemoveAllAuraMods();
         void _ApplyAllAuraMods();