Rename Faction to NpcFaction (#18079)
This commit is contained in:
@@ -4,14 +4,14 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
|
||||
namespace Content.Server.NPC.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[Access(typeof(FactionSystem))]
|
||||
public sealed class FactionComponent : Component
|
||||
[Access(typeof(NpcFactionSystem))]
|
||||
public sealed class NpcFactionMemberComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Factions this entity is a part of.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite),
|
||||
DataField("factions", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<FactionPrototype>))]
|
||||
DataField("factions", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<NpcFactionPrototype>))]
|
||||
public HashSet<string> Factions = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -1,23 +1,22 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.NPC.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data about this faction's relations with other factions.
|
||||
/// </summary>
|
||||
[Prototype("faction")]
|
||||
public sealed class FactionPrototype : IPrototype
|
||||
[Prototype("npcFaction")]
|
||||
public sealed class NpcFactionPrototype : IPrototype
|
||||
{
|
||||
[ViewVariables]
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("friendly", customTypeSerializer:typeof(PrototypeIdListSerializer<FactionPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("friendly", customTypeSerializer:typeof(PrototypeIdListSerializer<NpcFactionPrototype>))]
|
||||
public List<string> Friendly = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("hostile", customTypeSerializer:typeof(PrototypeIdListSerializer<FactionPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("hostile", customTypeSerializer:typeof(PrototypeIdListSerializer<NpcFactionPrototype>))]
|
||||
public List<string> Hostile = new();
|
||||
}
|
||||
}
|
||||
@@ -483,7 +483,7 @@ public sealed partial class NPCSteeringSystem
|
||||
var objectRadius = 0.25f;
|
||||
var detectionRadius = MathF.Max(0.35f, agentRadius + objectRadius);
|
||||
var ourVelocity = body.LinearVelocity;
|
||||
var factionQuery = GetEntityQuery<FactionComponent>();
|
||||
var factionQuery = GetEntityQuery<NpcFactionMemberComponent>();
|
||||
factionQuery.TryGetComponent(uid, out var ourFaction);
|
||||
|
||||
foreach (var ent in _lookup.GetEntitiesInRange(uid, detectionRadius, LookupFlags.Dynamic))
|
||||
@@ -496,7 +496,7 @@ public sealed partial class NPCSteeringSystem
|
||||
(mask & otherBody.CollisionLayer) == 0x0 &&
|
||||
(layer & otherBody.CollisionMask) == 0x0 ||
|
||||
!factionQuery.TryGetComponent(ent, out var otherFaction) ||
|
||||
!_faction.IsEntityFriendly(uid, ent, ourFaction, otherFaction) ||
|
||||
!_npcFaction.IsEntityFriendly(uid, ent, ourFaction, otherFaction) ||
|
||||
// Use <= 0 so we ignore stationary friends in case.
|
||||
Vector2.Dot(otherBody.LinearVelocity, ourVelocity) <= 0f)
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ public sealed partial class NPCSteeringSystem : SharedNPCSteeringSystem
|
||||
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly DoorSystem _doors = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly FactionSystem _faction = default!;
|
||||
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
|
||||
[Dependency] private readonly PathfindingSystem _pathfindingSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedMeleeWeaponSystem _melee = default!;
|
||||
|
||||
@@ -26,7 +26,7 @@ public sealed class NPCUtilitySystem : EntitySystem
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly ContainerSystem _container = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly FactionSystem _faction = default!;
|
||||
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
|
||||
[Dependency] private readonly FoodSystem _food = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly PuddleSystem _puddle = default!;
|
||||
@@ -264,7 +264,7 @@ public sealed class NPCUtilitySystem : EntitySystem
|
||||
|
||||
break;
|
||||
case NearbyHostilesQuery:
|
||||
foreach (var ent in _faction.GetNearbyHostiles(owner, vision))
|
||||
foreach (var ent in _npcFaction.GetNearbyHostiles(owner, vision))
|
||||
{
|
||||
entities.Add(ent);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Server.NPC.Systems;
|
||||
/// <summary>
|
||||
/// Outlines faction relationships with each other.
|
||||
/// </summary>
|
||||
public sealed class FactionSystem : EntitySystem
|
||||
public sealed class NpcFactionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly FactionExceptionSystem _factionException = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
@@ -24,7 +24,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
_sawmill = Logger.GetSawmill("faction");
|
||||
SubscribeLocalEvent<FactionComponent, ComponentStartup>(OnFactionStartup);
|
||||
SubscribeLocalEvent<NpcFactionMemberComponent, ComponentStartup>(OnFactionStartup);
|
||||
_protoManager.PrototypesReloaded += OnProtoReload;
|
||||
RefreshFactions();
|
||||
}
|
||||
@@ -37,33 +37,33 @@ public sealed class FactionSystem : EntitySystem
|
||||
|
||||
private void OnProtoReload(PrototypesReloadedEventArgs obj)
|
||||
{
|
||||
if (!obj.ByType.ContainsKey(typeof(FactionPrototype)))
|
||||
if (!obj.ByType.ContainsKey(typeof(NpcFactionPrototype)))
|
||||
return;
|
||||
|
||||
RefreshFactions();
|
||||
}
|
||||
|
||||
private void OnFactionStartup(EntityUid uid, FactionComponent component, ComponentStartup args)
|
||||
private void OnFactionStartup(EntityUid uid, NpcFactionMemberComponent memberComponent, ComponentStartup args)
|
||||
{
|
||||
RefreshFactions(component);
|
||||
RefreshFactions(memberComponent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the cached factions for this component.
|
||||
/// </summary>
|
||||
private void RefreshFactions(FactionComponent component)
|
||||
private void RefreshFactions(NpcFactionMemberComponent memberComponent)
|
||||
{
|
||||
component.FriendlyFactions.Clear();
|
||||
component.HostileFactions.Clear();
|
||||
memberComponent.FriendlyFactions.Clear();
|
||||
memberComponent.HostileFactions.Clear();
|
||||
|
||||
foreach (var faction in component.Factions)
|
||||
foreach (var faction in memberComponent.Factions)
|
||||
{
|
||||
// YAML Linter already yells about this
|
||||
if (!_factions.TryGetValue(faction, out var factionData))
|
||||
continue;
|
||||
|
||||
component.FriendlyFactions.UnionWith(factionData.Friendly);
|
||||
component.HostileFactions.UnionWith(factionData.Hostile);
|
||||
memberComponent.FriendlyFactions.UnionWith(factionData.Friendly);
|
||||
memberComponent.HostileFactions.UnionWith(factionData.Hostile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ public sealed class FactionSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void AddFaction(EntityUid uid, string faction, bool dirty = true)
|
||||
{
|
||||
if (!_protoManager.HasIndex<FactionPrototype>(faction))
|
||||
if (!_protoManager.HasIndex<NpcFactionPrototype>(faction))
|
||||
{
|
||||
_sawmill.Error($"Unable to find faction {faction}");
|
||||
return;
|
||||
}
|
||||
|
||||
var comp = EnsureComp<FactionComponent>(uid);
|
||||
var comp = EnsureComp<NpcFactionMemberComponent>(uid);
|
||||
if (!comp.Factions.Add(faction))
|
||||
return;
|
||||
|
||||
@@ -93,13 +93,13 @@ public sealed class FactionSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void RemoveFaction(EntityUid uid, string faction, bool dirty = true)
|
||||
{
|
||||
if (!_protoManager.HasIndex<FactionPrototype>(faction))
|
||||
if (!_protoManager.HasIndex<NpcFactionPrototype>(faction))
|
||||
{
|
||||
_sawmill.Error($"Unable to find faction {faction}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryComp<FactionComponent>(uid, out var component))
|
||||
if (!TryComp<NpcFactionMemberComponent>(uid, out var component))
|
||||
return;
|
||||
|
||||
if (!component.Factions.Remove(faction))
|
||||
@@ -111,7 +111,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetNearbyHostiles(EntityUid entity, float range, FactionComponent? component = null)
|
||||
public IEnumerable<EntityUid> GetNearbyHostiles(EntityUid entity, float range, NpcFactionMemberComponent? component = null)
|
||||
{
|
||||
if (!Resolve(entity, ref component, false))
|
||||
return Array.Empty<EntityUid>();
|
||||
@@ -126,7 +126,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
return hostiles;
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetNearbyFriendlies(EntityUid entity, float range, FactionComponent? component = null)
|
||||
public IEnumerable<EntityUid> GetNearbyFriendlies(EntityUid entity, float range, NpcFactionMemberComponent? component = null)
|
||||
{
|
||||
if (!Resolve(entity, ref component, false))
|
||||
return Array.Empty<EntityUid>();
|
||||
@@ -141,7 +141,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
if (!xformQuery.TryGetComponent(entity, out var entityXform))
|
||||
yield break;
|
||||
|
||||
foreach (var comp in _lookup.GetComponentsInRange<FactionComponent>(entityXform.MapPosition, range))
|
||||
foreach (var comp in _lookup.GetComponentsInRange<NpcFactionMemberComponent>(entityXform.MapPosition, range))
|
||||
{
|
||||
if (comp.Owner == entity)
|
||||
continue;
|
||||
@@ -153,7 +153,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEntityFriendly(EntityUid uidA, EntityUid uidB, FactionComponent? factionA = null, FactionComponent? factionB = null)
|
||||
public bool IsEntityFriendly(EntityUid uidA, EntityUid uidB, NpcFactionMemberComponent? factionA = null, NpcFactionMemberComponent? factionB = null)
|
||||
{
|
||||
if (!Resolve(uidA, ref factionA, false) || !Resolve(uidB, ref factionB, false))
|
||||
return false;
|
||||
@@ -166,7 +166,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
return _factions[target].Friendly.Contains(with) && _factions[with].Friendly.Contains(target);
|
||||
}
|
||||
|
||||
public bool IsFactionFriendly(string target, EntityUid with, FactionComponent? factionWith = null)
|
||||
public bool IsFactionFriendly(string target, EntityUid with, NpcFactionMemberComponent? factionWith = null)
|
||||
{
|
||||
if (!Resolve(with, ref factionWith, false))
|
||||
return false;
|
||||
@@ -180,7 +180,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
return _factions[target].Hostile.Contains(with) && _factions[with].Hostile.Contains(target);
|
||||
}
|
||||
|
||||
public bool IsFactionHostile(string target, EntityUid with, FactionComponent? factionWith = null)
|
||||
public bool IsFactionHostile(string target, EntityUid with, NpcFactionMemberComponent? factionWith = null)
|
||||
{
|
||||
if (!Resolve(with, ref factionWith, false))
|
||||
return false;
|
||||
@@ -220,7 +220,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
{
|
||||
_factions.Clear();
|
||||
|
||||
foreach (var faction in _protoManager.EnumeratePrototypes<FactionPrototype>())
|
||||
foreach (var faction in _protoManager.EnumeratePrototypes<NpcFactionPrototype>())
|
||||
{
|
||||
_factions[faction.ID] = new FactionData()
|
||||
{
|
||||
@@ -229,7 +229,7 @@ public sealed class FactionSystem : EntitySystem
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var comp in EntityQuery<FactionComponent>(true))
|
||||
foreach (var comp in EntityQuery<NpcFactionMemberComponent>(true))
|
||||
{
|
||||
comp.FriendlyFactions.Clear();
|
||||
comp.HostileFactions.Clear();
|
||||
Reference in New Issue
Block a user