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>
This commit is contained in:
8
Content.Client/DeviceNetwork/JammerSystem.cs
Normal file
8
Content.Client/DeviceNetwork/JammerSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Radio.EntitySystems;
|
||||
|
||||
namespace Content.Client.DeviceNetwork;
|
||||
|
||||
public sealed class JammerSystem : SharedJammerSystem
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// When activated (<see cref="ActiveRadioJammerComponent"/>) prevents from sending messages in range
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(JammerSystem))]
|
||||
public sealed partial class RadioJammerComponent : Component
|
||||
{
|
||||
[DataField("range"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Range = 8f;
|
||||
|
||||
/// <summary>
|
||||
/// Power usage per second when enabled
|
||||
/// </summary>
|
||||
[DataField("wattage"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Wattage = 2f;
|
||||
}
|
||||
@@ -1,26 +1,22 @@
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Medical.CrewMonitoring;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Server.Radio.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.PowerCell.Components;
|
||||
using Content.Shared.RadioJammer;
|
||||
using Content.Shared.Radio.EntitySystems;
|
||||
|
||||
namespace Content.Server.Radio.EntitySystems;
|
||||
|
||||
public sealed class JammerSystem : EntitySystem
|
||||
public sealed class JammerSystem : SharedJammerSystem
|
||||
{
|
||||
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
||||
[Dependency] private readonly BatterySystem _battery = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly StationSystem _stationSystem = default!;
|
||||
[Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -35,14 +31,37 @@ public sealed class JammerSystem : EntitySystem
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent>();
|
||||
|
||||
while (query.MoveNext(out var uid, out var _, out var jam))
|
||||
{
|
||||
if (_powerCell.TryGetBatteryFromSlot(uid, out var batteryUid, out var battery) &&
|
||||
!_battery.TryUseCharge(batteryUid.Value, jam.Wattage * frameTime, battery))
|
||||
|
||||
if (_powerCell.TryGetBatteryFromSlot(uid, out var batteryUid, out var battery))
|
||||
{
|
||||
RemComp<ActiveRadioJammerComponent>(uid);
|
||||
RemComp<DeviceNetworkJammerComponent>(uid);
|
||||
if (!_battery.TryUseCharge(batteryUid.Value, GetCurrentWattage(jam) * frameTime, battery))
|
||||
{
|
||||
ChangeLEDState(false, uid);
|
||||
RemComp<ActiveRadioJammerComponent>(uid);
|
||||
RemComp<DeviceNetworkJammerComponent>(uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
var percentCharged = battery.CurrentCharge / battery.MaxCharge;
|
||||
if (percentCharged > .50)
|
||||
{
|
||||
ChangeChargeLevel(RadioJammerChargeLevel.High, uid);
|
||||
}
|
||||
else if (percentCharged < .15)
|
||||
{
|
||||
ChangeChargeLevel(RadioJammerChargeLevel.Low, uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeChargeLevel(RadioJammerChargeLevel.Medium, uid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,40 +69,49 @@ public sealed class JammerSystem : EntitySystem
|
||||
{
|
||||
var activated = !HasComp<ActiveRadioJammerComponent>(uid) &&
|
||||
_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
|
||||
battery.CurrentCharge > comp.Wattage;
|
||||
battery.CurrentCharge > GetCurrentWattage(comp);
|
||||
if (activated)
|
||||
{
|
||||
ChangeLEDState(true, uid);
|
||||
EnsureComp<ActiveRadioJammerComponent>(uid);
|
||||
EnsureComp<DeviceNetworkJammerComponent>(uid, out var jammingComp);
|
||||
jammingComp.Range = comp.Range;
|
||||
jammingComp.Range = GetCurrentRange(comp);
|
||||
jammingComp.JammableNetworks.Add(DeviceNetworkComponent.DeviceNetIdDefaults.Wireless.ToString());
|
||||
Dirty(uid, jammingComp);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemComp<ActiveRadioJammerComponent>(uid);
|
||||
RemComp<DeviceNetworkJammerComponent>(uid);
|
||||
ChangeLEDState(false, uid);
|
||||
RemCompDeferred<ActiveRadioJammerComponent>(uid);
|
||||
RemCompDeferred<DeviceNetworkJammerComponent>(uid);
|
||||
}
|
||||
var state = Loc.GetString(activated ? "radio-jammer-component-on-state" : "radio-jammer-component-off-state");
|
||||
var message = Loc.GetString("radio-jammer-component-on-use", ("state", state));
|
||||
_popup.PopupEntity(message, args.User, args.User);
|
||||
Popup.PopupEntity(message, args.User, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnPowerCellChanged(EntityUid uid, ActiveRadioJammerComponent comp, PowerCellChangedEvent args)
|
||||
{
|
||||
if (args.Ejected)
|
||||
RemComp<ActiveRadioJammerComponent>(uid);
|
||||
{
|
||||
ChangeLEDState(false, uid);
|
||||
RemCompDeferred<ActiveRadioJammerComponent>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, RadioJammerComponent comp, ExaminedEvent args)
|
||||
{
|
||||
if (args.IsInDetailsRange)
|
||||
{
|
||||
var msg = HasComp<ActiveRadioJammerComponent>(uid)
|
||||
var powerIndicator = HasComp<ActiveRadioJammerComponent>(uid)
|
||||
? Loc.GetString("radio-jammer-component-examine-on-state")
|
||||
: Loc.GetString("radio-jammer-component-examine-off-state");
|
||||
args.PushMarkup(msg);
|
||||
args.PushMarkup(powerIndicator);
|
||||
|
||||
var powerLevel = Loc.GetString(comp.Settings[comp.SelectedPowerLevel].Name);
|
||||
var switchIndicator = Loc.GetString("radio-jammer-component-switch-setting", ("powerLevel", powerLevel));
|
||||
args.PushMarkup(switchIndicator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +130,7 @@ public sealed class JammerSystem : EntitySystem
|
||||
|
||||
while (query.MoveNext(out _, out _, out var jam, out var transform))
|
||||
{
|
||||
if (source.InRange(EntityManager, _transform, transform.Coordinates, jam.Range))
|
||||
if (source.InRange(EntityManager, _transform, transform.Coordinates, GetCurrentRange(jam)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.RadioJammer;
|
||||
|
||||
/// <summary>
|
||||
/// When activated (<see cref="ActiveRadioJammerComponent"/>) prevents from sending messages in range
|
||||
/// Suit sensors will also stop working.
|
||||
/// </summary>
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
public sealed partial class RadioJammerComponent : Component
|
||||
{
|
||||
[DataDefinition]
|
||||
public partial struct RadioJamSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// Power usage per second when enabled.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public float Wattage;
|
||||
|
||||
/// <summary>
|
||||
/// Range of the jammer.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public float Range;
|
||||
|
||||
/// <summary>
|
||||
/// The message that is displayed when switched
|
||||
/// to this setting.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public LocId Message = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the setting.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public LocId Name = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of all the settings for the radio jammer.
|
||||
/// </summary>
|
||||
[DataField(required: true), ViewVariables(VVAccess.ReadOnly)]
|
||||
public RadioJamSetting[] Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Index of the currently selected setting.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int SelectedPowerLevel = 1;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum RadioJammerChargeLevel : byte
|
||||
{
|
||||
Low,
|
||||
Medium,
|
||||
High
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum RadioJammerLayers : byte
|
||||
{
|
||||
LED
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum RadioJammerVisuals : byte
|
||||
{
|
||||
ChargeLevel,
|
||||
LEDOn
|
||||
}
|
||||
78
Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs
Normal file
78
Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -83,5 +83,7 @@ namespace Content.Shared.Verbs
|
||||
public static readonly VerbCategory Lever = new("verb-categories-lever", null);
|
||||
|
||||
public static readonly VerbCategory SelectType = new("verb-categories-select-type", null);
|
||||
|
||||
public static readonly VerbCategory PowerLevel = new("verb-categories-power-level", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,3 +4,13 @@ radio-jammer-component-off-state = off
|
||||
|
||||
radio-jammer-component-examine-on-state = The light is currently [color=darkgreen]on[/color].
|
||||
radio-jammer-component-examine-off-state = The light is currently [color=darkred]off[/color].
|
||||
|
||||
radio-jammer-component-setting-high = High
|
||||
radio-jammer-component-setting-medium = Medium
|
||||
radio-jammer-component-setting-low = Low
|
||||
|
||||
radio-jammer-component-set-message-high = The jammer is now operating at high power.
|
||||
radio-jammer-component-set-message-medium = The jammer is now operating at medium power.
|
||||
radio-jammer-component-set-message-low = The jammer is now operating at low power.
|
||||
|
||||
radio-jammer-component-switch-setting = The power level switch is set to "[color=yellow]{$powerLevel}[/color]".
|
||||
|
||||
@@ -28,6 +28,7 @@ verb-categories-timer = Set Delay
|
||||
verb-categories-lever = Lever
|
||||
verb-categories-select-type = Select Type
|
||||
verb-categories-fax = Set Destination
|
||||
verb-categories-power-level = Power Level
|
||||
|
||||
verb-common-toggle-light = Toggle light
|
||||
verb-common-close = Close
|
||||
|
||||
@@ -6,8 +6,26 @@
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: Objects/Devices/jammer.rsi
|
||||
state: jammer
|
||||
layers:
|
||||
- state: jammer
|
||||
- state: jammer_high_charge
|
||||
map: ["enum.RadioJammerLayers.LED"]
|
||||
shader: unshaded
|
||||
visible: false
|
||||
- type: RadioJammer
|
||||
settings:
|
||||
- wattage: 1
|
||||
range: 2.5
|
||||
message: radio-jammer-component-set-message-low
|
||||
name: radio-jammer-component-setting-low
|
||||
- wattage: 2
|
||||
range: 6
|
||||
message: radio-jammer-component-set-message-medium
|
||||
name: radio-jammer-component-setting-medium
|
||||
- wattage: 12
|
||||
range: 12
|
||||
message: radio-jammer-component-set-message-high
|
||||
name: radio-jammer-component-setting-high
|
||||
- type: PowerCellSlot
|
||||
cellSlotId: cell_slot
|
||||
- type: ContainerContainer
|
||||
@@ -18,3 +36,15 @@
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellMedium
|
||||
- type: Appearance
|
||||
- type: GenericVisualizer
|
||||
visuals:
|
||||
enum.RadioJammerVisuals.LEDOn:
|
||||
RadioJammerLayers.LED:
|
||||
True: { visible: True }
|
||||
False: { visible: False }
|
||||
enum.RadioJammerVisuals.ChargeLevel:
|
||||
RadioJammerLayers.LED:
|
||||
Low: {state: jammer_low_charge}
|
||||
Medium: {state: jammer_medium_charge}
|
||||
High: {state: jammer_high_charge}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 495 B After Width: | Height: | Size: 939 B |
Binary file not shown.
|
After Width: | Height: | Size: 609 B |
Binary file not shown.
|
After Width: | Height: | Size: 617 B |
Binary file not shown.
|
After Width: | Height: | Size: 608 B |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"license": "CC-BY-SA-3.0",
|
||||
"copyright": "Taken from https://github.com/tgstation/tgstation/commit/c65da5a49477413310c81c460ea4b243a9f864dd",
|
||||
"copyright": "Taken from https://github.com/tgstation/tgstation/commit/c65da5a49477413310c81c460ea4b243a9f864dd with minor edits.",
|
||||
"size": {
|
||||
"x": 32,
|
||||
"y": 32
|
||||
@@ -10,6 +10,24 @@
|
||||
{
|
||||
"name": "jammer",
|
||||
"directions": 1
|
||||
},
|
||||
{
|
||||
"name": "jammer_high_charge",
|
||||
"directions": 1
|
||||
},
|
||||
{
|
||||
"name": "jammer_medium_charge",
|
||||
"directions": 1
|
||||
},
|
||||
{
|
||||
"name": "jammer_low_charge",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
0.3,
|
||||
0.3
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user