Files
wwdpublic/Content.Shared/Strip/SharedStrippableSystem.cs
SimpleStation14 89a6bb3ab5 Mirror: StrippableSystem doafter overhaul (#205)
## Mirror of PR #25994: [StrippableSystem doafter
overhaul](https://github.com/space-wizards/space-station-14/pull/25994)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `41ca8f3dfcb986432e1e509247bf239cac137836`

PR opened by <img
src="https://avatars.githubusercontent.com/u/42424291?v=4"
width="16"/><a href="https://github.com/Krunklehorn"> Krunklehorn</a> at
2024-03-11 12:36:28 UTC

---

PR changed 7 files with 465 additions and 305 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> ## About the PR
> 
> Refactors Strippable DoAfter events to make them synchronous and
organized.
> 
> 
> ## Technical details
> 
> ### Strippable System & Component
> - Synchronous DoAfters
> - Made use of `TimeSpan`, `GetStripTimeModifiers()` and `ByRefEvent`
> - Reorganized checks, removed some redundant ones
> - Resolve pattern where useful
> - Added more asserts
> - Lots of cleanup
> 
> The DoAfters were grouped under one event to avoid copy-pasting eight
separate cancel checks, asserts and function signatures.
> 
> Let me know if this is bad for performance and I'll roll them out
instead.
> 
> 
> ## Media
> 
> - [x] I have added screenshots/videos to this PR showcasing its
changes ingame, **or** this PR does not require an ingame showcase
> 
> 
> ## Breaking changes
> 
> ### TimeSpans
> `ThievingComponent`, `InventoryTemplatePrototype` and
`ToggleableClothingSystem` use `TimeSpan` in places where they intersect
with `StrippableComponent`.
> 
> 
> **Changelog**
> 
> N/A
> 


</details>

Signed-off-by: VMSolidus <evilexecutive@gmail.com>
Co-authored-by: SimpleStation14 <Unknown>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
2024-07-01 14:37:45 -04:00

59 lines
2.0 KiB
C#

using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;
using Content.Shared.Strip.Components;
namespace Content.Shared.Strip;
public abstract class SharedStrippableSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StrippingComponent, CanDropTargetEvent>(OnCanDropOn);
SubscribeLocalEvent<StrippableComponent, CanDropDraggedEvent>(OnCanDrop);
SubscribeLocalEvent<StrippableComponent, DragDropDraggedEvent>(OnDragDrop);
}
public (TimeSpan Time, bool Stealth) GetStripTimeModifiers(EntityUid user, EntityUid target, TimeSpan initialTime)
{
var userEv = new BeforeStripEvent(initialTime);
RaiseLocalEvent(user, ref userEv);
var ev = new BeforeGettingStrippedEvent(userEv.Time, userEv.Stealth);
RaiseLocalEvent(target, ref ev);
return (ev.Time, ev.Stealth);
}
private void OnDragDrop(EntityUid uid, StrippableComponent component, ref DragDropDraggedEvent args)
{
// If the user drags a strippable thing onto themselves.
if (args.Handled || args.Target != args.User)
return;
StartOpeningStripper(args.User, (uid, component));
args.Handled = true;
}
public virtual void StartOpeningStripper(EntityUid user, Entity<StrippableComponent> component, bool openInCombat = false)
{
}
private void OnCanDropOn(EntityUid uid, StrippingComponent component, ref CanDropTargetEvent args)
{
args.Handled = true;
args.CanDrop |= uid == args.User &&
HasComp<StrippableComponent>(args.Dragged) &&
HasComp<HandsComponent>(args.User);
}
private void OnCanDrop(EntityUid uid, StrippableComponent component, ref CanDropDraggedEvent args)
{
args.CanDrop |= args.Target == args.User &&
HasComp<StrippingComponent>(args.User) &&
HasComp<HandsComponent>(args.User);
if (args.CanDrop)
args.Handled = true;
}
}