Skip to content

Commit

Permalink
Make marines spawn in full gear in the character editor (RMC-14#5065)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutch-VanDerLinde authored Dec 6, 2024
1 parent 4a7c733 commit 164082d
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 23 deletions.
18 changes: 18 additions & 0 deletions Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Client.Lobby.UI;
using Content.Client.Players.PlayTimeTracking;
using Content.Client.Station;
using Content.Shared._RMC14.Armor;
using Content.Shared.CCVar;
using Content.Shared.Clothing;
using Content.Shared.GameTicking;
Expand Down Expand Up @@ -46,6 +47,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
[UISystemDependency] private readonly StationSpawningSystem _spawn = default!;
[UISystemDependency] private readonly GuidebookSystem _guide = default!;
[UISystemDependency] private readonly LoadoutSystem _loadouts = default!;
[UISystemDependency] private readonly CMArmorSystem _armorSystem = default!;

private CharacterSetupGui? _characterSetup;
private HumanoidProfileEditor? _profileEditor;
Expand Down Expand Up @@ -436,10 +438,15 @@ public void GiveDummyJobClothes(EntityUid dummy, HumanoidCharacterProfile profil
if (!_prototypeManager.TryIndex(job.StartingGear, out var gear))
return;

_prototypeManager.TryIndex(job.DummyStartingGear, out var dummyGear);

foreach (var slot in slots)
{
var itemType = ((IEquipmentLoadout) gear).GetGear(slot.Name);

if (itemType == string.Empty && dummyGear != null)
itemType = ((IEquipmentLoadout) dummyGear).GetGear(slot.Name);

if (_inventory.TryUnequip(dummy, slot.Name, out var unequippedItem, silent: true, force: true, reparent: false))
{
EntityManager.DeleteEntity(unequippedItem.Value);
Expand All @@ -448,6 +455,17 @@ public void GiveDummyJobClothes(EntityUid dummy, HumanoidCharacterProfile profil
if (itemType != string.Empty)
{
var item = EntityManager.SpawnEntity(itemType, MapCoordinates.Nullspace);

if (EntityManager.TryGetComponent<RMCArmorVariantComponent>(item, out var variantComponent))
{
var variantItemProtoId = _armorSystem.GetArmorVariant((item, variantComponent), profile.ArmorPreference);
var variantItem = EntityManager.SpawnEntity(variantItemProtoId, MapCoordinates.Nullspace);
_inventory.TryEquip(dummy, variantItem, slot.Name, true, true);
EntityManager.QueueDeleteEntity(item);

continue;
}

_inventory.TryEquip(dummy, item, slot.Name, true, true);
}
}
Expand Down
15 changes: 2 additions & 13 deletions Content.Server/_RMC14/Armor/RMCArmorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public sealed class RMCArmorSystem : EntitySystem
[Dependency] private readonly IServerPreferencesManager _prefs = default!;
[Dependency] protected readonly InventorySystem InventorySystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly CMArmorSystem _armorSystem = default!;

private EntityQuery<RMCArmorVariantComponent> _armorVariantQuery;

Expand All @@ -39,19 +40,7 @@ private void OnAutomatedVenderUser(Entity<MarineComponent> ent, ref RMCAutomated
if (profile == null)
return;

var armorType = profile.ArmorPreference;
var equipmentEntityID = armor.DefaultType;

if (armor.Types.TryGetValue(armorType.ToString(), out var equipment))
equipmentEntityID = equipment;

if (armorType == ArmorPreference.Random)
{
var random = new Random();
var randomType = armor.Types.ElementAt(random.Next(0, armor.Types.Count)).Value;
equipmentEntityID = randomType;
}

var equipmentEntityID = _armorSystem.GetArmorVariant((args.Item, armor), profile.ArmorPreference);
var equipmentEntity = Spawn(equipmentEntityID, _transform.GetMapCoordinates(ent));
InventorySystem.TryEquip(ent, equipmentEntity, "outerClothing", force: true, predicted: false);

Expand Down
22 changes: 21 additions & 1 deletion Content.Shared/_RMC14/Armor/CMArmorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared._RMC14.Medical.Surgery;
using System.Linq;
using Content.Shared._RMC14.Medical.Surgery;
using Content.Shared._RMC14.Medical.Surgery.Steps;
using Content.Shared._RMC14.Xenonids;
using Content.Shared._RMC14.Xenonids.Projectile.Spit.Slowing;
Expand All @@ -10,6 +11,7 @@
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Preferences;
using Robust.Shared.Prototypes;

namespace Content.Shared._RMC14.Armor;
Expand Down Expand Up @@ -257,4 +259,22 @@ public void SetArmorPiercing(Entity<CMArmorPiercingComponent> ent, int amount)
ent.Comp.Amount = amount;
Dirty(ent);
}

public EntProtoId GetArmorVariant(Entity<RMCArmorVariantComponent> ent, ArmorPreference preference)
{
var comp = ent.Comp;
var equipmentEntityID = comp.DefaultType;

if (comp.Types.TryGetValue(preference.ToString(), out var equipment))
equipmentEntityID = equipment;

if (preference == ArmorPreference.Random)
{
var random = new System.Random();
var randomType = comp.Types.ElementAt(random.Next(0, comp.Types.Count)).Value;
equipmentEntityID = randomType;
}

return equipmentEntityID;
}
}
3 changes: 3 additions & 0 deletions Content.Shared/_RMC14/Marines/Roles/JobPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ public sealed partial class JobPrototype : IInheritingPrototype, ICMSpecific

[DataField]
public float RoleWeight;

[DataField]
public ProtoId<StartingGearPrototype>? DummyStartingGear { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
department: CMSquad
time: 3600 # 1 hour
startingGear: CMGearCombatTech
dummyStartingGear: CMGearCombatTechEquipped
icon: "CMJobIconCombatTech"
joinNotifyCrew: false
supervisors: cm-job-supervisors-sl
Expand Down Expand Up @@ -49,9 +50,8 @@
jumpsuit: CMJumpsuitMarineEngineer
back: CMSatchelMarineTech
shoes: CMBootsBlackFilled
eyes: ClothingEyesGlassesMeson
head: CMArmorHelmetM10Tech
outerClothing: CMArmorM3Medium
outerClothing: RMCArmorM3MediumVariants
gloves: CMHandsInsulated
id: CMDogtagCombatTech
ears: CMHeadsetAlphaEngineer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
department: CMSquad
time: 28800 # 8 hours
startingGear: CMGearFireteamLeader
dummyStartingGear: CMGearFireteamLeaderEquipped
icon: "CMJobIconFireteamLeader"
joinNotifyCrew: false
supervisors: cm-job-supervisors-sl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
department: CMSquad
time: 3600 # 1 hour
startingGear: CMGearHospitalCorpsman
dummyStartingGear: CMGearHospitalCorpsmanEquipped
icon: "CMJobIconHospitalCorpsman"
joinNotifyCrew: false
supervisors: cm-job-supervisors-sl
Expand Down Expand Up @@ -51,10 +52,9 @@
jumpsuit: CMJumpsuitMarineMedic
back: CMSatchelMarineMedic
shoes: CMBootsBlackFilled
gloves: CMHandsBlackMarine
eyes: RMCGlassesMedicalHUDGlasses
gloves: RMCHandsLatexMarine
head: CMArmorHelmetM10Medic
outerClothing: CMArmorM3Medium
outerClothing: RMCArmorM3MediumVariants
id: CMDogtagHospitalCorpsman
ears: CMHeadsetAlphaMedic
belt: CMBeltMedicBagFilled
Expand Down
3 changes: 2 additions & 1 deletion Resources/Prototypes/_RMC14/Roles/Jobs/Marines/rifleman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
description: cm-job-description-rifleman
playTimeTracker: CMJobRifleman
startingGear: CMGearRifleman
dummyStartingGear: CMGearRiflemanEquipped
icon: "CMJobIconEmpty"
joinNotifyCrew: false
supervisors: cm-job-supervisors-sl
Expand Down Expand Up @@ -40,7 +41,7 @@
back: CMSatchelMarine
shoes: CMBootsBlackFilled
head: ArmorHelmetM10
outerClothing: CMArmorM3Medium
outerClothing: RMCArmorM3MediumVariants
gloves: CMHandsBlackMarine
id: CMDogtagRifleman
ears: CMHeadsetAlpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
department: CMSquad
time: 18000 # 5 hours
startingGear: CMGearSmartGunOperator
dummyStartingGear: CMGearSmartGunOperatorEquipped
icon: "CMJobIconSmartGunOperator"
joinNotifyCrew: false
supervisors: cm-job-supervisors-sl
Expand Down Expand Up @@ -48,7 +49,7 @@
back: CMSatchelMarine
shoes: CMBootsBlackFilled
head: ArmorHelmetM10
outerClothing: CMArmorM3Medium
outerClothing: CMArmorSmartGunCombatHarness
gloves: CMHandsBlackMarine
id: CMDogtagSmartGunOperator
ears: CMHeadsetAlpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
department: CMSquad
time: 36000 # 10 hours
startingGear: CMGearSquadLeader
dummyStartingGear: CMGearSquadLeaderEquipped
icon: "CMJobIconSquadLeader"
joinNotifyCrew: false
supervisors: cm-job-supervisors-co
Expand Down Expand Up @@ -60,7 +61,7 @@
back: CMSatchelMarine
shoes: CMBootsBlackFilled
head: CMArmorHelmetM11
outerClothing: CMArmorM3Medium
outerClothing: CMArmorB12
gloves: CMHandsBlackMarine
id: CMDogtagSquadLeader
ears: CMHeadsetAlphaLeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
department: CMSquad
time: 18000 # 5 hours
startingGear: CMGearWeaponsSpecialist
dummyStartingGear: CMGearWeaponsSpecialistEquipped
icon: "CMJobIconWeaponsSpecialist"
joinNotifyCrew: false
supervisors: cm-job-supervisors-sl
Expand Down Expand Up @@ -56,7 +57,6 @@
back: CMSatchelMarine
shoes: CMBootsBlackFilled
head: ArmorHelmetM10
outerClothing: CMArmorM3Medium
gloves: CMHandsBlackMarine
id: CMDogtagWeaponsSpecialist
ears: CMHeadsetAlpha
Expand Down

0 comments on commit 164082d

Please sign in to comment.