CatStation/Content.Shared/Friends/Systems/PettableFriendSystem.cs
ArtisticRoomba 376f16504c
Content.Shared EntityQuery<T> dependency injection refactor (#43498)
* part 1

* second pass

* final fix

* last fix i swear

* an even bigger genius

* regex missed this

* should be all of em?

* oops

* yeah

* Revert "should be all of em?"

This reverts commit 4dd54d1b9a76977b4cf8d6008358e4dacdee6eb1.

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-04-11 21:30:36 +00:00

59 lines
2.2 KiB
C#

using Content.Shared.Chemistry.Components;
using Content.Shared.Friends.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Systems;
using Content.Shared.Popups;
using Content.Shared.Timing;
namespace Content.Shared.Friends.Systems;
public sealed class PettableFriendSystem : EntitySystem
{
[Dependency] private readonly NpcFactionSystem _factionException = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly EntityQuery<FactionExceptionComponent> _exceptionQuery = default!;
[Dependency] private readonly EntityQuery<UseDelayComponent> _useDelayQuery = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PettableFriendComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<PettableFriendComponent, GotRehydratedEvent>(OnRehydrated);
}
private void OnUseInHand(Entity<PettableFriendComponent> ent, ref UseInHandEvent args)
{
var (uid, comp) = ent;
var user = args.User;
if (args.Handled || !_exceptionQuery.TryComp(uid, out var exceptionComp))
return;
var exception = (uid, exceptionComp);
if (!_factionException.IsIgnored(exception, user))
{
// you have made a new friend :)
_popup.PopupClient(Loc.GetString(comp.SuccessString, ("target", uid)), user, user);
_factionException.IgnoreEntity(exception, user);
args.Handled = true;
return;
}
if (_useDelayQuery.TryComp(uid, out var useDelay) && !_useDelay.TryResetDelay((uid, useDelay), true))
return;
_popup.PopupClient(Loc.GetString(comp.FailureString, ("target", uid)), user, user);
}
private void OnRehydrated(Entity<PettableFriendComponent> ent, ref GotRehydratedEvent args)
{
// can only pet before hydrating, after that the fish cannot be negotiated with
if (!TryComp<FactionExceptionComponent>(ent, out var comp))
return;
_factionException.IgnoreEntities(args.Target, comp.Ignored);
}
}