Files
tbd-station-14/Content.Server/StationEvents/Events/RandomEntityStorageSpawnRule.cs
Nemanja 161fd6c83c Mega Antag Refactor (#25786)
* Mega Antag Refactor

* last minute delta save

* more workshopping

* more shit

* ok tested this for once

* okkkkk sure

* generic delays for starting rules

* well darn

* nukies partially

* ouagh

* ballin' faded and smonkin wed

* obliterated the diff

* Spread my arms and soak up congratulations

* I've got plenty of love, but nothing to show for it

* but there’s too much sunlight
Shining on my laptop monitor, so I
Can’t see anything with any amount of clarity

* ok this junk

* OOK!

* fubar

* most of sloth's review

* oh boy

* eek

* hell yea!

* ASDFJASDJFvsakcvjkzjnhhhyh
2024-04-25 11:31:45 +10:00

50 lines
1.6 KiB
C#

using Content.Server.GameTicking.Components;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Components;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Robust.Shared.Map;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
public sealed class RandomEntityStorageSpawnRule : StationEventSystem<RandomEntityStorageSpawnRuleComponent>
{
[Dependency] private readonly EntityStorageSystem _entityStorage = default!;
protected override void Started(EntityUid uid, RandomEntityStorageSpawnRuleComponent comp, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, comp, gameRule, args);
if (!TryGetRandomStation(out var station))
return;
var validLockers = new List<(EntityUid, EntityStorageComponent)>();
var spawn = Spawn(comp.Prototype, MapCoordinates.Nullspace);
var query = EntityQueryEnumerator<EntityStorageComponent, TransformComponent>();
while (query.MoveNext(out var ent, out var storage, out var xform))
{
if (StationSystem.GetOwningStation(ent, xform) != station)
continue;
if (!_entityStorage.CanInsert(spawn, ent, storage))
continue;
validLockers.Add((ent, storage));
}
if (validLockers.Count == 0)
{
Del(spawn);
return;
}
var (locker, storageComp) = RobustRandom.Pick(validLockers);
if (!_entityStorage.Insert(spawn, locker, storageComp))
{
Del(spawn);
}
}
}