mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 17:13:47 +00:00
feat(Core/Unit): NPCFlags helpers (#11286)
* cherry-pick commit (TrinityCore/TrinityCore@d611925) Co-Authored-By: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
@@ -492,9 +492,9 @@ bool Creature::UpdateEntry(uint32 Entry, const CreatureData* data, bool changele
|
||||
ObjectMgr::ChooseCreatureFlags(cInfo, npcflag, unit_flags, dynamicflags, data);
|
||||
|
||||
if (cInfo->flags_extra & CREATURE_FLAG_EXTRA_WORLDEVENT)
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, npcflag | sGameEventMgr->GetNPCFlag(this));
|
||||
ReplaceAllNpcFlags(NPCFlags(npcflag | sGameEventMgr->GetNPCFlag(this)));
|
||||
else
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, npcflag);
|
||||
ReplaceAllNpcFlags(NPCFlags(npcflag));
|
||||
|
||||
// Xinef: NPC is in combat, keep this flag!
|
||||
unit_flags &= ~UNIT_FLAG_IN_COMBAT;
|
||||
@@ -1301,7 +1301,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
|
||||
CreatureData& data = sObjectMgr->NewOrExistCreatureData(m_spawnId);
|
||||
|
||||
uint32 displayId = GetNativeDisplayId();
|
||||
uint32 npcflag = GetUInt32Value(UNIT_NPC_FLAGS);
|
||||
uint32 npcflag = GetNpcFlags();
|
||||
uint32 unit_flags = GetUnitFlags();
|
||||
uint32 dynamicflags = GetDynamicFlags();
|
||||
|
||||
@@ -1846,7 +1846,7 @@ void Creature::setDeathState(DeathState s, bool despawn)
|
||||
SaveRespawnTime();
|
||||
|
||||
SetTarget(); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
|
||||
ReplaceAllNpcFlags(UNIT_NPC_FLAG_NONE);
|
||||
|
||||
Dismount(); // if creature is mounted on a virtual mount, remove it at death
|
||||
|
||||
@@ -1888,7 +1888,7 @@ void Creature::setDeathState(DeathState s, bool despawn)
|
||||
|
||||
UpdateMovementFlags();
|
||||
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, cinfo->npcflag);
|
||||
ReplaceAllNpcFlags(NPCFlags(cinfo->npcflag));
|
||||
ClearUnitState(uint32(UNIT_STATE_ALL_STATE & ~(UNIT_STATE_IGNORE_PATHFINDING | UNIT_STATE_NO_ENVIRONMENT_UPD)));
|
||||
SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool c
|
||||
SetNativeDisplayId(petInfo->DisplayId);
|
||||
UpdatePositionData();
|
||||
uint8 petlevel = petInfo->Level;
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
|
||||
ReplaceAllNpcFlags(UNIT_NPC_FLAG_NONE);
|
||||
SetName(petInfo->Name);
|
||||
|
||||
switch (getPetType())
|
||||
@@ -991,7 +991,7 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas
|
||||
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
|
||||
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
|
||||
SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32(sObjectMgr->GetXPForLevel(getLevel() + 1)* sWorld->getRate(RATE_XP_PET_NEXT_LEVEL)));
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
|
||||
ReplaceAllNpcFlags(UNIT_NPC_FLAG_NONE);
|
||||
|
||||
if (cinfo->type == CREATURE_TYPE_BEAST)
|
||||
{
|
||||
|
||||
@@ -2062,7 +2062,7 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask)
|
||||
return nullptr;
|
||||
|
||||
// appropriate npc type
|
||||
if (npcflagmask && !creature->HasFlag(UNIT_NPC_FLAGS, npcflagmask))
|
||||
if (npcflagmask && !creature->HasNpcFlag(NPCFlags(npcflagmask)))
|
||||
return nullptr;
|
||||
|
||||
// not allow interaction under control, but allow with own pets
|
||||
@@ -7543,7 +7543,7 @@ void Player::SendQuestGiverStatusMultiple()
|
||||
Creature* questgiver = ObjectAccessor::GetCreatureOrPetOrVehicle(*this, *itr);
|
||||
if (!questgiver || questgiver->IsHostileTo(this))
|
||||
continue;
|
||||
if (!questgiver->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER))
|
||||
if (!questgiver->HasNpcFlag(UNIT_NPC_FLAG_QUESTGIVER))
|
||||
continue;
|
||||
|
||||
questStatus = GetQuestDialogStatus(questgiver);
|
||||
@@ -8826,7 +8826,7 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy
|
||||
pet->SetCreatorGUID(GetGUID());
|
||||
pet->SetFaction(GetFaction());
|
||||
pet->setPowerType(POWER_MANA);
|
||||
pet->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
|
||||
pet->ReplaceAllNpcFlags(UNIT_NPC_FLAG_NONE);
|
||||
pet->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
|
||||
pet->InitStatsForLevel(getLevel());
|
||||
|
||||
@@ -13866,7 +13866,7 @@ bool Player::CanResummonPet(uint32 spellid)
|
||||
|
||||
bool Player::CanSeeSpellClickOn(Creature const* c) const
|
||||
{
|
||||
if (!c->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
|
||||
if (!c->HasNpcFlag(UNIT_NPC_FLAG_SPELLCLICK))
|
||||
return false;
|
||||
|
||||
SpellClickInfoMapBounds clickPair = sObjectMgr->GetSpellClickInfoMapBounds(c->GetEntry());
|
||||
@@ -13889,7 +13889,7 @@ bool Player::CanSeeSpellClickOn(Creature const* c) const
|
||||
|
||||
bool Player::CanSeeVendor(Creature const* creature) const
|
||||
{
|
||||
if (!creature->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR))
|
||||
if (!creature->HasNpcFlag(UNIT_NPC_FLAG_VENDOR))
|
||||
return true;
|
||||
|
||||
ConditionList conditions = sConditionMgr->GetConditionsForNpcVendorEvent(creature->GetEntry(), 0);
|
||||
|
||||
@@ -45,7 +45,7 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool
|
||||
|
||||
if (source->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
npcflags = source->GetUInt32Value(UNIT_NPC_FLAGS);
|
||||
npcflags = source->ToUnit()->GetNpcFlags();
|
||||
if (showQuests && npcflags & UNIT_NPC_FLAG_QUESTGIVER)
|
||||
PrepareQuestMenu(source->GetGUID());
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void Player::SendPreparedGossip(WorldObject* source)
|
||||
if (source->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
// in case no gossip flag and quest menu not empty, open quest menu (client expect gossip menu with this flag)
|
||||
if (!source->ToCreature()->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP) && !PlayerTalkClass->GetQuestMenu().Empty())
|
||||
if (!source->ToCreature()->HasNpcFlag(UNIT_NPC_FLAG_GOSSIP) && !PlayerTalkClass->GetQuestMenu().Empty())
|
||||
{
|
||||
SendPreparedQuest(source->GetGUID());
|
||||
return;
|
||||
@@ -259,7 +259,7 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men
|
||||
|
||||
if (sWorld->getIntConfig(CONFIG_INSTANT_TAXI) == 2 && source->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
if (gossipOptionId == GOSSIP_ACTION_TOGGLE_INSTANT_FLIGHT && source->GetUInt32Value(UNIT_NPC_FLAGS) & UNIT_NPC_FLAG_FLIGHTMASTER)
|
||||
if (gossipOptionId == GOSSIP_ACTION_TOGGLE_INSTANT_FLIGHT && source->ToUnit()->GetNpcFlags() & UNIT_NPC_FLAG_FLIGHTMASTER)
|
||||
{
|
||||
ToggleInstantFlight();
|
||||
|
||||
|
||||
@@ -1739,7 +1739,7 @@ void Player::UpdateForQuestWorldObjects()
|
||||
continue;
|
||||
|
||||
// check if this unit requires quest specific flags
|
||||
if (!obj->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
|
||||
if (!obj->HasNpcFlag(UNIT_NPC_FLAG_SPELLCLICK))
|
||||
continue;
|
||||
|
||||
SpellClickInfoMapBounds clickPair = sObjectMgr->GetSpellClickInfoMapBounds(obj->GetEntry());
|
||||
|
||||
@@ -18183,7 +18183,7 @@ void Unit::RemoveVehicleKit()
|
||||
|
||||
m_updateFlag &= ~UPDATEFLAG_VEHICLE;
|
||||
m_unitTypeMask &= ~UNIT_MASK_VEHICLE;
|
||||
RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK | UNIT_NPC_FLAG_PLAYER_VEHICLE);
|
||||
RemoveNpcFlag(UNIT_NPC_FLAG_SPELLCLICK | UNIT_NPC_FLAG_PLAYER_VEHICLE);
|
||||
}
|
||||
|
||||
Unit* Unit::GetVehicleBase() const
|
||||
|
||||
@@ -540,6 +540,8 @@ enum NPCFlags : uint32
|
||||
UNIT_NPC_FLAG_VENDOR_MASK = UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_VENDOR_AMMO | UNIT_NPC_FLAG_VENDOR_POISON | UNIT_NPC_FLAG_VENDOR_REAGENT
|
||||
};
|
||||
|
||||
DEFINE_ENUM_FLAG(NPCFlags);
|
||||
|
||||
enum MovementFlags
|
||||
{
|
||||
MOVEMENTFLAG_NONE = 0x00000000,
|
||||
@@ -1606,20 +1608,26 @@ public:
|
||||
MeleeHitOutcome RollMeleeOutcomeAgainst (Unit const* victim, WeaponAttackType attType) const;
|
||||
MeleeHitOutcome RollMeleeOutcomeAgainst (Unit const* victim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const;
|
||||
|
||||
[[nodiscard]] bool IsVendor() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR); }
|
||||
[[nodiscard]] bool IsTrainer() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER); }
|
||||
[[nodiscard]] bool IsQuestGiver() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER); }
|
||||
[[nodiscard]] bool IsGossip() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); }
|
||||
[[nodiscard]] bool IsTaxi() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER); }
|
||||
[[nodiscard]] bool IsGuildMaster() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER); }
|
||||
[[nodiscard]] bool IsBattleMaster() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER); }
|
||||
[[nodiscard]] bool IsBanker() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER); }
|
||||
[[nodiscard]] bool IsInnkeeper() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER); }
|
||||
[[nodiscard]] bool IsSpiritHealer() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER); }
|
||||
[[nodiscard]] bool IsSpiritGuide() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE); }
|
||||
[[nodiscard]] bool IsTabardDesigner()const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER); }
|
||||
[[nodiscard]] bool IsAuctioner() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER); }
|
||||
[[nodiscard]] bool IsArmorer() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR); }
|
||||
NPCFlags GetNpcFlags() const { return NPCFlags(GetUInt32Value(UNIT_NPC_FLAGS)); }
|
||||
bool HasNpcFlag(NPCFlags flags) const { return HasFlag(UNIT_NPC_FLAGS, flags) != 0; }
|
||||
void SetNpcFlag(NPCFlags flags) { SetFlag(UNIT_NPC_FLAGS, flags); }
|
||||
void RemoveNpcFlag(NPCFlags flags) { RemoveFlag(UNIT_NPC_FLAGS, flags); }
|
||||
void ReplaceAllNpcFlags(NPCFlags flags) { SetUInt32Value(UNIT_NPC_FLAGS, flags); }
|
||||
|
||||
[[nodiscard]] bool IsVendor() const { return HasNpcFlag(UNIT_NPC_FLAG_VENDOR); }
|
||||
[[nodiscard]] bool IsTrainer() const { return HasNpcFlag(UNIT_NPC_FLAG_TRAINER); }
|
||||
[[nodiscard]] bool IsQuestGiver() const { return HasNpcFlag(UNIT_NPC_FLAG_QUESTGIVER); }
|
||||
[[nodiscard]] bool IsGossip() const { return HasNpcFlag(UNIT_NPC_FLAG_GOSSIP); }
|
||||
[[nodiscard]] bool IsTaxi() const { return HasNpcFlag(UNIT_NPC_FLAG_FLIGHTMASTER); }
|
||||
[[nodiscard]] bool IsGuildMaster() const { return HasNpcFlag(UNIT_NPC_FLAG_PETITIONER); }
|
||||
[[nodiscard]] bool IsBattleMaster() const { return HasNpcFlag(UNIT_NPC_FLAG_BATTLEMASTER); }
|
||||
[[nodiscard]] bool IsBanker() const { return HasNpcFlag(UNIT_NPC_FLAG_BANKER); }
|
||||
[[nodiscard]] bool IsInnkeeper() const { return HasNpcFlag(UNIT_NPC_FLAG_INNKEEPER); }
|
||||
[[nodiscard]] bool IsSpiritHealer() const { return HasNpcFlag(UNIT_NPC_FLAG_SPIRITHEALER); }
|
||||
[[nodiscard]] bool IsSpiritGuide() const { return HasNpcFlag(UNIT_NPC_FLAG_SPIRITGUIDE); }
|
||||
[[nodiscard]] bool IsTabardDesigner()const { return HasNpcFlag(UNIT_NPC_FLAG_TABARDDESIGNER); }
|
||||
[[nodiscard]] bool IsAuctioner() const { return HasNpcFlag(UNIT_NPC_FLAG_AUCTIONEER); }
|
||||
[[nodiscard]] bool IsArmorer() const { return HasNpcFlag(UNIT_NPC_FLAG_REPAIR); }
|
||||
[[nodiscard]] bool IsServiceProvider() const
|
||||
{
|
||||
return HasFlag(UNIT_NPC_FLAGS,
|
||||
@@ -1628,7 +1636,7 @@ public:
|
||||
UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_SPIRITHEALER |
|
||||
UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER);
|
||||
}
|
||||
[[nodiscard]] bool IsSpiritService() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE); }
|
||||
[[nodiscard]] bool IsSpiritService() const { return HasNpcFlag(UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE); }
|
||||
[[nodiscard]] bool IsCritter() const { return GetCreatureType() == CREATURE_TYPE_CRITTER; }
|
||||
|
||||
[[nodiscard]] bool IsInFlight() const { return HasUnitState(UNIT_STATE_IN_FLIGHT); }
|
||||
|
||||
@@ -119,14 +119,14 @@ void Vehicle::Reset(bool evading /*= false*/)
|
||||
if (_me->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
if (_usableSeatNum)
|
||||
_me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PLAYER_VEHICLE);
|
||||
_me->SetNpcFlag(UNIT_NPC_FLAG_PLAYER_VEHICLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyAllImmunities();
|
||||
InstallAllAccessories(evading);
|
||||
if (_usableSeatNum)
|
||||
_me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
|
||||
_me->SetNpcFlag(UNIT_NPC_FLAG_SPELLCLICK);
|
||||
}
|
||||
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
@@ -355,9 +355,9 @@ bool Vehicle::AddPassenger(Unit* unit, int8 seatId)
|
||||
if (!_usableSeatNum)
|
||||
{
|
||||
if (_me->GetTypeId() == TYPEID_PLAYER)
|
||||
_me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PLAYER_VEHICLE);
|
||||
_me->RemoveNpcFlag(UNIT_NPC_FLAG_PLAYER_VEHICLE);
|
||||
else
|
||||
_me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
|
||||
_me->RemoveNpcFlag(UNIT_NPC_FLAG_SPELLCLICK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ void Vehicle::RemovePassenger(Unit* unit)
|
||||
unit->GetName(), _me->GetEntry(), _vehicleInfo->m_ID, _me->GetGUID().ToString(), (int32)seat->first);
|
||||
|
||||
if (seat->second.SeatInfo->CanEnterOrExit() && ++_usableSeatNum)
|
||||
_me->SetFlag(UNIT_NPC_FLAGS, (_me->GetTypeId() == TYPEID_PLAYER ? UNIT_NPC_FLAG_PLAYER_VEHICLE : UNIT_NPC_FLAG_SPELLCLICK));
|
||||
_me->SetNpcFlag((_me->GetTypeId() == TYPEID_PLAYER ? UNIT_NPC_FLAG_PLAYER_VEHICLE : UNIT_NPC_FLAG_SPELLCLICK));
|
||||
|
||||
// Remove UNIT_FLAG_NOT_SELECTABLE if passenger did not have it before entering vehicle
|
||||
if (seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE && !seat->second.Passenger.IsUnselectable)
|
||||
|
||||
Reference in New Issue
Block a user