Add mob retaliation (#19901)

This commit is contained in:
Nemanja
2023-10-06 20:56:18 -04:00
committed by GitHub
parent 45234b25b6
commit 02df8cd263
10 changed files with 339 additions and 47 deletions

View File

@@ -1,15 +1,15 @@
using Content.Server.NPC.Components;
using Robust.Shared.Prototypes;
using System.Linq;
using JetBrains.Annotations;
namespace Content.Server.NPC.Systems;
/// <summary>
/// Outlines faction relationships with each other.
/// </summary>
public sealed class NpcFactionSystem : EntitySystem
public sealed partial class NpcFactionSystem : EntitySystem
{
[Dependency] private readonly FactionExceptionSystem _factionException = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
@@ -26,6 +26,8 @@ public sealed class NpcFactionSystem : EntitySystem
_sawmill = Logger.GetSawmill("faction");
SubscribeLocalEvent<NpcFactionMemberComponent, ComponentStartup>(OnFactionStartup);
_protoManager.PrototypesReloaded += OnProtoReload;
InitializeException();
RefreshFactions();
}
@@ -134,12 +136,15 @@ public sealed class NpcFactionSystem : EntitySystem
if (TryComp<FactionExceptionComponent>(entity, out var factionException))
{
// ignore anything from enemy faction that we are explicitly friendly towards
return hostiles.Where(target => !_factionException.IsIgnored(factionException, target));
return hostiles
.Union(GetHostiles(entity, factionException))
.Where(target => !IsIgnored(entity, target, factionException));
}
return hostiles;
}
[PublicAPI]
public IEnumerable<EntityUid> GetNearbyFriendlies(EntityUid entity, float range, NpcFactionMemberComponent? component = null)
{
if (!Resolve(entity, ref component, false))