diff options
author | treeston <treeston.mmoc@gmail.com> | 2016-09-09 16:21:27 +0200 |
---|---|---|
committer | treeston <treeston.mmoc@gmail.com> | 2016-09-09 16:21:27 +0200 |
commit | b3d44d6c366c7e4f12a6ce30ee5cf6b9bff68a06 (patch) | |
tree | 5b0518a14d556de4944ebaa977a17a1ce2f5955a /src | |
parent | 9180bcd404ff0a89144bbe834a2efe189bd0eb86 (diff) |
Creature/Scripting: Move CreatureAI::CanRespawn to CreatureScript::CanSpawn. Now also applies to initial spawn. Dynamic spawning prep.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/CreatureAI.h | 3 | ||||
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 8 | ||||
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 11 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 6 |
6 files changed, 22 insertions, 15 deletions
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<Cre // Called when the dialog status between a player and the creature is requested. virtual uint32 GetDialogStatus(Player* /*player*/, Creature* /*creature*/) { return DIALOG_STATUS_SCRIPTED_NO_STATUS; } + // Called when the creature tries to spawn. Return false to block spawn and re-evaluate on next tick. + virtual bool CanSpawn(ObjectGuid::LowType /*spawnId*/, CreatureTemplate const* /*cTemplate*/, CreatureData const* /*cData*/, Map const* /*map*/) { return true; } + // Called when a CreatureAI object is needed for the creature. virtual CreatureAI* GetAI(Creature* /*creature*/) const { return NULL; } }; @@ -957,6 +962,7 @@ class TC_GAME_API ScriptMgr bool OnQuestSelect(Player* player, Creature* creature, Quest const* quest); bool OnQuestReward(Player* player, Creature* creature, Quest const* quest, uint32 opt); uint32 GetDialogStatus(Player* player, Creature* creature); + bool CanSpawn(ObjectGuid::LowType spawnId, CreatureTemplate const* cTemplate, CreatureData const* cData, Map const* map); CreatureAI* GetCreatureAI(Creature* creature); void OnCreatureUpdate(Creature* creature, uint32 diff); |