Remove IAfterInteract (#9715)

* remove gas analyzer iafterinteract

* solution transfer + obsolete

* cuffable

* remove
This commit is contained in:
Kara
2022-07-14 04:45:31 -07:00
committed by GitHub
parent a2d22837c6
commit fab331742a
11 changed files with 163 additions and 241 deletions

View File

@@ -15,7 +15,7 @@ namespace Content.Server.Atmos.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedGasAnalyzerComponent))]
public sealed class GasAnalyzerComponent : SharedGasAnalyzerComponent, IAfterInteract
public sealed class GasAnalyzerComponent : SharedGasAnalyzerComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
@@ -245,21 +245,5 @@ namespace Content.Server.Atmos.Components
break;
}
}
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.CanReach)
{
eventArgs.User.PopupMessage(Loc.GetString("gas-analyzer-component-player-cannot-reach-message"));
return true;
}
if (_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor))
{
OpenInterface(actor.PlayerSession, eventArgs.ClickLocation);
}
return true;
}
}
}

View File

@@ -1,11 +1,24 @@
using Content.Server.Atmos.Components;
using Content.Server.Popups;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.Atmos.EntitySystems
{
[UsedImplicitly]
public sealed class GasAnalyzerSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
}
public override void Update(float frameTime)
{
foreach (var analyzer in EntityManager.EntityQuery<GasAnalyzerComponent>(true))
@@ -13,5 +26,21 @@ namespace Content.Server.Atmos.EntitySystems
analyzer.Update(frameTime);
}
}
private void OnAfterInteract(EntityUid uid, GasAnalyzerComponent component, AfterInteractEvent args)
{
if (!args.CanReach)
{
_popup.PopupEntity(Loc.GetString("gas-analyzer-component-player-cannot-reach-message"), args.User, Filter.Entities(args.User));
return;
}
if (TryComp(args.User, out ActorComponent? actor))
{
component.OpenInterface(actor.PlayerSession, args.ClickLocation);
}
args.Handled = true;
}
}
}

View File

@@ -14,15 +14,8 @@ namespace Content.Server.Chemistry.Components
/// Gives click behavior for transferring to/from other reagent containers.
/// </summary>
[RegisterComponent]
public sealed class SolutionTransferComponent : Component, IAfterInteract
public sealed class SolutionTransferComponent : Component
{
[Dependency] private readonly IEntityManager _entities = default!;
// Behavior is as such:
// If it's a reagent tank, TAKE reagent.
// If it's anything else, GIVE reagent.
// Of course, only if possible.
/// <summary>
/// The amount of solution to be transferred from this solution when clicking on other solutions with it.
/// </summary>
@@ -102,70 +95,5 @@ namespace Content.Server.Chemistry.Components
MaximumTransferAmount.Int()));
TransferAmount = amount;
}
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.CanReach || eventArgs.Target == null)
return false;
var target = eventArgs.Target!.Value;
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
var transferSystem = EntitySystem.Get<SolutionTransferSystem>();
//Special case for reagent tanks, because normally clicking another container will give solution, not take it.
if (CanReceive && !_entities.HasComponent<RefillableSolutionComponent>(target) // target must not be refillable (e.g. Reagent Tanks)
&& solutionsSys.TryGetDrainableSolution(target, out var targetDrain) // target must be drainable
&& _entities.TryGetComponent(Owner, out RefillableSolutionComponent? refillComp)
&& solutionsSys.TryGetRefillableSolution(Owner, out var ownerRefill, refillable: refillComp))
{
var transferAmount = TransferAmount; // This is the player-configurable transfer amount of "Owner," not the target reagent tank.
if (_entities.TryGetComponent(Owner, out RefillableSolutionComponent? refill) && refill.MaxRefill != null) // Owner is the entity receiving solution from target.
{
transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill); // if the receiver has a smaller transfer limit, use that instead
}
var transferred = transferSystem.Transfer(eventArgs.User, target, targetDrain, Owner, ownerRefill, transferAmount);
if (transferred > 0)
{
var toTheBrim = ownerRefill.AvailableVolume == 0;
var msg = toTheBrim
? "comp-solution-transfer-fill-fully"
: "comp-solution-transfer-fill-normal";
target.PopupMessage(eventArgs.User,
Loc.GetString(msg, ("owner", eventArgs.Target), ("amount", transferred), ("target", Owner)));
return true;
}
}
// if target is refillable, and owner is drainable
if (CanSend && solutionsSys.TryGetRefillableSolution(target, out var targetRefill)
&& solutionsSys.TryGetDrainableSolution(Owner, out var ownerDrain))
{
var transferAmount = TransferAmount;
if (_entities.TryGetComponent(target, out RefillableSolutionComponent? refill) && refill.MaxRefill != null)
{
transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill);
}
var transferred = transferSystem.Transfer(eventArgs.User, Owner, ownerDrain, target, targetRefill, transferAmount);
if (transferred > 0)
{
Owner.PopupMessage(eventArgs.User,
Loc.GetString("comp-solution-transfer-transfer-solution",
("amount", transferred),
("target", target)));
return true;
}
}
return false;
}
}
}

View File

@@ -1,9 +1,11 @@
using Content.Shared.Verbs;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Popups;
namespace Content.Server.Chemistry.EntitySystems
@@ -11,6 +13,8 @@ namespace Content.Server.Chemistry.EntitySystems
[UsedImplicitly]
public sealed class SolutionTransferSystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
/// <summary>
/// Default transfer amounts for the set-transfer verb.
/// </summary>
@@ -21,6 +25,7 @@ namespace Content.Server.Chemistry.EntitySystems
base.Initialize();
SubscribeLocalEvent<SolutionTransferComponent, GetVerbsEvent<AlternativeVerb>>(AddSetTransferVerbs);
SubscribeLocalEvent<SolutionTransferComponent, AfterInteractEvent>(OnAfterInteract);
}
private void AddSetTransferVerbs(EntityUid uid, SolutionTransferComponent component, GetVerbsEvent<AlternativeVerb> args)
@@ -63,6 +68,70 @@ namespace Content.Server.Chemistry.EntitySystems
}
}
private void OnAfterInteract(EntityUid uid, SolutionTransferComponent component, AfterInteractEvent args)
{
if (!args.CanReach || args.Target == null)
return;
var target = args.Target!.Value;
//Special case for reagent tanks, because normally clicking another container will give solution, not take it.
if (component.CanReceive && !EntityManager.HasComponent<RefillableSolutionComponent>(target) // target must not be refillable (e.g. Reagent Tanks)
&& _solutionContainer.TryGetDrainableSolution(target, out var targetDrain) // target must be drainable
&& EntityManager.TryGetComponent(uid, out RefillableSolutionComponent? refillComp)
&& _solutionContainer.TryGetRefillableSolution(uid, out var ownerRefill, refillable: refillComp))
{
var transferAmount = component.TransferAmount; // This is the player-configurable transfer amount of "uid," not the target reagent tank.
if (EntityManager.TryGetComponent(uid, out RefillableSolutionComponent? refill) && refill.MaxRefill != null) // uid is the entity receiving solution from target.
{
transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill); // if the receiver has a smaller transfer limit, use that instead
}
var transferred = Transfer(args.User, target, targetDrain, uid, ownerRefill, transferAmount);
if (transferred > 0)
{
var toTheBrim = ownerRefill.AvailableVolume == 0;
var msg = toTheBrim
? "comp-solution-transfer-fill-fully"
: "comp-solution-transfer-fill-normal";
target.PopupMessage(args.User,
Loc.GetString(msg, ("owner", args.Target), ("amount", transferred), ("target", uid)));
args.Handled = true;
return;
}
}
// if target is refillable, and owner is drainable
if (component.CanSend && _solutionContainer.TryGetRefillableSolution(target, out var targetRefill)
&& _solutionContainer.TryGetDrainableSolution(uid, out var ownerDrain))
{
var transferAmount = component.TransferAmount;
if (EntityManager.TryGetComponent(target, out RefillableSolutionComponent? refill) && refill.MaxRefill != null)
{
transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill);
}
var transferred = Transfer(args.User, uid, ownerDrain, target, targetRefill, transferAmount);
if (transferred > 0)
{
uid.PopupMessage(args.User,
Loc.GetString("comp-solution-transfer-transfer-solution",
("amount", transferred),
("target", target)));
args.Handled = true;
return;
}
}
}
/// <summary>
/// Transfer from a solution to another.
/// </summary>

View File

@@ -13,7 +13,7 @@ namespace Content.Server.Cuffs.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedHandcuffComponent))]
public sealed class HandcuffComponent : SharedHandcuffComponent, IAfterInteract
public sealed class HandcuffComponent : SharedHandcuffComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
@@ -128,66 +128,17 @@ namespace Content.Server.Cuffs.Components
/// <summary>
/// Used to prevent DoAfter getting spammed.
/// </summary>
private bool _cuffing;
public bool Cuffing;
public override ComponentState GetComponentState()
{
return new HandcuffedComponentState(Broken ? BrokenState : string.Empty);
}
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (_cuffing) return true;
if (eventArgs.Target is not {Valid: true} target ||
!_entities.TryGetComponent<CuffableComponent?>(eventArgs.Target.Value, out var cuffed))
{
return false;
}
if (Broken)
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-cuffs-broken-error"));
return true;
}
if (!_entities.TryGetComponent<HandsComponent?>(target, out var hands))
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", eventArgs.Target)));
return true;
}
if (cuffed.CuffedHandCount >= hands.Count)
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-free-hands-error",("targetName", eventArgs.Target)));
return true;
}
if (!eventArgs.CanReach)
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-too-far-away-error"));
return true;
}
if (eventArgs.Target == eventArgs.User)
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-self"));
}
else
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", eventArgs.Target)));
eventArgs.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", eventArgs.User)));
}
SoundSystem.Play(StartCuffSound.GetSound(), Filter.Pvs(Owner), Owner);
TryUpdateCuff(eventArgs.User, target, cuffed);
return true;
}
/// <summary>
/// Update the cuffed state of an entity
/// </summary>
private async void TryUpdateCuff(EntityUid user, EntityUid target, CuffableComponent cuffs)
public async void TryUpdateCuff(EntityUid user, EntityUid target, CuffableComponent cuffs)
{
var cuffTime = CuffTime;
@@ -205,11 +156,11 @@ namespace Content.Server.Cuffs.Components
NeedHand = true
};
_cuffing = true;
Cuffing = true;
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterEventArgs);
_cuffing = false;
Cuffing = false;
if (result != DoAfterStatus.Cancelled)
{

View File

@@ -9,6 +9,8 @@ using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Shared.Player;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Robust.Shared.Audio;
namespace Content.Server.Cuffs
{
@@ -25,6 +27,7 @@ namespace Content.Server.Cuffs
SubscribeLocalEvent<HandCountChangedEvent>(OnHandCountChanged);
SubscribeLocalEvent<UncuffAttemptEvent>(OnUncuffAttempt);
SubscribeLocalEvent<CuffableComponent, GetVerbsEvent<Verb>>(AddUncuffVerb);
SubscribeLocalEvent<HandcuffComponent, AfterInteractEvent>(OnCuffAfterInteract);
}
private void AddUncuffVerb(EntityUid uid, CuffableComponent component, GetVerbsEvent<Verb> args)
@@ -46,6 +49,57 @@ namespace Content.Server.Cuffs
args.Verbs.Add(verb);
}
private void OnCuffAfterInteract(EntityUid uid, HandcuffComponent component, AfterInteractEvent args)
{
if (component.Cuffing)
return;
if (args.Target is not {Valid: true} target ||
!EntityManager.TryGetComponent<CuffableComponent>(args.Target.Value, out var cuffed))
{
return;
}
if (component.Broken)
{
args.User.PopupMessage(Loc.GetString("handcuff-component-cuffs-broken-error"));
return;
}
if (!EntityManager.TryGetComponent<HandsComponent?>(target, out var hands))
{
args.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", args.Target)));
return;
}
if (cuffed.CuffedHandCount >= hands.Count)
{
args.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-free-hands-error",("targetName", args.Target)));
return;
}
if (!args.CanReach)
{
args.User.PopupMessage(Loc.GetString("handcuff-component-too-far-away-error"));
return;
}
if (args.Target == args.User)
{
args.User.PopupMessage(Loc.GetString("handcuff-component-target-self"));
}
else
{
args.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", args.Target)));
args.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", args.User)));
}
SoundSystem.Play(component.StartCuffSound.GetSound(), Filter.Pvs(uid), uid);
component.TryUpdateCuff(args.User, target, cuffed);
args.Handled = true;
}
private void OnUncuffAttempt(UncuffAttemptEvent args)
{
if (args.Cancelled)