From f690338de16d47dac4c1a5c464f0b6f13875b7a6 Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Fri, 24 Dec 2010 16:18:23 +0100 Subject: [PATCH] =?UTF-8?q?Core/CreatureAI:=20Add=20virtual=20bool=20CanRe?= =?UTF-8?q?spawn().=20This=20method=20will=20be=20checked=20on=20Creature:?= =?UTF-8?q?:Update=20with=20deathstate=20=C2=A8DEAD=C2=A8,=20and=20allows?= =?UTF-8?q?=20inherited=20scripts=20to=20manipulate=20respawn=20behaviour?= =?UTF-8?q?=20based=20on=20scripted=20events.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : trunk --- src/server/game/AI/CreatureAI.h | 3 +++ src/server/game/Entities/Creature/Creature.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 98e0e44819..9d2b986da6 100755 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -88,6 +88,9 @@ class CreatureAI : public UnitAI // Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter void MoveInLineOfSight_Safe(Unit *who); + // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events. + virtual bool CanRespawn() { return true; } + // Called for reaction at stopping attack at no attackers or targets virtual void EnterEvadeMode(); diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index f2347e0882..82498d6874 100755 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -457,18 +457,23 @@ void Creature::Update(uint32 diff) break; case DEAD: { - if (m_respawnTime <= time(NULL)) + time_t now = time(NULL); + if (m_respawnTime <= now) { + bool allowed = IsAIEnabled ? AI()->CanRespawn() : true; // First check if there are any scripts that object to us respawning + if (!allowed) // Will be rechecked on next Update call + break; + if (!GetLinkedCreatureRespawnTime()) // Can respawn Respawn(); - else // the master is dead + else // the master is dead { if (uint32 targetGuid = sObjectMgr->GetLinkedRespawnGuid(m_DBTableGuid)) { if (targetGuid == m_DBTableGuid) // if linking self, never respawn (check delayed to next day) SetRespawnTime(DAY); else - m_respawnTime = (time(NULL)>GetLinkedCreatureRespawnTime()? time(NULL):GetLinkedCreatureRespawnTime())+urand(5,MINUTE); // else copy time from master and add a little + m_respawnTime = (now > GetLinkedCreatureRespawnTime() ? now : GetLinkedCreatureRespawnTime())+urand(5,MINUTE); // else copy time from master and add a little SaveRespawnTime(); // also save to DB immediately } else