1
0

SharedPriceGunSystem.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Shared.Cargo.Components;
  2. using Content.Shared.IdentityManagement;
  3. using Content.Shared.Interaction;
  4. using Content.Shared.Verbs;
  5. namespace Content.Shared.Cargo.Systems;
  6. /// <summary>
  7. /// The price gun system! If this component is on an entity, you can scan objects (Click or use verb) to see their price.
  8. /// </summary>
  9. public abstract class SharedPriceGunSystem : EntitySystem
  10. {
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<PriceGunComponent, GetVerbsEvent<UtilityVerb>>(OnUtilityVerb);
  15. SubscribeLocalEvent<PriceGunComponent, AfterInteractEvent>(OnAfterInteract);
  16. }
  17. private void OnUtilityVerb(EntityUid uid, PriceGunComponent component, GetVerbsEvent<UtilityVerb> args)
  18. {
  19. if (!args.CanAccess || !args.CanInteract || args.Using == null)
  20. return;
  21. var verb = new UtilityVerb()
  22. {
  23. Act = () =>
  24. {
  25. GetPriceOrBounty((uid, component), args.Target, args.User);
  26. },
  27. Text = Loc.GetString("price-gun-verb-text"),
  28. Message = Loc.GetString("price-gun-verb-message", ("object", Identity.Entity(args.Target, EntityManager)))
  29. };
  30. args.Verbs.Add(verb);
  31. }
  32. private void OnAfterInteract(Entity<PriceGunComponent> entity, ref AfterInteractEvent args)
  33. {
  34. if (!args.CanReach || args.Target == null || args.Handled)
  35. return;
  36. args.Handled |= GetPriceOrBounty(entity, args.Target.Value, args.User);
  37. }
  38. /// <summary>
  39. /// Find the price or confirm if the item is a bounty. Will give a popup of the result to the passed user.
  40. /// </summary>
  41. /// <returns></returns>
  42. /// <remarks>
  43. /// This is abstract for prediction. When the bounty system / cargo systems that are necessary are moved to shared,
  44. /// combine all the server, client, and shared stuff into one non abstract file.
  45. /// </remarks>
  46. protected abstract bool GetPriceOrBounty(Entity<PriceGunComponent> entity, EntityUid target, EntityUid user);
  47. }