Files
OldThink/Content.Shared/_White/ClothingGrant/Systems/ClothingGrantingSystem.cs
ThereDrD0 d627758826 Баффы (#510)
* Moodsystem cleanups

* remove overhydrated and overfed mood debuffs

* admins now join game deadmined + new player timers

* faster arrivals

* recharging rcd with metal, glass, plastic or cable coils

* better timings and costs + building apc and camera

* preparing for rpd

* RPD + make RCD more generic

* add rpd to atmos lockers, rcd to engivend

* rcd and rpd to technologies

* dont deadmin me in debug

* rcd ammo buff

* add ChargeCountModifier logic for non stackable items

* increase time to become experienced player

* Dynamic Radial Menus (#29678)

* fix

* Clean Some Code

* Some Commentaries

* Update Content.Client/UserInterface/Controls/RadialContainer.cs

* Update Content.Client/UserInterface/Controls/RadialContainer.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* more dynamically parameters

---------

Co-authored-by: Rinary <72972221+Rinary1@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-07-29 06:04:21 +03:00

105 lines
3.4 KiB
C#

using Content.Shared.Clothing.Components;
using Content.Shared.Inventory.Events;
using Robust.Shared.Serialization.Manager;
using Content.Shared.Tag;
using Content.Shared._White.ClothingGrant.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared._White.ClothingGrant.Systems;
public sealed class ClothingGrantingSystem : EntitySystem
{
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ClothingGrantComponentComponent, GotEquippedEvent>(OnCompEquip);
SubscribeLocalEvent<ClothingGrantComponentComponent, GotUnequippedEvent>(OnCompUnequip);
SubscribeLocalEvent<ClothingGrantTagComponent, GotEquippedEvent>(OnTagEquip);
SubscribeLocalEvent<ClothingGrantTagComponent, GotUnequippedEvent>(OnTagUnequip);
}
private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent component, GotEquippedEvent args)
{
if (_timing.ApplyingState)
return;
if (!TryComp<ClothingComponent>(uid, out var clothing))
return;
if (!clothing.Slots.HasFlag(args.SlotFlags))
return;
if (component.Components.Count > 8)
{
Logger.Error("Although a component registry supports multiple components, we cannot bookkeep more than 8 component for ClothingGrantComponent at this time.");
return;
}
AddComponents(args.Equipee, component.Components);
component.IsActive = true;
Dirty(uid, component);
}
public void AddComponents(EntityUid uid, ComponentRegistry components)
{
foreach (var (name, data) in components)
{
var newComp = (Component) _componentFactory.GetComponent(name);
if (HasComp(uid, newComp.GetType()))
continue;
newComp.Owner = uid;
var temp = (object) newComp;
_serializationManager.CopyTo(data.Component, ref temp);
EntityManager.AddComponent(uid, (Component)temp!);
}
}
private void OnCompUnequip(EntityUid uid, ClothingGrantComponentComponent component, GotUnequippedEvent args)
{
if (!component.IsActive) return;
foreach (var (name, data) in component.Components)
{
var newComp = (Component) _componentFactory.GetComponent(name);
RemComp(args.Equipee, newComp.GetType());
}
component.IsActive = false;
Dirty(uid, component);
}
private void OnTagEquip(EntityUid uid, ClothingGrantTagComponent component, GotEquippedEvent args)
{
if (!TryComp<ClothingComponent>(uid, out var clothing)) return;
if (!clothing.Slots.HasFlag(args.SlotFlags)) return;
EnsureComp<TagComponent>(args.Equipee);
_tagSystem.AddTag(args.Equipee, component.Tag);
component.IsActive = true;
Dirty(uid, component);
}
private void OnTagUnequip(EntityUid uid, ClothingGrantTagComponent component, GotUnequippedEvent args)
{
if (!component.IsActive) return;
_tagSystem.RemoveTag(args.Equipee, component.Tag);
component.IsActive = false;
Dirty(uid, component);
}
}