Fix humanoid appearances for placement manager (#18291)
This commit is contained in:
16
Content.Shared/Clothing/Components/LoadoutComponent.cs
Normal file
16
Content.Shared/Clothing/Components/LoadoutComponent.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Clothing.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class LoadoutComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of starting gears, of which one will be given.
|
||||
/// All elements are weighted the same in the list.
|
||||
/// </summary>
|
||||
[DataField("prototypes", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<StartingGearPrototype>)), AutoNetworkedField]
|
||||
public List<string>? Prototypes;
|
||||
}
|
||||
35
Content.Shared/Clothing/LoadoutSystem.cs
Normal file
35
Content.Shared/Clothing/LoadoutSystem.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Station;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Clothing;
|
||||
|
||||
/// <summary>
|
||||
/// Assigns a loadout to an entity based on the startingGear prototype
|
||||
/// </summary>
|
||||
public sealed class LoadoutSystem : EntitySystem
|
||||
{
|
||||
// Shared so we can predict it for placement manager.
|
||||
|
||||
[Dependency] private readonly SharedStationSpawningSystem _station = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<LoadoutComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.Prototypes == null)
|
||||
return;
|
||||
|
||||
var proto = _protoMan.Index<StartingGearPrototype>(_random.Pick(component.Prototypes));
|
||||
_station.EquipStartingGear(uid, proto, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user