Sentry turrets - Part 4: The sentry turret and its primary systems (#35123)

* Initial commit

* Removed mention of StationAiTurretComponent (for now)

* Prep for moving out of draft

* Fixing merge conflict

* Re-added new net frequencies to AI turrets

* Removed turret control content

* Removed unintended change

* Final tweaks

* Fixed incorrect file name

* Improvement to fire mode handling

* Addressed review comments

* Updated how turret wire panel auto-closing is handled

* Ranged NPCs no longer waste shots on stunned targets

* Fixed bug in tracking broken state

* Addressed review comments

* Bug fix

* Removed unnecessary event call
This commit is contained in:
chromiumboy
2025-03-29 12:55:58 -05:00
committed by GitHub
parent 587afe7598
commit dfd3e36a0a
24 changed files with 1005 additions and 30 deletions

View File

@@ -1,7 +1,8 @@
using System.Linq;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components;
@@ -14,12 +15,14 @@ public sealed class BatteryWeaponFireModesSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ActivateInWorldEvent>(OnInteractHandEvent);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, UseInHandEvent>(OnUseInHandEvent);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ExaminedEvent>(OnExamined);
}
@@ -44,12 +47,15 @@ public sealed class BatteryWeaponFireModesSystem : EntitySystem
private void OnGetVerb(EntityUid uid, BatteryWeaponFireModesComponent component, GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract)
return;
if (component.FireModes.Count < 2)
return;
if (!_accessReaderSystem.IsAllowed(args.User, uid))
return;
for (var i = 0; i < component.FireModes.Count; i++)
{
var fireMode = component.FireModes[i];
@@ -62,11 +68,11 @@ public sealed class BatteryWeaponFireModesSystem : EntitySystem
Category = VerbCategory.SelectType,
Text = entProto.Name,
Disabled = i == component.CurrentFireMode,
Impact = LogImpact.Low,
Impact = LogImpact.Medium,
DoContactInteraction = true,
Act = () =>
{
SetFireMode(uid, component, index, args.User);
TrySetFireMode(uid, component, index, args.User);
}
};
@@ -74,24 +80,31 @@ public sealed class BatteryWeaponFireModesSystem : EntitySystem
}
}
private void OnInteractHandEvent(EntityUid uid, BatteryWeaponFireModesComponent component, ActivateInWorldEvent args)
private void OnUseInHandEvent(EntityUid uid, BatteryWeaponFireModesComponent component, UseInHandEvent args)
{
if (!args.Complex)
return;
if (component.FireModes.Count < 2)
return;
CycleFireMode(uid, component, args.User);
TryCycleFireMode(uid, component, args.User);
}
private void CycleFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, EntityUid user)
public void TryCycleFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, EntityUid? user = null)
{
if (component.FireModes.Count < 2)
return;
var index = (component.CurrentFireMode + 1) % component.FireModes.Count;
TrySetFireMode(uid, component, index, user);
}
public bool TrySetFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, int index, EntityUid? user = null)
{
if (index < 0 || index >= component.FireModes.Count)
return false;
if (user != null && !_accessReaderSystem.IsAllowed(user.Value, uid))
return false;
SetFireMode(uid, component, index, user);
return true;
}
private void SetFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, int index, EntityUid? user = null)
@@ -100,26 +113,30 @@ public sealed class BatteryWeaponFireModesSystem : EntitySystem
component.CurrentFireMode = index;
Dirty(uid, component);
if (_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var prototype))
{
if (TryComp<AppearanceComponent>(uid, out var appearance))
_appearanceSystem.SetData(uid, BatteryWeaponFireModeVisuals.State, prototype.ID, appearance);
if (user != null)
_popupSystem.PopupClient(Loc.GetString("gun-set-fire-mode", ("mode", prototype.Name)), uid, user.Value);
}
if (TryComp(uid, out ProjectileBatteryAmmoProviderComponent? projectileBatteryAmmoProviderComponent))
{
if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var prototype))
return;
// TODO: Have this get the info directly from the batteryComponent when power is moved to shared.
var OldFireCost = projectileBatteryAmmoProviderComponent.FireCost;
projectileBatteryAmmoProviderComponent.Prototype = fireMode.Prototype;
projectileBatteryAmmoProviderComponent.FireCost = fireMode.FireCost;
float FireCostDiff = (float)fireMode.FireCost / (float)OldFireCost;
projectileBatteryAmmoProviderComponent.Shots = (int)Math.Round(projectileBatteryAmmoProviderComponent.Shots/FireCostDiff);
projectileBatteryAmmoProviderComponent.Capacity = (int)Math.Round(projectileBatteryAmmoProviderComponent.Capacity/FireCostDiff);
projectileBatteryAmmoProviderComponent.Shots = (int)Math.Round(projectileBatteryAmmoProviderComponent.Shots / FireCostDiff);
projectileBatteryAmmoProviderComponent.Capacity = (int)Math.Round(projectileBatteryAmmoProviderComponent.Capacity / FireCostDiff);
Dirty(uid, projectileBatteryAmmoProviderComponent);
var updateClientAmmoEvent = new UpdateClientAmmoEvent();
RaiseLocalEvent(uid, ref updateClientAmmoEvent);
if (user != null)
{
_popupSystem.PopupClient(Loc.GetString("gun-set-fire-mode", ("mode", prototype.Name)), uid, user.Value);
}
}
}
}