-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSpawnerSystem.cs
More file actions
61 lines (48 loc) · 1.86 KB
/
Copy pathSpawnerSystem.cs
File metadata and controls
61 lines (48 loc) · 1.86 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
using Content.Goobstation.Common.Spawner;
using Content.Server.Spawners.Components;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.Spawners.EntitySystems;
public sealed partial class SpawnerSystem : EntitySystem
{
[Dependency] private IGameTiming _timing = default!;
[Dependency] private IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TimedSpawnerComponent, MapInitEvent>(OnMapInit);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var curTime = _timing.CurTime;
var query = EntityQueryEnumerator<TimedSpawnerComponent>();
while (query.MoveNext(out var uid, out var timedSpawner))
{
if (timedSpawner.NextFire > curTime)
continue;
OnTimerFired(uid, timedSpawner);
timedSpawner.NextFire += timedSpawner.IntervalSeconds;
}
}
private void OnMapInit(Entity<TimedSpawnerComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextFire = _timing.CurTime + ent.Comp.IntervalSeconds;
}
private void OnTimerFired(EntityUid uid, TimedSpawnerComponent component)
{
if (!_random.Prob(component.Chance))
return;
var number = _random.Next(component.MinimumEntitiesSpawned, component.MaximumEntitiesSpawned);
var coordinates = Transform(uid).Coordinates;
for (var i = 0; i < number; i++)
{
var entity = _random.Pick(component.Prototypes);
var spawned = SpawnAtPosition(entity, coordinates); // Goobstation edit - saved in variable
// Goobstation edit start
var spawnedEv = new SpawnerActivationEvent(spawned);
RaiseLocalEvent(uid, ref spawnedEv);
// Goobstation edit end
}
}
}