Cleanup factions code (#11075)
Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -84,7 +84,7 @@ namespace Content.Client.Entry
|
|||||||
prototypes.RegisterIgnore("htnCompound");
|
prototypes.RegisterIgnore("htnCompound");
|
||||||
prototypes.RegisterIgnore("htnPrimitive");
|
prototypes.RegisterIgnore("htnPrimitive");
|
||||||
prototypes.RegisterIgnore("gameMap");
|
prototypes.RegisterIgnore("gameMap");
|
||||||
prototypes.RegisterIgnore("behaviorSet");
|
prototypes.RegisterIgnore("faction");
|
||||||
prototypes.RegisterIgnore("lobbyBackground");
|
prototypes.RegisterIgnore("lobbyBackground");
|
||||||
prototypes.RegisterIgnore("advertisementsPack");
|
prototypes.RegisterIgnore("advertisementsPack");
|
||||||
prototypes.RegisterIgnore("metabolizerType");
|
prototypes.RegisterIgnore("metabolizerType");
|
||||||
|
|||||||
@@ -45,11 +45,12 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
|||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
[Dependency] private readonly IMapLoader _mapLoader = default!;
|
[Dependency] private readonly IMapLoader _mapLoader = default!;
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
[Dependency] private readonly IPlayerManager _playerSystem = default!;
|
||||||
|
[Dependency] private readonly FactionSystem _faction = default!;
|
||||||
[Dependency] private readonly StationSpawningSystem _stationSpawningSystem = default!;
|
[Dependency] private readonly StationSpawningSystem _stationSpawningSystem = default!;
|
||||||
[Dependency] private readonly StationSystem _stationSystem = default!;
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
||||||
[Dependency] private readonly ShuttleSystem _shuttleSystem = default!;
|
[Dependency] private readonly ShuttleSystem _shuttleSystem = default!;
|
||||||
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
|
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
|
||||||
[Dependency] private readonly IPlayerManager _playerSystem = default!;
|
|
||||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||||
|
|
||||||
|
|
||||||
@@ -667,9 +668,8 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
|||||||
if(_startingGearPrototypes.TryGetValue(gear, out var gearPrototype))
|
if(_startingGearPrototypes.TryGetValue(gear, out var gearPrototype))
|
||||||
_stationSpawningSystem.EquipStartingGear(mob, gearPrototype, null);
|
_stationSpawningSystem.EquipStartingGear(mob, gearPrototype, null);
|
||||||
|
|
||||||
var faction = EnsureComp<AiFactionTagComponent>(mob);
|
_faction.RemoveFaction(mob, "NanoTrasen", false);
|
||||||
faction.Factions |= Faction.Syndicate;
|
_faction.AddFaction(mob, "Syndicate", true);
|
||||||
faction.Factions &= ~Faction.NanoTrasen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SpawnOperatives(int spawnCount, List<IPlayerSession> sessions, bool addSpawnPoints)
|
private void SpawnOperatives(int spawnCount, List<IPlayerSession> sessions, bool addSpawnPoints)
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using Content.Server.Administration;
|
|
||||||
using Content.Server.NPC.Systems;
|
|
||||||
using Content.Shared.Administration;
|
|
||||||
using Robust.Shared.Console;
|
|
||||||
|
|
||||||
namespace Content.Server.NPC.Commands
|
|
||||||
{
|
|
||||||
[AdminCommand(AdminFlags.Fun)]
|
|
||||||
public sealed class FactionCommand : IConsoleCommand
|
|
||||||
{
|
|
||||||
public string Command => "factions";
|
|
||||||
public string Description => Loc.GetString("faction-command-description");
|
|
||||||
public string Help => Loc.GetString("faction-command-help-text");
|
|
||||||
|
|
||||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
||||||
{
|
|
||||||
if (args.Length == 0)
|
|
||||||
{
|
|
||||||
var result = new StringBuilder();
|
|
||||||
foreach (Faction value in Enum.GetValues(typeof(Faction)))
|
|
||||||
{
|
|
||||||
if (value == Faction.None)
|
|
||||||
continue;
|
|
||||||
result.Append(value + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
shell.WriteLine(result.ToString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Length < 2)
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("shell-wrong-arguments-number"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Enum.TryParse(args[0], true, out Faction faction))
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("faction-command-invalid-faction-error"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Faction targetFaction;
|
|
||||||
|
|
||||||
switch (args[1])
|
|
||||||
{
|
|
||||||
case "friendly":
|
|
||||||
if (args.Length < 3)
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("faction-command-no-target-faction-error"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Enum.TryParse(args[2], true, out targetFaction))
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("faction-command-invalid-target-faction-error"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntitySystem.Get<AiFactionTagSystem>().MakeFriendly(faction, targetFaction);
|
|
||||||
shell.WriteLine(Loc.GetString("shell-command-success"));
|
|
||||||
break;
|
|
||||||
case "hostile":
|
|
||||||
if (args.Length < 3)
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("faction-command-no-target-faction-error"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Enum.TryParse(args[2], true, out targetFaction))
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("faction-command-invalid-target-faction-error"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntitySystem.Get<AiFactionTagSystem>().MakeHostile(faction, targetFaction);
|
|
||||||
shell.WriteLine(Loc.GetString("shell-command-success"));
|
|
||||||
break;
|
|
||||||
case "list":
|
|
||||||
shell.WriteLine(EntitySystem.Get<AiFactionTagSystem>().GetHostileFactions(faction).ToString());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
shell.WriteLine(Loc.GetString("faction-command-unknown-faction-argument-error"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.NPC.Components
|
|
||||||
{
|
|
||||||
[Prototype("aiFaction")]
|
|
||||||
public sealed class AiFactionPrototype : IPrototype
|
|
||||||
{
|
|
||||||
// These are immutable so any dynamic changes aren't saved back over.
|
|
||||||
// AiFactionSystem will just read these and then store them.
|
|
||||||
[ViewVariables]
|
|
||||||
[IdDataField]
|
|
||||||
public string ID { get; } = default!;
|
|
||||||
|
|
||||||
[DataField("hostile")]
|
|
||||||
public IReadOnlyList<string> Hostile { get; private set; } = new List<string>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using Content.Server.NPC.Systems;
|
|
||||||
|
|
||||||
namespace Content.Server.NPC.Components
|
|
||||||
{
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class AiFactionTagComponent : Component
|
|
||||||
{
|
|
||||||
[DataField("factions")]
|
|
||||||
public Faction Factions { get; set; } = Faction.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
29
Content.Server/NPC/Components/FactionComponent.cs
Normal file
29
Content.Server/NPC/Components/FactionComponent.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using Content.Server.NPC.Systems;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||||
|
|
||||||
|
namespace Content.Server.NPC.Components
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
[Access(typeof(FactionSystem))]
|
||||||
|
public sealed class FactionComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Factions this entity is a part of.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite),
|
||||||
|
DataField("factions", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<FactionPrototype>))]
|
||||||
|
public HashSet<string> Factions = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cached friendly factions.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public readonly HashSet<string> FriendlyFactions = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cached hostile factions.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public readonly HashSet<string> HostileFactions = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
Content.Server/NPC/Components/FactionPrototype.cs
Normal file
23
Content.Server/NPC/Components/FactionPrototype.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
[ViewVariables]
|
||||||
|
[IdDataField]
|
||||||
|
public string ID { get; } = default!;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField("friendly", customTypeSerializer:typeof(PrototypeIdListSerializer<FactionPrototype>))]
|
||||||
|
public List<string> Friendly = new();
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField("hostile", customTypeSerializer:typeof(PrototypeIdListSerializer<FactionPrototype>))]
|
||||||
|
public List<string> Hostile = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Content.Server/NPC/FactionData.cs
Normal file
13
Content.Server/NPC/FactionData.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Content.Server.NPC;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cached data for the faction prototype. Can be modified at runtime.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class FactionData
|
||||||
|
{
|
||||||
|
[ViewVariables]
|
||||||
|
public HashSet<string> Friendly = new();
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public HashSet<string> Hostile = new();
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
|
|||||||
public abstract class NPCCombatOperator : HTNOperator
|
public abstract class NPCCombatOperator : HTNOperator
|
||||||
{
|
{
|
||||||
[Dependency] protected readonly IEntityManager EntManager = default!;
|
[Dependency] protected readonly IEntityManager EntManager = default!;
|
||||||
private AiFactionTagSystem _tags = default!;
|
private FactionSystem _tags = default!;
|
||||||
protected InteractionSystem Interaction = default!;
|
protected InteractionSystem Interaction = default!;
|
||||||
|
|
||||||
[ViewVariables, DataField("key")] public string Key = "CombatTarget";
|
[ViewVariables, DataField("key")] public string Key = "CombatTarget";
|
||||||
@@ -24,7 +24,7 @@ public abstract class NPCCombatOperator : HTNOperator
|
|||||||
public override void Initialize(IEntitySystemManager sysManager)
|
public override void Initialize(IEntitySystemManager sysManager)
|
||||||
{
|
{
|
||||||
base.Initialize(sysManager);
|
base.Initialize(sysManager);
|
||||||
_tags = sysManager.GetEntitySystem<AiFactionTagSystem>();
|
_tags = sysManager.GetEntitySystem<FactionSystem>();
|
||||||
Interaction = sysManager.GetEntitySystem<InteractionSystem>();
|
Interaction = sysManager.GetEntitySystem<InteractionSystem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
using Content.Server.NPC.Components;
|
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.NPC.Systems
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Outlines faction relationships with each other for AI.
|
|
||||||
/// </summary>
|
|
||||||
public sealed class AiFactionTagSystem : EntitySystem
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Currently factions are implicitly friendly if they are not hostile.
|
|
||||||
* This may change where specified friendly factions are listed. (e.g. to get number of friendlies in area).
|
|
||||||
*/
|
|
||||||
|
|
||||||
private readonly Dictionary<Faction, Faction> _hostileFactions = new();
|
|
||||||
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
|
||||||
|
|
||||||
foreach (var faction in protoManager.EnumeratePrototypes<AiFactionPrototype>())
|
|
||||||
{
|
|
||||||
if (Enum.TryParse(faction.ID, out Faction @enum))
|
|
||||||
{
|
|
||||||
var parsedFaction = Faction.None;
|
|
||||||
|
|
||||||
foreach (var hostile in faction.Hostile)
|
|
||||||
{
|
|
||||||
if (Enum.TryParse(hostile, out Faction parsedHostile))
|
|
||||||
{
|
|
||||||
parsedFaction |= parsedHostile;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.Error($"Unable to parse hostile faction {hostile} for {faction.ID}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_hostileFactions[@enum] = parsedFaction;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.Error($"Unable to parse AI faction {faction.ID}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Faction GetHostileFactions(Faction faction) => _hostileFactions.TryGetValue(faction, out var hostiles) ? hostiles : Faction.None;
|
|
||||||
|
|
||||||
public Faction GetFactions(EntityUid entity) =>
|
|
||||||
EntityManager.TryGetComponent(entity, out AiFactionTagComponent? factionTags)
|
|
||||||
? factionTags.Factions
|
|
||||||
: Faction.None;
|
|
||||||
|
|
||||||
public IEnumerable<EntityUid> GetNearbyHostiles(EntityUid entity, float range)
|
|
||||||
{
|
|
||||||
var ourFaction = GetFactions(entity);
|
|
||||||
var hostile = GetHostileFactions(ourFaction);
|
|
||||||
if (ourFaction == Faction.None || hostile == Faction.None)
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Yes I know this system is shithouse
|
|
||||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
|
||||||
var xform = xformQuery.GetComponent(entity);
|
|
||||||
|
|
||||||
foreach (var component in EntityManager.EntityQuery<AiFactionTagComponent>(true))
|
|
||||||
{
|
|
||||||
if ((component.Factions & hostile) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!xformQuery.TryGetComponent(component.Owner, out var targetXform))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (targetXform.MapID != xform.MapID)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!targetXform.Coordinates.InRange(EntityManager, xform.Coordinates, range))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
yield return component.Owner;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MakeFriendly(Faction source, Faction target)
|
|
||||||
{
|
|
||||||
if (!_hostileFactions.TryGetValue(source, out var hostileFactions))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hostileFactions &= ~target;
|
|
||||||
_hostileFactions[source] = hostileFactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MakeHostile(Faction source, Faction target)
|
|
||||||
{
|
|
||||||
if (!_hostileFactions.TryGetValue(source, out var hostileFactions))
|
|
||||||
{
|
|
||||||
_hostileFactions[source] = target;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hostileFactions |= target;
|
|
||||||
_hostileFactions[source] = hostileFactions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum Faction
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Dragon = 1 << 0,
|
|
||||||
NanoTrasen = 1 << 1,
|
|
||||||
SimpleHostile = 1 << 2,
|
|
||||||
SimpleNeutral = 1 << 3,
|
|
||||||
Syndicate = 1 << 4,
|
|
||||||
Xeno = 1 << 5,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
207
Content.Server/NPC/Systems/FactionSystem.cs
Normal file
207
Content.Server/NPC/Systems/FactionSystem.cs
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using Content.Server.NPC.Components;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
|
namespace Content.Server.NPC.Systems
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Outlines faction relationships with each other.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class FactionSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||||
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
|
|
||||||
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To avoid prototype mutability we store an intermediary data class that gets used instead.
|
||||||
|
/// </summary>
|
||||||
|
private Dictionary<string, FactionData> _factions = new();
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
_sawmill = Logger.GetSawmill("faction");
|
||||||
|
SubscribeLocalEvent<FactionComponent, ComponentStartup>(OnFactionStartup);
|
||||||
|
_protoManager.PrototypesReloaded += OnProtoReload;
|
||||||
|
RefreshFactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
_protoManager.PrototypesReloaded -= OnProtoReload;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnProtoReload(PrototypesReloadedEventArgs obj)
|
||||||
|
{
|
||||||
|
RefreshFactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFactionStartup(EntityUid uid, FactionComponent component, ComponentStartup args)
|
||||||
|
{
|
||||||
|
RefreshFactions(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refreshes the cached factions for this component.
|
||||||
|
/// </summary>
|
||||||
|
private void RefreshFactions(FactionComponent component)
|
||||||
|
{
|
||||||
|
foreach (var faction in component.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds this entity to the particular faction.
|
||||||
|
/// </summary>
|
||||||
|
public void AddFaction(EntityUid uid, string faction, bool dirty = true)
|
||||||
|
{
|
||||||
|
if (!_protoManager.HasIndex<FactionPrototype>(faction))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Unable to find faction {faction}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var comp = EnsureComp<FactionComponent>(uid);
|
||||||
|
if (!comp.Factions.Add(faction))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (dirty)
|
||||||
|
{
|
||||||
|
RefreshFactions(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes this entity from the particular faction.
|
||||||
|
/// </summary>
|
||||||
|
public void RemoveFaction(EntityUid uid, string faction, bool dirty = true)
|
||||||
|
{
|
||||||
|
if (!_protoManager.HasIndex<FactionPrototype>(faction))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Unable to find faction {faction}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryComp<FactionComponent>(uid, out var component))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!component.Factions.Remove(faction))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (dirty)
|
||||||
|
{
|
||||||
|
RefreshFactions(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EntityUid> GetNearbyHostiles(EntityUid entity, float range, FactionComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(entity, ref component, false))
|
||||||
|
return Array.Empty<EntityUid>();
|
||||||
|
|
||||||
|
return GetNearbyFactions(entity, range, component.HostileFactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EntityUid> GetNearbyFriendlies(EntityUid entity, float range, FactionComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(entity, ref component, false))
|
||||||
|
return Array.Empty<EntityUid>();
|
||||||
|
|
||||||
|
return GetNearbyFactions(entity, range, component.FriendlyFactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<EntityUid> GetNearbyFactions(EntityUid entity, float range, HashSet<string> factions)
|
||||||
|
{
|
||||||
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
|
if (!xformQuery.TryGetComponent(entity, out var entityXform))
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
foreach (var comp in _lookup.GetComponentsInRange<FactionComponent>(entityXform.MapPosition, range))
|
||||||
|
{
|
||||||
|
if (comp.Owner == entity)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!factions.Overlaps(comp.Factions))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
yield return comp.Owner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the source faction friendly to the target faction, 1-way.
|
||||||
|
/// </summary>
|
||||||
|
public void MakeFriendly(string source, string target)
|
||||||
|
{
|
||||||
|
if (!_factions.TryGetValue(source, out var sourceFaction))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Unable to find faction {source}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_factions.ContainsKey(target))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Unable to find faction {target}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceFaction.Friendly.Add(target);
|
||||||
|
sourceFaction.Hostile.Remove(target);
|
||||||
|
RefreshFactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshFactions()
|
||||||
|
{
|
||||||
|
_factions.Clear();
|
||||||
|
|
||||||
|
foreach (var faction in _protoManager.EnumeratePrototypes<FactionPrototype>())
|
||||||
|
{
|
||||||
|
_factions[faction.ID] = new FactionData()
|
||||||
|
{
|
||||||
|
Friendly = faction.Friendly.ToHashSet(),
|
||||||
|
Hostile = faction.Hostile.ToHashSet(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var comp in EntityQuery<FactionComponent>(true))
|
||||||
|
{
|
||||||
|
comp.FriendlyFactions.Clear();
|
||||||
|
comp.HostileFactions.Clear();
|
||||||
|
RefreshFactions(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the source faction hostile to the target faction, 1-way.
|
||||||
|
/// </summary>
|
||||||
|
public void MakeHostile(string source, string target)
|
||||||
|
{
|
||||||
|
if (!_factions.TryGetValue(source, out var sourceFaction))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Unable to find faction {source}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_factions.ContainsKey(target))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Unable to find faction {target}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceFaction.Friendly.Remove(target);
|
||||||
|
sourceFaction.Hostile.Add(target);
|
||||||
|
RefreshFactions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
faction-command-no-target-faction-error = Need to supply a target faction
|
|
||||||
faction-command-unknown-faction-argument-error = Unknown faction argument
|
|
||||||
|
|
||||||
faction-command-description = Update / list factional relationships for NPCs.
|
|
||||||
faction-command-help-text = faction <source> <friendly/hostile> target
|
|
||||||
faction <source> list: hostile factions
|
|
||||||
faction-command-invalid-faction-error = Invalid faction
|
|
||||||
faction-command-invalid-target-faction-error = Invalid target faction
|
|
||||||
@@ -143,7 +143,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: SimpleHostileCompound
|
rootTask: SimpleHostileCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Bloodstream
|
- type: Bloodstream
|
||||||
@@ -668,7 +668,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: SimpleHostileCompound
|
rootTask: SimpleHostileCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
|
|
||||||
@@ -1151,7 +1151,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: SimpleHostileCompound
|
rootTask: SimpleHostileCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Syndicate
|
- Syndicate
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
@@ -1309,7 +1309,7 @@
|
|||||||
id: MobGiantSpiderAngry
|
id: MobGiantSpiderAngry
|
||||||
suffix: Angry
|
suffix: Angry
|
||||||
components:
|
components:
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Xeno
|
- Xeno
|
||||||
- type: InputMover
|
- type: InputMover
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
components:
|
components:
|
||||||
- type: InputMover
|
- type: InputMover
|
||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: SimpleHostileCompound
|
rootTask: SimpleHostileCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: Loadout
|
- type: Loadout
|
||||||
prototype: PassengerGear
|
prototype: PassengerGear
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
id: MobSpirate
|
id: MobSpirate
|
||||||
description: Yarr!
|
description: Yarr!
|
||||||
components:
|
components:
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Syndicate
|
- Syndicate
|
||||||
- type: InputMover
|
- type: InputMover
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
- FootstepSound
|
- FootstepSound
|
||||||
- type: InputMover
|
- type: InputMover
|
||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Hands
|
- type: Hands
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: SimpleHostileCompound
|
rootTask: SimpleHostileCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: InteractionPopup
|
- type: InteractionPopup
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
groups:
|
groups:
|
||||||
Flammable: [Touch]
|
Flammable: [Touch]
|
||||||
Extinguish: [Touch]
|
Extinguish: [Touch]
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
@@ -177,7 +177,7 @@
|
|||||||
groups:
|
groups:
|
||||||
Flammable: [Touch]
|
Flammable: [Touch]
|
||||||
Extinguish: [Touch]
|
Extinguish: [Touch]
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
netsync: false
|
netsync: false
|
||||||
- type: Recyclable
|
- type: Recyclable
|
||||||
safe: false
|
safe: false
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleNeutral
|
- SimpleNeutral
|
||||||
- type: HealthExaminable
|
- type: HealthExaminable
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
rootTask: IdleCompound
|
rootTask: IdleCompound
|
||||||
- type: Input
|
- type: Input
|
||||||
context: "human"
|
context: "human"
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleNeutral
|
- SimpleNeutral
|
||||||
- type: MovementSpeedModifier
|
- type: MovementSpeedModifier
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
components:
|
components:
|
||||||
- type: InputMover
|
- type: InputMover
|
||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
groups:
|
groups:
|
||||||
Flammable: [Touch]
|
Flammable: [Touch]
|
||||||
Extinguish: [Touch]
|
Extinguish: [Touch]
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Xeno
|
- Xeno
|
||||||
- type: Hands
|
- type: Hands
|
||||||
@@ -357,7 +357,7 @@
|
|||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: SimpleHostileCompound
|
rootTask: SimpleHostileCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Xeno
|
- Xeno
|
||||||
- type: MeleeWeapon
|
- type: MeleeWeapon
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
description: Call in 3 carp rifts and take over this quadrant! You have only 5 minutes in between each rift before you will disappear.
|
description: Call in 3 carp rifts and take over this quadrant! You have only 5 minutes in between each rift before you will disappear.
|
||||||
- type: HTN
|
- type: HTN
|
||||||
rootTask: XenoCompound
|
rootTask: XenoCompound
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Dragon
|
- Dragon
|
||||||
- type: Speech
|
- type: Speech
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
- type: CameraRecoil
|
- type: CameraRecoil
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
- type: CanHostGuardian
|
- type: CanHostGuardian
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
Slash: 7
|
Slash: 7
|
||||||
- type: InputMover
|
- type: InputMover
|
||||||
- type: MobMover
|
- type: MobMover
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- SimpleNeutral
|
- SimpleNeutral
|
||||||
- type: InteractionPopup
|
- type: InteractionPopup
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
- type: CameraRecoil
|
- type: CameraRecoil
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
- type: CanHostGuardian
|
- type: CanHostGuardian
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
- type: CameraRecoil
|
- type: CameraRecoil
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
- type: CanHostGuardian
|
- type: CanHostGuardian
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
- type: Respirator
|
- type: Respirator
|
||||||
|
|||||||
@@ -23,6 +23,6 @@
|
|||||||
- type: CameraRecoil
|
- type: CameraRecoil
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
- type: CanHostGuardian
|
- type: CanHostGuardian
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
|
|||||||
@@ -22,6 +22,6 @@
|
|||||||
- type: CameraRecoil
|
- type: CameraRecoil
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
- type: CanHostGuardian
|
- type: CanHostGuardian
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
- type: CameraRecoil
|
- type: CameraRecoil
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
- type: CanHostGuardian
|
- type: CanHostGuardian
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
- type: Respirator
|
- type: Respirator
|
||||||
|
|||||||
@@ -72,6 +72,6 @@
|
|||||||
blackboard:
|
blackboard:
|
||||||
SoundTargetInLOS: !type:SoundPathSpecifier
|
SoundTargetInLOS: !type:SoundPathSpecifier
|
||||||
path: /Audio/Effects/double_beep.ogg
|
path: /Audio/Effects/double_beep.ogg
|
||||||
- type: AiFactionTag
|
- type: Faction
|
||||||
factions:
|
factions:
|
||||||
- Syndicate
|
- Syndicate
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
- type: aiFaction
|
- type: faction
|
||||||
id: Dragon
|
id: Dragon
|
||||||
hostile:
|
hostile:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
- Syndicate
|
- Syndicate
|
||||||
- Xeno
|
- Xeno
|
||||||
|
|
||||||
- type: aiFaction
|
- type: faction
|
||||||
id: NanoTrasen
|
id: NanoTrasen
|
||||||
hostile:
|
hostile:
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- Syndicate
|
- Syndicate
|
||||||
- Xeno
|
- Xeno
|
||||||
|
|
||||||
- type: aiFaction
|
- type: faction
|
||||||
id: SimpleHostile
|
id: SimpleHostile
|
||||||
hostile:
|
hostile:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
- Syndicate
|
- Syndicate
|
||||||
|
|
||||||
- type: aiFaction
|
- type: faction
|
||||||
id: SimpleNeutral
|
id: SimpleNeutral
|
||||||
|
|
||||||
- type: aiFaction
|
- type: faction
|
||||||
id: Syndicate
|
id: Syndicate
|
||||||
hostile:
|
hostile:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
- SimpleHostile
|
- SimpleHostile
|
||||||
- Xeno
|
- Xeno
|
||||||
|
|
||||||
- type: aiFaction
|
- type: faction
|
||||||
id: Xeno
|
id: Xeno
|
||||||
hostile:
|
hostile:
|
||||||
- NanoTrasen
|
- NanoTrasen
|
||||||
|
|||||||
Reference in New Issue
Block a user