fix(Core/Creature): Implement respond to call for help faction flag. (#21959)

This commit is contained in:
Benjamin Jackson
2025-04-29 21:19:58 -04:00
committed by GitHub
parent d8bc1d1797
commit 5686f1e87a
3 changed files with 16 additions and 11 deletions

View File

@@ -1937,17 +1937,8 @@ bool Creature::CanStartAttack(Unit const* who) const
if (!_IsTargetAcceptable(who))
return false;
// pussywizard: at this point we are either hostile to who or friendly to who->getAttackerForHelper()
// pussywizard: if who is in combat and has an attacker, help him if the distance is right (help because who is hostile or help because attacker is friendly)
bool assist = false;
if (who->IsEngaged() && IsWithinDist(who, ATTACK_DISTANCE))
if (Unit* victim = who->getAttackerForHelper())
if (IsWithinDistInMap(victim, sWorld->getFloatConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS)))
assist = true;
if (!assist)
if (IsNeutralToAll() || !IsWithinDistInMap(who, GetAggroRange(who) + m_CombatDistance, true, false)) // pussywizard: +m_combatDistance for turrets and similar
return false;
if (IsNeutralToAll() || !IsWithinDistInMap(who, GetAggroRange(who) + m_CombatDistance, true, false)) // pussywizard: +m_combatDistance for turrets and similar
return false;
if (!CanCreatureAttack(who))
return false;
@@ -1955,6 +1946,9 @@ bool Creature::CanStartAttack(Unit const* who) const
if (HasUnitState(UNIT_STATE_STUNNED))
return false;
if (!IsHostileTo(who))
return false;
return IsWithinLOSInMap(who);
}
@@ -2537,6 +2531,9 @@ bool Creature::CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction /
{
if (GetFaction() != u->GetFaction())
return false;
if (!RespondsToCallForHelp())
return false;
}
else
{

View File

@@ -986,6 +986,13 @@ public:
return false;
}
[[nodiscard]] bool RespondsToCallForHelp() const
{
if (FactionTemplateEntry const* entry = GetFactionTemplateEntry())
return entry->FactionRespondsToCallForHelp();
return false;
}
[[nodiscard]] bool IsInSanctuary() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_SANCTUARY); }
[[nodiscard]] bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
[[nodiscard]] bool IsFFAPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); }

View File

@@ -986,6 +986,7 @@ struct FactionTemplateEntry
return hostileMask == 0 && friendlyMask == 0;
}
[[nodiscard]] bool IsContestedGuardFaction() const { return (factionFlags & FACTION_TEMPLATE_FLAG_ATTACK_PVP_ACTIVE_PLAYERS) != 0; }
[[nodiscard]] bool FactionRespondsToCallForHelp() const { return (factionFlags & FACTION_TEMPLATE_FLAG_RESPOND_TO_CALL_FOR_HELP) != 0; }
};
struct GameObjectArtKitEntry