mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
183 lines
5.5 KiB
C#
183 lines
5.5 KiB
C#
using System.Linq;
|
|
using Content.Shared.Body;
|
|
using Content.Shared.Clothing.Components;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Preferences.Loadouts;
|
|
using Content.Shared.Roles;
|
|
using Content.Shared.Station.Systems;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Shared.Clothing;
|
|
|
|
/// <summary>
|
|
/// Assigns a loadout to an entity based on the RoleLoadout prototype
|
|
/// </summary>
|
|
public sealed partial class LoadoutSystem : EntitySystem
|
|
{
|
|
// Shared so we can predict it for placement manager.
|
|
|
|
[Dependency] private ActorSystem _actors = default!;
|
|
[Dependency] private StationSpawningSystem _station = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
// Wait until the character has all their organs before we give them their loadout
|
|
SubscribeLocalEvent<LoadoutComponent, MapInitEvent>(OnMapInit, after: [typeof(InitialBodySystem)]);
|
|
}
|
|
|
|
public static string GetJobPrototype(string? loadout)
|
|
{
|
|
if (string.IsNullOrEmpty(loadout))
|
|
return string.Empty;
|
|
|
|
return "Job" + loadout;
|
|
}
|
|
|
|
public EntProtoId? GetFirstOrNull(LoadoutPrototype loadout)
|
|
{
|
|
EntProtoId? proto = null;
|
|
|
|
if (ProtoMan.Resolve(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(IEquipmentLoadout? gear)
|
|
{
|
|
if (gear == null)
|
|
return null;
|
|
|
|
var count = gear.Equipment.Count + gear.Inhand.Count + gear.Storage.Values.Sum(x => x.Count);
|
|
|
|
if (count == 1)
|
|
{
|
|
if (gear.Equipment.Count == 1 && ProtoMan.Resolve(gear.Equipment.Values.First(), out var proto))
|
|
{
|
|
return proto.ID;
|
|
}
|
|
|
|
if (gear.Inhand.Count == 1 && ProtoMan.Resolve(gear.Inhand[0], out proto))
|
|
{
|
|
return proto.ID;
|
|
}
|
|
|
|
// Storage moment
|
|
foreach (var ents in gear.Storage.Values)
|
|
{
|
|
foreach (var ent in ents)
|
|
{
|
|
return ent;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public string GetName(LoadoutPrototype loadout)
|
|
{
|
|
if (loadout.DummyEntity is not null && ProtoMan.Resolve(loadout.DummyEntity, out var proto))
|
|
return proto.Name;
|
|
|
|
if (ProtoMan.Resolve(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(IEquipmentLoadout? gear)
|
|
{
|
|
if (gear == null)
|
|
return string.Empty;
|
|
|
|
var count = gear.Equipment.Count + gear.Storage.Values.Sum(o => o.Count) + gear.Inhand.Count;
|
|
|
|
if (count == 1)
|
|
{
|
|
if (gear.Equipment.Count == 1 && ProtoMan.TryIndex<EntityPrototype>(gear.Equipment.Values.First(), out var proto))
|
|
{
|
|
return proto.Name;
|
|
}
|
|
|
|
if (gear.Inhand.Count == 1 && ProtoMan.TryIndex<EntityPrototype>(gear.Inhand[0], out proto))
|
|
{
|
|
return proto.Name;
|
|
}
|
|
|
|
foreach (var values in gear.Storage.Values)
|
|
{
|
|
if (values.Count != 1)
|
|
continue;
|
|
|
|
if (ProtoMan.TryIndex<EntityPrototype>(values[0], out proto))
|
|
{
|
|
return proto.Name;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return Loc.GetString($"unknown");
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent args)
|
|
{
|
|
Equip(uid, component.StartingGear, component.RoleLoadout);
|
|
}
|
|
|
|
public void Equip(EntityUid uid, List<ProtoId<StartingGearPrototype>>? startingGear,
|
|
List<ProtoId<RoleLoadoutPrototype>>? loadoutGroups)
|
|
{
|
|
// First, randomly pick a startingGear profile from those specified, and equip it.
|
|
if (startingGear != null && startingGear.Count > 0)
|
|
_station.EquipStartingGear(uid, _random.Pick(startingGear), false);
|
|
|
|
if (loadoutGroups == null)
|
|
{
|
|
GearEquipped(uid);
|
|
return;
|
|
}
|
|
|
|
// Then, randomly pick a RoleLoadout profile from those specified, and process/equip all LoadoutGroups from it.
|
|
// For non-roundstart mobs there is no SelectedLoadout data, so minValue must be set in each LoadoutGroup to force selection.
|
|
var id = _random.Pick(loadoutGroups);
|
|
var proto = ProtoMan.Index(id);
|
|
var loadout = new RoleLoadout(id);
|
|
loadout.SetDefault(GetProfile(uid), _actors.GetSession(uid), ProtoMan, true);
|
|
_station.EquipRoleLoadout(uid, loadout, proto);
|
|
|
|
GearEquipped(uid);
|
|
}
|
|
|
|
public void GearEquipped(EntityUid uid)
|
|
{
|
|
var ev = new StartingGearEquippedEvent(uid);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
}
|
|
|
|
public HumanoidCharacterProfile GetProfile(EntityUid? uid)
|
|
{
|
|
return TryComp<HumanoidProfileComponent>(uid, out var profile)
|
|
? HumanoidCharacterProfile.DefaultWithSpecies(profile.Species, profile.Sex)
|
|
: HumanoidCharacterProfile.Random();
|
|
}
|
|
}
|