Skip to content

Commit

Permalink
I hate this so much
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Aug 2, 2024
1 parent 8ccbf7e commit 5b8f41e
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 478 deletions.
36 changes: 32 additions & 4 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Inventory;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
Expand Down Expand Up @@ -1688,6 +1689,26 @@ private void UpdateLoadouts(bool showUnusable)
// Get all loadout categories
var categories = _prototypeManager.EnumeratePrototypes<LoadoutCategoryPrototype>().ToList();

// This is Urist McShoppingMall, his purpose is to try on new clothes. He's about to try on several thousand clothes. Say Hi.
var dummy = (EntityUid?) null;
var dummySlots = new List<SlotDefinition>();
if (Profile is not null
&& _prototypeManager.TryIndex($"Mob{Profile.Species}", out var speciesProto))
{
dummy = _entityManager.Spawn(speciesProto.ID);
if (_entityManager.TryGetComponent<InventoryComponent>(dummy, out var inventory))
foreach (var slot in inventory.Slots)
{
if (slot.Whitelist != null)
dummySlots.Add(slot);

if (slot.Blacklist != null)
dummySlots.Add(slot);
}

}


// If showUnusable is false filter out loadouts that are unusable based on your current character setup
var loadouts = enumeratedLoadouts.Where(loadout =>
showUnusable || // Ignore everything if this is true
Expand All @@ -1700,10 +1721,12 @@ private void UpdateLoadouts(bool showUnusable)
_entityManager,
_prototypeManager,
_configurationManager,
out _
out _,
loadout,
dummy,
dummySlots
)
).ToList();

// Loadouts to highlight red when showUnusable is true
var loadoutsUnusable = enumeratedLoadouts.Where(loadout =>
_characterRequirementsSystem.CheckRequirementsValid(
Expand All @@ -1715,10 +1738,16 @@ out _
_entityManager,
_prototypeManager,
_configurationManager,
out _
out _,
loadout,
dummy,
dummySlots
)
).ToList();

// And now we kill Urist. He has served his purpose.
_entityManager.QueueDeleteEntity(dummy);

// Every loadout not in the loadouts list
var otherLoadouts = enumeratedLoadouts.Where(loadout => !loadouts.Contains(loadout)).ToList();

Expand Down Expand Up @@ -1842,7 +1871,6 @@ out _
else
match.AddChild(selector);


AddSelector(selector, loadout.Cost, loadout.ID);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

using System.Linq;
using System.Text;
using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.Loadouts.Prototypes;
using Content.Shared.Inventory;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Shared.Configuration;
Expand All @@ -10,10 +15,11 @@ namespace Content.Shared.Customization.Systems;

public sealed class CharacterRequirementsSystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public bool CheckRequirementsValid(List<CharacterRequirement> requirements, JobPrototype job,
HumanoidCharacterProfile profile, Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out List<FormattedMessage> reasons)
out List<FormattedMessage> reasons, LoadoutPrototype? loadout = null, EntityUid? dummy = null, List<SlotDefinition>? dummySlots = null)
{
reasons = new List<FormattedMessage>();
var valid = true;
Expand All @@ -39,6 +45,17 @@ public bool CheckRequirementsValid(List<CharacterRequirement> requirements, JobP
reasons.Add(reason);
}

if (loadout is not null
&& dummy is not null
&& dummySlots is not null
&& CheckSpeciesCanEquip(dummy.Value, dummySlots, loadout, profile, out var species))
{
foreach (var speciesReason in species)
reasons.Add(speciesReason);
if (species.Count != 0)
valid = false;
}

return valid;
}

Expand Down Expand Up @@ -66,4 +83,41 @@ public string GetRequirementsMarkup(List<FormattedMessage> reasons)

return text.ToString().Trim();
}

public bool CheckSpeciesCanEquip(EntityUid dummy, List<SlotDefinition> dummySlots, LoadoutPrototype loadout, HumanoidCharacterProfile profile, out List<FormattedMessage> reasons)
{
reasons = new List<FormattedMessage>();
if (!_entityManager.TryGetComponent<InventoryComponent>(dummy, out var inv))
return false;

foreach (var item in loadout.Items)
{
var toEquip = _entityManager.Spawn(item);
if (!_entityManager.TryGetComponent<ClothingComponent>(toEquip, out var clothing))
{
QueueDel(toEquip);
continue;
}

foreach (var slots in dummySlots)
if (slots.SlotFlags == clothing.Slots)
{
if (slots.Whitelist != null && !slots.Whitelist.IsValid(toEquip))
reasons.Add(FormattedMessage.FromMarkup(Loc.GetString("species-cannot-equip", ("species", profile.Species), ("item", item))));

if (slots.Blacklist != null && slots.Blacklist.IsValid(toEquip))
reasons.Add(FormattedMessage.FromMarkup(Loc.GetString("species-cannot-equip", ("species", profile.Species), ("item", item))));
}

var slotCount = inv.Slots.Count();
foreach (var fullSlots in inv.Slots)
if (fullSlots.SlotFlags == clothing.Slots)
--slotCount;
if (slotCount != inv.Slots.Count())
reasons.Add(FormattedMessage.FromMarkup(Loc.GetString("species-cannot-equip", ("species", profile.Species), ("item", item))));

QueueDel(toEquip);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ character-whitelist-requirement = You must {$inverted ->
[true] not be
*[other] be
} whitelisted
# Species
species-cannot-equip = {$species} cannot equip {$item}
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/Heads/captain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- Captain
Expand Down
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/Heads/chiefEngineer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- ChiefEngineer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- ChiefMedicalOfficer
Expand Down
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/Heads/headOfPersonnel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- HeadOfPersonnel
Expand Down
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/Heads/headOfSecurity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- HeadOfSecurity
Expand Down
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/Heads/quarterMaster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- Quartermaster
Expand Down
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/Heads/researchDirector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
cost: 1
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
- !type:CharacterJobRequirement
jobs:
- ResearchDirector
Expand Down
5 changes: 0 additions & 5 deletions Resources/Prototypes/Loadouts/Jobs/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
- !type:CharacterJobRequirement
jobs:
- CargoTechnician
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Diona
- Harpy
items:
- ClothingShoesBootsWinterCargo

Expand Down
8 changes: 0 additions & 8 deletions Resources/Prototypes/Loadouts/Jobs/engineering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
cost: 2
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- StationEngineer
Expand Down Expand Up @@ -53,10 +49,6 @@
cost: 2
exclusive: true
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- StationEngineer
Expand Down
Loading

0 comments on commit 5b8f41e

Please sign in to comment.