From b3d44d6c366c7e4f12a6ce30ee5cf6b9bff68a06 Mon Sep 17 00:00:00 2001 From: treeston Date: Fri, 9 Sep 2016 16:21:27 +0200 Subject: Creature/Scripting: Move CreatureAI::CanRespawn to CreatureScript::CanSpawn. Now also applies to initial spawn. Dynamic spawning prep. --- src/server/game/AI/CreatureAI.h | 3 --- src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 8 -------- src/server/game/AI/ScriptedAI/ScriptedCreature.h | 1 - src/server/game/Entities/Creature/Creature.cpp | 11 ++++++++--- src/server/game/Scripting/ScriptMgr.cpp | 8 ++++++++ src/server/game/Scripting/ScriptMgr.h | 6 ++++++ 6 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index f8fa6ba532b..e93a89fb07d 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -106,9 +106,6 @@ class TC_GAME_API CreatureAI : public UnitAI // Trigger Creature "Alert" state (creature can see stealthed unit) void TriggerAlert(Unit const* who) const; - // 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(EvadeReason why = EVADE_REASON_OTHER); diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index cfbe90d53a7..241441db958 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -507,14 +507,6 @@ void BossAI::_EnterCombat() ScheduleTasks(); } -bool BossAI::CanRespawn() -{ - if (instance && instance->GetBossState(_bossId) == DONE) - return false; - - return true; -} - void BossAI::TeleportCheaters() { float x, y, z; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index 6a130d8f20f..e310c954838 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -361,7 +361,6 @@ class TC_GAME_API BossAI : public ScriptedAI void JustReachedHome() override { _JustReachedHome(); } bool CanAIAttack(Unit const* target) const override { return CheckBoundary(target); } - bool CanRespawn() override; protected: void _Reset(); diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 7a40b43f236..86dff1592c2 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -518,9 +518,9 @@ void Creature::Update(uint32 diff) 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; + // First check if there are any scripts that object to us respawning + if (!sScriptMgr->CanSpawn(GetSpawnId(), GetCreatureTemplate(), GetCreatureData(), GetMap())) + break; // Will be rechecked on next Update call ObjectGuid dbtableHighGuid(HighGuid::Unit, GetEntry(), m_spawnId); time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid); @@ -1388,6 +1388,11 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad m_deathState = ALIVE; m_respawnTime = GetMap()->GetCreatureRespawnTime(m_spawnId); + + // Is the creature script objecting to us spawning? If yes, delay by one second (then re-check in ::Update) + if (!m_respawnTime && !sScriptMgr->CanSpawn(spawnId, GetCreatureTemplate(), GetCreatureData(), map)) + m_respawnTime = time(NULL)+1; + if (m_respawnTime) // respawn on Update { m_deathState = DEAD; diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index bd3f9cf2bfe..85e7fdb212f 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1602,6 +1602,14 @@ uint32 ScriptMgr::GetDialogStatus(Player* player, Creature* creature) return tmpscript->GetDialogStatus(player, creature); } +bool ScriptMgr::CanSpawn(ObjectGuid::LowType spawnId, CreatureTemplate const* cTemplate, CreatureData const* cData, Map const* map) +{ + ASSERT(cTemplate); + + GET_SCRIPT_RET(CreatureScript, cTemplate->ScriptID, tmpscript, true); + return tmpscript->CanSpawn(spawnId, cTemplate, cData, map); +} + CreatureAI* ScriptMgr::GetCreatureAI(Creature* creature) { ASSERT(creature); diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 233e56aadb2..d0f9ad32f1c 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -66,6 +66,8 @@ struct AchievementCriteriaData; struct AuctionEntry; struct ConditionSourceInfo; struct Condition; +struct CreatureTemplate; +struct CreatureData; struct ItemTemplate; struct OutdoorPvPData; @@ -432,6 +434,9 @@ class TC_GAME_API CreatureScript : public UnitScript, public UpdatableScript