De-duplicate loadout gear (#30341)

* De-duplicate loadout gear

Needs supporting code, probably with an interface with StartingGearPrototype which would also use it, but I regexed the yaml.

* Code updates

* Remaining yaml

* Fix automatic naming

* raiseEvent

* Don't code when tired kids
This commit is contained in:
metalgearsloth
2024-08-05 14:42:25 +10:00
committed by GitHub
parent 6264a557a6
commit 9a8620d9d8
47 changed files with 173 additions and 1641 deletions

View File

@@ -40,12 +40,25 @@ public sealed class LoadoutSystem : EntitySystem
return "Job" + loadout;
}
public EntProtoId? GetFirstOrNull(LoadoutPrototype loadout)
{
EntProtoId? proto = null;
if (_protoMan.TryIndex(loadout.StartingGear, out var gear))
{
proto = GetFirstOrNull(gear);
}
proto ??= GetFirstOrNull((IEquipmentLoadout)loadout);
return proto;
}
/// <summary>
/// Tries to get the first entity prototype for operations such as sprite drawing.
/// </summary>
public EntProtoId? GetFirstOrNull(LoadoutPrototype loadout)
public EntProtoId? GetFirstOrNull(IEquipmentLoadout? gear)
{
if (!_protoMan.TryIndex(loadout.Equipment, out var gear))
if (gear == null)
return null;
var count = gear.Equipment.Count + gear.Inhand.Count + gear.Storage.Values.Sum(x => x.Count);
@@ -75,13 +88,23 @@ public sealed class LoadoutSystem : EntitySystem
return null;
}
public string GetName(LoadoutPrototype loadout)
{
if (_protoMan.TryIndex(loadout.StartingGear, out var gear))
{
return GetName(gear);
}
return GetName((IEquipmentLoadout) loadout);
}
/// <summary>
/// Tries to get the name of a loadout.
/// </summary>
public string GetName(LoadoutPrototype loadout)
public string GetName(IEquipmentLoadout? gear)
{
if (!_protoMan.TryIndex(loadout.Equipment, out var gear))
return Loc.GetString("loadout-unknown");
if (gear == null)
return string.Empty;
var count = gear.Equipment.Count + gear.Storage.Values.Sum(o => o.Count) + gear.Inhand.Count;
@@ -111,7 +134,7 @@ public sealed class LoadoutSystem : EntitySystem
}
}
return Loc.GetString($"loadout-{loadout.ID}");
return Loc.GetString($"unknown");
}
private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent args)
@@ -119,8 +142,7 @@ public sealed class LoadoutSystem : EntitySystem
// Use starting gear if specified
if (component.StartingGear != null)
{
var gear = _protoMan.Index(_random.Pick(component.StartingGear));
_station.EquipStartingGear(uid, gear);
_station.EquipStartingGear(uid, _random.Pick(component.StartingGear));
return;
}