if (_prototypeManager.HasIndex<RoleLoadoutPrototype>(LoadoutSystem.GetJobPrototype(job.ID)))
{
- var loadout = profile.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), profile.Species, EntityManager, _prototypeManager);
+ var loadout = profile.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), _playerManager.LocalSession, profile.Species, EntityManager, _prototypeManager);
GiveDummyLoadout(dummy, loadout);
}
}
if (_prototypeManager.HasIndex<RoleLoadoutPrototype>(LoadoutSystem.GetJobPrototype(job.ID)))
{
- var loadout = humanoid.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), humanoid.Species, EntityManager, _prototypeManager);
+ var loadout = humanoid.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), _playerManager.LocalSession, humanoid.Species, EntityManager, _prototypeManager);
GiveDummyLoadout(dummyEnt, loadout);
}
}
if (loadout == null)
{
loadout = new RoleLoadout(roleLoadoutProto.ID);
- loadout.SetDefault(_prototypeManager);
+ loadout.SetDefault(Profile, _playerManager.LocalSession, _prototypeManager);
}
OpenLoadout(job, loadout, roleLoadoutProto);
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
+using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
[PublicAPI]
public sealed class StationSpawningSystem : SharedStationSpawningSystem
{
+ [Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
- [Dependency] private readonly IConfigurationManager _configurationManager = default!;
+ [Dependency] private readonly ActorSystem _actors = default!;
+ [Dependency] private readonly ArrivalsSystem _arrivalsSystem = default!;
+ [Dependency] private readonly ContainerSpawnPointSystem _containerSpawnPointSystem = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidSystem = default!;
[Dependency] private readonly IdCardSystem _cardSystem = default!;
- [Dependency] private readonly PdaSystem _pdaSystem = default!;
- [Dependency] private readonly SharedAccessSystem _accessSystem = default!;
[Dependency] private readonly IdentitySystem _identity = default!;
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
-
- [Dependency] private readonly ArrivalsSystem _arrivalsSystem = default!;
- [Dependency] private readonly ContainerSpawnPointSystem _containerSpawnPointSystem = default!;
+ [Dependency] private readonly PdaSystem _pdaSystem = default!;
+ [Dependency] private readonly SharedAccessSystem _accessSystem = default!;
private bool _randomizeCharacters;
if (loadout == null)
{
loadout = new RoleLoadout(jobLoadout);
- loadout.SetDefault(_prototypeManager);
+ loadout.SetDefault(profile, _actors.GetSession(entity), _prototypeManager);
}
EquipRoleLoadout(entity.Value, loadout, roleProto);
using System.Linq;
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;
+using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
{
// Shared so we can predict it for placement manager.
+ [Dependency] private readonly ActorSystem _actors = default!;
[Dependency] private readonly SharedStationSpawningSystem _station = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
var id = _random.Pick(component.RoleLoadout);
var proto = _protoMan.Index(id);
var loadout = new RoleLoadout(id);
- loadout.SetDefault(_protoMan, true);
+ loadout.SetDefault(GetProfile(uid), _actors.GetSession(uid), _protoMan, true);
_station.EquipRoleLoadout(uid, loadout, proto);
}
+
+ public HumanoidCharacterProfile GetProfile(EntityUid? uid)
+ {
+ if (TryComp(uid, out HumanoidAppearanceComponent? appearance))
+ {
+ return HumanoidCharacterProfile.DefaultWithSpecies(appearance.Species);
+ }
+
+ return HumanoidCharacterProfile.Random();
+ }
}
return profile;
}
- public RoleLoadout GetLoadoutOrDefault(string id, ProtoId<SpeciesPrototype>? species, IEntityManager entManager, IPrototypeManager protoManager)
+ public RoleLoadout GetLoadoutOrDefault(string id, ICommonSession? session, ProtoId<SpeciesPrototype>? species, IEntityManager entManager, IPrototypeManager protoManager)
{
if (!_loadouts.TryGetValue(id, out var loadout))
{
loadout = new RoleLoadout(id);
- loadout.SetDefault(protoManager, force: true);
+ loadout.SetDefault(this, session, protoManager, force: true);
}
- loadout.SetDefault(protoManager);
+ loadout.SetDefault(this, session, protoManager);
return loadout;
}
[DataField(required: true)]
public ProtoId<LoadoutEffectGroupPrototype> Proto;
- public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
+ public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
{
var effectsProto = collection.Resolve<IPrototypeManager>().Index(Proto);
[DataField(required: true)]
public JobRequirement Requirement = default!;
- public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
+ public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
{
+ if (session == null)
+ {
+ reason = FormattedMessage.Empty;
+ return true;
+ }
+
var manager = collection.Resolve<ISharedPlaytimeManager>();
var playtimes = manager.GetPlayTimes(session);
return JobRequirements.TryRequirementMet(Requirement, playtimes, out reason,
public abstract bool Validate(
HumanoidCharacterProfile profile,
RoleLoadout loadout,
- ICommonSession session,
+ ICommonSession? session,
IDependencyCollection collection,
[NotNullWhen(false)] out FormattedMessage? reason);
public override bool Validate(
HumanoidCharacterProfile profile,
RoleLoadout loadout,
- ICommonSession session,
+ ICommonSession? session,
IDependencyCollection collection,
[NotNullWhen(false)] out FormattedMessage? reason)
{
[DataField(required: true)]
public List<ProtoId<SpeciesPrototype>> Species = new();
- public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession session, IDependencyCollection collection,
+ public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection,
[NotNullWhen(false)] out FormattedMessage? reason)
{
if (Species.Contains(profile.Species))
/// <summary>
/// Resets the selected loadouts to default if no data is present.
/// </summary>
- /// <param name="force">Clear existing data first</param>
- public void SetDefault(IPrototypeManager protoManager, bool force = false)
+ public void SetDefault(HumanoidCharacterProfile? profile, ICommonSession? session, IPrototypeManager protoManager, bool force = false)
{
+ if (profile == null)
+ return;
+
if (force)
SelectedLoadouts.Clear();
+ var collection = IoCManager.Instance!;
var roleProto = protoManager.Index(Role);
for (var i = roleProto.Groups.Count - 1; i >= 0; i--)
if (SelectedLoadouts.ContainsKey(group))
continue;
- SelectedLoadouts[group] = new List<Loadout>();
+ var loadouts = new List<Loadout>();
+ SelectedLoadouts[group] = loadouts;
if (groupProto.MinLimit > 0)
{
// Apply any loadouts we can.
for (var j = 0; j < Math.Min(groupProto.MinLimit, groupProto.Loadouts.Count); j++)
{
- AddLoadout(group, groupProto.Loadouts[j], protoManager);
+ if (!protoManager.TryIndex(groupProto.Loadouts[j], out var loadoutProto))
+ continue;
+
+ var defaultLoadout = new Loadout()
+ {
+ Prototype = loadoutProto.ID,
+ };
+
+ // Not valid so don't default to it anyway.
+ if (!IsValid(profile, session, defaultLoadout.Prototype, collection, out _))
+ continue;
+
+ loadouts.Add(defaultLoadout);
+ Apply(loadoutProto);
}
}
}
/// <summary>
/// Returns whether a loadout is valid or not.
/// </summary>
- public bool IsValid(HumanoidCharacterProfile profile, ICommonSession session, ProtoId<LoadoutPrototype> loadout, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
+ public bool IsValid(HumanoidCharacterProfile profile, ICommonSession? session, ProtoId<LoadoutPrototype> loadout, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
{
reason = null;