closet skeleton event (#19802)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using Content.Server.StationEvents.Events;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.StationEvents.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Spawns a single entity in a random EntityStorage on the station
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(RandomEntityStorageSpawnRule))]
|
||||
public sealed partial class RandomEntityStorageSpawnRuleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity to be spawned.
|
||||
/// </summary>
|
||||
[DataField("prototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Prototype = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.StationEvents.Components;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
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, TransformComponent)>();
|
||||
|
||||
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(ent, storage) || storage.Open)
|
||||
continue;
|
||||
|
||||
validLockers.Add((ent, storage, xform));
|
||||
}
|
||||
|
||||
if (validLockers.Count == 0)
|
||||
return;
|
||||
|
||||
var (locker, storageComp, xformComp) = RobustRandom.Pick(validLockers);
|
||||
var spawn = Spawn(comp.Prototype, xformComp.Coordinates);
|
||||
if (!_entityStorage.Insert(spawn, locker, storageComp))
|
||||
{
|
||||
Del(spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user