Skip to content

Commit

Permalink
Refactor DropOnSlipSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
vaketola committed Apr 27, 2024
1 parent bd7f518 commit e197e49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Parkstation/Slippery/DropOnSlipComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Content.Server.Parkstation.Slippery;

/// <summary>
/// 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.
/// </summary>
[RegisterComponent]
public sealed partial class DropOnSlipComponent : Component
Expand Down
33 changes: 15 additions & 18 deletions Content.Server/Parkstation/Slippery/DropOnSlipSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Parkstation.Slippery.DropOnSlipComponent>(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<Parkstation.Slippery.DropOnSlipComponent>(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<ClumsyComponent>(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<ClumsyComponent>(entity))
return true;

Drop(entity, item.Value, slot.Name, popupString);
continue;
}
}
return false;
}

private void Drop(EntityUid entity, EntityUid item, string slot, string popupString)
Expand Down

0 comments on commit e197e49

Please sign in to comment.