Skip to content

Commit 0841615

Browse files
committed
Core/Creatures: moved summon duration handling to SummonInfo API and implement SummonPropertiesFlags::DespawnWhenExpired
1 parent 860f6b1 commit 0841615

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

src/server/game/Entities/Creature/Creature.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,9 @@ void Creature::Update(uint32 diff)
809809
{
810810
Unit::Update(diff);
811811

812+
if (SummonInfo* summonInfo = GetSummonInfo())
813+
summonInfo->UpdateRemainingDuration(Milliseconds(diff));
814+
812815
// creature can be dead after Unit::Update call
813816
// CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly)
814817
if (!IsAlive())

src/server/game/Entities/Creature/SummonInfo/SummonInfo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ Optional<uint8> SummonInfo::GetCreatureLevel() const
103103
return _creatureLevel;
104104
}
105105

106+
void SummonInfo::UpdateRemainingDuration(Milliseconds deltaTime)
107+
{
108+
if (!_remainingDuration.has_value() || _remainingDuration <= 0ms)
109+
return;
110+
111+
*_remainingDuration -= deltaTime;
112+
if (_remainingDuration <= 0ms)
113+
{
114+
if (DespawnsWhenExpired())
115+
GetSummonedCreature()->DespawnOrUnsummon();
116+
else
117+
GetSummonedCreature()->KillSelf();
118+
}
119+
}
120+
106121
bool SummonInfo::DespawnsOnSummonerLogout() const
107122
{
108123
return _flags.HasFlag(SummonPropertiesFlags::DespawnOnSummonerLogout);

src/server/game/Entities/Creature/SummonInfo/SummonInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class TC_GAME_API SummonInfo
5959
// Returns the level of the creature that will override the default level calculation. Nullopt when the creature uses its default values.
6060
Optional<uint8> GetCreatureLevel() const;
6161

62+
// Updates the remaining duration of a summon and triggers the expiration
63+
void UpdateRemainingDuration(Milliseconds deltaTime);
64+
6265
// Returns true when the summon will despawn when the summoner logs out. This also includes despawning and teleporting between map instances.
6366
bool DespawnsOnSummonerLogout() const;
6467
// Marks the summon to despawn when the summoner logs out. This also includes despawning and teleporting between map instaces.

src/server/game/Entities/Creature/TemporarySummon.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ObjectAccessor.h"
2525
#include "Pet.h"
2626
#include "Player.h"
27+
#include "SummonInfo.h"
2728

2829
TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
2930
Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN),
@@ -58,18 +59,8 @@ void TempSummon::Update(uint32 diff)
5859
{
5960
case TEMPSUMMON_MANUAL_DESPAWN:
6061
case TEMPSUMMON_DEAD_DESPAWN:
61-
break;
6262
case TEMPSUMMON_TIMED_DESPAWN:
63-
{
64-
if (m_timer <= diff)
65-
{
66-
UnSummon();
67-
return;
68-
}
69-
70-
m_timer -= diff;
7163
break;
72-
}
7364
case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT:
7465
{
7566
if (!IsInCombat())
@@ -216,6 +207,7 @@ void TempSummon::UpdateObjectVisibilityOnCreate()
216207
void TempSummon::SetTempSummonType(TempSummonType type)
217208
{
218209
m_type = type;
210+
GetSummonInfo()->SetDespawnWhenExpired(true); // To maintain legacy behavior in which all summons just despawn when expired
219211
}
220212

221213
void TempSummon::UnSummon(uint32 msTime)

0 commit comments

Comments
 (0)