using Content.Server.Administration.Commands; using Content.Server.Clothing.Systems; using Content.Server.Ghost.Roles.Components; using Content.Server.Ghost.Roles.Events; using Content.Server.Preferences.Managers; using Content.Server.Station.Systems; using Content.Shared.Mind.Components; using Content.Shared.Preferences; namespace Content.Server.Ghost.Roles { public sealed partial class GhostRoleSystem { [Dependency] private readonly IServerPreferencesManager _prefs = default!; [Dependency] private readonly OutfitSystem _outfit = default!; private void OnSpawnerTakeCharacter(Entity ent, ref TakeGhostRoleEvent args) { var uid = ent.Owner; var component = ent.Comp; if (!TryComp(uid, out GhostRoleComponent? ghostRole) || ghostRole.Taken) { args.TookRole = false; return; } var character = (HumanoidCharacterProfile) _prefs.GetPreferences(args.Player.UserId).SelectedCharacter; var mob = _ent.System() .SpawnPlayerMob(Transform(uid).Coordinates, null, character, null); _transform.AttachToGridOrMap(mob); var spawnedEvent = new GhostRoleSpawnerUsedEvent(uid, mob); RaiseLocalEvent(mob, spawnedEvent); EnsureComp(mob); GhostRoleInternalCreateMindAndTransfer(args.Player, uid, mob, ghostRole); _outfit.SetOutfit(mob, component.OutfitPrototype); EntityManager.AddComponents(mob, component.AddedComponents); if (++component.CurrentTakeovers < component.AvailableTakeovers) { args.TookRole = true; return; } ghostRole.Taken = true; if (component.DeleteOnSpawn) QueueDel(uid); args.TookRole = true; } } }