mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
# Description I am trying to port over the AI turrets being implemented into wizden made by chromiumboy. It looks fantastic and would like to port this now and work on any issues that might show. --- # Original PRs https://github.com/space-wizards/space-station-14/issues/35223 https://github.com/space-wizards/space-station-14/pull/35025 https://github.com/space-wizards/space-station-14/pull/35031 https://github.com/space-wizards/space-station-14/pull/35058 https://github.com/space-wizards/space-station-14/pull/35123 https://github.com/space-wizards/space-station-14/pull/35149 https://github.com/space-wizards/space-station-14/pull/35235 https://github.com/space-wizards/space-station-14/pull/35236 --- # TODO - [x] Port all related PRs to EE. - [x] Patch any bugs with turrets or potential issues. - [x] Cleanup my shitcode or changes. --- # Changelog 🆑 - add: Added recharging sentry turrets, one is AI-based or the other is Sec can make. - add: The sentry turrets can be made after researching in T3 arsenal. The boards are made in the sec fab. - add: New ID permissions for borgs and minibots for higher turret options. - tweak: Turrets stop shooting after someone goes crit. --------- Co-authored-by: Nathaniel Adams <60526456+Nathaniel-Adams@users.noreply.github.com> (cherry picked from commit 209d0537401cbda448a03e910cca9a898c9d566f)
127 lines
5.8 KiB
C#
127 lines
5.8 KiB
C#
using Content.Shared.Access;
|
|
using Content.Shared.Access.Systems;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Shared.Turrets;
|
|
|
|
/// <summary>
|
|
/// This system is used for validating potential targets for NPCs with a <see cref="TurretTargetSettingsComponent"/> (i.e., turrets).
|
|
/// A turret will consider an entity a valid target if the entity does not possess any access tags which appear on the
|
|
/// turret's <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list.
|
|
/// </summary>
|
|
public sealed partial class TurretTargetSettingsSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
|
|
|
private ProtoId<AccessLevelPrototype> _accessLevelBorg = "Borg";
|
|
private ProtoId<AccessLevelPrototype> _accessLevelBasicSilicon = "BasicSilicon";
|
|
|
|
/// <summary>
|
|
/// Adds or removes access levels from a <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list.
|
|
/// </summary>
|
|
/// <param name="ent">The entity and its <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="exemption">The proto ID for the access level</param>
|
|
/// <param name="enabled">Set 'true' to add the exemption, or 'false' to remove it</param>
|
|
[PublicAPI]
|
|
public void SetAccessLevelExemption(TurretTargetSettingsComponent comp, ProtoId<AccessLevelPrototype> exemption, bool enabled)
|
|
{
|
|
if (enabled)
|
|
comp.ExemptAccessLevels.Add(exemption);
|
|
else
|
|
comp.ExemptAccessLevels.Remove(exemption);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds or removes a collection of access levels from a <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list.
|
|
/// </summary>
|
|
/// <param name="comp">The Component and its <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="exemption">The collection of access level proto IDs to add or remove</param>
|
|
/// <param name="enabled">Set 'true' to add the collection as exemptions, or 'false' to remove them</param>
|
|
[PublicAPI]
|
|
public void SetAccessLevelExemptions(TurretTargetSettingsComponent comp, ICollection<ProtoId<AccessLevelPrototype>> exemptions, bool enabled)
|
|
{
|
|
foreach (var exemption in exemptions)
|
|
SetAccessLevelExemption(comp, exemption, enabled);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list to contain only a supplied collection of access levels.
|
|
/// </summary>
|
|
/// <param name="comp">The component and its <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="exemptions">The supplied collection of access level proto IDs</param>
|
|
[PublicAPI]
|
|
public void SyncAccessLevelExemptions(TurretTargetSettingsComponent comp, ICollection<ProtoId<AccessLevelPrototype>> exemptions)
|
|
{
|
|
comp.ExemptAccessLevels.Clear();
|
|
SetAccessLevelExemptions(comp, exemptions, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list to match that of another.
|
|
/// </summary>
|
|
/// <param name="target">The entity this is having its exemption list updated <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="source">The entity that is being used as a template for the target</param>
|
|
[PublicAPI]
|
|
public void SyncAccessLevelExemptions(Entity<TurretTargetSettingsComponent> target, Entity<TurretTargetSettingsComponent> source)
|
|
{
|
|
SyncAccessLevelExemptions(target.Comp, source.Comp.ExemptAccessLevels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns whether a <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list contains a specific access level.
|
|
/// </summary>
|
|
/// <param name="ent">The entity and its <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="exemption">The access level proto ID being checked</param>
|
|
[PublicAPI]
|
|
public bool HasAccessLevelExemption(Entity<TurretTargetSettingsComponent> ent, ProtoId<AccessLevelPrototype> exemption)
|
|
{
|
|
if (ent.Comp.ExemptAccessLevels.Count == 0)
|
|
return false;
|
|
|
|
return ent.Comp.ExemptAccessLevels.Contains(exemption);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns whether a <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list contains one or more access levels from another collection.
|
|
/// </summary>
|
|
/// <param name="ent">The entity and its <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="exemptions"></param>
|
|
[PublicAPI]
|
|
public bool HasAnyAccessLevelExemption(Entity<TurretTargetSettingsComponent> ent, ICollection<ProtoId<AccessLevelPrototype>> exemptions)
|
|
{
|
|
if (ent.Comp.ExemptAccessLevels.Count == 0)
|
|
return false;
|
|
|
|
foreach (var exemption in exemptions)
|
|
{
|
|
if (HasAccessLevelExemption(ent, exemption))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns whether an entity is a valid target for a turret.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Returns false if the target possesses one or more access tags that are present on the entity's <see cref="TurretTargetSettingsComponent.ExemptAccessLevels"/> list.
|
|
/// </remarks>
|
|
/// <param name="ent">The entity and its <see cref="TurretTargetSettingsComponent"/></param>
|
|
/// <param name="target">The target entity</param>
|
|
[PublicAPI]
|
|
public bool EntityIsTargetForTurret(Entity<TurretTargetSettingsComponent> ent, EntityUid target)
|
|
{
|
|
var accessLevels = _accessReader.FindAccessTags(target);
|
|
|
|
if (accessLevels.Contains(_accessLevelBorg))
|
|
return !HasAccessLevelExemption(ent, _accessLevelBorg);
|
|
|
|
if (accessLevels.Contains(_accessLevelBasicSilicon))
|
|
return !HasAccessLevelExemption(ent, _accessLevelBasicSilicon);
|
|
|
|
return !HasAnyAccessLevelExemption(ent, accessLevels);
|
|
}
|
|
}
|