mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
# Description This PR adds the ability to transfer objects from one player's hand to another player's hand, as in SS13. I have little coding experience, so my solutions may not be ideal. --- # TODO - [x] Make the code work - [x] Add popup - [x] Write a summary of the code - [x] Сorrect inaccuracies <details><summary><h1>Media</h1></summary> <p> https://youtu.be/zTQWTsYm1gw </p> </details> --- # Changelog 🆑 - add: Added system - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --------- Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using Content.Shared.Popups;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Input;
|
|
using Content.Shared.Hands.Components;
|
|
using Robust.Shared.Input.Binding;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Shared.OfferItem;
|
|
|
|
public abstract partial class SharedOfferItemSystem
|
|
{
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
|
|
private void InitializeInteractions()
|
|
{
|
|
CommandBinds.Builder
|
|
.Bind(ContentKeyFunctions.OfferItem, InputCmdHandler.FromDelegate(SetInOfferMode, handle: false, outsidePrediction: false))
|
|
.Register<SharedOfferItemSystem>();
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
|
|
CommandBinds.Unregister<SharedOfferItemSystem>();
|
|
}
|
|
|
|
private void SetInOfferMode(ICommonSession? session)
|
|
{
|
|
if (session is not { } playerSession)
|
|
return;
|
|
|
|
if ((playerSession.AttachedEntity is not { Valid: true } uid || !Exists(uid)) ||
|
|
!_actionBlocker.CanInteract(uid, null))
|
|
return;
|
|
|
|
if (!TryComp<OfferItemComponent>(uid, out var offerItem))
|
|
return;
|
|
|
|
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null)
|
|
return;
|
|
|
|
offerItem.Item = hands.ActiveHand.HeldEntity;
|
|
|
|
if (offerItem.IsInOfferMode == false)
|
|
{
|
|
if (offerItem.Item == null)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("offer-item-empty-hand"), uid, uid);
|
|
return;
|
|
}
|
|
|
|
if (offerItem.Hand == null || offerItem.Target == null)
|
|
{
|
|
offerItem.IsInOfferMode = true;
|
|
offerItem.Hand = hands.ActiveHand.Name;
|
|
|
|
Dirty(uid, offerItem);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (offerItem.Target != null)
|
|
{
|
|
UnReceive(offerItem.Target.Value, offerItem: offerItem);
|
|
offerItem.IsInOfferMode = false;
|
|
Dirty(uid, offerItem);
|
|
return;
|
|
}
|
|
|
|
UnOffer(uid, offerItem);
|
|
}
|
|
}
|