Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added all missing faction template masks #117

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/server/game/AuctionHouse/AuctionHouseMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
42 changes: 28 additions & 14 deletions src/server/game/DataStores/DBCEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 27 additions & 27 deletions src/server/game/DataStores/DBCStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,51 +706,51 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
Expand Down Expand Up @@ -12708,7 +12706,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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading