Files
wwdpublic/Content.Server/Clothing/ClothingSystem.cs
VMSolidus ec1803b44f Generic Clothing Equip Functions (#1407)
# Description

This PR was originally going to be called "Psionic Refactor V3 Part 2,
Items Of Power", but I began getting shakes and started vomiting when I
saw the list of Components that make items do things when equipped, and
I had a conniption about how much code there is constantly being
repeated. So instead of this PR adding Items Of Power, I added a
universal modular generic system for making clothing items do things
when equipped and unequipped. Which hooks into the library of
TraitFunctions that we've previously created. I also added a few
"Inverse" versions of trait functions that can be used by these new
clothing functions.

<!--
# Changelog

🆑
- add: Added a universal modular system for making clothing items DO
things when equipped and unequipped. This will be used for "Psionic
Artifacts" in conjunction with the Psionic Refactor V3.
-->

(cherry picked from commit 731e14f100d8161c0f8f7eb1bc5accc2abaa24da)
2025-01-14 00:34:58 +03:00

36 lines
1.6 KiB
C#

using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Inventory.Events;
using Robust.Shared.Serialization.Manager;
namespace Content.Server.Clothing;
public sealed class ServerClothingSystem : ClothingSystem
{
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ClothingComponent, DidEquipEvent>(OnClothingEquipped);
SubscribeLocalEvent<ClothingComponent, DidUnequipEvent>(OnClothingUnequipped);
}
private void OnClothingEquipped(EntityUid uid, ClothingComponent clothingComponent, DidEquipEvent args)
{
// Yes, this is using the trait system functions. I'm not going to write an entire third function library to do this.
// They're generic for a reason.
foreach (var function in clothingComponent.OnEquipFunctions)
function.OnPlayerSpawn(uid, _componentFactory, EntityManager, _serializationManager);
}
private void OnClothingUnequipped(EntityUid uid, ClothingComponent clothingComponent, DidUnequipEvent args)
{
// Yes, this is using the trait system functions. I'm not going to write an entire third function library to do this.
// They're generic for a reason.
foreach (var function in clothingComponent.OnUnequipFunctions)
function.OnPlayerSpawn(uid, _componentFactory, EntityManager, _serializationManager);
}
}