Core/Creatures: moved summon duration handling to SummonInfo API and implement SummonPropertiesFlags::DespawnWhenExpired
This commit is contained in:
1 parent
860f6b1bd3
commit
0841615951
4 files changed
+23
-10
No files matched your search
@@ -809,6 +809,9 @@ void Creature::Update(uint32 diff)
|
|||||||
{
|
{
|
||||||
Unit::Update(diff);
|
Unit::Update(diff);
|
||||||
|
|
||||||
|
if (SummonInfo* summonInfo = GetSummonInfo())
|
||||||
|
summonInfo->UpdateRemainingDuration(Milliseconds(diff));
|
||||||
|
|
||||||
// creature can be dead after Unit::Update call
|
// 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)
|
// CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly)
|
||||||
if (!IsAlive())
|
if (!IsAlive())
|
||||||
|
|||||||
@@ -103,6 +103,21 @@ Optional<uint8> SummonInfo::GetCreatureLevel() const
|
|||||||
return _creatureLevel;
|
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
|
bool SummonInfo::DespawnsOnSummonerLogout() const
|
||||||
{
|
{
|
||||||
return _flags.HasFlag(SummonPropertiesFlags::DespawnOnSummonerLogout);
|
return _flags.HasFlag(SummonPropertiesFlags::DespawnOnSummonerLogout);
|
||||||
|
|||||||
@@ -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.
|
// Returns the level of the creature that will override the default level calculation. Nullopt when the creature uses its default values.
|
||||||
Optional<uint8> GetCreatureLevel() const;
|
Optional<uint8> 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.
|
// Returns true when the summon will despawn when the summoner logs out. This also includes despawning and teleporting between map instances.
|
||||||
bool DespawnsOnSummonerLogout() const;
|
bool DespawnsOnSummonerLogout() const;
|
||||||
// Marks the summon to despawn when the summoner logs out. This also includes despawning and teleporting between map instaces.
|
// Marks the summon to despawn when the summoner logs out. This also includes despawning and teleporting between map instaces.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "ObjectAccessor.h"
|
#include "ObjectAccessor.h"
|
||||||
#include "Pet.h"
|
#include "Pet.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
|
#include "SummonInfo.h"
|
||||||
|
|
||||||
TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
|
TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
|
||||||
Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN),
|
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_MANUAL_DESPAWN:
|
||||||
case TEMPSUMMON_DEAD_DESPAWN:
|
case TEMPSUMMON_DEAD_DESPAWN:
|
||||||
break;
|
|
||||||
case TEMPSUMMON_TIMED_DESPAWN:
|
case TEMPSUMMON_TIMED_DESPAWN:
|
||||||
{
|
|
||||||
if (m_timer <= diff)
|
|
||||||
{
|
|
||||||
UnSummon();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_timer -= diff;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT:
|
case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT:
|
||||||
{
|
{
|
||||||
if (!IsInCombat())
|
if (!IsInCombat())
|
||||||
@@ -216,6 +207,7 @@ void TempSummon::UpdateObjectVisibilityOnCreate()
|
|||||||
void TempSummon::SetTempSummonType(TempSummonType type)
|
void TempSummon::SetTempSummonType(TempSummonType type)
|
||||||
{
|
{
|
||||||
m_type = type;
|
m_type = type;
|
||||||
|
GetSummonInfo()->SetDespawnWhenExpired(true); // To maintain legacy behavior in which all summons just despawn when expired
|
||||||
}
|
}
|
||||||
|
|
||||||
void TempSummon::UnSummon(uint32 msTime)
|
void TempSummon::UnSummon(uint32 msTime)
|
||||||
|
|||||||
Reference in new issue
Block a user