LubedSystem.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Shared.IdentityManagement;
  2. using Content.Shared.Lube;
  3. using Content.Shared.NameModifier.EntitySystems;
  4. using Content.Shared.Popups;
  5. using Content.Shared.Throwing;
  6. using Robust.Shared.Containers;
  7. using Robust.Shared.Random;
  8. namespace Content.Server.Lube;
  9. public sealed class LubedSystem : EntitySystem
  10. {
  11. [Dependency] private readonly ThrowingSystem _throwing = default!;
  12. [Dependency] private readonly IRobustRandom _random = default!;
  13. [Dependency] private readonly SharedTransformSystem _transform = default!;
  14. [Dependency] private readonly SharedPopupSystem _popup = default!;
  15. [Dependency] private readonly NameModifierSystem _nameMod = default!;
  16. public override void Initialize()
  17. {
  18. base.Initialize();
  19. SubscribeLocalEvent<LubedComponent, ComponentInit>(OnInit);
  20. SubscribeLocalEvent<LubedComponent, ContainerGettingInsertedAttemptEvent>(OnHandPickUp);
  21. SubscribeLocalEvent<LubedComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
  22. }
  23. private void OnInit(EntityUid uid, LubedComponent component, ComponentInit args)
  24. {
  25. _nameMod.RefreshNameModifiers(uid);
  26. }
  27. private void OnHandPickUp(EntityUid uid, LubedComponent component, ContainerGettingInsertedAttemptEvent args)
  28. {
  29. if (component.SlipsLeft <= 0)
  30. {
  31. RemComp<LubedComponent>(uid);
  32. _nameMod.RefreshNameModifiers(uid);
  33. return;
  34. }
  35. component.SlipsLeft--;
  36. args.Cancel();
  37. var user = args.Container.Owner;
  38. _transform.SetCoordinates(uid, Transform(user).Coordinates);
  39. _transform.AttachToGridOrMap(uid);
  40. _throwing.TryThrow(uid, _random.NextVector2(), baseThrowSpeed: component.SlipStrength);
  41. _popup.PopupEntity(Loc.GetString("lube-slip", ("target", Identity.Entity(uid, EntityManager))), user, user, PopupType.MediumCaution);
  42. }
  43. private void OnRefreshNameModifiers(Entity<LubedComponent> entity, ref RefreshNameModifiersEvent args)
  44. {
  45. args.AddModifier("lubed-name-prefix");
  46. }
  47. }