All pastes #876973 Raw Edit

Miscellany

public text v1 · immutable
#876973 ·published 2008-01-29 06:22 UTC
rendered paste body
Index: src/game/GameObject.cpp
===================================================================
--- src/game/GameObject.cpp    (revision 5092)
+++ src/game/GameObject.cpp    (working copy)
@@ -49,6 +49,7 @@
     m_spawnedByDefault = true;
     m_usetimes = 0;
     m_spellId = 0;
+    m_environmentcastTime = 0;
 }
 
 GameObject::~GameObject()
@@ -302,31 +303,23 @@
         }
     }
 
-    SpellEntry const *createSpell = m_spellId ? sSpellStore.LookupEntry(m_spellId) : NULL;
-    if (!createSpell)
-        return;
-    int i;
-    for (i = 0; i < 3; i++)
-        if (createSpell->Effect[i] == SPELL_EFFECT_SUMMON_OBJECT_SLOT1)
-            break;
-    if (i<3)
+    if(GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP)
     {
         // traps
+        Unit* owner = GetOwner();
+        Unit* ok = NULL;                                    // pointer to appropriate target if found any
+        if(!owner && m_respawnTime > 0)
+            return;
+
+        if(m_environmentcastTime && m_environmentcastTime >= time(NULL))
+            return;
+
+        bool NeedDespawn = GetGOInfo()->data4 ? true : false;
         CellPair p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
         Cell cell(p);
         cell.data.Part.reserved = ALL_DISTRICT;
 
-        Unit* owner = GetOwner();
-        if (!owner)
-        {
-            m_respawnTime = 0;                              // to prevent save respawn timer
-            Delete();
-            return;
-        }
-
-        Unit* ok = NULL;                                    // pointer to appropriate target if found any
-
-        float radius = GetRadius(sSpellRadiusStore.LookupEntry(createSpell->EffectRadiusIndex[i]));
+        float radius = GetGOInfo()->data2;
         MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, owner, radius);
         MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck> checker(ok, u_check);
 
@@ -347,9 +340,24 @@
 
         if (ok)
         {
-            owner->CastSpell(ok, GetGOInfo()->data3, true);
-            m_respawnTime = 0;                              // to prevent save respawn timer
-            Delete();
+            Unit *caster =  owner ? owner : ok;
+
+            caster->CastSpell(ok, GetGOInfo()->data3, true);
+            m_environmentcastTime = time(NULL) + 4;             // 4 seconds
+
+            if(NeedDespawn)
+            {
+                m_respawnTime = 0;                              // to prevent save respawn timer
+                Delete();
+            }
+
+            if(GetGOInfo()->data5 == 3 && ok->GetTypeId() == TYPEID_PLAYER)
+            {                
+                //BattleGround gameobjects case
+                //if(((Player*)ok)->InBattleGround())
+                //    if(BattleGround *bg = ((Player*)ok)->GetBattleGround())
+                //        bg->HandleBuffUse(GetGUID());
+            }
         }
     }
 
Index: src/game/GameObject.h
===================================================================
--- src/game/GameObject.h    (revision 5092)
+++ src/game/GameObject.h    (working copy)
@@ -202,6 +202,7 @@
         uint32      m_flags;
         LootState   m_lootState;
         bool        m_spawnedByDefault;
+        uint32      m_environmentcastTime;
         std::list<uint32> m_SkillupList;
 
         std::set<uint32> m_unique_users;
Index: src/game/GridNotifiers.h
===================================================================
--- src/game/GridNotifiers.h    (revision 5092)
+++ src/game/GridNotifiers.h    (working copy)
@@ -474,10 +474,20 @@
             AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
             bool operator()(Unit* u)
             {
-                if(u->isAlive() && !i_funit->IsFriendlyTo(u) && i_obj->IsWithinDistInMap(u, i_range))
-                    return true;
-
-                return false;
+                if(i_funit)               //If Owner exist (hunters traps)
+                {
+                    if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u))
+                        return true;
+                    else
+                        return false;
+                }
+                else                      //Environment traps
+                {
+                    if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range))
+                        return true;
+                    else
+                        return false;
+                }
             }
         private:
             WorldObject const* i_obj;
Index: src/game/Player.h
===================================================================
--- src/game/Player.h    (revision 5092)
+++ src/game/Player.h    (working copy)
@@ -1809,6 +1809,7 @@
         void SetGroupUpdateFlag(uint32 flag) { m_groupUpdateMask |= flag;}
 
         GridReference<Player> &GetGridRef() { return m_gridRef; }
+        void EnvironmentalDamage(uint64 Guid, uint8 Type, uint32 Amount);
 
     protected:
 
@@ -1888,7 +1889,6 @@
         void StartMirrorTimer(MirrorTimerType Type, uint32 MaxValue);
         void ModifyMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, uint32 Regen);
         void StopMirrorTimer(MirrorTimerType Type);
-        void EnvironmentalDamage(uint64 Guid, uint8 Type, uint32 Amount);
         uint8 m_isunderwater;
         bool m_isInWater;
 
Index: src/game/Spell.h
===================================================================
--- src/game/Spell.h    (revision 5092)
+++ src/game/Spell.h    (working copy)
@@ -379,6 +379,7 @@
         void EffectDistract(uint32 i);
         void EffectPull(uint32 i);
         void EffectSchoolDMG(uint32 i);
+        void EffectEnvirinmentalDMG(uint32 i);
         void EffectInstaKill(uint32 i);
         void EffectDummy(uint32 i);
         void EffectTeleportUnits(uint32 i);
Index: src/game/SpellEffects.cpp
===================================================================
--- src/game/SpellEffects.cpp    (revision 5092)
+++ src/game/SpellEffects.cpp    (working copy)
@@ -64,7 +64,7 @@
     &Spell::EffectNULL,                                     //  4 SPELL_EFFECT_PORTAL_TELEPORT          unused
     &Spell::EffectTeleportUnits,                            //  5 SPELL_EFFECT_TELEPORT_UNITS
     &Spell::EffectApplyAura,                                //  6 SPELL_EFFECT_APPLY_AURA
-    &Spell::EffectSchoolDMG,                                //  7 SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
+    &Spell::EffectEnvirinmentalDMG,                         //  7 SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
     &Spell::EffectManaDrain,                                //  8 SPELL_EFFECT_MANA_DRAIN
     &Spell::EffectHealthLeach,                              //  9 SPELL_EFFECT_HEALTH_LEECH
     &Spell::EffectHeal,                                     // 10 SPELL_EFFECT_HEAL
@@ -257,6 +257,22 @@
     m_caster->DealDamage(unitTarget, health, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_NORMAL, NULL, false);
 }
 
+void Spell::EffectEnvirinmentalDMG(uint32 i)
+{
+    if(m_caster)
+    {
+        uint32 absorb = 0;
+        uint32 resist = 0;
+        damage += m_spellInfo->EffectBasePoints[i];
+
+        m_caster->CalcAbsorbResist(m_caster,SpellSchools(m_spellInfo->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
+
+        m_caster->SendSpellNonMeleeDamageLog(m_caster, m_spellInfo->Id, damage, SpellSchools(m_spellInfo->School), absorb, resist, false, 0, false);
+        if(m_caster->GetTypeId() == TYPEID_PLAYER)
+            ((Player*)m_caster)->EnvironmentalDamage(m_caster->GetGUID(),DAMAGE_FIRE,damage);
+    }
+}
+
 void Spell::EffectSchoolDMG(uint32 /*i*/)
 {
     if( unitTarget && unitTarget->isAlive())