Remove IInteractHand (#7601)
* Plantholder * Strap * Finish him * Mirror review stuff
This commit is contained in:
@@ -7,7 +7,6 @@ using Content.Shared.Botany;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -15,9 +14,7 @@ using Robust.Shared.Timing;
|
||||
namespace Content.Server.Botany.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
#pragma warning disable 618
|
||||
public sealed class PlantHolderComponent : Component, IInteractHand, IActivate
|
||||
#pragma warning restore 618
|
||||
public sealed class PlantHolderComponent : Component
|
||||
{
|
||||
public const float HydroponicsSpeedMultiplier = 1f;
|
||||
public const float HydroponicsConsumptionMultiplier = 4f;
|
||||
@@ -629,17 +626,5 @@ namespace Content.Server.Botany.Components
|
||||
ForceUpdate = true;
|
||||
Update();
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
// DoHarvest does the sanity checks.
|
||||
return DoHarvest(eventArgs.User);
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
// DoHarvest does the sanity checks.
|
||||
DoHarvest(eventArgs.User);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Content.Server.Botany.Systems
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PlantHolderComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<PlantHolderComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<PlantHolderComponent, InteractHandEvent>(OnInteractHand);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, PlantHolderComponent component, ExaminedEvent args)
|
||||
@@ -257,5 +258,10 @@ namespace Content.Server.Botany.Systems
|
||||
EntityManager.QueueDeleteEntity(args.Used);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, PlantHolderComponent component, InteractHandEvent args)
|
||||
{
|
||||
component.DoHarvest(args.User);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
|
||||
namespace Content.Server.Buckle.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedStrapComponent))]
|
||||
public sealed class StrapComponent : SharedStrapComponent, IInteractHand, ISerializationHooks, IDestroyAct
|
||||
public sealed class StrapComponent : SharedStrapComponent, ISerializationHooks, IDestroyAct
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
@@ -216,18 +209,6 @@ namespace Content.Server.Buckle.Components
|
||||
return new StrapComponentState(Position);
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!entManager.TryGetComponent<BuckleComponent>(eventArgs.User, out var buckle))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return buckle.ToggleBuckle(eventArgs.User, Owner);
|
||||
}
|
||||
|
||||
public override bool DragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using Content.Server.Buckle.Components;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
|
||||
namespace Content.Server.Buckle.Systems
|
||||
{
|
||||
@@ -24,6 +21,7 @@ namespace Content.Server.Buckle.Systems
|
||||
|
||||
SubscribeLocalEvent<StrapComponent, GetVerbsEvent<InteractionVerb>>(AddStrapVerbs);
|
||||
SubscribeLocalEvent<StrapComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
|
||||
SubscribeLocalEvent<StrapComponent, InteractHandEvent>(OnInteractHand);
|
||||
}
|
||||
|
||||
private void OnInsertAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args)
|
||||
@@ -33,6 +31,14 @@ namespace Content.Server.Buckle.Systems
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, StrapComponent component, InteractHandEvent args)
|
||||
{
|
||||
if (!TryComp<BuckleComponent>(args.User, out var buckle))
|
||||
return;
|
||||
|
||||
buckle.ToggleBuckle(args.User, uid);
|
||||
}
|
||||
|
||||
// TODO ECS BUCKLE/STRAP These 'Strap' verbs are an incestuous mess of buckle component and strap component
|
||||
// functions. Whenever these are fully ECSed, maybe do it in a way that allows for these verbs to be handled in
|
||||
// a sensible manner in a single system?
|
||||
|
||||
@@ -1,66 +1,34 @@
|
||||
using System;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Radiation;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class RadiationCollectorComponent : Component, IInteractHand, IRadiationAct
|
||||
public sealed class RadiationCollectorComponent : Component, IRadiationAct
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
private bool _enabled;
|
||||
private TimeSpan _coolDownEnd;
|
||||
public bool Enabled;
|
||||
public TimeSpan CoolDownEnd;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Collecting {
|
||||
get => _enabled;
|
||||
get => Enabled;
|
||||
set
|
||||
{
|
||||
if (_enabled == value) return;
|
||||
_enabled = value;
|
||||
SetAppearance(_enabled ? RadiationCollectorVisualState.Activating : RadiationCollectorVisualState.Deactivating);
|
||||
if (Enabled == value) return;
|
||||
Enabled = value;
|
||||
SetAppearance(Enabled ? RadiationCollectorVisualState.Activating : RadiationCollectorVisualState.Deactivating);
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ChargeModifier = 30000f;
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
var curTime = _gameTiming.CurTime;
|
||||
|
||||
if(curTime < _coolDownEnd)
|
||||
return true;
|
||||
|
||||
if (!_enabled)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("radiation-collector-component-use-on"));
|
||||
Collecting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("radiation-collector-component-use-off"));
|
||||
Collecting = false;
|
||||
}
|
||||
|
||||
_coolDownEnd = curTime + TimeSpan.FromSeconds(0.81f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void IRadiationAct.RadiationAct(float frameTime, SharedRadiationPulseComponent radiation)
|
||||
{
|
||||
if (!_enabled) return;
|
||||
if (!Enabled) return;
|
||||
|
||||
// No idea if this is even vaguely accurate to the previous logic.
|
||||
// The maths is copied from that logic even though it works differently.
|
||||
@@ -73,7 +41,7 @@ namespace Content.Server.Singularity.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAppearance(RadiationCollectorVisualState state)
|
||||
public void SetAppearance(RadiationCollectorVisualState state)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(Owner, out var appearance))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using Content.Server.Singularity.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Server.Popups;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Singularity.EntitySystems
|
||||
{
|
||||
public sealed class RadiationCollectorSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RadiationCollectorComponent, InteractHandEvent>(OnInteractHand);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
|
||||
{
|
||||
var curTime = _gameTiming.CurTime;
|
||||
|
||||
if(curTime < component.CoolDownEnd)
|
||||
return;
|
||||
|
||||
if (!component.Enabled)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("radiation-collector-component-use-on"), uid, Filter.Pvs(args.User));
|
||||
component.Collecting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("radiation-collector-component-use-off"), uid, Filter.Pvs(args.User));
|
||||
component.Collecting = false;
|
||||
}
|
||||
|
||||
component.CoolDownEnd = curTime + TimeSpan.FromSeconds(0.81f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,7 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Interaction
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface gives components behavior when being clicked on by a user with an empty hand
|
||||
/// who is in range and has unobstructed reach of the target entity (allows inside blockers).
|
||||
/// </summary>
|
||||
[RequiresExplicitImplementation]
|
||||
public interface IInteractHand
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when a player directly interacts with an empty hand when user is in range of the target entity.
|
||||
/// </summary>
|
||||
[Obsolete("Use InteractHandEvent instead")]
|
||||
bool InteractHand(InteractHandEventArgs eventArgs);
|
||||
}
|
||||
|
||||
public sealed class InteractHandEventArgs : EventArgs, ITargetedInteractEventArgs
|
||||
{
|
||||
public InteractHandEventArgs(EntityUid user, EntityUid target)
|
||||
@@ -272,17 +272,6 @@ namespace Content.Shared.Interaction
|
||||
if (message.Handled)
|
||||
return;
|
||||
|
||||
var interactHandEventArgs = new InteractHandEventArgs(user, target);
|
||||
var interactHandComps = AllComps<IInteractHand>(target).ToList();
|
||||
foreach (var interactHandComp in interactHandComps)
|
||||
{
|
||||
// If an InteractHand returns a status completion we finish our interaction
|
||||
#pragma warning disable 618
|
||||
if (interactHandComp.InteractHand(interactHandEventArgs))
|
||||
#pragma warning restore 618
|
||||
return;
|
||||
}
|
||||
|
||||
// Else we run Activate.
|
||||
InteractionActivate(user, target,
|
||||
checkCanInteract: false,
|
||||
@@ -439,7 +428,7 @@ namespace Content.Shared.Interaction
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored? predicate = null,
|
||||
bool popup = false)
|
||||
{;
|
||||
{;
|
||||
Ignored combinedPredicate = e => e == origin || (predicate?.Invoke(e) ?? false);
|
||||
|
||||
var inRange = InRangeUnobstructed(Transform(origin).MapPosition, other, range, collisionMask, combinedPredicate);
|
||||
|
||||
Reference in New Issue
Block a user