refactor(Core): DespawnOrUnsummon (#23141)

This commit is contained in:
天鹭
2025-10-13 14:36:23 +08:00
committed by GitHub
parent 8e2e30328f
commit 53238a68d3
148 changed files with 363 additions and 366 deletions
+2 -2
View File
@@ -50,9 +50,9 @@ AISpellInfoType* GetAISpellInfo(uint32 i) { return &CreatureAI::AISpellInfo[i];
* @param WorldObject target The target of the speech, in case it has elements such as $n, where the target's name will be referrenced.
* @param Milliseconds delay Delay until the creature says the text line. Creatures will talk immediately by default.
*/
void CreatureAI::Talk(uint8 id, WorldObject const* target /*= nullptr*/, Milliseconds delay /*= 0s*/)
void CreatureAI::Talk(uint8 id, WorldObject const* target /*= nullptr*/, Milliseconds delay /*= 0ms*/)
{
if (delay > Seconds::zero())
if (delay > 0ms)
{
ObjectGuid targetGuid;
+1 -1
View File
@@ -94,7 +94,7 @@ public:
EVADE_REASON_OTHER
};
void Talk(uint8 id, WorldObject const* whisperTarget = nullptr, Milliseconds delay = 0s);
void Talk(uint8 id, WorldObject const* whisperTarget = nullptr, Milliseconds delay = 0ms);
void Talk(uint8 id, Milliseconds delay) { Talk(id, nullptr, delay); }
WorldObject* GetSummoner() const;
@@ -68,7 +68,7 @@ void SummonList::DespawnEntry(uint32 entry)
}
}
void SummonList::DespawnAll(uint32 delay /*= 0*/)
void SummonList::DespawnAll(Milliseconds delay /*= 0ms*/)
{
while (!storage_.empty())
{
@@ -325,13 +325,13 @@ void ScriptedAI::ScheduleTimedEvent(Milliseconds timerMin, Milliseconds timerMax
return;
}
scheduler.Schedule(timerMin == 0s ? timerMax : timerMin, timerMax, [exec, repeatMin, repeatMax, uniqueId](TaskContext context)
scheduler.Schedule(timerMin == 0ms ? timerMax : timerMin, timerMax, [exec, repeatMin, repeatMax, uniqueId](TaskContext context)
{
exec();
if (!uniqueId)
{
repeatMax > 0s ? context.Repeat(repeatMin, repeatMax) : context.Repeat(repeatMin);
repeatMax > 0ms ? context.Repeat(repeatMin, repeatMax) : context.Repeat(repeatMin);
}
});
@@ -654,7 +654,7 @@ void BossAI::_JustEngagedWith()
ScheduleTasks();
if (callForHelpRange)
{
ScheduleTimedEvent(0s, [&]
ScheduleTimedEvent(0ms, [&]
{
me->CallForHelp(callForHelpRange);
}, 2s);
@@ -88,7 +88,7 @@ public:
void Summon(Creature const* summon) { storage_.push_back(summon->GetGUID()); }
void Despawn(Creature const* summon) { storage_.remove(summon->GetGUID()); }
void DespawnEntry(uint32 entry);
void DespawnAll(uint32 delay = 0);
void DespawnAll(Milliseconds delay = 0ms);
bool IsAnyCreatureAlive() const;
bool IsAnyCreatureWithEntryAlive(uint32 entry) const;
bool IsAnyCreatureInCombat() const;
@@ -355,11 +355,11 @@ struct ScriptedAI : public CreatureAI
void ClearUniqueTimedEventsDone() { _uniqueTimedEvents.clear(); }
// Schedules a timed event using task scheduler.
void ScheduleTimedEvent(Milliseconds timerMin, Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0s, uint32 uniqueId = 0);
void ScheduleTimedEvent(Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0s, uint32 uniqueId = 0) { ScheduleTimedEvent(0s, timerMax, exec, repeatMin, repeatMax, uniqueId); };
void ScheduleTimedEvent(Milliseconds timerMin, Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0ms, uint32 uniqueId = 0);
void ScheduleTimedEvent(Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0ms, uint32 uniqueId = 0) { ScheduleTimedEvent(0ms, timerMax, exec, repeatMin, repeatMax, uniqueId); };
// Schedules a timed event using task scheduler that never repeats. Requires an unique non-zero ID.
void ScheduleUniqueTimedEvent(Milliseconds timer, std::function<void()> exec, uint32 uniqueId) { ScheduleTimedEvent(0s, timer, exec, 0s, 0s, uniqueId); };
void ScheduleUniqueTimedEvent(Milliseconds timer, std::function<void()> exec, uint32 uniqueId) { ScheduleTimedEvent(0ms, timer, exec, 0ms, 0ms, uniqueId); };
bool HealthBelowPct(uint32 pct) const { return me->HealthBelowPct(pct); }
bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); }
@@ -463,7 +463,7 @@ enum HealthCheckStatus
struct HealthCheckEventData
{
HealthCheckEventData(uint8 healthPct, std::function<void()> exec, uint8 status = HEALTH_CHECK_SCHEDULED, bool allowedWhileCasting = true, Milliseconds Delay = 0s) : _healthPct(healthPct), _exec(exec), _status(status), _allowedWhileCasting(allowedWhileCasting), _delay(Delay) { };
HealthCheckEventData(uint8 healthPct, std::function<void()> exec, uint8 status = HEALTH_CHECK_SCHEDULED, bool allowedWhileCasting = true, Milliseconds Delay = 0ms) : _healthPct(healthPct), _exec(exec), _status(status), _allowedWhileCasting(allowedWhileCasting), _delay(Delay) { };
uint8 _healthPct;
std::function<void()> _exec;
+1 -1
View File
@@ -410,7 +410,7 @@ void SmartAI::UpdatePath(const uint32 diff)
// Xinef: allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
GetScript()->ProcessEventsFor(SMART_EVENT_DEATH, me);
me->DespawnOrUnsummon(1);
me->DespawnOrUnsummon(1ms);
return;
}
mEscortInvokerCheckTimer = 1000;
@@ -415,7 +415,7 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
{
for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
creature->DespawnOrUnsummon(1);
creature->DespawnOrUnsummon(1ms);
m_vehicles[team].clear();
}
@@ -251,7 +251,7 @@ CreatureBaseStats const* CreatureBaseStats::GetBaseStats(uint8 level, uint8 unit
bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
m_owner.DespawnOrUnsummon(0s, m_respawnTimer); // since we are here, we are not TempSummon as object type cannot change during runtime
m_owner.DespawnOrUnsummon(0ms, m_respawnTimer); // since we are here, we are not TempSummon as object type cannot change during runtime
return true;
}
@@ -2174,12 +2174,12 @@ void Creature::ForcedDespawn(uint32 timeMSToDespawn, Seconds forceRespawnTimer)
// Xinef: Set new respawn time, ignore corpse decay time...
RemoveCorpse(true);
if (forceRespawnTimer > Seconds::zero())
if (forceRespawnTimer > 0s)
if (GetMap())
GetMap()->ScheduleCreatureRespawn(GetGUID(), forceRespawnTimer);
}
void Creature::DespawnOrUnsummon(Milliseconds msTimeToDespawn /*= 0*/, Seconds forcedRespawnTimer)
void Creature::DespawnOrUnsummon(Milliseconds msTimeToDespawn /*= 0ms*/, Seconds forcedRespawnTimer /*= 0s*/)
{
if (TempSummon* summon = this->ToTempSummon())
summon->UnSummon(msTimeToDespawn.count());
@@ -2204,7 +2204,7 @@ void Creature::DespawnOnEvade(Seconds respawnDelay)
return;
}
DespawnOrUnsummon(Milliseconds(0), respawnDelay);
DespawnOrUnsummon(0ms, respawnDelay);
}
void Creature::InitializeReactState()
+1 -2
View File
@@ -283,8 +283,7 @@ public:
void RemoveCorpse(bool setSpawnTime = true, bool skipVisibility = false);
void DespawnOrUnsummon(Milliseconds msTimeToDespawn, Seconds forcedRespawnTimer);
void DespawnOrUnsummon(uint32 msTimeToDespawn = 0) { DespawnOrUnsummon(Milliseconds(msTimeToDespawn), 0s); };
void DespawnOrUnsummon(Milliseconds msTimeToDespawn = 0ms, Seconds forcedRespawnTimer = 0s);
void DespawnOnEvade(Seconds respawnDelay = 20s);
[[nodiscard]] time_t const& GetRespawnTime() const { return m_respawnTime; }
@@ -929,7 +929,7 @@ void GameObject::AddUniqueUse(Player* player)
m_unique_users.insert(player->GetGUID());
}
void GameObject::DespawnOrUnsummon(Milliseconds delay, Seconds forceRespawnTime)
void GameObject::DespawnOrUnsummon(Milliseconds delay /*= 0ms*/, Seconds forceRespawnTime /*= 0s*/)
{
if (delay > 0ms)
{
+3 -3
View File
@@ -692,7 +692,7 @@ void Pet::Update(uint32 diff)
}
}
if (m_duration > 0s)
if (m_duration > 0ms)
{
if (m_duration > _diff)
m_duration -= _diff;
@@ -708,7 +708,7 @@ void Pet::Update(uint32 diff)
if (getPowerType() == POWER_FOCUS)
{
m_petRegenTimer -= _diff;
if (m_petRegenTimer <= 0s)
if (m_petRegenTimer <= 0ms)
{
m_petRegenTimer += PET_FOCUS_REGEN_INTERVAL;
Regenerate(POWER_FOCUS);
@@ -1026,7 +1026,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
Unit* owner = GetOwner();
if (!owner) // just to be sure, asynchronous now
{
DespawnOrUnsummon(1000);
DespawnOrUnsummon(1s);
return false;
}
+1 -1
View File
@@ -52,7 +52,7 @@ public:
PetType getPetType() const { return m_petType; }
void setPetType(PetType type) { m_petType = type; }
bool isControlled() const { return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET; }
bool isTemporarySummoned() const { return m_duration > 0s; }
bool isTemporarySummoned() const { return m_duration > 0ms; }
bool IsPermanentPetFor(Player* owner) const; // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
+3 -3
View File
@@ -9014,7 +9014,7 @@ Pet* Player::GetPet() const
return nullptr;
}
Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, Milliseconds duration /*= 0s*/, uint32 healthPct /*= 0*/)
Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, Milliseconds duration /*= 0ms*/, uint32 healthPct /*= 0*/)
{
PetStable& petStable = GetOrInitPetStable();
@@ -9035,7 +9035,7 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy
++itr;
}
if (duration > 0s)
if (duration > 0ms)
pet->SetDuration(duration);
// Generate a new name for the newly summoned ghoul
@@ -9129,7 +9129,7 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy
}
}
if (duration > 0s)
if (duration > 0ms)
pet->SetDuration(duration);
if (NeedSendSpectatorData() && pet->GetCreatureTemplate()->family)
+1 -1
View File
@@ -1210,7 +1210,7 @@ public:
[[nodiscard]] PetStable const* GetPetStable() const { return m_petStable.get(); }
[[nodiscard]] Pet* GetPet() const;
Pet* SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, Milliseconds duration = 0s, uint32 healthPct = 0);
Pet* SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, Milliseconds duration = 0ms, uint32 healthPct = 0);
void RemovePet(Pet* pet, PetSaveMode mode, bool returnreagent = false);
bool CanPetResurrect();
bool IsExistPet();
+1 -1
View File
@@ -19681,7 +19681,7 @@ void Unit::_ExitVehicle(Position const* exitPosition)
else if (vehicleBase->IsCreature())
{
vehicle->Uninstall();
vehicleBase->m_Events.AddEvent(new VehicleDespawnEvent(*vehicleBase, 2000), vehicleBase->m_Events.CalculateTime(2000));
vehicleBase->m_Events.AddEventAtOffset(new VehicleDespawnEvent(*vehicleBase, 2s), 2s);
}
// xinef: ugly hack, no appripriate hook later to cast spell
+2 -2
View File
@@ -100,12 +100,12 @@ private:
class VehicleDespawnEvent : public BasicEvent
{
public:
VehicleDespawnEvent(Unit& self, uint32 duration) : _self(self), _duration(duration) { }
VehicleDespawnEvent(Unit& self, Milliseconds duration) : _self(self), _duration(duration) { }
bool Execute(uint64 e_time, uint32 p_time) override;
protected:
Unit& _self;
uint32 _duration;
Milliseconds _duration;
};
#endif
+1 -1
View File
@@ -757,7 +757,7 @@ void Map::ScriptsProcess()
case SCRIPT_COMMAND_DESPAWN_SELF:
// Target or source must be Creature.
if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script, true))
cSource->DespawnOrUnsummon(step.script->DespawnSelf.DespawnDelay);
cSource->DespawnOrUnsummon(Milliseconds(step.script->DespawnSelf.DespawnDelay));
break;
case SCRIPT_COMMAND_LOAD_PATH:
+1 -1
View File
@@ -5213,7 +5213,7 @@ void Spell::EffectResurrectPet(SpellEffIndex /*effIndex*/)
{
// Position passed to SummonPet is irrelevant with current implementation,
// pet will be relocated without using these coords in Pet::LoadPetFromDB
player->SummonPet(0, 0.0f, 0.0f, 0.0f, 0.0f, SUMMON_PET, 0s, damage);
player->SummonPet(0, 0.0f, 0.0f, 0.0f, 0.0f, SUMMON_PET, 0ms, damage);
return;
}
+1 -1
View File
@@ -162,7 +162,7 @@ void WorldUpdateTime::SetRecordUpdateTimeInterval(Milliseconds t)
void WorldUpdateTime::RecordUpdateTime(Milliseconds gameTimeMs, uint32 diff, uint32 sessionCount)
{
if (_recordUpdateTimeInverval > 0s && diff > _recordUpdateTimeMin.count())
if (_recordUpdateTimeInverval > 0ms && diff > _recordUpdateTimeMin.count())
{
if (GetMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval)
{