From a629e7a2485092dcc4734d4f7015215e074c6e6e Mon Sep 17 00:00:00 2001 From: Jose Joya Date: Tue, 8 Aug 2023 01:25:00 -0500 Subject: [PATCH] feat: added all missing faction template masks (#117) --- .../game/AuctionHouse/AuctionHouseMgr.cpp | 12 ++--- src/server/game/DataStores/DBCEnums.h | 42 ++++++++++----- src/server/game/DataStores/DBCStructure.h | 54 +++++++++---------- .../game/Entities/Creature/Creature.cpp | 2 +- src/server/game/Entities/Player/Player.cpp | 2 +- src/server/game/Entities/Unit/Unit.cpp | 16 +++--- src/server/game/Spells/SpellEffects.cpp | 2 +- 7 files changed, 71 insertions(+), 59 deletions(-) diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index adf3101c..c37120ab 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -62,12 +62,12 @@ AuctionHouseObject* AuctionHouseMgr::GetAuctionsMap(uint32 factionTemplateId) return &mNeutralAuctions; // teams have linked auction houses - FactionTemplateEntry const* uEntry = sFactionTemplateStore.LookupEntry(factionTemplateId); - if (!uEntry) + FactionTemplateEntry const* factonTemplate = sFactionTemplateStore.LookupEntry(factionTemplateId); + if (!factonTemplate) return &mNeutralAuctions; - else if (uEntry->FactionGroup & FACTION_MASK_ALLIANCE) + else if (factonTemplate->FactionGroup & FACTION_GROUP_MASK_ALLIANCE) return &mAllianceAuctions; - else if (uEntry->FactionGroup & FACTION_MASK_HORDE) + else if (factonTemplate->FactionGroup & FACTION_GROUP_MASK_HORDE) return &mHordeAuctions; else return &mNeutralAuctions; @@ -578,9 +578,9 @@ AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTem FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId); if (!u_entry) houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house - else if (u_entry->FactionGroup & FACTION_MASK_ALLIANCE) + else if (u_entry->FactionGroup & FACTION_GROUP_MASK_ALLIANCE) houseid = AUCTIONHOUSE_ALLIANCE; // human auction house - else if (u_entry->FactionGroup & FACTION_MASK_HORDE) + else if (u_entry->FactionGroup & FACTION_GROUP_MASK_HORDE) houseid = AUCTIONHOUSE_HORDE; // orc auction house else houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house diff --git a/src/server/game/DataStores/DBCEnums.h b/src/server/game/DataStores/DBCEnums.h index 1731117d..5954a149 100644 --- a/src/server/game/DataStores/DBCEnums.h +++ b/src/server/game/DataStores/DBCEnums.h @@ -430,20 +430,34 @@ enum SpawnMask SPAWNMASK_RAID_ALL = (SPAWNMASK_RAID_NORMAL_ALL | SPAWNMASK_RAID_HEROIC_ALL) }; -enum FactionTemplateFlags -{ - FACTION_TEMPLATE_FLAG_PVP = 0x00000800, // flagged for PvP - FACTION_TEMPLATE_FLAG_CONTESTED_GUARD = 0x00001000, // faction will attack players that were involved in PvP combats - FACTION_TEMPLATE_FLAG_HOSTILE_BY_DEFAULT= 0x00002000 -}; - -enum FactionMasks -{ - FACTION_MASK_PLAYER = 1, // any player - FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team - FACTION_MASK_HORDE = 4, // player or creature from horde team - FACTION_MASK_MONSTER = 8 // aggressive creature from monster team - // if none flags set then non-aggressive creature +enum class FactionTemplateFlags : uint32 +{ + None = 0x0000, + RespondToCallForHelp = 0x0001, + BroadcastToEnemiesLowPriority = 0x0002, + BroadcastToEnemiesMedPriority = 0x0004, + BroadcastToEnemiesHighPriority = 0x0008, + SearchForEnemiesLowPriority = 0x0010, + SearchForEnemiesMedPriority = 0x0020, + SearchForEnemiesHighPriority = 0x0040, + SearchForFriendsLowPriority = 0x0080, + SearchForFriendsMedPriority = 0x0100, + SearchForFriendsHighPriority = 0x0200, + FleeFromCallForHelp = 0x0400, + AssistPlayers = 0x0800, // flagged for PvP + AttackPvPActivePlayers = 0x1000, // faction will attack players that were involved in PvP combats + HatesAllExceptFriends = 0x2000 +}; + +DEFINE_ENUM_FLAG(FactionTemplateFlags); + +enum FactionGroupMasks : uint8 +{ + FACTION_GROUP_MASK_NONE = 0x0, // none = neutral + FACTION_GROUP_MASK_PLAYER = 0x1, // any player + FACTION_GROUP_MASK_ALLIANCE = 0x2, // player or creature from alliance team + FACTION_GROUP_MASK_HORDE = 0x4, // player or creature from horde team + FACTION_GROUP_MASK_MONSTER = 0x8 // aggressive creature from monster team }; enum MapTypes // Lua_IsInInstance diff --git a/src/server/game/DataStores/DBCStructure.h b/src/server/game/DataStores/DBCStructure.h index 1b9e06f9..4585778c 100644 --- a/src/server/game/DataStores/DBCStructure.h +++ b/src/server/game/DataStores/DBCStructure.h @@ -706,51 +706,51 @@ struct FactionTemplateEntry uint32 Enemies[MAX_FACTION_RELATIONS]; // 6 uint32 Friend[MAX_FACTION_RELATIONS]; // 10 + EnumFlag GetFlags() const { return static_cast(Flags); } // helpers - bool IsFriendlyTo(FactionTemplateEntry const& entry) const + bool IsFriendlyTo(FactionTemplateEntry const* entry) const { - if (ID == entry.ID) + if (ID == entry->ID) return true; - if (entry.Faction) - { - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (Enemies[i] == entry.Faction) - return false; - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (Friend[i] == entry.Faction) - return true; - } - return (FriendGroup & entry.FactionGroup) || (FactionGroup & entry.FriendGroup); + for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) + if (Friend[i] == entry->Faction) + return true; + + if (FactionGroup > 0 && (FactionGroup & entry->FriendGroup) != 0) + return true; + + return false; } - bool IsHostileTo(FactionTemplateEntry const& entry) const + + bool IsHostileTo(FactionTemplateEntry const* entry) const { - if (ID == entry.ID) + if (ID == entry->ID) return false; - if (entry.Faction) - { - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; i++) - if (Enemies[i] == entry.Faction) - return true; + if (GetFlags().HasFlag(FactionTemplateFlags::HatesAllExceptFriends) && !IsFriendlyTo(entry)) + return true; - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; i++) - if (Friend[i] == entry.Faction) - return false; - } - return (EnemyGroup & entry.FactionGroup) != 0; + for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) + if (Enemies[i] == entry->Faction) + return true; + + if (FactionGroup > 0 && (FactionGroup & entry->EnemyGroup) != 0) + return true; + + return false; } - bool IsHostileToPlayers() const { return (EnemyGroup & FACTION_MASK_PLAYER) != 0; } + bool IsHostileToPlayers() const { return (EnemyGroup & FACTION_GROUP_MASK_PLAYER) != 0; } + bool IsHostileToPvpActivePlayers() const { return GetFlags().HasFlag(FactionTemplateFlags::AttackPvPActivePlayers); } bool IsNeutralToAll() const { for (uint8 i = 0; i < MAX_FACTION_RELATIONS; i++) if (Enemies[i] != 0) return false; - return EnemyGroup == 0 && FriendGroup == 0; + return EnemyGroup == FACTION_GROUP_MASK_NONE && FriendGroup == FACTION_GROUP_MASK_NONE; } - bool IsContestedGuardFaction() const { return (Flags & FACTION_TEMPLATE_FLAG_CONTESTED_GUARD) != 0; } }; struct GameObjectArtKitEntry diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 719418de..c9052a4b 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -623,7 +623,7 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/, // checked and error show at loading templates if (FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(cInfo->faction)) - SetPvP((factionTemplate->Flags & FACTION_TEMPLATE_FLAG_PVP) != 0); + SetPvP(factionTemplate->GetFlags().HasFlag(FactionTemplateFlags::AssistPlayers)); // updates spell bars for vehicles and set player's faction - should be called here, to overwrite faction that is set from the new template if (IsVehicle()) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 492cd740..a9f0d51f 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -24385,7 +24385,7 @@ bool Player::CanUseBattlegroundObject(GameObject* gameobject) const FactionTemplateEntry const* playerFaction = GetFactionTemplateEntry(); FactionTemplateEntry const* faction = sFactionTemplateStore.LookupEntry(gameobject->GetFaction()); - if (playerFaction && faction && !playerFaction->IsFriendlyTo(*faction)) return false; + if (playerFaction && faction && !playerFaction->IsFriendlyTo(faction)) return false; } // BUG: sometimes when player clicks on flag in AB - client won't send gameobject_use, only gameobject_report_use packet diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 20d8f080..6ea61676 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -5555,7 +5555,7 @@ ReputationRank Unit::GetReactionTo(Unit const* target) const if (targetFactionEntry->CanHaveReputation()) { // check contested flags - if (targetFactionTemplateEntry->Flags & FACTION_TEMPLATE_FLAG_CONTESTED_GUARD + if (targetFactionTemplateEntry->IsHostileToPvpActivePlayers() && selfPlayerOwner->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP)) return REP_HOSTILE; @@ -5585,7 +5585,7 @@ ReputationRank Unit::GetFactionReactionTo(FactionTemplateEntry const* factionTem if (Player const* targetPlayerOwner = target->GetAffectingPlayer()) { // check contested flags - if (factionTemplateEntry->Flags & FACTION_TEMPLATE_FLAG_CONTESTED_GUARD + if (factionTemplateEntry->IsHostileToPvpActivePlayers() && targetPlayerOwner->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP)) return REP_HOSTILE; if (ReputationRank const* repRank = targetPlayerOwner->GetReputationMgr().GetForcedRankIfAny(factionTemplateEntry)) @@ -5607,14 +5607,12 @@ ReputationRank Unit::GetFactionReactionTo(FactionTemplateEntry const* factionTem } // common faction based check - if (factionTemplateEntry->IsHostileTo(*targetFactionTemplateEntry)) + if (factionTemplateEntry->IsHostileTo(targetFactionTemplateEntry)) return REP_HOSTILE; - if (factionTemplateEntry->IsFriendlyTo(*targetFactionTemplateEntry)) + if (factionTemplateEntry->IsFriendlyTo(targetFactionTemplateEntry)) return REP_FRIENDLY; - if (targetFactionTemplateEntry->IsFriendlyTo(*factionTemplateEntry)) + if (targetFactionTemplateEntry->IsFriendlyTo(factionTemplateEntry)) return REP_FRIENDLY; - if (factionTemplateEntry->Flags & FACTION_TEMPLATE_FLAG_HOSTILE_BY_DEFAULT) - return REP_HOSTILE; // neutral by default return REP_NEUTRAL; } @@ -12708,7 +12706,7 @@ void Unit::GetPartyMembers(std::list &TagUnitMap) bool Unit::IsContestedGuard() const { if (FactionTemplateEntry const* entry = GetFactionTemplateEntry()) - return entry->IsContestedGuardFaction(); + return entry->IsHostileToPvpActivePlayers(); return false; } @@ -14805,7 +14803,7 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target) { FactionTemplateEntry const* ft1 = GetFactionTemplateEntry(); FactionTemplateEntry const* ft2 = target->GetFactionTemplateEntry(); - if (ft1 && ft2 && !ft1->IsFriendlyTo(*ft2)) + if (ft1 && ft2 && !ft1->IsFriendlyTo(ft2)) { if (index == UNIT_FIELD_BYTES_2) // Allow targetting opposite faction in party when enabled in config diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 5dd443f1..0bdb9aa7 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -5323,7 +5323,7 @@ void Spell::EffectGameObjectDamage(SpellEffIndex /*effIndex*/) FactionTemplateEntry const* casterFaction = caster->GetFactionTemplateEntry(); FactionTemplateEntry const* targetFaction = sFactionTemplateStore.LookupEntry(gameObjTarget->GetFaction()); // Do not allow to damage GO's of friendly factions (ie: Wintergrasp Walls/Ulduar Storm Beacons) - if (!targetFaction || (casterFaction && !casterFaction->IsFriendlyTo(*targetFaction))) + if (!targetFaction || (casterFaction && !casterFaction->IsFriendlyTo(targetFaction))) gameObjTarget->ModifyHealth(-damage, caster, GetSpellInfo()->Id); }