CatStation/Content.Shared/Friends/Systems/PettableFriendSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +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 partial class PettableFriendSystem : EntitySystem
{
[Dependency] private NpcFactionSystem _factionException = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private UseDelaySystem _useDelay = default!;
[Dependency] private EntityQuery<FactionExceptionComponent> _exceptionQuery = default!;
[Dependency] private 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);
}
}