feat(Core/SAI): Allow forcing creatures/gameobjects's respawn timers when using SMART_ACTION_FORCE_DESPAWN (#8714)
This commit is contained in:
@@ -1301,12 +1301,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
|
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
|
||||||
{
|
|
||||||
if (Creature* creature = (*itr)->ToCreature())
|
|
||||||
{
|
|
||||||
creature->DespawnOrUnsummon(e.action.forceDespawn.delay + 1);
|
|
||||||
}
|
|
||||||
else if (GameObject* go = (*itr)->ToGameObject())
|
|
||||||
{
|
{
|
||||||
Milliseconds despawnDelay(e.action.forceDespawn.delay);
|
Milliseconds despawnDelay(e.action.forceDespawn.delay);
|
||||||
|
|
||||||
@@ -1315,7 +1309,15 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
{
|
{
|
||||||
despawnDelay = 1ms;
|
despawnDelay = 1ms;
|
||||||
}
|
}
|
||||||
go->DespawnOrUnsummon(despawnDelay);
|
|
||||||
|
Seconds forceRespawnTimer(e.action.forceDespawn.forceRespawnTimer);
|
||||||
|
if (Creature* creature = (*itr)->ToCreature())
|
||||||
|
{
|
||||||
|
creature->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
|
||||||
|
}
|
||||||
|
else if (GameObject* go = (*itr)->ToGameObject())
|
||||||
|
{
|
||||||
|
go->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -873,6 +873,7 @@ struct SmartAction
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32 delay;
|
uint32 delay;
|
||||||
|
uint32 forceRespawnTimer;
|
||||||
} forceDespawn;
|
} forceDespawn;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ CreatureBaseStats const* CreatureBaseStats::GetBaseStats(uint8 level, uint8 unit
|
|||||||
|
|
||||||
bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||||
{
|
{
|
||||||
m_owner.DespawnOrUnsummon(); // since we are here, we are not TempSummon as object type cannot change during runtime
|
m_owner.DespawnOrUnsummon(0s, m_respawnTimer); // since we are here, we are not TempSummon as object type cannot change during runtime
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1916,12 +1916,11 @@ void Creature::Respawn(bool force)
|
|||||||
UpdateObjectVisibility(false);
|
UpdateObjectVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::ForcedDespawn(uint32 timeMSToDespawn)
|
void Creature::ForcedDespawn(uint32 timeMSToDespawn, Seconds forceRespawnTimer)
|
||||||
{
|
{
|
||||||
if (timeMSToDespawn)
|
if (timeMSToDespawn)
|
||||||
{
|
{
|
||||||
ForcedDespawnDelayEvent* pEvent = new ForcedDespawnDelayEvent(*this);
|
ForcedDespawnDelayEvent* pEvent = new ForcedDespawnDelayEvent(*this, forceRespawnTimer);
|
||||||
|
|
||||||
m_Events.AddEvent(pEvent, m_Events.CalculateTime(timeMSToDespawn));
|
m_Events.AddEvent(pEvent, m_Events.CalculateTime(timeMSToDespawn));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1931,14 +1930,20 @@ void Creature::ForcedDespawn(uint32 timeMSToDespawn)
|
|||||||
|
|
||||||
// Xinef: set new respawn time, ignore corpse decay time...
|
// Xinef: set new respawn time, ignore corpse decay time...
|
||||||
RemoveCorpse(true);
|
RemoveCorpse(true);
|
||||||
|
|
||||||
|
if (forceRespawnTimer > Seconds::zero())
|
||||||
|
{
|
||||||
|
m_respawnTime = time(nullptr) + forceRespawnTimer.count();
|
||||||
|
m_respawnDelay = forceRespawnTimer.count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::DespawnOrUnsummon(uint32 msTimeToDespawn /*= 0*/)
|
void Creature::DespawnOrUnsummon(Milliseconds msTimeToDespawn /*= 0*/, Seconds forcedRespawnTimer)
|
||||||
{
|
{
|
||||||
if (TempSummon* summon = this->ToTempSummon())
|
if (TempSummon* summon = this->ToTempSummon())
|
||||||
summon->UnSummon(msTimeToDespawn);
|
summon->UnSummon(msTimeToDespawn.count());
|
||||||
else
|
else
|
||||||
ForcedDespawn(msTimeToDespawn);
|
ForcedDespawn(msTimeToDespawn.count(), forcedRespawnTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::DespawnOnEvade()
|
void Creature::DespawnOnEvade()
|
||||||
|
|||||||
@@ -267,7 +267,8 @@ public:
|
|||||||
|
|
||||||
void RemoveCorpse(bool setSpawnTime = true, bool skipVisibility = false);
|
void RemoveCorpse(bool setSpawnTime = true, bool skipVisibility = false);
|
||||||
|
|
||||||
void DespawnOrUnsummon(uint32 msTimeToDespawn = 0);
|
void DespawnOrUnsummon(Milliseconds msTimeToDespawn, Seconds forcedRespawnTimer);
|
||||||
|
void DespawnOrUnsummon(uint32 msTimeToDespawn = 0) { DespawnOrUnsummon(Milliseconds(msTimeToDespawn), 0s); };
|
||||||
void DespawnOnEvade();
|
void DespawnOnEvade();
|
||||||
void RespawnOnEvade();
|
void RespawnOnEvade();
|
||||||
|
|
||||||
@@ -438,7 +439,7 @@ protected:
|
|||||||
bool CanAlwaysSee(WorldObject const* obj) const override;
|
bool CanAlwaysSee(WorldObject const* obj) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ForcedDespawn(uint32 timeMSToDespawn = 0);
|
void ForcedDespawn(uint32 timeMSToDespawn = 0, Seconds forcedRespawnTimer = 0s);
|
||||||
|
|
||||||
[[nodiscard]] bool CanPeriodicallyCallForAssistance() const;
|
[[nodiscard]] bool CanPeriodicallyCallForAssistance() const;
|
||||||
|
|
||||||
@@ -483,11 +484,12 @@ private:
|
|||||||
class ForcedDespawnDelayEvent : public BasicEvent
|
class ForcedDespawnDelayEvent : public BasicEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ForcedDespawnDelayEvent(Creature& owner) : BasicEvent(), m_owner(owner) { }
|
ForcedDespawnDelayEvent(Creature& owner, Seconds respawnTimer) : BasicEvent(), m_owner(owner), m_respawnTimer(respawnTimer) { }
|
||||||
bool Execute(uint64 e_time, uint32 p_time) override;
|
bool Execute(uint64 e_time, uint32 p_time) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Creature& m_owner;
|
Creature& m_owner;
|
||||||
|
Seconds const m_respawnTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user