Creature/Scripting: Move CreatureAI::CanRespawn to CreatureScript::CanSpawn. Now also applies to initial spawn. Dynamic spawning prep.

This commit is contained in:
treeston
2016-09-09 16:21:27 +02:00
parent 9180bcd404
commit b3d44d6c36
6 changed files with 22 additions and 15 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);