Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Diff by Funky ( 15 years ago )
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 07b1707..ea9dc50 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -161,7 +161,7 @@ m_subtype(subtype), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0),
 m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false),
 m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_needNotify(false),
 m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),
-m_creatureInfo(NULL), m_splineFlags(SPLINEFLAG_WALKMODE)
+m_creatureInfo(NULL), m_uiSpawnPassiveTimer(CREATURE_SPAWN_PASSIVE_TIME), m_splineFlags(SPLINEFLAG_WALKMODE)
 {
     m_regenTimer = 200;
     m_valuesCount = UNIT_END;
@@ -361,6 +361,12 @@ bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data /*=
 
     SetUInt32Value(UNIT_FIELD_FLAGS, unitFlags);
 
+    // if not pet or totem add passiv state
+    if (!IsPet() && !IsTotem() && !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
+        m_bShouldSpawnPassive = true;
+    else
+        m_bShouldSpawnPassive = false;
+
     // preserve all current dynamic flags if exist
     uint32 dynFlags = GetUInt32Value(UNIT_DYNAMIC_FLAGS);
     SetUInt32Value(UNIT_DYNAMIC_FLAGS, dynFlags ? dynFlags : GetCreatureInfo()->dynamicflags);
@@ -395,6 +401,22 @@ bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data /*=
     return true;
 }
 
+void Creature::SetUInt32Value( uint16 index, uint32 value )
+{
+    if (index == UNIT_FIELD_FLAGS && value == UNIT_FLAG_PASSIVE)
+        m_bShouldSpawnPassive = false;
+
+    Object::SetUInt32Value(index, value);
+}
+
+void Creature::RemoveFlag( uint16 index, uint32 oldFlag )
+{
+    if (index == UNIT_FIELD_FLAGS && oldFlag == UNIT_FLAG_PASSIVE)
+        m_bShouldSpawnPassive = false;
+
+    Object::SetUInt32Value(index, oldFlag);
+}
+
 uint32 Creature::ChooseDisplayId(const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/, GameEventCreatureData const* eventData /*=NULL*/)
 {
     // Use creature event model explicit, override any other static models
@@ -547,6 +569,18 @@ void Creature::Update(uint32 update_diff, uint32 diff)
         }
         case ALIVE:
         {
+            // remove passive state after some time
+            if (m_bShouldSpawnPassive)
+            {
+                if (m_uiSpawnPassiveTimer <= update_diff)
+                {
+                    m_bShouldSpawnPassive = false;
+                    SpawnPassiveDelayExceeded();
+                }
+                else
+                    m_uiSpawnPassiveTimer -= update_diff;
+            }
+
             if (m_isDeadByDefault)
             {
                 if (m_corpseDecayTimer <= update_diff)
@@ -1558,6 +1592,18 @@ void Creature::Respawn()
             GetMap()->GetPersistentState()->SaveCreatureRespawnTime(GetGUIDLow(), 0);
         m_respawnTime = time(NULL);                         // respawn at next tick
     }
+
+    // if not pet or totem set passive state
+    if (!IsPet() && !IsTotem() && !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
+    {
+        m_bShouldSpawnPassive = true;
+        m_uiSpawnPassiveTimer = CREATURE_SPAWN_PASSIVE_TIME;
+    }
+    else
+    {
+        m_bShouldSpawnPassive = false;
+        m_uiSpawnPassiveTimer = 0;
+    }
 }
 
 void Creature::ForcedDespawn(uint32 timeMSToDespawn)
@@ -1819,7 +1865,7 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
     if (IsCivilian())
         return false;
 
-    if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_PASSIVE))
+    if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_PASSIVE) | m_bShouldSpawnPassive)
         return false;
 
     // skip fighting creature
diff --git a/src/game/Creature.h b/src/game/Creature.h
index fe48550..c0b8a41 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -421,6 +421,8 @@ enum CreatureSubtype
 
 typedef std::list<Player*> EnemyPlayerList;
 
+#define CREATURE_SPAWN_PASSIVE_TIME 5000
+
 class MANGOS_DLL_SPEC Creature : public Unit
 {
     CreatureAI *i_AI;
@@ -688,7 +690,12 @@ class MANGOS_DLL_SPEC Creature : public Unit
 
         void SetVirtualItem(VirtualItemSlot slot, uint32 item_id);
         void SetVirtualItemRaw(VirtualItemSlot slot, uint32 display_id, uint32 info0, uint32 info1);
+
+        bool isPassiveToHostile() { return (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE) | m_bShouldSpawnPassive); }
+        void SetUInt32Value( uint16 index, uint32  value );
+        void RemoveFlag( uint16 index, uint32 oldFlag );
     protected:
+        virtual void SpawnPassiveDelayExceeded() {}
         bool CreateFromProto(uint32 guidlow,uint32 Entry, Team team, const CreatureData *data = NULL, GameEventCreatureData const* eventData =NULL);
         bool InitEntry(uint32 entry, const CreatureData* data = NULL, GameEventCreatureData const* eventData = NULL);
         void RelocationNotify();
@@ -710,6 +717,8 @@ class MANGOS_DLL_SPEC Creature : public Unit
         uint32 m_lootGroupRecipientId;                      // group who will have rights for looting if set and exist
 
         /// Timers
+        uint32 m_uiSpawnPassiveTimer;                             // (msecs)timer for remove passive flag after get spawned/respawned
+        bool m_bShouldSpawnPassive;
         uint32 m_corpseDecayTimer;                          // (msecs)timer for death or corpse disappearance
         time_t m_respawnTime;                               // (secs) time of next respawn
         uint32 m_respawnDelay;                              // (secs) delay between corpse disappearance and respawning
diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h
index 7875973..0b1503f 100644
--- a/src/game/CreatureAI.h
+++ b/src/game/CreatureAI.h
@@ -106,6 +106,9 @@ class MANGOS_DLL_SPEC CreatureAI
         // Called when the creature summon successfully other creature
         virtual void JustSummoned(Creature* ) {}
 
+        // Called when the summoned creature had the spawn/respawn delay
+        virtual void JustExceededSpawnDelay(Creature *) {}
+
         // Called when the creature summon despawn
         virtual void SummonedCreatureDespawn(Creature* /*unit*/) {}
 
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 0b553b2..a0dae4e 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1594,7 +1594,7 @@ void WorldObject::AddObjectToRemoveList()
     GetMap()->AddObjectToRemoveList(this);
 }
 
-Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime, bool asActiveObject)
+Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime, bool asActiveObject, uint32 spawnPassivetime)
 {
     TemporarySummon* pCreature = new TemporarySummon(GetObjectGuid());
 
@@ -1618,7 +1618,7 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
     // Active state set before added to map
     pCreature->SetActiveObjectState(asActiveObject);
 
-    pCreature->Summon(spwtype, despwtime);
+    pCreature->Summon(spwtype, despwtime, spawnPassivetime);
 
     if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->AI())
         ((Creature*)this)->AI()->JustSummoned(pCreature);
diff --git a/src/game/Object.h b/src/game/Object.h
index ff1169f..716151d 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -559,7 +559,7 @@ class MANGOS_DLL_SPEC WorldObject : public Object
         void RemoveFromClientUpdateList();
         void BuildUpdateData(UpdateDataMapType &);
 
-        Creature* SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime, bool asActiveObject = false);
+        Creature* SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime, bool asActiveObject = false, uint32 spawnPassiveTime = 1900);
 
         GameObject* SummonGameObject(uint32 id, float x, float y, float z, float ang, TempSummonType spwtype, uint32 despwtime = 1000 , float  rotation0 = 0, float rotation1 = 0, float rotation2 = 0, float rotation3 = 0, uint32 animprogress = 100);
 
diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp
index a93c836..7d3ad3d 100644
--- a/src/game/TemporarySummon.cpp
+++ b/src/game/TemporarySummon.cpp
@@ -149,8 +149,9 @@ void TemporarySummon::Update( uint32 update_diff,  uint32 diff )
     Creature::Update( update_diff, diff );
 }
 
-void TemporarySummon::Summon(TempSummonType type, uint32 lifetime)
+void TemporarySummon::Summon(TempSummonType type, uint32 lifetime, uint32 spawnPassiveTime)
 {
+    m_uiSpawnPassiveTimer = spawnPassiveTime;
     m_type = type;
     m_timer = lifetime;
     m_lifetime = lifetime;
@@ -174,3 +175,10 @@ void TemporarySummon::UnSummon()
 void TemporarySummon::SaveToDB()
 {
 }
+
+void TemporarySummon::SpawnPassiveDelayExceeded()
+{
+    Unit *pSummoner = GetMap()->GetUnit(m_summoner);
+    if(pSummoner && pSummoner->GetTypeId()==TYPEID_UNIT && ((Creature*)pSummoner)->AI())
+        ((Creature*)pSummoner)->AI()->JustExceededSpawnDelay(this);
+}
diff --git a/src/game/TemporarySummon.h b/src/game/TemporarySummon.h
index ede581b..2d7f73b 100644
--- a/src/game/TemporarySummon.h
+++ b/src/game/TemporarySummon.h
@@ -28,11 +28,13 @@ class TemporarySummon : public Creature
         explicit TemporarySummon(ObjectGuid summoner = ObjectGuid());
         virtual ~TemporarySummon(){};
         void Update(uint32 update_diff, uint32 time);
-        void Summon(TempSummonType type, uint32 lifetime);
+        void Summon(TempSummonType type, uint32 lifetime, uint32 spawnPassiveTime);
         void MANGOS_DLL_SPEC UnSummon();
         void SaveToDB();
         ObjectGuid const& GetSummonerGuid() const { return m_summoner ; }
         Unit* GetSummoner() const { return ObjectAccessor::GetUnit(*this, m_summoner); }
+    protected:
+        void SpawnPassiveDelayExceeded();
     private:
         TempSummonType m_type;
         uint32 m_timer;

 

Revise this Paste

Your Name: Code Language: