mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 10:05:32 +01:00
Creature/Scripting: Move CreatureAI::CanRespawn to CreatureScript::CanSpawn. Now also applies to initial spawn. Dynamic spawning prep.
This commit is contained in:
@@ -106,9 +106,6 @@ class TC_GAME_API CreatureAI : public UnitAI
|
|||||||
// Trigger Creature "Alert" state (creature can see stealthed unit)
|
// Trigger Creature "Alert" state (creature can see stealthed unit)
|
||||||
void TriggerAlert(Unit const* who) const;
|
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
|
// Called for reaction at stopping attack at no attackers or targets
|
||||||
virtual void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
|
virtual void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
|
||||||
|
|
||||||
|
|||||||
@@ -507,14 +507,6 @@ void BossAI::_EnterCombat()
|
|||||||
ScheduleTasks();
|
ScheduleTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BossAI::CanRespawn()
|
|
||||||
{
|
|
||||||
if (instance && instance->GetBossState(_bossId) == DONE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BossAI::TeleportCheaters()
|
void BossAI::TeleportCheaters()
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|||||||
@@ -361,7 +361,6 @@ class TC_GAME_API BossAI : public ScriptedAI
|
|||||||
void JustReachedHome() override { _JustReachedHome(); }
|
void JustReachedHome() override { _JustReachedHome(); }
|
||||||
|
|
||||||
bool CanAIAttack(Unit const* target) const override { return CheckBoundary(target); }
|
bool CanAIAttack(Unit const* target) const override { return CheckBoundary(target); }
|
||||||
bool CanRespawn() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _Reset();
|
void _Reset();
|
||||||
|
|||||||
@@ -518,9 +518,9 @@ void Creature::Update(uint32 diff)
|
|||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
if (m_respawnTime <= now)
|
if (m_respawnTime <= now)
|
||||||
{
|
{
|
||||||
bool allowed = IsAIEnabled ? AI()->CanRespawn() : true; // First check if there are any scripts that object to us respawning
|
// First check if there are any scripts that object to us respawning
|
||||||
if (!allowed) // Will be rechecked on next Update call
|
if (!sScriptMgr->CanSpawn(GetSpawnId(), GetCreatureTemplate(), GetCreatureData(), GetMap()))
|
||||||
break;
|
break; // Will be rechecked on next Update call
|
||||||
|
|
||||||
ObjectGuid dbtableHighGuid(HighGuid::Unit, GetEntry(), m_spawnId);
|
ObjectGuid dbtableHighGuid(HighGuid::Unit, GetEntry(), m_spawnId);
|
||||||
time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid);
|
time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid);
|
||||||
@@ -1388,6 +1388,11 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
|
|||||||
m_deathState = ALIVE;
|
m_deathState = ALIVE;
|
||||||
|
|
||||||
m_respawnTime = GetMap()->GetCreatureRespawnTime(m_spawnId);
|
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
|
if (m_respawnTime) // respawn on Update
|
||||||
{
|
{
|
||||||
m_deathState = DEAD;
|
m_deathState = DEAD;
|
||||||
|
|||||||
@@ -1602,6 +1602,14 @@ uint32 ScriptMgr::GetDialogStatus(Player* player, Creature* creature)
|
|||||||
return tmpscript->GetDialogStatus(player, 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)
|
CreatureAI* ScriptMgr::GetCreatureAI(Creature* creature)
|
||||||
{
|
{
|
||||||
ASSERT(creature);
|
ASSERT(creature);
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ struct AchievementCriteriaData;
|
|||||||
struct AuctionEntry;
|
struct AuctionEntry;
|
||||||
struct ConditionSourceInfo;
|
struct ConditionSourceInfo;
|
||||||
struct Condition;
|
struct Condition;
|
||||||
|
struct CreatureTemplate;
|
||||||
|
struct CreatureData;
|
||||||
struct ItemTemplate;
|
struct ItemTemplate;
|
||||||
struct OutdoorPvPData;
|
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.
|
// 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; }
|
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.
|
// Called when a CreatureAI object is needed for the creature.
|
||||||
virtual CreatureAI* GetAI(Creature* /*creature*/) const { return NULL; }
|
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 OnQuestSelect(Player* player, Creature* creature, Quest const* quest);
|
||||||
bool OnQuestReward(Player* player, Creature* creature, Quest const* quest, uint32 opt);
|
bool OnQuestReward(Player* player, Creature* creature, Quest const* quest, uint32 opt);
|
||||||
uint32 GetDialogStatus(Player* player, Creature* creature);
|
uint32 GetDialogStatus(Player* player, Creature* creature);
|
||||||
|
bool CanSpawn(ObjectGuid::LowType spawnId, CreatureTemplate const* cTemplate, CreatureData const* cData, Map const* map);
|
||||||
CreatureAI* GetCreatureAI(Creature* creature);
|
CreatureAI* GetCreatureAI(Creature* creature);
|
||||||
void OnCreatureUpdate(Creature* creature, uint32 diff);
|
void OnCreatureUpdate(Creature* creature, uint32 diff);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user