Partial buckling refactor (#29031)

* partial buckling refactor

* git mv test

* change test namespace

* git mv test

* Update test namespace

* Add pulling test

* Network BuckleTime

* Add two more tests

* smelly
This commit is contained in:
Leon Friedrich
2024-06-20 03:14:18 +12:00
committed by GitHub
parent e33f0341ad
commit fa3c89a521
38 changed files with 1053 additions and 890 deletions

View File

@@ -71,6 +71,7 @@ namespace Content.Shared.Cuffs
SubscribeLocalEvent<CuffableComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
SubscribeLocalEvent<CuffableComponent, BeingPulledAttemptEvent>(OnBeingPulledAttempt);
SubscribeLocalEvent<CuffableComponent, BuckleAttemptEvent>(OnBuckleAttemptEvent);
SubscribeLocalEvent<CuffableComponent, UnbuckleAttemptEvent>(OnUnbuckleAttemptEvent);
SubscribeLocalEvent<CuffableComponent, GetVerbsEvent<Verb>>(AddUncuffVerb);
SubscribeLocalEvent<CuffableComponent, UnCuffDoAfterEvent>(OnCuffableDoAfter);
SubscribeLocalEvent<CuffableComponent, PullStartedMessage>(OnPull);
@@ -195,21 +196,33 @@ namespace Content.Shared.Cuffs
args.Cancel();
}
private void OnBuckleAttemptEvent(EntityUid uid, CuffableComponent component, ref BuckleAttemptEvent args)
private void OnBuckleAttempt(Entity<CuffableComponent> ent, EntityUid? user, ref bool cancelled, bool buckling, bool popup)
{
// if someone else is doing it, let it pass.
if (args.UserEntity != uid)
if (cancelled || user != ent.Owner)
return;
if (!TryComp<HandsComponent>(uid, out var hands) || component.CuffedHandCount != hands.Count)
if (!TryComp<HandsComponent>(ent, out var hands) || ent.Comp.CuffedHandCount != hands.Count)
return;
args.Cancelled = true;
var message = args.Buckling
cancelled = true;
if (!popup)
return;
var message = buckling
? Loc.GetString("handcuff-component-cuff-interrupt-buckled-message")
: Loc.GetString("handcuff-component-cuff-interrupt-unbuckled-message");
_popup.PopupClient(message, uid, args.UserEntity);
_popup.PopupClient(message, ent, user);
}
private void OnBuckleAttemptEvent(Entity<CuffableComponent> ent, ref BuckleAttemptEvent args)
{
OnBuckleAttempt(ent, args.User, ref args.Cancelled, true, args.Popup);
}
private void OnUnbuckleAttemptEvent(Entity<CuffableComponent> ent, ref UnbuckleAttemptEvent args)
{
OnBuckleAttempt(ent, args.User, ref args.Cancelled, false, args.Popup);
}
private void OnPull(EntityUid uid, CuffableComponent component, PullMessage args)