Files
tbd-station-14/Content.Shared/Weapons/Ranged/Systems/BatteryWeaponFireModesSystem.cs
BramvanZijp ce9fc82382 Rework the HoS's Energy Shotgun (Varying energy consumption depending on fire-mode + re-adds a toned down self recharge.) (#32104)
* Rebalance HoS's Energy Shotgun

* SLIGHTLY Up the max charge so the gun properly recharges all of its charges, which matters a lot more with the self charge cooldown system.

* Prevent recharge cooldown if 0 power is used.

* Makes the clientside HUD actually update to reflect the changes in firecost and thus max/current charges.

* Properly fix that recharging to just under full issue instead of applying a budget fix to only the eshotgun.

* Clean up the client ammo UI fix.

* Update the self recharger component to comply with maintainer request.

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Remove code that was made redundant by a hotfix from another PR.

* Make the recharge pause on EMP, document things where needed, clean up code as per maintainer request, add a note to make the code better when power is moved to shared.

* Fix another internal issue

* Code cleanup + fix the rapid recharge verb to remove pause.

* cleanup

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-12-11 17:21:04 +01:00

126 lines
4.6 KiB
C#

using System.Linq;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Prototypes;
namespace Content.Shared.Weapons.Ranged.Systems;
public sealed class BatteryWeaponFireModesSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ActivateInWorldEvent>(OnInteractHandEvent);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ExaminedEvent>(OnExamined);
}
private void OnExamined(EntityUid uid, BatteryWeaponFireModesComponent component, ExaminedEvent args)
{
if (component.FireModes.Count < 2)
return;
var fireMode = GetMode(component);
if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var proto))
return;
args.PushMarkup(Loc.GetString("gun-set-fire-mode", ("mode", proto.Name)));
}
private BatteryWeaponFireMode GetMode(BatteryWeaponFireModesComponent component)
{
return component.FireModes[component.CurrentFireMode];
}
private void OnGetVerb(EntityUid uid, BatteryWeaponFireModesComponent component, GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
return;
if (component.FireModes.Count < 2)
return;
for (var i = 0; i < component.FireModes.Count; i++)
{
var fireMode = component.FireModes[i];
var entProto = _prototypeManager.Index<EntityPrototype>(fireMode.Prototype);
var index = i;
var v = new Verb
{
Priority = 1,
Category = VerbCategory.SelectType,
Text = entProto.Name,
Disabled = i == component.CurrentFireMode,
Impact = LogImpact.Low,
DoContactInteraction = true,
Act = () =>
{
SetFireMode(uid, component, index, args.User);
}
};
args.Verbs.Add(v);
}
}
private void OnInteractHandEvent(EntityUid uid, BatteryWeaponFireModesComponent component, ActivateInWorldEvent args)
{
if (!args.Complex)
return;
if (component.FireModes.Count < 2)
return;
CycleFireMode(uid, component, args.User);
}
private void CycleFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, EntityUid user)
{
if (component.FireModes.Count < 2)
return;
var index = (component.CurrentFireMode + 1) % component.FireModes.Count;
SetFireMode(uid, component, index, user);
}
private void SetFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, int index, EntityUid? user = null)
{
var fireMode = component.FireModes[index];
component.CurrentFireMode = index;
Dirty(uid, component);
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);
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);
}
}
}
}