PettableFriendSystem.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-FileCopyrightText: 2024 deltanedas <39013340+deltanedas@users.noreply.github.com>
  2. // SPDX-FileCopyrightText: 2024 deltanedas <@deltanedas:kde.org>
  3. // SPDX-FileCopyrightText: 2024 metalgearsloth <comedian_vs_clown@hotmail.com>
  4. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  5. // SPDX-FileCopyrightText: 2025 Piras314 <p1r4s@proton.me>
  6. // SPDX-FileCopyrightText: 2025 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  7. //
  8. // SPDX-License-Identifier: AGPL-3.0-or-later
  9. using Content.Shared.Chemistry.Components;
  10. using Content.Shared.Friends.Components;
  11. using Content.Shared.Interaction.Events;
  12. using Content.Shared.NPC.Components;
  13. using Content.Shared.NPC.Systems;
  14. using Content.Shared.Popups;
  15. using Content.Shared.Timing;
  16. using Content.Shared._Shitmed.Spawners.EntitySystems; // Shitmed Change
  17. namespace Content.Shared.Friends.Systems;
  18. public sealed class PettableFriendSystem : EntitySystem
  19. {
  20. [Dependency] private readonly NpcFactionSystem _factionException = default!;
  21. [Dependency] private readonly SharedPopupSystem _popup = default!;
  22. [Dependency] private readonly UseDelaySystem _useDelay = default!;
  23. private EntityQuery<FactionExceptionComponent> _exceptionQuery;
  24. private EntityQuery<UseDelayComponent> _useDelayQuery;
  25. public override void Initialize()
  26. {
  27. base.Initialize();
  28. _exceptionQuery = GetEntityQuery<FactionExceptionComponent>();
  29. _useDelayQuery = GetEntityQuery<UseDelayComponent>();
  30. SubscribeLocalEvent<PettableFriendComponent, UseInHandEvent>(OnUseInHand);
  31. SubscribeLocalEvent<PettableFriendComponent, GotRehydratedEvent>(OnRehydrated);
  32. SubscribeLocalEvent<PettableFriendComponent, SpawnerSpawnedEvent>(OnSpawned); // Shitmed Change
  33. }
  34. private void OnUseInHand(Entity<PettableFriendComponent> ent, ref UseInHandEvent args)
  35. {
  36. var (uid, comp) = ent;
  37. var user = args.User;
  38. if (args.Handled || !_exceptionQuery.TryComp(uid, out var exceptionComp))
  39. return;
  40. var exception = (uid, exceptionComp);
  41. if (!_factionException.IsIgnored(exception, user))
  42. {
  43. // you have made a new friend :)
  44. _popup.PopupClient(Loc.GetString(comp.SuccessString, ("target", uid)), user, user);
  45. _factionException.IgnoreEntity(exception, user);
  46. args.Handled = true;
  47. return;
  48. }
  49. if (_useDelayQuery.TryComp(uid, out var useDelay) && !_useDelay.TryResetDelay((uid, useDelay), true))
  50. return;
  51. _popup.PopupClient(Loc.GetString(comp.FailureString, ("target", uid)), user, user);
  52. }
  53. private void OnRehydrated(Entity<PettableFriendComponent> ent, ref GotRehydratedEvent args)
  54. {
  55. // can only pet before hydrating, after that the fish cannot be negotiated with
  56. if (!TryComp<FactionExceptionComponent>(ent, out var comp))
  57. return;
  58. _factionException.IgnoreEntities(args.Target, comp.Ignored);
  59. }
  60. // Shitmed Change
  61. private void OnSpawned(Entity<PettableFriendComponent> ent, ref SpawnerSpawnedEvent args)
  62. {
  63. if (!TryComp<FactionExceptionComponent>(ent, out var comp))
  64. return;
  65. _factionException.IgnoreEntities(args.Entity, comp.Ignored);
  66. }
  67. }