mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-30 03:57:35 +03:00
This cherry-pick's Wizden's Antag Refactor, which is needed for all future antag updates, as well as for me to cherry-pick over Cultists(Who are going to need some editing to fit the antag refactor), Changelings, Heretics, and Wizards. I actually selected the White-Dream-Public version of the Antag Refactor, due to it having commits made tailored to our repository, so it comes prepackaged with all the changes necessary for our repo-specific content. https://github.com/frosty-dev/ss14-wwdp/pull/10 Signed-off-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com> Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Jeff <velcroboy333@hotmail.com> Co-authored-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com> Co-authored-by: Timemaster99 <elijahrobot@gmail.com> Co-authored-by: luckywill339@gmail.com <luckywill339@gmail.com> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: Azzy <azzydev@icloud.com>
50 lines
1.6 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|