Core/CreatureAI: Add virtual bool CanRespawn().
This method will be checked on Creature::Update with deathstate ¨DEAD¨, and allows inherited scripts to manipulate respawn behaviour based on scripted events. --HG-- branch : trunk
This commit is contained in:
@@ -88,6 +88,9 @@ class CreatureAI : public UnitAI
|
|||||||
// Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
|
// Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
|
||||||
void MoveInLineOfSight_Safe(Unit *who);
|
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
|
// Called for reaction at stopping attack at no attackers or targets
|
||||||
virtual void EnterEvadeMode();
|
virtual void EnterEvadeMode();
|
||||||
|
|
||||||
|
|||||||
@@ -457,18 +457,23 @@ void Creature::Update(uint32 diff)
|
|||||||
break;
|
break;
|
||||||
case DEAD:
|
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
|
if (!GetLinkedCreatureRespawnTime()) // Can respawn
|
||||||
Respawn();
|
Respawn();
|
||||||
else // the master is dead
|
else // the master is dead
|
||||||
{
|
{
|
||||||
if (uint32 targetGuid = sObjectMgr->GetLinkedRespawnGuid(m_DBTableGuid))
|
if (uint32 targetGuid = sObjectMgr->GetLinkedRespawnGuid(m_DBTableGuid))
|
||||||
{
|
{
|
||||||
if (targetGuid == m_DBTableGuid) // if linking self, never respawn (check delayed to next day)
|
if (targetGuid == m_DBTableGuid) // if linking self, never respawn (check delayed to next day)
|
||||||
SetRespawnTime(DAY);
|
SetRespawnTime(DAY);
|
||||||
else
|
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
|
SaveRespawnTime(); // also save to DB immediately
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user