Files
tbd-station-14/Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs
beck-thompson d3b1178428 Radio jammer update! (#25912)
* Added selectable power level to radio jammer

* Cleaned up OnGetVerb

* Settings are now stored in the .yml file. Simplified stuff a lot!

* Minor fixes!

* Small little baby fix :)

* Added the power level switch to the examine menu and also removed the ftl file as it was in the incorrect location.

* Minor code cleanup

* Changed byte -> int

* Update sprite

* Fixed licence

* Added power LED that changes if the jammer is on low power.

* Removed tabs

* Changed github link to the commit

* Changed all the RemComp to RemComDeferred

* Moved NetworkedComponent to shared

* Changed radio jammer textures back with minor edits

* Added a space because it was annoying me

* Jammer now updates range for suit sensors properly! Thanks nikthechampiongr :)

* Removed useless comment

* Cleaned up code that updates the range of tracking devices.

* Fixed client namespace and removed newline

* Cleaned up ChangeLEDState and ChangeChargeLevel.

* Added comments

* Read only

* Fixed another comment

* Locked in

* Made server inherit shared

* Update Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs

* Update Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs

* review fixes

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-04-25 12:19:16 +10:00

79 lines
2.6 KiB
C#

using Content.Shared.Popups;
using Content.Shared.DeviceNetwork.Components;
using Content.Shared.Verbs;
using Content.Shared.RadioJammer;
namespace Content.Shared.Radio.EntitySystems;
public abstract class SharedJammerSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RadioJammerComponent, GetVerbsEvent<Verb>>(OnGetVerb);
}
private void OnGetVerb(Entity<RadioJammerComponent> entity, ref GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
var user = args.User;
byte index = 0;
foreach (var setting in entity.Comp.Settings)
{
// This is because Act wont work with index.
// Needs it to be saved in the loop.
var currIndex = index;
var verb = new Verb
{
Priority = currIndex,
Category = VerbCategory.PowerLevel,
Disabled = entity.Comp.SelectedPowerLevel == currIndex,
Act = () =>
{
entity.Comp.SelectedPowerLevel = currIndex;
if (TryComp<DeviceNetworkJammerComponent>(entity.Owner, out var jammerComp))
{
// This is a little sketcy but only way to do it.
jammerComp.Range = GetCurrentRange(entity.Comp);
Dirty(entity.Owner, jammerComp);
}
Popup.PopupPredicted(Loc.GetString(setting.Message), user, user);
},
Text = Loc.GetString(setting.Name),
};
args.Verbs.Add(verb);
index++;
}
}
public float GetCurrentWattage(RadioJammerComponent jammer)
{
return jammer.Settings[jammer.SelectedPowerLevel].Wattage;
}
public float GetCurrentRange(RadioJammerComponent jammer)
{
return jammer.Settings[jammer.SelectedPowerLevel].Range;
}
protected void ChangeLEDState(bool isLEDOn, EntityUid uid,
AppearanceComponent? appearance = null)
{
_appearance.SetData(uid, RadioJammerVisuals.LEDOn, isLEDOn, appearance);
}
protected void ChangeChargeLevel(RadioJammerChargeLevel chargeLevel, EntityUid uid,
AppearanceComponent? appearance = null)
{
_appearance.SetData(uid, RadioJammerVisuals.ChargeLevel, chargeLevel, appearance);
}
}