Fix two interaction prediction issues (#7356)
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Emag.Components;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Emag
|
||||
{
|
||||
public sealed class EmagSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedAdminLogSystem _adminLog = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EmagComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -28,5 +43,27 @@ namespace Content.Server.Emag
|
||||
emag.Charges++;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAfterInteract(EntityUid uid, EmagComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
if (component.Charges <= 0)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("emag-no-charges"), args.User, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
|
||||
var emaggedEvent = new GotEmaggedEvent(args.User);
|
||||
RaiseLocalEvent(args.Target.Value, emaggedEvent, false);
|
||||
if (emaggedEvent.Handled)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("emag-success", ("target", args.Target)), args.User, Filter.Entities(args.User));
|
||||
_adminLog.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(args.User):player} emagged {ToPrettyString(args.Target.Value):target}");
|
||||
component.Charges--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (slot.Item != null)
|
||||
_handsSystem.TryPickupAnyHand(args.User, slot.Item.Value, handsComp: hands);
|
||||
|
||||
Insert(uid, slot, args.Used, args.User, excludeUserAudio: args.Predicted);
|
||||
Insert(uid, slot, args.Used, args.User, excludeUserAudio: true);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ namespace Content.Shared.Emag.Components
|
||||
[RegisterComponent]
|
||||
public sealed class EmagComponent : Component
|
||||
{
|
||||
[DataField("maxCharges")]
|
||||
[DataField("maxCharges"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public int MaxCharges = 3;
|
||||
|
||||
[DataField("charges")]
|
||||
[DataField("charges"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Charges = 3;
|
||||
|
||||
[DataField("rechargeTime")]
|
||||
[DataField("rechargeTime"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float RechargeTime = 90f;
|
||||
public float Accumulator = 0f;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using Content.Shared.Emag.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Shared.Emag.Systems
|
||||
{
|
||||
@@ -15,13 +10,9 @@ namespace Content.Shared.Emag.Systems
|
||||
/// 4. Past the check, add all the effects you desire and HANDLE THE EVENT ARGUMENT so a charge is spent
|
||||
public sealed class SharedEmagSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedAdminLogSystem _adminLog = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EmagComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<EmagComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
@@ -36,28 +27,6 @@ namespace Content.Shared.Emag.Systems
|
||||
}
|
||||
args.PushMarkup(Loc.GetString("emag-recharging", ("seconds", Math.Round(timeRemaining))));
|
||||
}
|
||||
|
||||
private void OnAfterInteract(EntityUid uid, EmagComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
if (component.Charges <= 0)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("emag-no-charges"), args.User, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
|
||||
var emaggedEvent = new GotEmaggedEvent(args.User);
|
||||
RaiseLocalEvent(args.Target.Value, emaggedEvent, false);
|
||||
if (emaggedEvent.Handled)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("emag-success",("target", args.Target)), args.User, Filter.Entities(args.User));
|
||||
_adminLog.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(args.User):player} emagged {ToPrettyString(args.Target.Value):target}");
|
||||
component.Charges--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class GotEmaggedEvent : HandledEntityEventArgs
|
||||
@@ -66,7 +35,7 @@ namespace Content.Shared.Emag.Systems
|
||||
|
||||
public GotEmaggedEvent(EntityUid userUid)
|
||||
{
|
||||
userUid = UserUid;
|
||||
UserUid = userUid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,13 +71,7 @@ namespace Content.Shared.Interaction
|
||||
/// </summary>
|
||||
public EntityCoordinates ClickLocation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, this prediction is also being predicted client-side. So care has to be taken to avoid audio
|
||||
/// duplication.
|
||||
/// </summary>
|
||||
public bool Predicted { get; }
|
||||
|
||||
public InteractUsingEvent(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation, bool predicted = false)
|
||||
public InteractUsingEvent(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation)
|
||||
{
|
||||
// Interact using should not have the same used and target.
|
||||
// That should be a use-in-hand event instead.
|
||||
@@ -88,7 +82,6 @@ namespace Content.Shared.Interaction
|
||||
Used = used;
|
||||
Target = target;
|
||||
ClickLocation = clickLocation;
|
||||
Predicted = predicted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,7 +627,6 @@ namespace Content.Shared.Interaction
|
||||
EntityUid used,
|
||||
EntityUid target,
|
||||
EntityCoordinates clickLocation,
|
||||
bool predicted = false,
|
||||
bool checkCanInteract = true,
|
||||
bool checkCanUse = true)
|
||||
{
|
||||
@@ -641,7 +640,7 @@ namespace Content.Shared.Interaction
|
||||
return;
|
||||
|
||||
// all interactions should only happen when in range / unobstructed, so no range check is needed
|
||||
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation, predicted);
|
||||
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
|
||||
RaiseLocalEvent(target, interactUsingEvent);
|
||||
if (interactUsingEvent.Handled)
|
||||
return;
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract partial class InventorySystem
|
||||
if (held != null && itemUid != null)
|
||||
{
|
||||
_interactionSystem.InteractUsing(actor, held.Value, itemUid.Value,
|
||||
new EntityCoordinates(), predicted: true);
|
||||
new EntityCoordinates());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user