Cleanup and small update to the stethoscope! (#36210)
* First commit * Address most of the review!
This commit is contained in:
@@ -67,6 +67,8 @@ public partial class InventorySystem
|
||||
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RefRelayInventoryEvent);
|
||||
|
||||
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
|
||||
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<InnateVerb>>(OnGetInnateVerbs);
|
||||
|
||||
}
|
||||
|
||||
protected void RefRelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, ref T args) where T : IInventoryRelayEvent
|
||||
@@ -121,6 +123,17 @@ public partial class InventorySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetInnateVerbs(EntityUid uid, InventoryComponent component, GetVerbsEvent<InnateVerb> args)
|
||||
{
|
||||
// Automatically relay stripping related verbs to all equipped clothing.
|
||||
var ev = new InventoryRelayedEvent<GetVerbsEvent<InnateVerb>>(args);
|
||||
var enumerator = new InventorySlotEnumerator(component, SlotFlags.WITHOUT_POCKET);
|
||||
while (enumerator.NextItem(out var item))
|
||||
{
|
||||
RaiseLocalEvent(item, ev);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Medical.Stethoscope.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a verb and action that allows the user to listen to the entity's breathing.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class StethoscopeComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Time between each use of the stethoscope.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Delay = TimeSpan.FromSeconds(1.75);
|
||||
|
||||
/// <summary>
|
||||
/// Last damage that was measured. Used to indicate if breathing is improving or getting worse.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2? LastMeasuredDamage;
|
||||
|
||||
[DataField]
|
||||
public EntProtoId Action = "ActionStethoscope";
|
||||
|
||||
[DataField]
|
||||
public EntityUid? ActionEntity;
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
|
||||
namespace Content.Shared.Medical.Stethoscope;
|
||||
|
||||
public sealed partial class StethoscopeActionEvent : EntityTargetActionEvent
|
||||
{
|
||||
}
|
||||
148
Content.Shared/Medical/Stethoscope/StethoscopeSystem.cs
Normal file
148
Content.Shared/Medical/Stethoscope/StethoscopeSystem.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Medical.Stethoscope.Components;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Shared.Medical.Stethoscope;
|
||||
|
||||
public sealed class StethoscopeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
// The damage type to "listen" for with the stethoscope.
|
||||
private const string DamageToListenFor = "Asphyxiation";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StethoscopeComponent, InventoryRelayedEvent<GetVerbsEvent<InnateVerb>>>(AddStethoscopeVerb);
|
||||
SubscribeLocalEvent<StethoscopeComponent, GetItemActionsEvent>(OnGetActions);
|
||||
SubscribeLocalEvent<StethoscopeComponent, StethoscopeActionEvent>(OnStethoscopeAction);
|
||||
SubscribeLocalEvent<StethoscopeComponent, StethoscopeDoAfterEvent>(OnDoAfter);
|
||||
}
|
||||
|
||||
private void OnGetActions(Entity<StethoscopeComponent> ent, ref GetItemActionsEvent args)
|
||||
{
|
||||
args.AddAction(ref ent.Comp.ActionEntity, ent.Comp.Action);
|
||||
}
|
||||
|
||||
private void OnStethoscopeAction(Entity<StethoscopeComponent> ent, ref StethoscopeActionEvent args)
|
||||
{
|
||||
StartListening(ent, args.Target);
|
||||
}
|
||||
|
||||
private void AddStethoscopeVerb(Entity<StethoscopeComponent> ent, ref InventoryRelayedEvent<GetVerbsEvent<InnateVerb>> args)
|
||||
{
|
||||
if (!args.Args.CanInteract || !args.Args.CanAccess)
|
||||
return;
|
||||
|
||||
if (!HasComp<MobStateComponent>(args.Args.Target))
|
||||
return;
|
||||
|
||||
var target = args.Args.Target;
|
||||
|
||||
InnateVerb verb = new()
|
||||
{
|
||||
Act = () => StartListening(ent, target),
|
||||
Text = Loc.GetString("stethoscope-verb"),
|
||||
IconEntity = GetNetEntity(ent),
|
||||
Priority = 2,
|
||||
};
|
||||
args.Args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void StartListening(Entity<StethoscopeComponent> ent, EntityUid target)
|
||||
{
|
||||
if (!_container.TryGetContainingContainer((ent, null, null), out var container))
|
||||
return;
|
||||
|
||||
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, container.Owner, ent.Comp.Delay, new StethoscopeDoAfterEvent(), ent, target: target, used: ent)
|
||||
{
|
||||
DuplicateCondition = DuplicateConditions.SameEvent,
|
||||
BreakOnMove = true,
|
||||
Hidden = true,
|
||||
BreakOnHandChange = false,
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDoAfter(Entity<StethoscopeComponent> ent, ref StethoscopeDoAfterEvent args)
|
||||
{
|
||||
var target = args.Target;
|
||||
|
||||
if (args.Handled || target == null || args.Cancelled)
|
||||
{
|
||||
ent.Comp.LastMeasuredDamage = null;
|
||||
return;
|
||||
}
|
||||
|
||||
ExamineWithStethoscope(ent, args.Args.User, target.Value);
|
||||
|
||||
args.Repeat = true;
|
||||
}
|
||||
|
||||
private void ExamineWithStethoscope(Entity<StethoscopeComponent> stethoscope, EntityUid user, EntityUid target)
|
||||
{
|
||||
// TODO: Add check for respirator component when it gets moved to shared.
|
||||
// If the mob is dead or cannot asphyxiation damage, the popup shows nothing.
|
||||
if (!TryComp<MobStateComponent>(target, out var mobState) ||
|
||||
!TryComp<DamageableComponent>(target, out var damageComp) ||
|
||||
_mobState.IsDead(target, mobState) ||
|
||||
!damageComp.Damage.DamageDict.TryGetValue(DamageToListenFor, out var asphyxDmg))
|
||||
{
|
||||
_popup.PopupPredicted(Loc.GetString("stethoscope-nothing"), target, user);
|
||||
stethoscope.Comp.LastMeasuredDamage = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var absString = GetAbsoluteDamageString(asphyxDmg);
|
||||
|
||||
// Don't show the change if this is the first time listening.
|
||||
if (stethoscope.Comp.LastMeasuredDamage == null)
|
||||
{
|
||||
_popup.PopupPredicted(absString, target, user);
|
||||
}
|
||||
else
|
||||
{
|
||||
var deltaString = GetDeltaDamageString(stethoscope.Comp.LastMeasuredDamage.Value, asphyxDmg);
|
||||
_popup.PopupPredicted(Loc.GetString("stethoscope-combined-status", ("absolute", absString), ("delta", deltaString)), target, user);
|
||||
}
|
||||
|
||||
stethoscope.Comp.LastMeasuredDamage = asphyxDmg;
|
||||
}
|
||||
|
||||
private string GetAbsoluteDamageString(FixedPoint2 asphyxDmg)
|
||||
{
|
||||
var msg = (int) asphyxDmg switch
|
||||
{
|
||||
< 10 => "stethoscope-normal",
|
||||
< 30 => "stethoscope-raggedy",
|
||||
< 60 => "stethoscope-hyper",
|
||||
< 80 => "stethoscope-irregular",
|
||||
_ => "stethoscope-fucked",
|
||||
};
|
||||
return Loc.GetString(msg);
|
||||
}
|
||||
|
||||
private string GetDeltaDamageString(FixedPoint2 lastDamage, FixedPoint2 currentDamage)
|
||||
{
|
||||
if (lastDamage > currentDamage)
|
||||
return Loc.GetString("stethoscope-delta-improving");
|
||||
if (lastDamage < currentDamage)
|
||||
return Loc.GetString("stethoscope-delta-worsening");
|
||||
return Loc.GetString("stethoscope-delta-steady");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed partial class StethoscopeActionEvent : EntityTargetActionEvent;
|
||||
@@ -4,6 +4,4 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Shared.Medical;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class StethoscopeDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
public sealed partial class StethoscopeDoAfterEvent : SimpleDoAfterEvent;
|
||||
|
||||
@@ -281,12 +281,11 @@ namespace Content.Shared.Verbs
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is for verbs facilitated by components on the user.
|
||||
/// This is for verbs facilitated by components on the user or their clothing.
|
||||
/// Verbs from clothing, species, etc. rather than a held item.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Add a component to the user's entity and sub to the get verbs event
|
||||
/// and it'll appear in the verbs menu on any target.
|
||||
/// This will get relayed to all clothing (Not pockets) through an inventory relay event.
|
||||
/// </remarks>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InnateVerb : Verb
|
||||
|
||||
Reference in New Issue
Block a user