using Content.Shared._White.Move; using Content.Shared.Interaction; using Content.Shared.IdentityManagement; using Content.Shared.Hands.Components; using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction.Events; using Robust.Shared.Player; namespace Content.Shared.OfferItem; public abstract partial class SharedOfferItemSystem : EntitySystem { [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedHandsSystem _hands = default!; public override void Initialize() { SubscribeLocalEvent(SetInReceiveMode); SubscribeLocalEvent(OnMove); // WD EDIT: MoveEvent -> MoveEventProxy SubscribeLocalEvent(OnAcceptOfferAlert); InitializeInteractions(); } private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, InteractUsingEvent args) { if (!TryComp(args.User, out var offerItem)) return; if (args.User == uid || component.IsInReceiveMode || !offerItem.IsInOfferMode || (offerItem.IsInReceiveMode && offerItem.Target != uid)) return; component.IsInReceiveMode = true; component.Target = args.User; Dirty(uid, component); offerItem.Target = uid; offerItem.IsInOfferMode = false; Dirty(args.User, offerItem); if (offerItem.Item == null) return; _popup.PopupEntity(Loc.GetString("offer-item-try-give", ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), ("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value); _popup.PopupEntity(Loc.GetString("offer-item-try-give-target", ("user", Identity.Entity(component.Target.Value, EntityManager)), ("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid); args.Handled = true; } private void OnMove(EntityUid uid, OfferItemComponent component, MoveEventProxy args) // WD EDIT: MoveEvent -> MoveEventProxy { if (component.Target == null || args.NewPosition.InRange(EntityManager, _transform, Transform(component.Target.Value).Coordinates, component.MaxOfferDistance)) return; UnOffer(uid, component); } private void OnAcceptOfferAlert(EntityUid uid, OfferItemComponent component, AcceptOfferAlertEvent args) { if (!TryComp(component.Target, out var offerItem) || !TryComp(uid, out var hands) || offerItem.Hand == null) return; if (offerItem.Item != null) { if (!_hands.TryPickup(uid, offerItem.Item.Value, handsComp: hands)) { _popup.PopupClient(Loc.GetString("offer-item-full-hand"), uid, uid); return; } _popup.PopupClient( Loc.GetString( "offer-item-give", ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), ("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value); _popup.PopupEntity( Loc.GetString( "offer-item-give-other", ("user", Identity.Entity(component.Target.Value, EntityManager)), ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), ("target", Identity.Entity(uid, EntityManager))), component.Target.Value, Filter.PvsExcept(component.Target.Value, entityManager: EntityManager), true); RaiseLocalEvent(offerItem.Item.Value, new DroppedEvent(uid)); // WD EDIT } offerItem.Item = null; UnReceive(uid, component, offerItem); } /// /// Resets the of the user and the target /// protected void UnOffer(EntityUid uid, OfferItemComponent component) { if (!TryComp(uid, out var hands) || hands.ActiveHand == null) return; if (TryComp(component.Target, out var offerItem) && component.Target != null) { if (component.Item != null) { _popup.PopupEntity(Loc.GetString("offer-item-no-give", ("item", Identity.Entity(component.Item.Value, EntityManager)), ("target", Identity.Entity(component.Target.Value, EntityManager))), uid, uid); _popup.PopupEntity(Loc.GetString("offer-item-no-give-target", ("user", Identity.Entity(uid, EntityManager)), ("item", Identity.Entity(component.Item.Value, EntityManager))), uid, component.Target.Value); } else if (offerItem.Item != null) { _popup.PopupEntity(Loc.GetString("offer-item-no-give", ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), ("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value); _popup.PopupEntity(Loc.GetString("offer-item-no-give-target", ("user", Identity.Entity(component.Target.Value, EntityManager)), ("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid); } offerItem.IsInOfferMode = false; offerItem.IsInReceiveMode = false; offerItem.Hand = null; offerItem.Target = null; offerItem.Item = null; Dirty(component.Target.Value, offerItem); } component.IsInOfferMode = false; component.IsInReceiveMode = false; component.Hand = null; component.Target = null; component.Item = null; Dirty(uid, component); } /// /// Cancels the transfer of the item /// protected void UnReceive(EntityUid uid, OfferItemComponent? component = null, OfferItemComponent? offerItem = null) { if (component == null && !TryComp(uid, out component)) return; if (offerItem == null && !TryComp(component.Target, out offerItem)) return; if (!TryComp(uid, out var hands) || hands.ActiveHand == null || component.Target == null) return; if (offerItem.Item != null) { _popup.PopupEntity(Loc.GetString("offer-item-no-give", ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), ("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value); _popup.PopupEntity(Loc.GetString("offer-item-no-give-target", ("user", Identity.Entity(component.Target.Value, EntityManager)), ("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid); } if (!offerItem.IsInReceiveMode) { offerItem.Target = null; component.Target = null; } offerItem.Item = null; offerItem.Hand = null; component.IsInReceiveMode = false; Dirty(uid, component); } /// /// Returns true if = true /// protected bool IsInOfferMode(EntityUid? entity, OfferItemComponent? component = null) { return entity != null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode; } }