Move faction exception and everything it needs to shared (#25154)
* move faction prototype to shared * move faction exception and member stuff to shared * fix breaking changes for random stuff * move pettable friend stuff to shared * mostly fix * final fixy * dragonops * final fixy II * use querys and fix warpspeed fish (probably) * fixer * Rrrr! --------- Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
24
Content.Shared/Friends/Components/PettableFriendComponent.cs
Normal file
24
Content.Shared/Friends/Components/PettableFriendComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Shared.Friends.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Friends.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Pet something to become friends with it (use in hand, press Z)
|
||||
/// Requires this entity to have FactionExceptionComponent to work.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(PettableFriendSystem))]
|
||||
public sealed partial class PettableFriendComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Localized popup sent when petting for the first time
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public LocId SuccessString = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Localized popup sent when petting multiple times
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public LocId FailureString = string.Empty;
|
||||
}
|
||||
62
Content.Shared/Friends/Systems/PettableFriendSystem.cs
Normal file
62
Content.Shared/Friends/Systems/PettableFriendSystem.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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!;
|
||||
|
||||
private EntityQuery<FactionExceptionComponent> _exceptionQuery;
|
||||
private EntityQuery<UseDelayComponent> _useDelayQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_exceptionQuery = GetEntityQuery<FactionExceptionComponent>();
|
||||
_useDelayQuery = GetEntityQuery<UseDelayComponent>();
|
||||
|
||||
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.TryGetComponent(uid, out var exceptionComp))
|
||||
return;
|
||||
|
||||
if (_useDelayQuery.TryGetComponent(uid, out var useDelay) && !_useDelay.TryResetDelay((uid, useDelay), true))
|
||||
return;
|
||||
|
||||
var exception = (uid, exceptionComp);
|
||||
if (_factionException.IsIgnored(exception, user))
|
||||
{
|
||||
_popup.PopupClient(Loc.GetString(comp.FailureString, ("target", uid)), user, user);
|
||||
return;
|
||||
}
|
||||
|
||||
// you have made a new friend :)
|
||||
_popup.PopupClient(Loc.GetString(comp.SuccessString, ("target", uid)), user, user);
|
||||
_factionException.IgnoreEntity(exception, user);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user