Core/Units: defined all faction template flags and properly implemented FactionTemplateFlags::HatesAllExceptFriends
*refactored FactionTemplateEntry helpers to use pointers instead of references since we use datastore pointers in all cases so there is no need to create references
This commit is contained in:
1 parent
45af6bbd4b
commit
fd27f0020d
7 files changed
+69
-55
No files matched your search
@@ -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* factionTemplate = sFactionTemplateStore.LookupEntry(factionTemplateId);
|
||||
if (!factionTemplate)
|
||||
return &mNeutralAuctions;
|
||||
else if (uEntry->FactionGroup & FACTION_MASK_ALLIANCE)
|
||||
else if (factionTemplate->FactionGroup & FACTION_GROUP_MASK_ALLIANCE)
|
||||
return &mAllianceAuctions;
|
||||
else if (uEntry->FactionGroup & FACTION_MASK_HORDE)
|
||||
else if (factionTemplate->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
|
||||
|
||||
@@ -430,20 +430,34 @@ enum SpawnMask
|
||||
SPAWNMASK_RAID_ALL = (SPAWNMASK_RAID_NORMAL_ALL | SPAWNMASK_RAID_HEROIC_ALL)
|
||||
};
|
||||
|
||||
enum FactionTemplateFlags
|
||||
enum class FactionTemplateFlags : uint32
|
||||
{
|
||||
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
|
||||
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
|
||||
};
|
||||
|
||||
enum FactionMasks
|
||||
DEFINE_ENUM_FLAG(FactionTemplateFlags);
|
||||
|
||||
enum FactionGroupMasks : uint8
|
||||
{
|
||||
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
|
||||
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
|
||||
|
||||
@@ -706,51 +706,53 @@ struct FactionTemplateEntry
|
||||
uint32 Enemies[MAX_FACTION_RELATIONS]; // 6
|
||||
uint32 Friend[MAX_FACTION_RELATIONS]; // 10
|
||||
|
||||
EnumFlag<FactionTemplateFlags> GetFlags() const { return static_cast<FactionTemplateFlags>(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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -25293,7 +25293,7 @@ bool Player::CanUseBattlegroundObject(GameObject* gameobject) const
|
||||
FactionTemplateEntry const* playerFaction = GetFactionTemplateEntry();
|
||||
FactionTemplateEntry const* faction = sFactionTemplateStore.LookupEntry(gameobject->GetFaction());
|
||||
|
||||
if (playerFaction && faction && !playerFaction->IsFriendlyTo(*faction))
|
||||
if (playerFaction && faction && !playerFaction->IsFriendlyTo(faction))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5522,7 +5522,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;
|
||||
|
||||
@@ -5552,7 +5552,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))
|
||||
@@ -5574,14 +5574,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;
|
||||
}
|
||||
@@ -12671,7 +12669,7 @@ void Unit::GetPartyMembers(std::list<Unit*> &TagUnitMap)
|
||||
bool Unit::IsContestedGuard() const
|
||||
{
|
||||
if (FactionTemplateEntry const* entry = GetFactionTemplateEntry())
|
||||
return entry->IsContestedGuardFaction();
|
||||
return entry->IsHostileToPvpActivePlayers();
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -14750,7 +14748,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
|
||||
|
||||
@@ -5314,7 +5314,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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user