2021-11-11 16:10:57 -07:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using Content.Server.Body.Components;
|
2021-09-20 19:06:48 +10:00
|
|
|
using Content.Server.GameTicking;
|
2022-05-13 21:04:45 -07:00
|
|
|
using Content.Server.Kitchen.Components;
|
2021-09-20 19:06:48 +10:00
|
|
|
using Content.Server.Mind.Components;
|
2021-11-11 16:10:57 -07:00
|
|
|
using Content.Shared.Body.Components;
|
2021-11-08 15:11:58 +01:00
|
|
|
using Content.Shared.MobState.Components;
|
2022-06-24 17:44:30 +10:00
|
|
|
using Content.Shared.Movement.Events;
|
2021-11-11 11:17:23 -04:00
|
|
|
using Robust.Shared.Timing;
|
2021-09-20 19:06:48 +10:00
|
|
|
|
2021-11-11 16:10:57 -07:00
|
|
|
namespace Content.Server.Body.Systems
|
2021-09-20 19:06:48 +10:00
|
|
|
{
|
|
|
|
|
public sealed class BodySystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly GameTicker _ticker = default!;
|
2021-11-11 11:17:23 -04:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2021-09-20 19:06:48 +10:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<BodyComponent, RelayMoveInputEvent>(OnRelayMoveInput);
|
2022-04-15 18:53:52 -04:00
|
|
|
SubscribeLocalEvent<BodyComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
|
2022-05-13 21:04:45 -07:00
|
|
|
SubscribeLocalEvent<BodyComponent, BeingMicrowavedEvent>(OnBeingMicrowaved);
|
2021-09-20 19:06:48 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRelayMoveInput(EntityUid uid, BodyComponent component, RelayMoveInputEvent args)
|
|
|
|
|
{
|
2021-11-08 15:11:58 +01:00
|
|
|
if (EntityManager.TryGetComponent<MobStateComponent>(uid, out var mobState) &&
|
2021-09-20 19:06:48 +10:00
|
|
|
mobState.IsDead() &&
|
2021-09-28 13:35:29 +02:00
|
|
|
EntityManager.TryGetComponent<MindComponent>(uid, out var mind) &&
|
2021-09-20 19:06:48 +10:00
|
|
|
mind.HasMind)
|
|
|
|
|
{
|
2021-11-11 11:17:23 -04:00
|
|
|
if (!mind.Mind!.TimeOfDeath.HasValue)
|
|
|
|
|
{
|
|
|
|
|
mind.Mind.TimeOfDeath = _gameTiming.RealTime;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 19:06:48 +10:00
|
|
|
_ticker.OnGhostAttempt(mind.Mind!, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-11 16:10:57 -07:00
|
|
|
|
2022-04-15 18:53:52 -04:00
|
|
|
private void OnApplyMetabolicMultiplier(EntityUid uid, BodyComponent component, ApplyMetabolicMultiplierEvent args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (part, _) in component.Parts)
|
|
|
|
|
foreach (var mechanism in part.Mechanisms)
|
|
|
|
|
{
|
|
|
|
|
RaiseLocalEvent(mechanism.Owner, args, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 21:04:45 -07:00
|
|
|
private void OnBeingMicrowaved(EntityUid uid, BodyComponent component, BeingMicrowavedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Don't microwave animals, kids
|
|
|
|
|
Transform(uid).AttachToGridOrMap();
|
|
|
|
|
component.Gib();
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 18:25:02 -07:00
|
|
|
/// <summary>
|
2022-01-04 02:17:39 -07:00
|
|
|
/// Returns a list of ValueTuples of <see cref="T"/> and MechanismComponent on each mechanism
|
2021-11-30 18:25:02 -07:00
|
|
|
/// in the given body.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">The entity to check for the component on.</param>
|
|
|
|
|
/// <param name="body">The body to check for mechanisms on.</param>
|
|
|
|
|
/// <typeparam name="T">The component to check for.</typeparam>
|
2022-03-28 13:52:53 -07:00
|
|
|
public List<(T Comp, MechanismComponent Mech)> GetComponentsOnMechanisms<T>(EntityUid uid,
|
2021-11-30 18:25:02 -07:00
|
|
|
SharedBodyComponent? body=null) where T : Component
|
2021-11-11 16:10:57 -07:00
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref body))
|
2022-03-28 13:52:53 -07:00
|
|
|
return new();
|
2021-11-11 16:10:57 -07:00
|
|
|
|
2022-03-28 13:52:53 -07:00
|
|
|
var query = EntityManager.GetEntityQuery<T>();
|
|
|
|
|
var list = new List<(T Comp, MechanismComponent Mech)>(3);
|
2021-11-11 16:10:57 -07:00
|
|
|
foreach (var (part, _) in body.Parts)
|
|
|
|
|
foreach (var mechanism in part.Mechanisms)
|
|
|
|
|
{
|
2022-03-28 13:52:53 -07:00
|
|
|
if (query.TryGetComponent(mechanism.Owner, out var comp))
|
|
|
|
|
list.Add((comp, mechanism));
|
2021-11-11 16:10:57 -07:00
|
|
|
}
|
2022-03-28 13:52:53 -07:00
|
|
|
|
|
|
|
|
return list;
|
2021-11-11 16:10:57 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-30 18:25:02 -07:00
|
|
|
/// <summary>
|
2022-01-04 02:17:39 -07:00
|
|
|
/// Tries to get a list of ValueTuples of <see cref="T"/> and MechanismComponent on each mechanism
|
2021-11-30 18:25:02 -07:00
|
|
|
/// in the given body.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">The entity to check for the component on.</param>
|
|
|
|
|
/// <param name="comps">The list of components.</param>
|
|
|
|
|
/// <param name="body">The body to check for mechanisms on.</param>
|
|
|
|
|
/// <typeparam name="T">The component to check for.</typeparam>
|
|
|
|
|
/// <returns>Whether any were found.</returns>
|
2021-11-11 16:10:57 -07:00
|
|
|
public bool TryGetComponentsOnMechanisms<T>(EntityUid uid,
|
2022-03-28 13:52:53 -07:00
|
|
|
[NotNullWhen(true)] out List<(T Comp, MechanismComponent Mech)>? comps,
|
2021-11-30 18:25:02 -07:00
|
|
|
SharedBodyComponent? body=null) where T: Component
|
2021-11-11 16:10:57 -07:00
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref body))
|
|
|
|
|
{
|
|
|
|
|
comps = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 13:52:53 -07:00
|
|
|
comps = GetComponentsOnMechanisms<T>(uid, body);
|
2021-11-11 16:10:57 -07:00
|
|
|
|
2022-03-28 13:52:53 -07:00
|
|
|
if (comps.Count == 0)
|
2021-11-11 16:10:57 -07:00
|
|
|
{
|
|
|
|
|
comps = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-09-20 19:06:48 +10:00
|
|
|
}
|
|
|
|
|
}
|