From 0841615951bb7b970a293003a82bdeed30c0aea8 Mon Sep 17 00:00:00 2001 From: Ovahlord <18347559+Ovahlord@users.noreply.github.com> Date: Wed, 20 Aug 2025 19:47:15 +0200 Subject: [PATCH] Core/Creatures: moved summon duration handling to SummonInfo API and implement SummonPropertiesFlags::DespawnWhenExpired --- src/server/game/Entities/Creature/Creature.cpp | 3 +++ .../Entities/Creature/SummonInfo/SummonInfo.cpp | 15 +++++++++++++++ .../Entities/Creature/SummonInfo/SummonInfo.h | 3 +++ .../game/Entities/Creature/TemporarySummon.cpp | 12 ++---------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index e6fc5c3d97..dd5261cb54 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -809,6 +809,9 @@ void Creature::Update(uint32 diff) { Unit::Update(diff); + if (SummonInfo* summonInfo = GetSummonInfo()) + summonInfo->UpdateRemainingDuration(Milliseconds(diff)); + // creature can be dead after Unit::Update call // CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly) if (!IsAlive()) diff --git a/src/server/game/Entities/Creature/SummonInfo/SummonInfo.cpp b/src/server/game/Entities/Creature/SummonInfo/SummonInfo.cpp index dc96903fad..d3305f0f33 100644 --- a/src/server/game/Entities/Creature/SummonInfo/SummonInfo.cpp +++ b/src/server/game/Entities/Creature/SummonInfo/SummonInfo.cpp @@ -103,6 +103,21 @@ Optional SummonInfo::GetCreatureLevel() const return _creatureLevel; } +void SummonInfo::UpdateRemainingDuration(Milliseconds deltaTime) +{ + if (!_remainingDuration.has_value() || _remainingDuration <= 0ms) + return; + + *_remainingDuration -= deltaTime; + if (_remainingDuration <= 0ms) + { + if (DespawnsWhenExpired()) + GetSummonedCreature()->DespawnOrUnsummon(); + else + GetSummonedCreature()->KillSelf(); + } +} + bool SummonInfo::DespawnsOnSummonerLogout() const { return _flags.HasFlag(SummonPropertiesFlags::DespawnOnSummonerLogout); diff --git a/src/server/game/Entities/Creature/SummonInfo/SummonInfo.h b/src/server/game/Entities/Creature/SummonInfo/SummonInfo.h index 5987847af1..bb3fe1e19b 100644 --- a/src/server/game/Entities/Creature/SummonInfo/SummonInfo.h +++ b/src/server/game/Entities/Creature/SummonInfo/SummonInfo.h @@ -59,6 +59,9 @@ public: // Returns the level of the creature that will override the default level calculation. Nullopt when the creature uses its default values. Optional GetCreatureLevel() const; + // Updates the remaining duration of a summon and triggers the expiration + void UpdateRemainingDuration(Milliseconds deltaTime); + // Returns true when the summon will despawn when the summoner logs out. This also includes despawning and teleporting between map instances. bool DespawnsOnSummonerLogout() const; // Marks the summon to despawn when the summoner logs out. This also includes despawning and teleporting between map instaces. diff --git a/src/server/game/Entities/Creature/TemporarySummon.cpp b/src/server/game/Entities/Creature/TemporarySummon.cpp index acd262f2a6..e1f4563490 100644 --- a/src/server/game/Entities/Creature/TemporarySummon.cpp +++ b/src/server/game/Entities/Creature/TemporarySummon.cpp @@ -24,6 +24,7 @@ #include "ObjectAccessor.h" #include "Pet.h" #include "Player.h" +#include "SummonInfo.h" TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN), @@ -58,18 +59,8 @@ void TempSummon::Update(uint32 diff) { case TEMPSUMMON_MANUAL_DESPAWN: case TEMPSUMMON_DEAD_DESPAWN: - break; case TEMPSUMMON_TIMED_DESPAWN: - { - if (m_timer <= diff) - { - UnSummon(); - return; - } - - m_timer -= diff; break; - } case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT: { if (!IsInCombat()) @@ -216,6 +207,7 @@ void TempSummon::UpdateObjectVisibilityOnCreate() void TempSummon::SetTempSummonType(TempSummonType type) { m_type = type; + GetSummonInfo()->SetDespawnWhenExpired(true); // To maintain legacy behavior in which all summons just despawn when expired } void TempSummon::UnSummon(uint32 msTime)