mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Entities/GO: Add forceRespawnTimer support to DespawnOrUnsummon. Use it in SAI.
(cherry picked from commit 264d4e1d30)
This commit is contained in:
@@ -518,7 +518,6 @@ void SmartAI::InitializeAI()
|
||||
GetScript()->OnInitialize(me);
|
||||
|
||||
mDespawnTime = 0;
|
||||
mRespawnTime = 0;
|
||||
mDespawnState = 0;
|
||||
_escortState = SMART_ESCORT_NONE;
|
||||
|
||||
@@ -962,7 +961,7 @@ void SmartAI::UpdateDespawn(uint32 diff)
|
||||
mDespawnState++;
|
||||
}
|
||||
else
|
||||
me->DespawnOrUnsummon(0, Seconds(mRespawnTime));
|
||||
me->DespawnOrUnsummon();
|
||||
}
|
||||
else
|
||||
mDespawnTime -= diff;
|
||||
|
||||
@@ -178,13 +178,11 @@ class TC_GAME_API SmartAI : public CreatureAI
|
||||
void QuestReward(Player* player, Quest const* quest, LootItemType type, uint32 opt) override;
|
||||
void OnGameEvent(bool start, uint16 eventId) override;
|
||||
|
||||
void SetDespawnTime (uint32 t, uint32 r = 0)
|
||||
void SetDespawnTime (uint32 t)
|
||||
{
|
||||
mDespawnTime = t;
|
||||
mRespawnTime = r;
|
||||
mDespawnState = t ? 1 : 0;
|
||||
}
|
||||
|
||||
void StartDespawn() { mDespawnState = 2; }
|
||||
|
||||
void OnSpellClick(Unit* clicker, bool& result) override;
|
||||
@@ -233,7 +231,6 @@ class TC_GAME_API SmartAI : public CreatureAI
|
||||
uint32 mInvincibilityHpLevel;
|
||||
|
||||
uint32 mDespawnTime;
|
||||
uint32 mRespawnTime;
|
||||
uint32 mDespawnState;
|
||||
|
||||
// Vehicle conditions
|
||||
|
||||
@@ -1043,22 +1043,18 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
case SMART_ACTION_FORCE_DESPAWN:
|
||||
{
|
||||
// there should be at least a world update tick before despawn, to avoid breaking linked actions
|
||||
int32 const respawnDelay = std::max<int32>(e.action.forceDespawn.delay, 1);
|
||||
Milliseconds despawnDelay(e.action.forceDespawn.delay);
|
||||
if (despawnDelay <= 0ms)
|
||||
despawnDelay = 1ms;
|
||||
|
||||
Seconds forceRespawnTimer(e.action.forceDespawn.forceRespawnTimer);
|
||||
|
||||
for (WorldObject* target : targets)
|
||||
{
|
||||
if (Creature* creature = target->ToCreature())
|
||||
{
|
||||
if (SmartAI* smartAI = CAST_AI(SmartAI, creature->AI()))
|
||||
{
|
||||
smartAI->SetDespawnTime(respawnDelay);
|
||||
smartAI->StartDespawn();
|
||||
}
|
||||
else
|
||||
creature->DespawnOrUnsummon(respawnDelay);
|
||||
}
|
||||
creature->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
|
||||
else if (GameObject* goTarget = target->ToGameObject())
|
||||
goTarget->DespawnOrUnsummon(Milliseconds(respawnDelay));
|
||||
goTarget->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -810,7 +810,7 @@ struct SmartAction
|
||||
struct
|
||||
{
|
||||
uint32 delay;
|
||||
uint32 respawn;
|
||||
uint32 forceRespawnTimer;
|
||||
} forceDespawn;
|
||||
|
||||
struct
|
||||
|
||||
@@ -524,7 +524,7 @@ void GameObject::Update(uint32 diff)
|
||||
if (m_despawnDelay > diff)
|
||||
m_despawnDelay -= diff;
|
||||
else
|
||||
DespawnOrUnsummon();
|
||||
DespawnOrUnsummon(0ms, m_despawnRespawnTime);
|
||||
}
|
||||
|
||||
switch (m_lootState)
|
||||
@@ -954,17 +954,21 @@ void GameObject::AddUniqueUse(Player* player)
|
||||
m_unique_users.insert(player->GetGUID());
|
||||
}
|
||||
|
||||
void GameObject::DespawnOrUnsummon(Milliseconds const& delay)
|
||||
void GameObject::DespawnOrUnsummon(Milliseconds const& delay, Seconds const& forceRespawnTime)
|
||||
{
|
||||
if (delay > Milliseconds::zero())
|
||||
if (delay > 0ms)
|
||||
{
|
||||
if (!m_despawnDelay || m_despawnDelay > delay.count())
|
||||
{
|
||||
m_despawnDelay = delay.count();
|
||||
m_despawnRespawnTime = forceRespawnTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_goData && m_respawnDelayTime)
|
||||
SaveRespawnTime(m_respawnDelayTime);
|
||||
uint32 const respawnDelay = (forceRespawnTime > 0s) ? forceRespawnTime.count() : m_respawnDelayTime;
|
||||
if (m_goData && respawnDelay)
|
||||
SaveRespawnTime(respawnDelay);
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
|
||||
void SetSpawnedByDefault(bool b) { m_spawnedByDefault = b; }
|
||||
uint32 GetRespawnDelay() const { return m_respawnDelayTime; }
|
||||
void Refresh();
|
||||
void DespawnOrUnsummon(Milliseconds const& delay = 0ms);
|
||||
void DespawnOrUnsummon(Milliseconds const& delay = 0ms, Seconds const& forceRespawnTime = 0s);
|
||||
void Delete();
|
||||
void SendGameObjectDespawn();
|
||||
void getFishLoot(Loot* loot, Player* loot_owner);
|
||||
@@ -318,6 +318,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
|
||||
time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
|
||||
uint32 m_respawnDelayTime; // (secs) if 0 then current GO state no dependent from timer
|
||||
uint32 m_despawnDelay;
|
||||
Seconds m_despawnRespawnTime; // override respawn time after delayed despawn
|
||||
LootState m_lootState;
|
||||
ObjectGuid m_lootStateUnitGUID; // GUID of the unit passed with SetLootState(LootState, Unit*)
|
||||
bool m_spawnedByDefault;
|
||||
|
||||
Reference in New Issue
Block a user