From e197e49a532f1fc0b665b054e2c257e538202651 Mon Sep 17 00:00:00 2001 From: Finket Date: Sat, 27 Apr 2024 13:21:27 +0300 Subject: [PATCH] Refactor DropOnSlipSystem --- .../Slippery/DropOnSlipComponent.cs | 2 +- .../Parkstation/Slippery/DropOnSlipSystem.cs | 33 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Content.Server/Parkstation/Slippery/DropOnSlipComponent.cs b/Content.Server/Parkstation/Slippery/DropOnSlipComponent.cs index 7b7b533959..18b9191e0c 100644 --- a/Content.Server/Parkstation/Slippery/DropOnSlipComponent.cs +++ b/Content.Server/Parkstation/Slippery/DropOnSlipComponent.cs @@ -1,7 +1,7 @@ namespace Content.Server.Parkstation.Slippery; /// -/// Uses provided chance to try and drop the item when slipped, if equipped. +/// Marks this item as one that may be dropped when its wearer slips with it equipped. /// [RegisterComponent] public sealed partial class DropOnSlipComponent : Component diff --git a/Content.Server/Parkstation/Slippery/DropOnSlipSystem.cs b/Content.Server/Parkstation/Slippery/DropOnSlipSystem.cs index e2c1f554c0..88f77aeb61 100644 --- a/Content.Server/Parkstation/Slippery/DropOnSlipSystem.cs +++ b/Content.Server/Parkstation/Slippery/DropOnSlipSystem.cs @@ -47,33 +47,30 @@ private void HandleSlip(EntityUid entity, InventoryComponent invComp, ParkSlipEv if (!_inventory.TryGetSlotEntity(entity, slot.Name, out var item)) continue; - // Check for DropOnSlipComponent - if (slot.Name != "pocket1" && slot.Name != "pocket2" && EntityManager.TryGetComponent(item, out var dropComp) && _random.NextFloat(0, 100) < dropComp.Chance) + if (ShouldBeDropped(entity, slot, item)) { var popupString = Loc.GetString("system-drop-on-slip-text-component", ("name", entity), ("item", item)); Drop(entity, item.Value, slot.Name, popupString); - continue; } + } + } - // Check for any items in pockets - if (slot.Name == "pocket1" | slot.Name == "pocket2" && _random.NextFloat(0, 100) < PocketDropChance) - { - var popupString = Loc.GetString("system-drop-on-slip-text-pocket", ("name", entity), ("item", item)); + private bool ShouldBeDropped(EntityUid entity, SlotDefinition slot, EntityUid? item) + { + // Check for any items in pockets or other criteria + if (slot.SlotFlags == SlotFlags.POCKET && _random.NextFloat(0, 100) < PocketDropChance) + return true; - Drop(entity, item.Value, slot.Name, popupString); - continue; - } + // Check for DropOnSlipComponent + if (EntityManager.TryGetComponent(item, out var dropComp) && _random.NextFloat(0, 100) < dropComp.Chance) + return true; - // Check for ClumsyComponent - if (slot.Name != "jumpsuit" && _random.NextFloat(0, 100) < ClumsyDropChance && HasComp(entity)) - { - var popupString = Loc.GetString("system-drop-on-slip-text-clumsy", ("name", entity), ("item", item)); + // Check for ClumsyComponent + if (slot.Name != "jumpsuit" && _random.NextFloat(0, 100) < ClumsyDropChance && HasComp(entity)) + return true; - Drop(entity, item.Value, slot.Name, popupString); - continue; - } - } + return false; } private void Drop(EntityUid entity, EntityUid item, string slot, string popupString)