random loadout support (#11027)

This commit is contained in:
Nemanja
2022-09-16 10:03:45 -04:00
committed by GitHub
parent 2003a58138
commit dc1d8ec9b4
5 changed files with 26 additions and 20 deletions

View File

@@ -1,12 +1,16 @@
using Content.Shared.Roles;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Server.Clothing.Components
{
[RegisterComponent]
public sealed class LoadoutComponent : Component
{
[DataField("prototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
public string Prototype = string.Empty;
/// <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>))]
public List<string>? Prototypes;
}
}

View File

@@ -2,6 +2,7 @@ using Content.Server.Clothing.Components;
using Content.Server.Station.Systems;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Clothing
{
@@ -12,6 +13,7 @@ namespace Content.Server.Clothing
{
[Dependency] private readonly StationSpawningSystem _station = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
@@ -22,10 +24,10 @@ namespace Content.Server.Clothing
private void OnStartup(EntityUid uid, LoadoutComponent component, ComponentStartup args)
{
if (component.Prototype == string.Empty)
if (component.Prototypes == null)
return;
var proto = _protoMan.Index<StartingGearPrototype>(component.Prototype);
var proto = _protoMan.Index<StartingGearPrototype>(_random.Pick(component.Prototypes));
_station.EquipStartingGear(uid, proto, null);
}
}