using Content.Server.Antag; using Content.Server.GameTicking.Rules.Components; using Content.Server.Humanoid; using Content.Server.Preferences.Managers; using Content.Shared.Humanoid; using Content.Shared.Humanoid.Prototypes; using Content.Shared.Preferences; using Robust.Shared.Prototypes; namespace Content.Server.GameTicking.Rules; public sealed class AntagLoadProfileRuleSystem : GameRuleSystem { [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!; [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IServerPreferencesManager _prefs = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnSelectEntity); } private void OnSelectEntity(Entity ent, ref AntagSelectEntityEvent args) { if (args.Handled) return; var profile = args.Session != null ? _prefs.GetPreferences(args.Session.UserId).SelectedCharacter as HumanoidCharacterProfile : HumanoidCharacterProfile.RandomWithSpecies(); if (profile?.Species is not { } speciesId || !_proto.TryIndex(speciesId, out var species)) { species = _proto.Index(SharedHumanoidAppearanceSystem.DefaultSpecies); } if (ent.Comp.SpeciesOverride != null && (ent.Comp.SpeciesOverrideBlacklist?.Contains(new ProtoId(species.ID)) ?? false)) { species = _proto.Index(ent.Comp.SpeciesOverride.Value); } args.Entity = Spawn(species.Prototype); _humanoid.LoadProfile(args.Entity.Value, profile?.WithSpecies(species.ID)); } }