refactor(Core/Misc): Make DeathState enum class (#17607)

This commit is contained in:
Kitzunu
2023-10-28 10:54:03 +02:00
committed by GitHub
parent 79b39f9655
commit f757e93da5
47 changed files with 112 additions and 112 deletions
+24 -24
View File
@@ -316,7 +316,7 @@ void Creature::DisappearAndDie()
//SetVisibility(VISIBILITY_OFF);
//ObjectAccessor::UpdateObjectVisibility(this);
if (IsAlive())
setDeathState(JUST_DIED, true);
setDeathState(DeathState::JustDied, true);
RemoveCorpse(false, true);
}
@@ -342,11 +342,11 @@ void Creature::SearchFormation()
void Creature::RemoveCorpse(bool setSpawnTime, bool skipVisibility)
{
if (getDeathState() != CORPSE)
if (getDeathState() != DeathState::Corpse)
return;
m_corpseRemoveTime = GameTime::GetGameTime().count();
setDeathState(DEAD);
setDeathState(DeathState::Dead);
RemoveAllAuras();
if (!skipVisibility) // pussywizard
DestroyForNearbyPlayers(); // pussywizard: previous UpdateObjectVisibility()
@@ -604,15 +604,15 @@ void Creature::Update(uint32 diff)
switch (m_deathState)
{
case JUST_RESPAWNED:
case DeathState::JustRespawned:
// Must not be called, see Creature::setDeathState JUST_RESPAWNED -> ALIVE promoting.
LOG_ERROR("entities.unit", "Creature ({}) in wrong state: JUST_RESPAWNED (4)", GetGUID().ToString());
LOG_ERROR("entities.unit", "Creature ({}) in wrong state: DeathState::JustRespawned (4)", GetGUID().ToString());
break;
case JUST_DIED:
case DeathState::JustDied:
// Must not be called, see Creature::setDeathState JUST_DIED -> CORPSE promoting.
LOG_ERROR("entities.unit", "Creature ({}) in wrong state: JUST_DEAD (1)", GetGUID().ToString());
LOG_ERROR("entities.unit", "Creature ({}) in wrong state: DeathState::JustDead (1)", GetGUID().ToString());
break;
case DEAD:
case DeathState::Dead:
{
time_t now = GameTime::GetGameTime().count();
if (m_respawnTime <= now)
@@ -654,11 +654,11 @@ void Creature::Update(uint32 diff)
}
break;
}
case CORPSE:
case DeathState::Corpse:
{
Unit::Update(diff);
// deathstate changed on spells update, prevent problems
if (m_deathState != CORPSE)
if (m_deathState != DeathState::Corpse)
break;
if (m_groupLootTimer && lootingGroupLowGUID)
@@ -683,7 +683,7 @@ void Creature::Update(uint32 diff)
}
break;
}
case ALIVE:
case DeathState::Alive:
{
Unit::Update(diff);
@@ -1720,12 +1720,12 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
m_wanderDistance = data->wander_distance;
m_respawnDelay = data->spawntimesecs;
m_deathState = ALIVE;
m_deathState = DeathState::Alive;
m_respawnTime = GetMap()->GetCreatureRespawnTime(m_spawnId);
if (m_respawnTime) // respawn on Update
{
m_deathState = DEAD;
m_deathState = DeathState::Dead;
if (CanFly())
{
float tz = map->GetHeight(GetPhaseMask(), data->posX, data->posY, data->posZ, true, MAX_FALL_DISTANCE);
@@ -1755,7 +1755,7 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
}
SetHealth(m_deathState == ALIVE ? curhealth : 0);
SetHealth(m_deathState == DeathState::Alive ? curhealth : 0);
// checked at creature_template loading
m_defaultMovementType = MovementGeneratorType(data->movementType);
@@ -1950,7 +1950,7 @@ void Creature::setDeathState(DeathState s, bool despawn)
{
Unit::setDeathState(s, despawn);
if (s == JUST_DIED)
if (s == DeathState::JustDied)
{
_lastDamagedTime.reset();
@@ -1984,9 +1984,9 @@ void Creature::setDeathState(DeathState s, bool despawn)
if (needsFalling)
GetMotionMaster()->MoveFall(0, true);
Unit::setDeathState(CORPSE, despawn);
Unit::setDeathState(DeathState::Corpse, despawn);
}
else if (s == JUST_RESPAWNED)
else if (s == DeathState::JustRespawned)
{
//if (IsPet())
// setActive(true);
@@ -2008,7 +2008,7 @@ void Creature::setDeathState(DeathState s, bool despawn)
ClearUnitState(uint32(UNIT_STATE_ALL_STATE & ~(UNIT_STATE_IGNORE_PATHFINDING | UNIT_STATE_NO_ENVIRONMENT_UPD)));
SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));
Unit::setDeathState(ALIVE, despawn);
Unit::setDeathState(DeathState::Alive, despawn);
Motion_Initialize();
LoadCreaturesAddon(true);
@@ -2024,14 +2024,14 @@ void Creature::Respawn(bool force)
if (force)
{
if (IsAlive())
setDeathState(JUST_DIED);
else if (getDeathState() != CORPSE)
setDeathState(CORPSE);
setDeathState(DeathState::JustDied);
else if (getDeathState() != DeathState::Corpse)
setDeathState(DeathState::Corpse);
}
RemoveCorpse(false, false);
if (getDeathState() == DEAD)
if (getDeathState() == DeathState::Dead)
{
if (m_spawnId)
{
@@ -2059,7 +2059,7 @@ void Creature::Respawn(bool force)
loot.clear();
SelectLevel();
setDeathState(JUST_RESPAWNED);
setDeathState(DeathState::JustRespawned);
// MDic - Acidmanifesto
// Do not override transform auras
@@ -2106,7 +2106,7 @@ void Creature::ForcedDespawn(uint32 timeMSToDespawn, Seconds forceRespawnTimer)
}
if (IsAlive())
setDeathState(JUST_DIED, true);
setDeathState(DeathState::JustDied, true);
// Xinef: set new respawn time, ignore corpse decay time...
RemoveCorpse(true);
@@ -67,7 +67,7 @@ void TempSummon::Update(uint32 diff)
{
Creature::Update(diff);
if (m_deathState == DEAD)
if (m_deathState == DeathState::Dead)
{
UnSummon();
return;
@@ -107,7 +107,7 @@ void TempSummon::Update(uint32 diff)
}
case TEMPSUMMON_TIMED_DESPAWN_OOC_ALIVE:
{
if (!IsInCombat() && m_deathState != CORPSE)
if (!IsInCombat() && m_deathState != DeathState::Corpse)
{
if (m_timer <= diff)
{
@@ -124,7 +124,7 @@ void TempSummon::Update(uint32 diff)
}
case TEMPSUMMON_CORPSE_TIMED_DESPAWN:
{
if (m_deathState == CORPSE)
if (m_deathState == DeathState::Corpse)
{
if (m_timer <= diff)
{
@@ -139,7 +139,7 @@ void TempSummon::Update(uint32 diff)
case TEMPSUMMON_CORPSE_DESPAWN:
{
// if m_deathState is DEAD, CORPSE was skipped
if (m_deathState == CORPSE)
if (m_deathState == DeathState::Corpse)
{
UnSummon();
return;
@@ -154,7 +154,7 @@ void TempSummon::Update(uint32 diff)
case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN:
{
// if m_deathState is DEAD, CORPSE was skipped
if (m_deathState == CORPSE)
if (m_deathState == DeathState::Corpse)
{
UnSummon();
return;
@@ -395,7 +395,7 @@ bool Minion::IsGuardianPet() const
void Minion::setDeathState(DeathState s, bool despawn)
{
Creature::setDeathState(s, despawn);
if (s == JUST_DIED && IsGuardianPet())
if (s == DeathState::JustDied && IsGuardianPet())
if (Unit* owner = GetOwner())
if (owner->GetTypeId() == TYPEID_PLAYER && owner->GetMinionGUID() == GetGUID())
for (Unit::ControlSet::const_iterator itr = owner->m_Controlled.begin(); itr != owner->m_Controlled.end(); ++itr)
+5 -5
View File
@@ -472,7 +472,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool c
else
{
if (!curHealth && getPetType() == HUNTER_PET)
setDeathState(JUST_DIED);
setDeathState(DeathState::JustDied);
else
{
SetHealth(curHealth > GetMaxHealth() ? GetMaxHealth() : curHealth);
@@ -616,7 +616,7 @@ void Pet::DeleteFromDB(ObjectGuid::LowType guidlow)
void Pet::setDeathState(DeathState s, bool /*despawn = false*/) // overwrite virtual Creature::setDeathState and Unit::setDeathState
{
Creature::setDeathState(s);
if (getDeathState() == CORPSE)
if (getDeathState() == DeathState::Corpse)
{
if (getPetType() == HUNTER_PET)
{
@@ -632,7 +632,7 @@ void Pet::setDeathState(DeathState s, bool /*despawn = false*/)
//SetUnitFlag(UNIT_FLAG_STUNNED);
}
}
else if (getDeathState() == ALIVE)
else if (getDeathState() == DeathState::Alive)
{
//RemoveUnitFlag(UNIT_FLAG_STUNNED);
CastPetAuras(true);
@@ -651,7 +651,7 @@ void Pet::Update(uint32 diff)
switch (m_deathState)
{
case CORPSE:
case DeathState::Corpse:
{
if (getPetType() != HUNTER_PET || m_corpseRemoveTime <= GameTime::GetGameTime().count())
{
@@ -660,7 +660,7 @@ void Pet::Update(uint32 diff)
}
break;
}
case ALIVE:
case DeathState::Alive:
{
// unsummon pet that lost owner
Player* owner = GetOwner();
+6 -6
View File
@@ -1010,7 +1010,7 @@ void Player::setDeathState(DeathState s, bool /*despawn = false*/)
bool cur = IsAlive();
if (s == JUST_DIED)
if (s == DeathState::JustDied)
{
if (!cur)
{
@@ -1025,7 +1025,7 @@ void Player::setDeathState(DeathState s, bool /*despawn = false*/)
clearResurrectRequestData();
//FIXME: is pet dismissed at dying or releasing spirit? if second, add setDeathState(DEAD) to HandleRepopRequestOpcode and define pet unsummon here with (s == DEAD)
//FIXME: is pet dismissed at dying or releasing spirit? if second, add setDeathState(DeathState::Dead) to HandleRepopRequestOpcode and define pet unsummon here with (s == DEAD)
RemovePet(nullptr, PET_SAVE_NOT_IN_SLOT, true);
// save value before aura remove in Unit::setDeathState
@@ -1045,7 +1045,7 @@ void Player::setDeathState(DeathState s, bool /*despawn = false*/)
ResetAchievementCriteria(ACHIEVEMENT_CRITERIA_CONDITION_NO_DEATH, 0);
}
// xinef: enable passive area auras!
else if (s == ALIVE)
else if (s == DeathState::Alive)
ClearUnitState(UNIT_STATE_ISOLATED);
Unit::setDeathState(s);
@@ -1054,7 +1054,7 @@ void Player::setDeathState(DeathState s, bool /*despawn = false*/)
ArenaSpectator::SendCommand_UInt32Value(FindMap(), GetGUID(), "STA", IsAlive() ? 1 : 0);
// restore resurrection spell id for player after aura remove
if (s == JUST_DIED && cur && ressSpellId)
if (s == DeathState::JustDied && cur && ressSpellId)
SetUInt32Value(PLAYER_SELF_RES_SPELL, ressSpellId);
if (IsAlive() && !cur)
@@ -4396,7 +4396,7 @@ void Player::ResurrectPlayer(float restore_percent, bool applySickness)
if (GetSession()->IsARecruiter() || (GetSession()->GetRecruiterId() != 0))
SetDynamicFlag(UNIT_DYNFLAG_REFER_A_FRIEND);
setDeathState(ALIVE);
setDeathState(DeathState::Alive);
SetMovement(MOVE_LAND_WALK);
SetMovement(MOVE_UNROOT);
SetWaterWalking(false);
@@ -4463,7 +4463,7 @@ void Player::KillPlayer()
StopMirrorTimers(); //disable timers(bars)
setDeathState(CORPSE);
setDeathState(DeathState::Corpse);
//SetUnitFlag(UNIT_FLAG_NOT_IN_PVP);
ReplaceAllDynamicFlags(UNIT_DYNFLAG_NONE);
@@ -5454,7 +5454,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
// add ghost flag (must be after aura load: PLAYER_FLAGS_GHOST set in aura)
if (HasPlayerFlag(PLAYER_FLAGS_GHOST))
{
m_deathState = DEAD;
m_deathState = DeathState::Dead;
AddUnitState(UNIT_STATE_ISOLATED);
}
@@ -311,7 +311,7 @@ void Player::Update(uint32 p_time)
RegenerateAll();
}
if (m_deathState == JUST_DIED)
if (m_deathState == DeathState::JustDied)
KillPlayer();
if (m_nextSave)
+12 -12
View File
@@ -247,7 +247,7 @@ Unit::Unit(bool isWorldObject) : WorldObject(isWorldObject),
m_rootTimes = 0;
m_state = 0;
m_deathState = ALIVE;
m_deathState = DeathState::Alive;
for (uint8 i = 0; i < CURRENT_MAX_SPELL; ++i)
m_currentSpells[i] = nullptr;
@@ -4535,7 +4535,7 @@ void Unit::_UnapplyAura(AuraApplicationMap::iterator& i, AuraRemoveMode removeMo
if (aurApp->GetRemoveMode() == AURA_REMOVE_BY_EXPIRE && IsTotem() && GetGUID() == aura->GetCasterGUID())
{
if (ToTotem()->GetSpell() == aura->GetId() && ToTotem()->GetTotemType() == TOTEM_PASSIVE)
ToTotem()->setDeathState(JUST_DIED);
ToTotem()->setDeathState(DeathState::JustDied);
}
// Remove aurastates only if were not found
@@ -14497,7 +14497,7 @@ void Unit::setDeathState(DeathState s, bool despawn)
// death state needs to be updated before RemoveAllAurasOnDeath() calls HandleChannelDeathItem(..) so that
// it can be used to check creation of death items (such as soul shards).
if (s != ALIVE && s != JUST_RESPAWNED)
if (s != DeathState::Alive && s != DeathState::JustRespawned)
{
CombatStop();
GetThreatMgr().ClearAllThreat();
@@ -14512,7 +14512,7 @@ void Unit::setDeathState(DeathState s, bool despawn)
RemoveAllAurasOnDeath();
}
if (s == JUST_DIED)
if (s == DeathState::JustDied)
{
// remove aurastates allowing special moves
ClearAllReactives();
@@ -14541,7 +14541,7 @@ void Unit::setDeathState(DeathState s, bool despawn)
if (ZoneScript* zoneScript = GetZoneScript() ? GetZoneScript() : (ZoneScript*)GetInstanceScript())
zoneScript->OnUnitDeath(this);
}
else if (s == JUST_RESPAWNED)
else if (s == DeathState::JustRespawned)
{
RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground)
}
@@ -15420,9 +15420,9 @@ void Unit::SetLevel(uint8 lvl, bool showLevelChange)
void Unit::SetHealth(uint32 val)
{
if (getDeathState() == JUST_DIED)
if (getDeathState() == DeathState::JustDied)
val = 0;
else if (GetTypeId() == TYPEID_PLAYER && getDeathState() == DEAD)
else if (GetTypeId() == TYPEID_PLAYER && getDeathState() == DeathState::Dead)
val = 1;
else
{
@@ -18086,12 +18086,12 @@ void Unit::Kill(Unit* killer, Unit* victim, bool durabilityLoss, WeaponAttackTyp
if (!spiritOfRedemption)
{
LOG_DEBUG("entities.unit", "SET JUST_DIED");
victim->setDeathState(JUST_DIED);
LOG_DEBUG("entities.unit", "SET DeathState::JustDied");
victim->setDeathState(DeathState::JustDied);
}
// Inform pets (if any) when player kills target)
// MUST come after victim->setDeathState(JUST_DIED); or pet next target
// MUST come after victim->setDeathState(DeathState::JustDied); or pet next target
// selection will get stuck on same target and break pet react state
if (player)
{
@@ -20105,8 +20105,8 @@ void Unit::_ExitVehicle(Position const* exitPosition)
if (HasUnitTypeMask(UNIT_MASK_ACCESSORY))
{
// Vehicle just died, we die too
if (vehicleBase->getDeathState() == JUST_DIED)
setDeathState(JUST_DIED);
if (vehicleBase->getDeathState() == DeathState::JustDied)
setDeathState(DeathState::JustDied);
// If for other reason we as minion are exiting the vehicle (ejected, master dismounted) - unsummon
else
{
+9 -9
View File
@@ -311,13 +311,13 @@ enum BaseModType
#define MOD_END (PCT_MOD+1)
enum DeathState
enum class DeathState : uint8
{
ALIVE = 0,
JUST_DIED = 1,
CORPSE = 2,
DEAD = 3,
JUST_RESPAWNED = 4,
Alive = 0,
JustDied = 1,
Corpse = 2,
Dead = 3,
JustRespawned = 4,
};
enum UnitState
@@ -1817,9 +1817,9 @@ public:
void BuildHeartBeatMsg(WorldPacket* data) const;
[[nodiscard]] bool IsAlive() const { return (m_deathState == ALIVE); };
[[nodiscard]] bool isDying() const { return (m_deathState == JUST_DIED); };
[[nodiscard]] bool isDead() const { return (m_deathState == DEAD || m_deathState == CORPSE); };
[[nodiscard]] bool IsAlive() const { return (m_deathState == DeathState::Alive); };
[[nodiscard]] bool isDying() const { return (m_deathState == DeathState::JustDied); };
[[nodiscard]] bool isDead() const { return (m_deathState == DeathState::Dead || m_deathState == DeathState::Corpse); };
DeathState getDeathState() { return m_deathState; };
virtual void setDeathState(DeathState s, bool despawn = false); // overwrited in Creature/Player/Pet