Files
wwdpublic/Content.Shared/TurretController/SharedDeployableTurretControllerSystem.cs
Solaris a64b5164e3 Port AI Sentry Turrets (#1990)
# 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)
2025-03-21 18:28:40 +03:00

92 lines
3.7 KiB
C#

using Content.Shared.Access;
using Content.Shared.Access.Systems;
using Content.Shared.Popups;
using Content.Shared.Turrets;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
namespace Content.Shared.TurretController;
public abstract partial class SharedDeployableTurretControllerSystem : EntitySystem
{
[Dependency] private readonly AccessReaderSystem _accessreader = default!;
[Dependency] private readonly TurretTargetSettingsSystem _turretTargetingSettings = default!;
[Dependency] private readonly SharedUserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
// Handling of client messages
SubscribeLocalEvent<DeployableTurretControllerComponent, DeployableTurretArmamentSettingChangedMessage>(OnArmamentSettingChanged);
SubscribeLocalEvent<DeployableTurretControllerComponent, DeployableTurretExemptAccessLevelChangedMessage>(OnExemptAccessLevelsChanged);
}
private void OnArmamentSettingChanged(Entity<DeployableTurretControllerComponent> ent, ref DeployableTurretArmamentSettingChangedMessage args)
{
if (IsUserAllowedAccess(ent, args.Actor))
ChangeArmamentSetting(ent, args.ArmamentState, args.Actor);
if (_userInterfaceSystem.TryGetOpenUi(ent.Owner, DeployableTurretControllerUiKey.Key, out var bui))
bui.Update<DeployableTurretControllerBoundInterfaceState>();
}
private void OnExemptAccessLevelsChanged(Entity<DeployableTurretControllerComponent> ent, ref DeployableTurretExemptAccessLevelChangedMessage args)
{
if (IsUserAllowedAccess(ent, args.Actor))
ChangeExemptAccessLevels(ent, args.AccessLevels, args.Enabled, args.Actor);
if (_userInterfaceSystem.TryGetOpenUi(ent.Owner, DeployableTurretControllerUiKey.Key, out var bui))
bui.Update<DeployableTurretControllerBoundInterfaceState>();
}
protected virtual void ChangeArmamentSetting(Entity<DeployableTurretControllerComponent> ent, int armamentState, EntityUid? user = null)
{
ent.Comp.ArmamentState = armamentState;
Dirty(ent);
if (TryComp<AppearanceComponent>(ent, out var appearance))
_appearance.SetData(ent, TurretControllerVisuals.ControlPanel, armamentState);
// Linked turrets are updated on the server side
}
protected virtual void ChangeExemptAccessLevels
(Entity<DeployableTurretControllerComponent> ent, HashSet<ProtoId<AccessLevelPrototype>> exemptions, bool enabled, EntityUid? user = null)
{
// Update the controller
if (!TryComp<TurretTargetSettingsComponent>(ent, out var targetSettings))
return;
var controller = new Entity<TurretTargetSettingsComponent>(ent, targetSettings);
foreach (var accessLevel in exemptions)
{
if (!ent.Comp.AccessLevels.Contains(accessLevel))
continue;
_turretTargetingSettings.SetAccessLevelExemption(controller, accessLevel, enabled);
}
Dirty(controller);
// Linked turrets are updated on the server side
}
public bool IsUserAllowedAccess(Entity<DeployableTurretControllerComponent> ent, EntityUid user)
{
if (!_accessreader.IsAllowed(user, ent))
{
_popup.PopupClient(Loc.GetString("turret-controls-access-denied"), ent, user);
_audio.PlayPredicted(ent.Comp.AccessDeniedSound, ent, user);
return false;
}
return true;
}
}