public string GetGear(Slots slot, HumanoidCharacterProfile?profile) { if (profile != null) { if ((slot == Slots.INNERCLOTHING) && (profile.Clothing == ClothingPreference.Jumpskirt) && (_innerClothingSkirt != "")) { return(_innerClothingSkirt); } if ((slot == Slots.BACKPACK) && (profile.Backpack == BackpackPreference.Satchel) && (_satchel != "")) { return(_satchel); } if ((slot == Slots.BACKPACK) && (profile.Backpack == BackpackPreference.Duffelbag) && (_duffelbag != "")) { return(_duffelbag); } } if (_equipment.ContainsKey(slot)) { return(_equipment[slot]); } else { return(""); } }
public static bool SetOutfit(EntityUid target, string gear, IEntityManager entityManager, Action <EntityUid, EntityUid>?onEquipped = null) { if (!entityManager.TryGetComponent <InventoryComponent?>(target, out var inventoryComponent)) { return(false); } var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); if (!prototypeManager.TryIndex <StartingGearPrototype>(gear, out var startingGear)) { return(false); } HumanoidCharacterProfile?profile = null; // Check if we are setting the outfit of a player to respect the preferences if (entityManager.TryGetComponent <ActorComponent?>(target, out var actorComponent)) { var userId = actorComponent.PlayerSession.UserId; var preferencesManager = IoCManager.Resolve <IServerPreferencesManager>(); var prefs = preferencesManager.GetPreferences(userId); profile = prefs.SelectedCharacter as HumanoidCharacterProfile; } var invSystem = EntitySystem.Get <InventorySystem>(); if (invSystem.TryGetSlots(target, out var slotDefinitions, inventoryComponent)) { foreach (var slot in slotDefinitions) { invSystem.TryUnequip(target, slot.Name, true, true, false, inventoryComponent); var gearStr = startingGear.GetGear(slot.Name, profile); if (gearStr == string.Empty) { continue; } var equipmentEntity = entityManager.SpawnEntity(gearStr, entityManager.GetComponent <TransformComponent>(target).Coordinates); if (slot.Name == "id" && entityManager.TryGetComponent <PDAComponent?>(equipmentEntity, out var pdaComponent) && pdaComponent.ContainedID != null) { pdaComponent.ContainedID.FullName = entityManager.GetComponent <MetaDataComponent>(target).EntityName; } invSystem.TryEquip(target, equipmentEntity, slot.Name, true, inventory: inventoryComponent); onEquipped?.Invoke(target, equipmentEntity); } } return(true); }
/// <summary> /// Attempts to spawn a player character onto the given station. /// </summary> /// <param name="station">Station to spawn onto.</param> /// <param name="job">The job to assign, if any.</param> /// <param name="profile">The character profile to use, if any.</param> /// <param name="stationSpawning">Resolve pattern, the station spawning component for the station.</param> /// <returns>The resulting player character, if any.</returns> /// <exception cref="ArgumentException">Thrown when the given station is not a station.</exception> /// <remarks> /// This only spawns the character, and does none of the mind-related setup you'd need for it to be playable. /// </remarks> public EntityUid?SpawnPlayerCharacterOnStation(EntityUid?station, Job?job, HumanoidCharacterProfile?profile, StationSpawningComponent?stationSpawning = null) { if (station != null && !Resolve(station.Value, ref stationSpawning)) { throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station)); } var ev = new PlayerSpawningEvent(job, profile, station); RaiseLocalEvent(ev); DebugTools.Assert(ev.SpawnResult is { Valid: true } or null); return(ev.SpawnResult); }
//TODO: Figure out if everything in the player spawning region belongs somewhere else. #region Player spawning helpers /// <summary> /// Spawns in a player's mob according to their job and character information at the given coordinates. /// Used by systems that need to handle spawning players. /// </summary> /// <param name="coordinates">Coordinates to spawn the character at.</param> /// <param name="job">Job to assign to the character, if any.</param> /// <param name="profile">Appearance profile to use for the character.</param> /// <param name="station">The station this player is being spawned on.</param> /// <returns>The spawned entity</returns> public EntityUid SpawnPlayerMob( EntityCoordinates coordinates, Job?job, HumanoidCharacterProfile?profile, EntityUid?station) { // If we're not spawning a humanoid, we're gonna exit early without doing all the humanoid stuff. if (job?.JobEntity != null) { var jobEntity = EntityManager.SpawnEntity(job.JobEntity, coordinates); MakeSentientCommand.MakeSentient(jobEntity, EntityManager); DoJobSpecials(job, jobEntity); _identity.QueueIdentityUpdate(jobEntity); return(jobEntity); } var entity = EntityManager.SpawnEntity( _prototypeManager.Index <SpeciesPrototype>(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype, coordinates); if (job?.StartingGear != null) { var startingGear = _prototypeManager.Index <StartingGearPrototype>(job.StartingGear); EquipStartingGear(entity, startingGear, profile); if (profile != null) { EquipIdCard(entity, profile.Name, job.Prototype, station); } } if (profile != null) { _humanoidAppearanceSystem.UpdateFromProfile(entity, profile); EntityManager.GetComponent <MetaDataComponent>(entity).EntityName = profile.Name; if (profile.FlavorText != "" && _configurationManager.GetCVar(CCVars.FlavorText)) { EntityManager.AddComponent <DetailExaminableComponent>(entity).Content = profile.FlavorText; } } DoJobSpecials(job, entity); _identity.QueueIdentityUpdate(entity); return(entity); }
public string GetGear(Slots slot, HumanoidCharacterProfile?profile) { if (profile != null) { if ((slot == Slots.INNERCLOTHING) && (profile.Clothing == ClothingPreference.Jumpskirt) && (_innerClothingSkirt != "")) { return(_innerClothingSkirt); } } if (_equipment.ContainsKey(slot)) { return(_equipment[slot]); } else { return(""); } }
//TODO: Figure out if everything in the player spawning region belongs somewhere else. #region Player spawning helpers /// <summary> /// Spawns in a player's mob according to their job and character information at the given coordinates. /// Used by systems that need to handle spawning players. /// </summary> /// <param name="coordinates">Coordinates to spawn the character at.</param> /// <param name="job">Job to assign to the character, if any.</param> /// <param name="profile">Appearance profile to use for the character.</param> /// <param name="station">The station this player is being spawned on.</param> /// <returns>The spawned entity</returns> public EntityUid SpawnPlayerMob( EntityCoordinates coordinates, Job?job, HumanoidCharacterProfile?profile, EntityUid?station) { var entity = EntityManager.SpawnEntity( _prototypeManager.Index <SpeciesPrototype>(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype, coordinates); if (job?.StartingGear != null) { var startingGear = _prototypeManager.Index <StartingGearPrototype>(job.StartingGear); EquipStartingGear(entity, startingGear, profile); if (profile != null) { EquipIdCard(entity, profile.Name, job.Prototype, station); } } if (profile != null) { _humanoidAppearanceSystem.UpdateFromProfile(entity, profile); EntityManager.GetComponent <MetaDataComponent>(entity).EntityName = profile.Name; if (profile.FlavorText != "" && _configurationManager.GetCVar(CCVars.FlavorText)) { EntityManager.AddComponent <DetailExaminableComponent>(entity).Content = profile.FlavorText; } } foreach (var jobSpecial in job?.Prototype.Special ?? Array.Empty <JobSpecial>()) { jobSpecial.AfterEquip(entity); } return(entity); }
public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager, IEntityManager entityManager) { RobustXamlLoader.Load(this); _random = IoCManager.Resolve <IRobustRandom>(); _prototypeManager = prototypeManager; _entMan = entityManager; _preferencesManager = preferencesManager; #region Left #region Randomize #endregion Randomize #region Name _nameEdit.OnTextChanged += args => { SetName(args.Text); }; _nameRandomButton.OnPressed += args => RandomizeName(); _randomizeEverythingButton.OnPressed += args => { RandomizeEverything(); }; _warningLabel.SetMarkup($"[color=red]{Loc.GetString("humanoid-profile-editor-naming-rules-warning")}[/color]"); #endregion Name #region Appearance _tabContainer.SetTabTitle(0, Loc.GetString("humanoid-profile-editor-appearance-tab")); #region Sex var sexButtonGroup = new ButtonGroup(); _sexMaleButton.Group = sexButtonGroup; _sexMaleButton.OnPressed += args => { SetSex(Sex.Male); if (Profile?.Gender == Gender.Female) { SetGender(Gender.Male); UpdateGenderControls(); } }; _sexFemaleButton.Group = sexButtonGroup; _sexFemaleButton.OnPressed += _ => { SetSex(Sex.Female); if (Profile?.Gender == Gender.Male) { SetGender(Gender.Female); UpdateGenderControls(); } }; #endregion Sex #region Age _ageEdit.OnTextChanged += args => { if (!int.TryParse(args.Text, out var newAge)) { return; } SetAge(newAge); }; #endregion Age #region Gender _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-male-text"), (int)Gender.Male); _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-female-text"), (int)Gender.Female); _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-epicene-text"), (int)Gender.Epicene); _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-neuter-text"), (int)Gender.Neuter); _genderButton.OnItemSelected += args => { _genderButton.SelectId(args.Id); SetGender((Gender)args.Id); }; #endregion Gender #region Species _speciesList = prototypeManager.EnumeratePrototypes <SpeciesPrototype>().ToList(); for (var i = 0; i < _speciesList.Count; i++) { CSpeciesButton.AddItem(_speciesList[i].Name, i); } CSpeciesButton.OnItemSelected += args => { CSpeciesButton.SelectId(args.Id); SetSpecies(_speciesList[args.Id].ID); OnSkinColorOnValueChanged(CSkin); }; #endregion Species #region Skin // 0 - 100, 0 being gold/yellowish and 100 being dark // HSV based // // 0 - 20 changes the hue // 20 - 100 changes the value // 0 is 45 - 20 - 100 // 20 is 25 - 20 - 100 // 100 is 25 - 100 - 20 _skinColor.OnValueChanged += OnSkinColorOnValueChanged; #endregion #region Hair _hairPicker.Populate(); _hairPicker.OnHairStylePicked += newStyle => { if (Profile is null) { return; } Profile = Profile.WithCharacterAppearance( Profile.Appearance.WithHairStyleName(newStyle)); IsDirty = true; }; _hairPicker.OnHairColorPicked += newColor => { if (Profile is null) { return; } Profile = Profile.WithCharacterAppearance( Profile.Appearance.WithHairColor(newColor)); IsDirty = true; }; _facialHairPicker.Populate(); _facialHairPicker.OnHairStylePicked += newStyle => { if (Profile is null) { return; } Profile = Profile.WithCharacterAppearance( Profile.Appearance.WithFacialHairStyleName(newStyle)); IsDirty = true; }; _facialHairPicker.OnHairColorPicked += newColor => { if (Profile is null) { return; } Profile = Profile.WithCharacterAppearance( Profile.Appearance.WithFacialHairColor(newColor)); IsDirty = true; }; #endregion Hair #region Clothing _clothingButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-jumpsuit"), (int)ClothingPreference.Jumpsuit); _clothingButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-jumpskirt"), (int)ClothingPreference.Jumpskirt); _clothingButton.OnItemSelected += args => { _clothingButton.SelectId(args.Id); SetClothing((ClothingPreference)args.Id); }; #endregion Clothing #region Backpack _backpackButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-backpack"), (int)BackpackPreference.Backpack); _backpackButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-satchel"), (int)BackpackPreference.Satchel); _backpackButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-duffelbag"), (int)BackpackPreference.Duffelbag); _backpackButton.OnItemSelected += args => { _backpackButton.SelectId(args.Id); SetBackpack((BackpackPreference)args.Id); }; #endregion Backpack #region Eyes _eyesPicker.OnEyeColorPicked += newColor => { if (Profile is null) { return; } Profile = Profile.WithCharacterAppearance( Profile.Appearance.WithEyeColor(newColor)); IsDirty = true; }; #endregion Eyes #endregion Appearance #region Jobs _tabContainer.SetTabTitle(1, Loc.GetString("humanoid-profile-editor-jobs-tab")); _preferenceUnavailableButton.AddItem( Loc.GetString("humanoid-profile-editor-preference-unavailable-stay-in-lobby-button"), (int)PreferenceUnavailableMode.StayInLobby); _preferenceUnavailableButton.AddItem( Loc.GetString("humanoid-profile-editor-preference-unavailable-spawn-as-overflow-button", ("overflowJob", Loc.GetString(SharedGameTicker.FallbackOverflowJobName))), (int)PreferenceUnavailableMode.SpawnAsOverflow); _preferenceUnavailableButton.OnItemSelected += args => { _preferenceUnavailableButton.SelectId(args.Id); Profile = Profile?.WithPreferenceUnavailable((PreferenceUnavailableMode)args.Id); IsDirty = true; }; _jobPriorities = new List <JobPrioritySelector>(); _jobCategories = new Dictionary <string, BoxContainer>(); var firstCategory = true; foreach (var job in prototypeManager.EnumeratePrototypes <JobPrototype>().OrderBy(j => j.Name)) { if (!job.SetPreference) { continue; } foreach (var department in job.Departments) { if (!_jobCategories.TryGetValue(department, out var category)) { category = new BoxContainer { Orientation = LayoutOrientation.Vertical, Name = department, ToolTip = Loc.GetString("humanoid-profile-editor-jobs-amount-in-department-tooltip", ("departmentName", department)) }; if (firstCategory) { firstCategory = false; } else { category.AddChild(new Control { MinSize = new Vector2(0, 23), }); } category.AddChild(new PanelContainer { PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex("#464966") }, Children = { new Label { Text = Loc.GetString("humanoid-profile-editor-department-jobs-label", ("departmentName", department)) } } });
public void Execute(IConsoleShell shell, string argStr, string[] args) { if (args.Length < 1) { shell.WriteLine(Loc.GetString("shell-wrong-arguments-number")); return; } if (!int.TryParse(args[0], out var entityUid)) { shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number")); return; } var entityManager = IoCManager.Resolve <IEntityManager>(); var target = new EntityUid(entityUid); if (!target.IsValid() || !entityManager.EntityExists(target)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } if (!entityManager.TryGetComponent <InventoryComponent?>(target, out var inventoryComponent)) { shell.WriteLine(Loc.GetString("shell-target-entity-does-not-have-message", ("missing", "inventory"))); return; } if (args.Length == 1) { if (shell.Player is not IPlayerSession player) { shell.WriteError(Loc.GetString("set-outfit-command-is-not-player-error")); return; } var eui = IoCManager.Resolve <EuiManager>(); var ui = new SetOutfitEui(target); eui.OpenEui(ui, player); return; } var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); if (!prototypeManager.TryIndex <StartingGearPrototype>(args[1], out var startingGear)) { shell.WriteLine(Loc.GetString("set-outfit-command-invalid-outfit-id-error")); return; } HumanoidCharacterProfile?profile = null; // Check if we are setting the outfit of a player to respect the preferences if (entityManager.TryGetComponent <ActorComponent?>(target, out var actorComponent)) { var userId = actorComponent.PlayerSession.UserId; var preferencesManager = IoCManager.Resolve <IServerPreferencesManager>(); var prefs = preferencesManager.GetPreferences(userId); profile = prefs.SelectedCharacter as HumanoidCharacterProfile; } var invSystem = EntitySystem.Get <InventorySystem>(); if (invSystem.TryGetSlots(target, out var slotDefinitions, inventoryComponent)) { foreach (var slot in slotDefinitions) { invSystem.TryUnequip(target, slot.Name, true, true, inventoryComponent); var gearStr = startingGear.GetGear(slot.Name, profile); if (gearStr == string.Empty) { continue; } var equipmentEntity = entityManager.SpawnEntity(gearStr, entityManager.GetComponent <TransformComponent>(target).Coordinates); if (slot.Name == "id" && entityManager.TryGetComponent <PDAComponent?>(equipmentEntity, out var pdaComponent) && pdaComponent.ContainedID != null) { pdaComponent.ContainedID.FullName = entityManager.GetComponent <MetaDataComponent>(target).EntityName; } invSystem.TryEquip(target, equipmentEntity, slot.Name, true, inventory: inventoryComponent); } } }
public PlayerSpawningEvent(Job?job, HumanoidCharacterProfile?humanoidCharacterProfile, EntityUid?station) { Job = job; HumanoidCharacterProfile = humanoidCharacterProfile; Station = station; }
/// <summary> /// Equips starting gear onto the given entity. /// </summary> /// <param name="entity">Entity to load out.</param> /// <param name="startingGear">Starting gear to use.</param> /// <param name="profile">Character profile to use, if any.</param> public void EquipStartingGear(EntityUid entity, StartingGearPrototype startingGear, HumanoidCharacterProfile?profile) { if (_inventorySystem.TryGetSlots(entity, out var slotDefinitions)) { foreach (var slot in slotDefinitions) { var equipmentStr = startingGear.GetGear(slot.Name, profile); if (!string.IsNullOrEmpty(equipmentStr)) { var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, EntityManager.GetComponent <TransformComponent>(entity).Coordinates); _inventorySystem.TryEquip(entity, equipmentEntity, slot.Name, true); } } } if (!TryComp(entity, out HandsComponent? handsComponent)) { return; } var inhand = startingGear.Inhand; var coords = EntityManager.GetComponent <TransformComponent>(entity).Coordinates; foreach (var(hand, prototype) in inhand) { var inhandEntity = EntityManager.SpawnEntity(prototype, coords); _handsSystem.TryPickup(entity, inhandEntity, hand, checkActionBlocker: false, handsComp: handsComponent); } }
public void Execute(IConsoleShell shell, string argStr, string[] args) { if (args.Length < 1) { shell.WriteLine(Loc.GetString("Wrong number of arguments.")); return; } if (!int.TryParse(args[0], out var entityUid)) { shell.WriteLine(Loc.GetString("EntityUid must be a number.")); return; } var entityManager = IoCManager.Resolve <IEntityManager>(); var eUid = new EntityUid(entityUid); if (!eUid.IsValid() || !entityManager.EntityExists(eUid)) { shell.WriteLine(Loc.GetString("Invalid entity ID.")); return; } var target = entityManager.GetEntity(eUid); if (!target.TryGetComponent <InventoryComponent>(out var inventoryComponent)) { shell.WriteLine(Loc.GetString("Target entity does not have an inventory!")); return; } if (args.Length == 1) { if (!(shell.Player is IPlayerSession player)) { shell.WriteError( Loc.GetString( "This does not work from the server console. You must pass the outfit id aswell.")); return; } var eui = IoCManager.Resolve <EuiManager>(); var ui = new SetOutfitEui(target); eui.OpenEui(ui, player); return; } var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); if (!prototypeManager.TryIndex <StartingGearPrototype>(args[1], out var startingGear)) { shell.WriteLine(Loc.GetString("Invalid outfit id")); return; } HumanoidCharacterProfile?profile = null; // Check if we are setting the outfit of a player to respect the preferences if (target.TryGetComponent <IActorComponent>(out var actorComponent)) { var userId = actorComponent.playerSession.UserId; var preferencesManager = IoCManager.Resolve <IServerPreferencesManager>(); var prefs = preferencesManager.GetPreferences(userId); profile = prefs.SelectedCharacter as HumanoidCharacterProfile; } foreach (var slot in inventoryComponent.Slots) { inventoryComponent.ForceUnequip(slot); var gearStr = startingGear.GetGear(slot, profile); if (gearStr == "") { continue; } var equipmentEntity = entityManager.SpawnEntity(gearStr, target.Transform.Coordinates); if (slot == EquipmentSlotDefines.Slots.IDCARD && equipmentEntity.TryGetComponent <PDAComponent>(out var pdaComponent) && pdaComponent.ContainedID != null) { pdaComponent.ContainedID.FullName = target.Name; } inventoryComponent.Equip(slot, equipmentEntity.GetComponent <ItemComponent>(), false); } }
public void EquipStartingGear(IEntity entity, StartingGearPrototype startingGear, HumanoidCharacterProfile?profile) { }