aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortreeston <treeston.mmoc@gmail.com>2016-09-09 16:21:27 +0200
committerjoschiwald <joschiwald.trinity@gmail.com>2017-02-26 15:30:15 +0100
commite941d7e04b41e9f7236db6981b7ddb1d071453ea (patch)
tree6c8f40a24a5e993646f9abc11035a7e2f50c0d65 /src
parent9c36dd7e947d483767b545b79e586c95e29e4305 (diff)
Creature/Scripting: Move CreatureAI::CanRespawn to CreatureScript::CanSpawn. Now also applies to initial spawn. Dynamic spawning prep.
(cherry picked from commit b3d44d6c366c7e4f12a6ce30ee5cf6b9bff68a06) Game/Scripting: Follow-up to b3d44d6. Fix script selection for creatures on difficulty > 0. (cherry picked from commit 91c2b3162d350ab1a09053574ad67f45f089175b) Build fix. (cherry picked from commit a9f1151f2ca56394e315d0b07741c240ef59c2ff) Fine, this time I actually built it. Promise. (cherry picked from commit 0c2c88ed5025d9b51b6cbdf0603ceaf1ea54c80a)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/CreatureAI.h3
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.cpp8
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.h1
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp11
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp9
-rw-r--r--src/server/game/Scripting/ScriptMgr.h6
6 files changed, 23 insertions, 15 deletions
diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h
index 007f6ceabc8..72c2e254c47 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 6503c703c58..f4dbb0e128a 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
@@ -496,14 +496,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 8eee577b097..7639f45ead8 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
@@ -358,7 +358,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 d19cc9602d4..958d97e785e 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -525,9 +525,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(), GetEntry(), GetCreatureTemplate(), GetCreatureData(), GetMap()))
+ break; // Will be rechecked on next Update call
ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Creature>(GetMapId(), GetEntry(), m_spawnId);
time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid);
@@ -1412,6 +1412,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, GetEntry(), 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 7c94aa3ed55..8ad749ef53a 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -1706,6 +1706,15 @@ uint32 ScriptMgr::GetDialogStatus(Player* player, Creature* creature)
return tmpscript->GetDialogStatus(player, creature);
}
+bool ScriptMgr::CanSpawn(ObjectGuid::LowType spawnId, uint32 entry, CreatureTemplate const* actTemplate, CreatureData const* cData, Map const* map)
+{
+ ASSERT(actTemplate);
+
+ CreatureTemplate const* baseTemplate = sObjectMgr->GetCreatureTemplate(entry);
+ GET_SCRIPT_RET(CreatureScript, baseTemplate->ScriptID, tmpscript, true);
+ return tmpscript->CanSpawn(spawnId, entry, baseTemplate, actTemplate, 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 76a5f663f82..72b71651bd9 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -68,6 +68,8 @@ struct AreaTriggerEntry;
struct AuctionEntry;
struct ConditionSourceInfo;
struct Condition;
+struct CreatureTemplate;
+struct CreatureData;
struct ItemTemplate;
struct MapEntry;
struct OutdoorPvPData;
@@ -436,6 +438,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*/, uint32 /*entry*/, CreatureTemplate const* /*baseTemplate*/, CreatureTemplate const* /*actTemplate*/, CreatureData const* /*cData*/, Map const* /*map*/) const { return true; }
+
// Called when a CreatureAI object is needed for the creature.
virtual CreatureAI* GetAI(Creature* /*creature*/) const { return NULL; }
};
@@ -1016,6 +1021,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, uint32 entry, CreatureTemplate const* actTemplate, CreatureData const* cData, Map const* map);
CreatureAI* GetCreatureAI(Creature* creature);
void OnCreatureUpdate(Creature* creature, uint32 diff);