Remove component.Initialize calls (#18230)
This commit is contained in:
38
Content.Server/Spawners/EntitySystems/SpawnerSystem.cs
Normal file
38
Content.Server/Spawners/EntitySystems/SpawnerSystem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Threading;
|
||||
using Content.Server.Spawners.Components;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Spawners.EntitySystems;
|
||||
|
||||
public sealed class SpawnerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<TimedSpawnerComponent, ComponentInit>(OnSpawnerInit);
|
||||
}
|
||||
|
||||
private void OnSpawnerInit(EntityUid uid, TimedSpawnerComponent component, ComponentInit args)
|
||||
{
|
||||
component.TokenSource?.Cancel();
|
||||
component.TokenSource = new CancellationTokenSource();
|
||||
uid.SpawnRepeatingTimer(TimeSpan.FromSeconds(component.IntervalSeconds), () => OnTimerFired(uid, component), component.TokenSource.Token);
|
||||
}
|
||||
|
||||
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);
|
||||
Spawn(entity, coordinates);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user