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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user