forked from space-syndicate/space-station-14-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlobRuleSystem.cs
303 lines (264 loc) · 11 KB
/
BlobRuleSystem.cs
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.AlertLevel;
using Content.Server.Antag;
using Content.Server._Goobstation.Blob;
using Content.Server._Goobstation.Blob.Components;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Chat.Managers;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.Mind;
using Content.Server.Nuke;
using Content.Server.Objectives;
using Content.Server.RoundEnd;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared._Goobstation.Blob.Components;
using Content.Shared.GameTicking.Components;
using Content.Shared.Objectives.Components;
using Robust.Shared.Audio;
using Robust.Shared.Player;
namespace Content.Server.GameTicking.Rules;
public sealed class BlobRuleSystem : GameRuleSystem<BlobRuleComponent>
{
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly NukeCodePaperSystem _nukeCode = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly ObjectivesSystem _objectivesSystem = default!;
[Dependency] private readonly AlertLevelSystem _alertLevelSystem = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
private static readonly SoundPathSpecifier BlobDetectAudio = new ("/Audio/_CorvaxNext/Misc/outbreak5.ogg");
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlobRuleComponent, AfterAntagEntitySelectedEvent>(AfterAntagSelected);
}
protected override void Started(EntityUid uid, BlobRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
var activeRules = QueryActiveRules();
while (activeRules.MoveNext(out var entityUid, out _, out _, out _))
{
if(uid == entityUid)
continue;
GameTicker.EndGameRule(uid, gameRule);
Log.Error("blob is active!!! remove!");
break;
}
}
protected override void ActiveTick(EntityUid uid, BlobRuleComponent component, GameRuleComponent gameRule, float frameTime)
{
component.Accumulator += frameTime;
if(component.Accumulator < 10)
return;
component.Accumulator = 0;
var check = new Dictionary<EntityUid, long>();
var blobCoreQuery = EntityQueryEnumerator<BlobCoreComponent, MetaDataComponent, TransformComponent>();
while (blobCoreQuery.MoveNext(out var ent, out var comp, out var md, out var xform))
{
if (TerminatingOrDeleted(ent, md) ||
!CheckBlobInStation(ent, xform, out var stationUid))
{
continue;
}
check.TryAdd(stationUid.Value, 0);
check[stationUid.Value] += comp.BlobTiles.Count;
}
foreach (var (station, length) in check.AsParallel())
{
CheckChangeStage(station, component, length);
}
}
private bool CheckBlobInStation(EntityUid blobCore, TransformComponent? xform, [NotNullWhen(true)] out EntityUid? stationUid)
{
var station = _stationSystem.GetOwningStation(blobCore, xform);
if (station == null || !HasComp<StationEventEligibleComponent>(station.Value))
{
_chatManager.SendAdminAlert(blobCore, Loc.GetString("blob-alert-out-off-station"));
QueueDel(blobCore);
stationUid = null;
return false;
}
stationUid = station.Value;
return true;
}
private const string StationAlertCritical = "delta";
private const string StationAlertDetected = "red";
private void CheckChangeStage(
Entity<StationBlobConfigComponent?> stationUid,
BlobRuleComponent blobRuleComp,
long blobTilesCount)
{
Resolve(stationUid, ref stationUid.Comp, false);
var stationName = Name(stationUid);
if (blobTilesCount >= (stationUid.Comp?.StageBegin ?? StationBlobConfigComponent.DefaultStageBegin)
&& _roundEndSystem.ExpectedCountdownEnd != null)
{
_roundEndSystem.CancelRoundEndCountdown(checkCooldown: false);
_chatSystem.DispatchStationAnnouncement(stationUid,
Loc.GetString("blob-alert-recall-shuttle"),
Loc.GetString("Station"),
false,
null,
Color.Red);
}
switch (blobRuleComp.Stage)
{
case BlobStage.Default when blobTilesCount >= (stationUid.Comp?.StageBegin ?? StationBlobConfigComponent.DefaultStageBegin):
blobRuleComp.Stage = BlobStage.Begin;
_chatSystem.DispatchGlobalAnnouncement(
Loc.GetString("blob-alert-detect"),
stationName,
true,
BlobDetectAudio,
Color.Red);
_alertLevelSystem.SetLevel(stationUid, StationAlertDetected, true, true, true, true);
RaiseLocalEvent(stationUid,
new BlobChangeLevelEvent
{
Station = stationUid,
Level = blobRuleComp.Stage
},
broadcast: true);
return;
case BlobStage.Begin when blobTilesCount >= (stationUid.Comp?.StageCritical ?? StationBlobConfigComponent.DefaultStageCritical):
{
if (_nukeCode.SendNukeCodes(stationUid))//send the nuke code?
{
blobRuleComp.Stage = BlobStage.Critical;
_chatSystem.DispatchGlobalAnnouncement(
Loc.GetString("blob-alert-critical"),
stationName,
true,
blobRuleComp.AlertAudio,
Color.Red);
}
else
{
blobRuleComp.Stage = BlobStage.Critical;
_chatSystem.DispatchGlobalAnnouncement(
Loc.GetString("blob-alert-critical-NoNukeCode"),
stationName,
true,
blobRuleComp.AlertAudio,
Color.Red);
}
_alertLevelSystem.SetLevel(stationUid, StationAlertCritical, true, true, true, true);
RaiseLocalEvent(stationUid,
new BlobChangeLevelEvent
{
Station = stationUid,
Level = blobRuleComp.Stage
},
broadcast: true);
return;
}
case BlobStage.Critical when blobTilesCount >= (stationUid.Comp?.StageTheEnd ?? StationBlobConfigComponent.DefaultStageEnd):
{
blobRuleComp.Stage = BlobStage.TheEnd;
_roundEndSystem.EndRound();
RaiseLocalEvent(stationUid,
new BlobChangeLevelEvent
{
Station = stationUid,
Level = blobRuleComp.Stage
},
broadcast: true);
return;
}
}
}
protected override void AppendRoundEndText(
EntityUid uid,
BlobRuleComponent blob,
GameRuleComponent gameRule,
ref RoundEndTextAppendEvent ev)
{
if (blob.Blobs.Count < 1)
return;
var result = Loc.GetString("blob-round-end-result", ("blobCount", blob.Blobs.Count));
// yeah this is duplicated from traitor rules lol, there needs to be a generic rewrite where it just goes through all minds with objectives
foreach (var (mindId, mind) in blob.Blobs)
{
var name = mind.CharacterName;
_mindSystem.TryGetSession(mindId, out var session);
var username = session?.Name;
var objectives = mind.Objectives.ToArray();
if (objectives.Length == 0)
{
if (username != null)
{
if (name == null)
result += "\n" + Loc.GetString("blob-user-was-a-blob", ("user", username));
else
{
result += "\n" + Loc.GetString("blob-user-was-a-blob-named",
("user", username),
("name", name));
}
}
else if (name != null)
result += "\n" + Loc.GetString("blob-was-a-blob-named", ("name", name));
continue;
}
if (username != null)
{
if (name == null)
{
result += "\n" + Loc.GetString("blob-user-was-a-blob-with-objectives",
("user", username));
}
else
{
result += "\n" + Loc.GetString("blob-user-was-a-blob-with-objectives-named",
("user", username),
("name", name));
}
}
else if (name != null)
result += "\n" + Loc.GetString("blob-was-a-blob-with-objectives-named", ("name", name));
foreach (var objectiveGroup in objectives.GroupBy(o => Comp<ObjectiveComponent>(o).LocIssuer))
{
foreach (var objective in objectiveGroup)
{
var info = _objectivesSystem.GetInfo(objective, mindId, mind);
if (info == null)
continue;
var objectiveTitle = info.Value.Title;
var progress = info.Value.Progress;
if (progress > 0.99f)
{
result += "\n- " + Loc.GetString(
"objective-condition-success",
("condition", objectiveTitle),
("markupColor", "green")
);
}
else
{
result += "\n- " + Loc.GetString(
"objective-condition-fail",
("condition", objectiveTitle),
("progress", (int) (progress * 100)),
("markupColor", "red")
);
}
}
}
}
ev.AddLine(result);
}
public void MakeBlob(EntityUid player)
{
var comp = EnsureComp<BlobCarrierComponent>(player);
comp.HasMind = HasComp<ActorComponent>(player);
comp.TransformationDelay = 10 * 60; // 10min
}
private void AfterAntagSelected(EntityUid uid, BlobRuleComponent component, AfterAntagEntitySelectedEvent args)
{
MakeBlob(args.EntityUid);
}
}