mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-29 08:33:47 +00:00
feat(Core/Players): PlayerFlag helpers (#11294)
* feat(Core/Players): PlayerFlag helpers * Update Player.h * fix build
This commit is contained in:
@@ -894,7 +894,7 @@ void Player::HandleDrowning(uint32 time_diff)
|
||||
uint32 damage = GetMaxHealth() / 5 + urand(0, getLevel() - 1);
|
||||
EnvironmentalDamage(DAMAGE_EXHAUSTED, damage);
|
||||
}
|
||||
else if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) // Teleport ghost to graveyard
|
||||
else if (HasPlayerFlag(PLAYER_FLAGS_GHOST)) // Teleport ghost to graveyard
|
||||
RepopAtGraveyard();
|
||||
}
|
||||
else if (!(m_MirrorTimerFlagsLast & UNDERWATER_INDARKWATER))
|
||||
@@ -1066,14 +1066,14 @@ void Player::SetRestState(uint32 triggerId)
|
||||
{
|
||||
_innTriggerId = triggerId;
|
||||
_restTime = GameTime::GetGameTime().count();
|
||||
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
|
||||
SetPlayerFlag(PLAYER_FLAGS_RESTING);
|
||||
}
|
||||
|
||||
void Player::RemoveRestState()
|
||||
{
|
||||
_innTriggerId = 0;
|
||||
_restTime = 0;
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_RESTING);
|
||||
}
|
||||
|
||||
bool Player::BuildEnumData(PreparedQueryResult result, WorldPacket* data)
|
||||
@@ -2172,7 +2172,7 @@ void Player::SetGameMaster(bool on)
|
||||
m_ExtraFlags |= PLAYER_EXTRA_GM_ON;
|
||||
if (AccountMgr::IsGMAccount(GetSession()->GetSecurity()))
|
||||
SetFaction(FACTION_FRIENDLY);
|
||||
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GM);
|
||||
SetPlayerFlag(PLAYER_FLAGS_GM);
|
||||
SetUnitFlag2(UNIT_FLAG2_ALLOW_CHEAT_SPELLS);
|
||||
|
||||
if (Pet* pet = GetPet())
|
||||
@@ -2203,7 +2203,7 @@ void Player::SetGameMaster(bool on)
|
||||
|
||||
m_ExtraFlags &= ~ PLAYER_EXTRA_GM_ON;
|
||||
SetFactionForRace(getRace(true));
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GM);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_GM);
|
||||
RemoveUnitFlag2(UNIT_FLAG2_ALLOW_CHEAT_SPELLS);
|
||||
|
||||
if (Pet* pet = GetPet())
|
||||
@@ -2337,7 +2337,7 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate, bool isLFGReward)
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
|
||||
if (HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -2654,7 +2654,7 @@ void Player::InitStatsForLevel(bool reapplyMods)
|
||||
SetUnitFlag2(UNIT_FLAG2_REGENERATE_POWER);// must be set
|
||||
|
||||
// cleanup player flags (will be re-applied if need at aura load), to avoid have ghost flag without ghost aura, for example.
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK | PLAYER_FLAGS_DND | PLAYER_FLAGS_GM | PLAYER_FLAGS_GHOST | PLAYER_ALLOW_ONLY_ABILITY);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_AFK | PLAYER_FLAGS_DND | PLAYER_FLAGS_GM | PLAYER_FLAGS_GHOST | PLAYER_ALLOW_ONLY_ABILITY);
|
||||
|
||||
RemoveStandFlags(UNIT_STAND_FLAGS_ALL); // one form stealth modified bytes
|
||||
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP | UNIT_BYTE2_FLAG_SANCTUARY);
|
||||
@@ -4497,9 +4497,9 @@ Corpse* Player::CreateCorpse()
|
||||
corpse->SetUInt32Value(CORPSE_FIELD_BYTES_2, _cfb2);
|
||||
|
||||
uint32 flags = CORPSE_FLAG_UNK2;
|
||||
if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_HELM))
|
||||
if (HasPlayerFlag(PLAYER_FLAGS_HIDE_HELM))
|
||||
flags |= CORPSE_FLAG_HIDE_HELM;
|
||||
if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_CLOAK))
|
||||
if (HasPlayerFlag(PLAYER_FLAGS_HIDE_CLOAK))
|
||||
flags |= CORPSE_FLAG_HIDE_CLOAK;
|
||||
|
||||
// Xinef: Player can loop corpses while in BG or in WG
|
||||
@@ -4842,7 +4842,7 @@ void Player::RepopAtGraveyard()
|
||||
else if (GetPositionZ() < GetMap()->GetMinHeight(GetPositionX(), GetPositionY()))
|
||||
TeleportTo(m_homebindMapId, m_homebindX, m_homebindY, m_homebindZ, GetOrientation());
|
||||
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_IS_OUT_OF_BOUNDS);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_IS_OUT_OF_BOUNDS);
|
||||
}
|
||||
|
||||
bool Player::CanJoinConstantChannelInZone(ChatChannelsEntry const* channel, AreaTableEntry const* zone)
|
||||
@@ -14301,7 +14301,7 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 0));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 2));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 3));
|
||||
stmt->SetData(index++, GetUInt32Value(PLAYER_FLAGS));
|
||||
stmt->SetData(index++, (uint32)GetPlayerFlags());
|
||||
stmt->SetData(index++, (uint16)GetMapId());
|
||||
stmt->SetData(index++, (uint32)GetInstanceId());
|
||||
stmt->SetData(index++, (uint8(GetDungeonDifficulty()) | uint8(GetRaidDifficulty()) << 4));
|
||||
@@ -14332,7 +14332,7 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(index++, m_Played_time[PLAYED_TIME_LEVEL]);
|
||||
stmt->SetData(index++, finiteAlways(_restBonus));
|
||||
stmt->SetData(index++, uint32(GameTime::GetGameTime().count()));
|
||||
stmt->SetData(index++, (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ? 1 : 0));
|
||||
stmt->SetData(index++, (HasPlayerFlag(PLAYER_FLAGS_RESTING) ? 1 : 0));
|
||||
//save, far from tavern/city
|
||||
//save, but in tavern/city
|
||||
stmt->SetData(index++, m_resetTalentsCost);
|
||||
@@ -14418,7 +14418,7 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 0));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 2));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 3));
|
||||
stmt->SetData(index++, GetUInt32Value(PLAYER_FLAGS));
|
||||
stmt->SetData(index++, GetPlayerFlags());
|
||||
|
||||
if (!IsBeingTeleported())
|
||||
{
|
||||
@@ -14471,7 +14471,7 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(index++, m_Played_time[PLAYED_TIME_LEVEL]);
|
||||
stmt->SetData(index++, finiteAlways(_restBonus));
|
||||
stmt->SetData(index++, uint32(GameTime::GetGameTime().count()));
|
||||
stmt->SetData(index++, (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ? 1 : 0));
|
||||
stmt->SetData(index++, (HasPlayerFlag(PLAYER_FLAGS_RESTING) ? 1 : 0));
|
||||
//save, far from tavern/city
|
||||
//save, but in tavern/city
|
||||
stmt->SetData(index++, m_resetTalentsCost);
|
||||
@@ -15733,7 +15733,7 @@ void Player::SetRestFlag(RestFlag restFlag, uint32 triggerId /*= 0*/)
|
||||
if (!oldRestMask && _restFlagMask) // only set flag/time on the first rest state
|
||||
{
|
||||
_restTime = GameTime::GetGameTime().count();
|
||||
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
|
||||
SetPlayerFlag(PLAYER_FLAGS_RESTING);
|
||||
}
|
||||
|
||||
if (triggerId)
|
||||
@@ -15748,7 +15748,7 @@ void Player::RemoveRestFlag(RestFlag restFlag)
|
||||
if (oldRestMask && !_restFlagMask) // only remove flag/time on the last rest state remove
|
||||
{
|
||||
_restTime = 0;
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_RESTING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "CinematicMgr.h"
|
||||
#include "DBCStores.h"
|
||||
#include "DatabaseEnvFwd.h"
|
||||
#include "EnumFlag.h"
|
||||
#include "GroupReference.h"
|
||||
#include "InstanceSaveMgr.h"
|
||||
#include "Item.h"
|
||||
@@ -464,7 +465,7 @@ enum DrunkenState
|
||||
|
||||
#define MAX_DRUNKEN 4
|
||||
|
||||
enum PlayerFlags
|
||||
enum PlayerFlags : uint32
|
||||
{
|
||||
PLAYER_FLAGS_GROUP_LEADER = 0x00000001,
|
||||
PLAYER_FLAGS_AFK = 0x00000002,
|
||||
@@ -500,6 +501,8 @@ enum PlayerFlags
|
||||
PLAYER_FLAGS_UNK31 = 0x80000000,
|
||||
};
|
||||
|
||||
DEFINE_ENUM_FLAG(PlayerFlags);
|
||||
|
||||
enum PlayerBytesOffsets //@todo: Implement
|
||||
{
|
||||
PLAYER_BYTES_OFFSET_SKIN_ID = 0,
|
||||
@@ -1078,6 +1081,12 @@ public:
|
||||
|
||||
void Update(uint32 time) override;
|
||||
|
||||
PlayerFlags GetPlayerFlags() const { return PlayerFlags(GetUInt32Value(PLAYER_FLAGS)); }
|
||||
bool HasPlayerFlag(PlayerFlags flags) const { return HasFlag(PLAYER_FLAGS, flags) != 0; }
|
||||
void SetPlayerFlag(PlayerFlags flags) { SetFlag(PLAYER_FLAGS, flags); }
|
||||
void RemovePlayerFlag(PlayerFlags flags) { RemoveFlag(PLAYER_FLAGS, flags); }
|
||||
void ReplaceAllPlayerFlags(PlayerFlags flags) { SetUInt32Value(PLAYER_FLAGS, flags); }
|
||||
|
||||
static bool BuildEnumData(PreparedQueryResult result, WorldPacket* data);
|
||||
|
||||
void SetInWater(bool apply);
|
||||
@@ -1097,8 +1106,8 @@ public:
|
||||
|
||||
void ToggleAFK();
|
||||
void ToggleDND();
|
||||
[[nodiscard]] bool isAFK() const { return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK); }
|
||||
[[nodiscard]] bool isDND() const { return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DND); }
|
||||
[[nodiscard]] bool isAFK() const { return HasPlayerFlag(PLAYER_FLAGS_AFK); }
|
||||
[[nodiscard]] bool isDND() const { return HasPlayerFlag(PLAYER_FLAGS_DND); }
|
||||
[[nodiscard]] uint8 GetChatTag() const;
|
||||
std::string autoReplyMsg;
|
||||
|
||||
@@ -1114,7 +1123,7 @@ public:
|
||||
void ContinueTaxiFlight();
|
||||
// mount_id can be used in scripting calls
|
||||
|
||||
[[nodiscard]] bool IsDeveloper() const { return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER); }
|
||||
[[nodiscard]] bool IsDeveloper() const { return HasPlayerFlag(PLAYER_FLAGS_DEVELOPER); }
|
||||
void SetDeveloper(bool on) { ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER, on); }
|
||||
[[nodiscard]] bool isAcceptWhispers() const { return m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS; }
|
||||
void SetAcceptWhispers(bool on) { if (on) m_ExtraFlags |= PLAYER_EXTRA_ACCEPT_WHISPERS; else m_ExtraFlags &= ~PLAYER_EXTRA_ACCEPT_WHISPERS; }
|
||||
@@ -1802,7 +1811,7 @@ public:
|
||||
void ResetContestedPvP()
|
||||
{
|
||||
ClearUnitState(UNIT_STATE_ATTACK_PLAYER);
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_CONTESTED_PVP);
|
||||
m_contestedPvPTimer = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -353,8 +353,8 @@ void Player::UpdatePvPFlag(time_t currTime)
|
||||
|
||||
if (currTime < (pvpInfo.EndTimer + 300 + 5))
|
||||
{
|
||||
if (currTime > (pvpInfo.EndTimer + 4) && !HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER))
|
||||
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
|
||||
if (currTime > (pvpInfo.EndTimer + 4) && !HasPlayerFlag(PLAYER_FLAGS_PVP_TIMER))
|
||||
SetPlayerFlag(PLAYER_FLAGS_PVP_TIMER);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5053,7 +5053,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
SetByteValue(PLAYER_BYTES_2, 3, fields[15].Get<uint8>());
|
||||
SetByteValue(PLAYER_BYTES_3, 0, fields[5].Get<uint8>());
|
||||
SetByteValue(PLAYER_BYTES_3, 1, fields[54].Get<uint8>());
|
||||
SetUInt32Value(PLAYER_FLAGS, fields[16].Get<uint32>());
|
||||
ReplaceAllPlayerFlags((PlayerFlags)fields[16].Get<uint32>());
|
||||
SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fields[53].Get<uint32>());
|
||||
|
||||
SetUInt64Value(PLAYER_FIELD_KNOWN_CURRENCIES, fields[52].Get<uint64>());
|
||||
@@ -5460,7 +5460,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
_LoadGlyphAuras();
|
||||
_LoadAuras(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_AURAS), time_diff);
|
||||
// add ghost flag (must be after aura load: PLAYER_FLAGS_GHOST set in aura)
|
||||
if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
|
||||
if (HasPlayerFlag(PLAYER_FLAGS_GHOST))
|
||||
{
|
||||
m_deathState = DEAD;
|
||||
AddUnitState(UNIT_STATE_ISOLATED);
|
||||
@@ -6514,7 +6514,7 @@ void Player::_LoadGroup()
|
||||
{
|
||||
if (group->IsLeader(GetGUID()))
|
||||
{
|
||||
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GROUP_LEADER);
|
||||
SetPlayerFlag(PLAYER_FLAGS_GROUP_LEADER);
|
||||
}
|
||||
|
||||
uint8 subgroup = group->GetMemberGroup(GetGUID());
|
||||
@@ -6528,7 +6528,7 @@ void Player::_LoadGroup()
|
||||
}
|
||||
|
||||
if (!GetGroup() || !GetGroup()->IsLeader(GetGUID()))
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GROUP_LEADER);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_GROUP_LEADER);
|
||||
}
|
||||
|
||||
void Player::BindToInstance()
|
||||
|
||||
@@ -232,7 +232,7 @@ void Player::Update(uint32 p_time)
|
||||
}
|
||||
}
|
||||
|
||||
if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))
|
||||
if (HasPlayerFlag(PLAYER_FLAGS_RESTING))
|
||||
{
|
||||
if (now > lastTick && _restTime > 0) // freeze update
|
||||
{
|
||||
@@ -1384,7 +1384,7 @@ void Player::UpdatePvPState()
|
||||
}
|
||||
else // in friendly area
|
||||
{
|
||||
if (IsPvP() && !HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP) &&
|
||||
if (IsPvP() && !HasPlayerFlag(PLAYER_FLAGS_IN_PVP) &&
|
||||
pvpInfo.EndTimer == 0)
|
||||
pvpInfo.EndTimer = GameTime::GetGameTime().count(); // start toggle-off
|
||||
}
|
||||
@@ -1472,7 +1472,7 @@ void Player::UpdatePvP(bool state, bool _override)
|
||||
SetPvP(state);
|
||||
}
|
||||
|
||||
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
|
||||
RemovePlayerFlag(PLAYER_FLAGS_PVP_TIMER);
|
||||
sScriptMgr->OnPlayerPVPFlagChange(this, state);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user