2024-07-18 01:33:28 +03:00
|
|
|
|
using Content.Server.Popups;
|
|
|
|
|
|
using Content.Shared.Hands.Components;
|
|
|
|
|
|
using Content.Shared.Alert;
|
|
|
|
|
|
using Content.Shared.Hands.EntitySystems;
|
|
|
|
|
|
using Content.Shared._White.OfferItem;
|
|
|
|
|
|
using Content.Shared.IdentityManagement;
|
|
|
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._White.OfferItem;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class OfferItemSystem : SharedOfferItemSystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
|
|
|
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
|
|
|
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
|
|
|
|
|
var query = EntityQueryEnumerator<OfferItemComponent>();
|
|
|
|
|
|
while (query.MoveNext(out var uid, out var offerItem))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (offerItem.Hand != null &&
|
|
|
|
|
|
hands.Hands[offerItem.Hand].HeldEntity == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (offerItem.Target != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnReceive(offerItem.Target.Value, offerItem: offerItem);
|
|
|
|
|
|
offerItem.IsInOfferMode = false;
|
|
|
|
|
|
Dirty(uid, offerItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
UnOffer(uid, offerItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!offerItem.IsInReceiveMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
_alertsSystem.ClearAlert(uid, AlertType.Offer);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_alertsSystem.ShowAlert(uid, AlertType.Offer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Accepting the offer and receive item
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Receive(EntityUid uid, OfferItemComponent? component = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Resolve(uid, ref component) ||
|
|
|
|
|
|
!TryComp<OfferItemComponent>(component.Target, out var offerItem) ||
|
|
|
|
|
|
offerItem.Hand == null ||
|
|
|
|
|
|
component.Target == null ||
|
|
|
|
|
|
!TryComp<HandsComponent>(uid, out var hands))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (offerItem.Item != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_hands.TryPickup(uid, offerItem.Item.Value, handsComp: hands))
|
|
|
|
|
|
{
|
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("offer-item-full-hand"), uid, uid);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("offer-item-give",
|
|
|
|
|
|
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
|
2024-07-30 03:13:05 +03:00
|
|
|
|
("target", Identity.Entity(uid, EntityManager))),
|
|
|
|
|
|
component.Target.Value,
|
|
|
|
|
|
component.Target.Value);
|
2024-07-18 01:33:28 +03:00
|
|
|
|
_popup.PopupEntity(Loc.GetString("offer-item-give-other",
|
|
|
|
|
|
("user", Identity.Entity(component.Target.Value, EntityManager)),
|
|
|
|
|
|
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
|
2024-07-30 03:13:05 +03:00
|
|
|
|
("target", Identity.Entity(uid, EntityManager))),
|
|
|
|
|
|
component.Target.Value,
|
|
|
|
|
|
Filter.PvsExcept(component.Target.Value, entityManager: EntityManager),
|
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
|
|
RaiseLocalEvent(offerItem.Item.Value, new HandedEvent(component.Target.Value, uid));
|
2024-07-18 01:33:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
offerItem.Item = null;
|
|
|
|
|
|
UnReceive(uid, component, offerItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|