Skip to content

Commit

Permalink
EMP
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 committed Jul 27, 2023
1 parent 591b880 commit 84002c3
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Content.Shared._NF.M_Emp;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

[NetworkedComponent, RegisterComponent]
public sealed class M_EmpGeneratorComponent : SharedM_EmpGeneratorComponent { }
public sealed class M_EmpGeneratorComponent : SharedM_EmpGeneratorComponent
{
}
20 changes: 13 additions & 7 deletions Content.Server/_NF/M_Emp/M_EmpGeneratorComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Shared.Radio;
using Content.Shared.Random;
using Content.Shared._NF.M_Emp;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
Expand Down Expand Up @@ -45,22 +44,29 @@ public sealed class M_EmpGeneratorComponent : SharedM_EmpGeneratorComponent
/// How long the generator Cooling Down
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("baseCoolingDownTime")]
public TimeSpan BaseCoolingDownTime = TimeSpan.FromSeconds(60);

/// <summary>
/// How long the generator actually has to cooldown after use
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("coolingDownTime")]
public TimeSpan CoolingDownTime = TimeSpan.FromSeconds(60);

/// <summary>
/// How long the generator has to cool down for after use
/// How long the generator has to recharge after use
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("baseCooldownTime")]
public TimeSpan BaseCooldownTime = TimeSpan.FromSeconds(60);
[DataField("baseRecharging")]
public TimeSpan BaseRecharging = TimeSpan.FromSeconds(60);

/// <summary>
/// How long the generator actually has to cool down for after use
/// How long the generator actually has to recharge after use
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("cooldownTime")]
public TimeSpan CooldownTime = TimeSpan.FromSeconds(60);
[DataField("Recharging")]
public TimeSpan Recharging = TimeSpan.FromSeconds(60);

[DataField("M_EmpChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
public string M_EmpChannel = "Security";
Expand Down
41 changes: 28 additions & 13 deletions Content.Server/_NF/M_Emp/M_EmpSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Content.Server.Chat.Managers;
using Content.Server.Station.Systems;
using Robust.Shared.Timing;
using Content.Server.Emp;
using Content.Shared.DeviceLinking;
using Content.Server.DeviceLinking.Systems;

// TO ANYONE LOOKING AT THIS CODE, IM SORRY
// This code was reused for the salvage magnet and is a mess right now as it is, it has no known issues with it as for now but its not cleaned as it sould be.
// If you know what you are doing, fix this please to look "usable"
// - Dvir01

namespace Content.Server._NF.M_Emp
{
Expand All @@ -34,6 +40,7 @@ public sealed partial class M_EmpSystem : EntitySystem
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly EmpSystem _emp = default!;
[Dependency] private readonly DeviceLinkSystem _linker = default!;

// TODO: This is probably not compatible with multi-station
private readonly Dictionary<EntityUid, M_EmpGridState> _M_EmpGridStates = new();
Expand All @@ -42,6 +49,7 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SharedM_EmpComponent, ComponentInit>(OnInit); // TODO make this function later
SubscribeLocalEvent<M_EmpGeneratorComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<M_EmpGeneratorComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<M_EmpGeneratorComponent, UpgradeExamineEvent>(OnUpgradeExamine);
Expand Down Expand Up @@ -89,7 +97,7 @@ private void UpdateChargeStateAppearance(EntityUid uid, TimeSpan currentTime, M_
GeneratorStateType.Inactive => 5,
GeneratorStateType.Engaged => timeLeft / (Convert.ToInt32(component.EngagedTime.TotalSeconds) / component.ChargeCapacity) + 1,
GeneratorStateType.CoolingDown => 0,
GeneratorStateType.Recharging => component.ChargeCapacity - timeLeft / (Convert.ToInt32(component.CooldownTime.TotalSeconds) / component.ChargeCapacity) - 1,
GeneratorStateType.Recharging => component.ChargeCapacity - timeLeft / (Convert.ToInt32(component.Recharging.TotalSeconds) / component.ChargeCapacity) - 1,
_ => component.ChargeRemaining
};

Expand Down Expand Up @@ -135,13 +143,13 @@ private void OnRefreshParts(EntityUid uid, M_EmpGeneratorComponent component, Re
{
var rating = args.PartRatings[component.MachinePartDelay] - 1;
var factor = MathF.Pow(component.PartRatingDelay, rating);
component.ActivatingTime = component.BaseActivatingTime * factor;
component.CooldownTime = component.BaseCooldownTime * factor;
component.CoolingDownTime = component.BaseCoolingDownTime * factor;
component.Recharging = component.BaseRecharging * factor;
}

private void OnUpgradeExamine(EntityUid uid, M_EmpGeneratorComponent component, UpgradeExamineEvent args)
{
args.AddPercentageUpgrade("m_emp-system-generator-delay-upgrade", (float) (component.CooldownTime / component.BaseCooldownTime));
args.AddPercentageUpgrade("m_emp-system-generator-delay-upgrade", (float) (component.Recharging / component.BaseRecharging));
}

private void OnExamined(EntityUid uid, M_EmpGeneratorComponent component, ExaminedEvent args)
Expand Down Expand Up @@ -196,6 +204,11 @@ private void OnInteractHand(EntityUid uid, M_EmpGeneratorComponent component, In
UpdateAppearance(uid, component);
}

private void OnInit(EntityUid uid, SharedM_EmpComponent component, ComponentInit args)
{
_linker.EnsureSinkPorts(uid, component.ReceiverPort);
}

private void StartGenerator(EntityUid uid, M_EmpGeneratorComponent component, EntityUid user)
{
switch (component.GeneratorState.StateType)
Expand All @@ -216,10 +229,7 @@ private void StartGenerator(EntityUid uid, M_EmpGeneratorComponent component, En
component.GeneratorState = new GeneratorState(GeneratorStateType.Activating, gridState.CurrentTime + component.ActivatingTime);
RaiseLocalEvent(new M_EmpGeneratorActivatedEvent(uid));

var station = _station.GetOwningStation(uid);
var stationName = station is null ? null : Name(station.Value);

Report(uid, component.M_EmpChannel, "m_emp-system-report-activate-success", ("grid", stationName));
//Report(uid, component.M_EmpChannel, "m_emp-system-report-activate-success"); Removed to lower spam

break;
case GeneratorStateType.Activating:
Expand All @@ -241,7 +251,12 @@ private void ShowPopup(EntityUid uid, string messageKey, EntityUid user)

private bool SpawnM_Emp(EntityUid uid, M_EmpGeneratorComponent component)
{
Report(uid, component.M_EmpChannel, "m_emp-system-announcement-active", ("timeLeft", component.EngagedTime.TotalSeconds));
var station = _station.GetOwningStation(uid);
var stationName = station is null ? null : Name(station.Value);

#pragma warning disable CS8620 // TODO need to fix it later, this is not creating an actual error
Report(uid, component.M_EmpChannel, "m_emp-system-announcement-active", ("timeLeft", component.EngagedTime.TotalSeconds), ("grid", stationName));
#pragma warning restore CS8620 // TODO need to fix it later, this is not creating an actual error

var empRange = 100;
var empEnergyConsumption = 50000;
Expand Down Expand Up @@ -270,16 +285,16 @@ private void Transition(EntityUid uid, M_EmpGeneratorComponent generator, TimeSp
}
else
{
generator.GeneratorState = new GeneratorState(GeneratorStateType.Recharging, currentTime + generator.CooldownTime);
generator.GeneratorState = new GeneratorState(GeneratorStateType.Recharging, currentTime + generator.Recharging);
}
break;
case GeneratorStateType.Engaged:
Report(uid, generator.M_EmpChannel, "m_emp-system-announcement-cooling-down", ("timeLeft", generator.CoolingDownTime.TotalSeconds));
generator.GeneratorState = new GeneratorState(GeneratorStateType.CoolingDown, currentTime + generator.CoolingDownTime);
break;
case GeneratorStateType.CoolingDown:
//Report(uid, generator.M_EmpChannel, "m_emp-system-announcement-recharging"); //Less chat spam
generator.GeneratorState = new GeneratorState(GeneratorStateType.Recharging, currentTime + generator.CooldownTime);
//Report(uid, generator.M_EmpChannel, "m_emp-system-announcement-recharging"); // Less chat spam
generator.GeneratorState = new GeneratorState(GeneratorStateType.Recharging, currentTime + generator.Recharging);
break;
case GeneratorStateType.Recharging:
generator.GeneratorState = GeneratorState.Inactive;
Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/_NF/M_Emp/SharedM_EmpComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Content.Shared._NF.M_Emp;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Content.Shared.MachineLinking;

namespace Content.Shared._NF.M_Emp;

[NetworkedComponent, RegisterComponent]
public sealed class SharedM_EmpComponent : Component
{
[DataField("receiverPort", customTypeSerializer: typeof(PrototypeIdSerializer<ReceiverPortPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string ReceiverPort = "M_Emp";
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/_NF/machine-linking/receiver_ports.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
signal-port-name-m_emp = M_EMP
signal-port-description-m_emp = Activate the device.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
m_emp-system-announcement-source = M_EMP Generator System
m_emp-system-announcement-active = Activated. Estimated EMP: {$timeLeft} seconds.
m_emp-system-announcement-active = Engaging on {$grid}. EMP: {$timeLeft} seconds.
m_emp-system-announcement-cooling-down = EMP effect is no longer active. Estimated Recharging: {$timeLeft} seconds.
m_emp-system-announcement-recharging = Recharging.
m_emp-system-report-already-active = The M_EMP Generator is already active.
m_emp-system-report-cooling-down = The M_EMP Generator is cooling down.
m_emp-system-report-activate-success = The M_EMP Generator engaging on {$grid}!
m_emp-system-report-activate-success = The M_EMP Generator engaging!
m_emp-system-generator-examined-inactive = The M_EMP Generator is inactive.
m_emp-system-generator-examined-starting = The M_EMP Generator is starting up.
Expand Down
4 changes: 4 additions & 0 deletions Resources/Prototypes/_NF/DeviceLinking/sink_ports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- type: sinkPort
id: M_Emp
name: signal-port-name-m_emp
description: signal-port-description-m_emp
Empty file.
12 changes: 10 additions & 2 deletions Resources/Prototypes/_NF/Entities/Structures/Machines/m_emp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
- Security
- type: M_EmpGenerator
- type: ApcPowerReceiver
powerLoad: 100 # TODO change this to a HV power draw that really hits the grid hard WHEN active
powerLoad: 2500 # TODO change this to a HV power draw that really hits the grid hard WHEN active
- type: Machine
board: M_EmpMachineCircuitboard
board: M_EmpMachineCircuitboard
- type: DeviceNetwork
deviceNetId: Wireless
receiveFrequencyId: BasicDevice
- type: WirelessNetworkConnection
range: 200
- type: DeviceLinkSink
ports:
- M_Emp
Empty file.

0 comments on commit 84002c3

Please sign in to comment.