| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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<AntagLoadProfileRuleComponent>
- {
- [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<AntagLoadProfileRuleComponent, AntagSelectEntityEvent>(OnSelectEntity);
- }
- private void OnSelectEntity(Entity<AntagLoadProfileRuleComponent> 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<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies);
- }
- if (ent.Comp.SpeciesOverride != null
- && (ent.Comp.SpeciesOverrideBlacklist?.Contains(new ProtoId<SpeciesPrototype>(species.ID)) ?? false))
- {
- species = _proto.Index(ent.Comp.SpeciesOverride.Value);
- }
- args.Entity = Spawn(species.Prototype);
- _humanoid.LoadProfile(args.Entity.Value, profile?.WithSpecies(species.ID));
- }
- }
|