This repository was archived by the owner on Mar 23, 2026. It is now read-only.
forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathSolarFlareGeneratorSystem.cs
More file actions
156 lines (135 loc) · 5.49 KB
/
SolarFlareGeneratorSystem.cs
File metadata and controls
156 lines (135 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using Content.Client;
using Content.Server.Bed.Components;
using Content.Server.Botany.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell;
using Content.Server.Radio;
using Content.Shared.Bed.Sleep;
using Content.Shared.Buckle.Components;
using Content.Shared.Damage;
using Content.Shared.DeviceNetwork.Components;
using Content.Shared.DeviceNetwork.Systems;
using Content.Shared.Interaction;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.PowerCell.Components;
using Content.Shared.Radio.Components;
using Content.Shared.Radio.EntitySystems;
using JetBrains.FormatRipper.Elf;
using Robust.Shared.GameObjects;
using Robust.Shared.Timing;
using System;
using System.ComponentModel;
namespace Content.Server.Solar.EntitySystems
{
public sealed class SolarFlareGeneratorSystem : EntitySystem
{
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedDeviceNetworkJammerSystem _jammer = default!;
[Dependency] private readonly SharedJammerSystem _jammerSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
private const float _cooldownTimerValue = 15;
private const float _effectTimer = 30;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SolarFlareGeneratorComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<RadioReceiveAttemptEvent>(OnRadioReceiveAttempt);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var frameTimeSpan = TimeSpan.FromSeconds(frameTime);
var query = EntityQueryEnumerator<SolarFlareGeneratorComponent>();
while (query.MoveNext(out var uid, out var solarFlareComponent))
{
if (solarFlareComponent.IsActive)
{
UpdateActiveGenerator(solarFlareComponent, frameTimeSpan);
}
else if (!solarFlareComponent.IsReady)
{
UpdateCooldown(solarFlareComponent, frameTimeSpan);
}
else
{
solarFlareComponent.EffectTimer = TimeSpan.Zero;
}
}
}
private void UpdateActiveGenerator(SolarFlareGeneratorComponent component, TimeSpan frameTime)
{
// Обновление таймера эффекта
if (component.EffectTimer > TimeSpan.Zero)
{
component.EffectTimer -= frameTime;
if (component.EffectTimer <= TimeSpan.Zero)
{
component.IsActive = false;
component.EffectTimer = TimeSpan.Zero;
}
}
// Обновление кулдауна
UpdateCooldown(component, frameTime);
}
private void UpdateCooldown(SolarFlareGeneratorComponent component, TimeSpan frameTime)
{
if (component.CooldownTimer > TimeSpan.Zero)
{
component.CooldownTimer -= frameTime;
}
else if (!component.IsReady)
{
component.IsReady = true;
component.CooldownTimer = TimeSpan.Zero;
}
}
private void OnInteractHand(Entity<SolarFlareGeneratorComponent> entity, ref InteractHandEvent args)
{
if (args.Handled)
return;
if (entity.Comp.IsReady)
{
var state = Loc.GetString("radio-jammer-component-on-state");
var message = Loc.GetString("radio-jammer-component-on-use", ("state", state));
Popup.PopupEntity(message, args.User, args.User);
OnActivate(entity, args);
}
}
private void OnActivate(Entity<SolarFlareGeneratorComponent> entity, InteractHandEvent args)
{
StartSolarFlareGenerator(entity.Comp);
args.Handled = true;
}
private void StartSolarFlareGenerator(SolarFlareGeneratorComponent component)
{
component.IsActive = true;
component.IsReady = false;
component.CooldownTimer = TimeSpan.FromMinutes(_cooldownTimerValue);
component.EffectTimer = TimeSpan.FromSeconds(_effectTimer);
}
private void OnRadioReceiveAttempt(ref RadioReceiveAttemptEvent args)
{
if (ShouldCancelReceive(args.RadioSource))
{
args.Cancelled = true;
}
}
private bool ShouldCancelReceive(EntityUid sourceUid)
{
var query = EntityQueryEnumerator<TransformComponent, SolarFlareGeneratorComponent>();
while (query.MoveNext(out var uid, out var transform, out var solarFlareGeneratorComponent))
{
var source = Transform(sourceUid).Coordinates;
if (_transform.InRange(source, transform.Coordinates, solarFlareGeneratorComponent.Radius) && solarFlareGeneratorComponent.IsActive)
{
return true;
}
}
return false;
}
}
}