Files
OldThink/Content.Shared/_White/OfferItem/SharedOfferItemSystem.Interactions.cs
Spatison d32eb158d4 Теперь предметы можно передавать из рук в руки (#462)
* add: Теперь предеты можно передовать из рук в руки

* Кудато не туда уехало
2024-07-18 01:33:28 +03:00

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._White.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);
}
}