Skip to content

Commit

Permalink
behold
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Nov 21, 2024
1 parent a161892 commit ebefda8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Content.Shared._CD.Clothing;
/// This component prevents equipping items in specified slots when this clothing item is worn,
/// and prevents equipping this item if any of the specified slots are occupied.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, Access(typeof(ClothingBlockSlotsOnEquipSystem))]
public sealed partial class ClothingBlockSlotsOnEquipComponent : Component
{
/// <summary>
Expand Down
38 changes: 38 additions & 0 deletions Content.Shared/_CD/Clothing/ClothingBlockSlotsOnEquipSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Content.Shared.Examine;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Robust.Shared.Utility;

namespace Content.Shared._CD.Clothing;

Expand All @@ -11,11 +13,39 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ClothingBlockSlotsOnEquipComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ClothingBlockSlotsOnEquipComponent, BeingEquippedAttemptEvent>(OnBeingEquippedAttempt);
SubscribeLocalEvent<ClothingBlockSlotsOnEquipComponent, IsEquippingAttemptEvent>(OnIsEquippingAttempt);
SubscribeLocalEvent<InventoryComponent, IsEquippingAttemptEvent>(OnEquippingAttempt);
}

/// <summary>
/// Sets the description to indicate what slots will be blocked by wearing this item.
/// </summary>
private void OnExamined(EntityUid uid, ClothingBlockSlotsOnEquipComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;

// we push it as a message so that we can add a newline at the end
var msg = new FormattedMessage();
msg.AddText(Loc.GetString("clothing-blocked-slots-description"));

foreach (var slot in component.BlockedSlots)
{
msg.PushNewline();
var slotName = Loc.GetString($"clothing-slot-{slot}");
msg.AddMarkupOrThrow(Loc.GetString("clothing-blocked-slots-entry", ("slot", slotName)));
}

msg.PushNewline();
args.PushMessage(msg, 1);
}

/// <summary>
/// Checks if we can equip the item.
/// </summary>
/// <remarks>This is called to see if the specified slots are empty.</remarks>
private void OnBeingEquippedAttempt(Entity<ClothingBlockSlotsOnEquipComponent> ent, ref BeingEquippedAttemptEvent args)
{
if (!HasComp<InventoryComponent>(args.EquipTarget))
Expand All @@ -33,6 +63,10 @@ private void OnBeingEquippedAttempt(Entity<ClothingBlockSlotsOnEquipComponent> e
}
}

/// <summary>
/// Checks if we can equip the item.
/// </summary>
/// <remarks>This is called to see if we're not trying to equip it in a slot it would block.</remarks>
private void OnIsEquippingAttempt(Entity<ClothingBlockSlotsOnEquipComponent> ent, ref IsEquippingAttemptEvent args)
{
if (!ent.Comp.BlockedSlots.Contains(args.Slot))
Expand All @@ -43,6 +77,10 @@ private void OnIsEquippingAttempt(Entity<ClothingBlockSlotsOnEquipComponent> ent
args.Cancel();
}

/// <summary>
/// Checks if we can equip other items.
/// </summary>
/// <remarks>This is called whenever we try to equip an item to see if the slot isn't currently blocked.</remarks>
private void OnEquippingAttempt(Entity<InventoryComponent> ent, ref IsEquippingAttemptEvent args)
{
var enumerator = _inventory.GetSlotEnumerator(ent.Owner);
Expand Down
18 changes: 18 additions & 0 deletions Resources/Locale/en-US/_CD/clothing/clothing-slots.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### General clothing slots because apparently they don't exist

clothing-slot-head = Head
clothing-slot-eyes = Eyes
clothing-slot-ears = Ears
clothing-slot-mask = Mask
clothing-slot-outerClothing = Outer Clothing
clothing-slot-jumpsuit = Jumpsuit
clothing-slot-innerClothing = Inner Clothing
clothing-slot-neck = Neck
clothing-slot-back = Back
clothing-slot-belt = Belt
clothing-slot-gloves = Gloves
clothing-slot-shoes = Shoes
clothing-slot-id = ID Card
clothing-slot-pocket1 = Left Pocket
clothing-slot-pocket2 = Right Pocket
clothing-slot-suitStorage = Suit Storage
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
clothing-blocked-slots-blocked = That slot is blocked by {$item}.
clothing-blocked-slots-description = This item blocks the following slots when worn:
clothing-blocked-slots-entry = - [color=yellow]{$slot}[/color]

0 comments on commit ebefda8

Please sign in to comment.