Files
Delta-v/Content.Shared/Mobs/Systems/MobStateSystem.StateMachine.cs
T
CorynandJanet Blackquill cb62b27fcf Nubody (2/3) - ShitMed removal (#5844)
* Reapply "Nubody Merge" (#5807)

This reverts commit d62f7cef10.

* Revert "Nubody Merge (#5670)"

This reverts commit b465cfb3fd.

* Revert "IPC fibers (#4968)"

This reverts commit c2b42211f0.

* Revert "IPC Polymorph fix (#4545)"

This reverts commit fa03d8c655.

* Revert "fix IPC not having humanoid emotes (#4445)"

This reverts commit 216fdf999f.

* Revert "ipc heat/cold (#4306)"

This reverts commit fafd5cf816.

* Revert "ipc cables (#4283)"

This reverts commit 54958039a1.

* Revert "feat: ipcs now have dynamic power draw based off movement speed (#3917)"

This reverts commit 71e8b7e64b.

* Revert "fix ipcs not being able to disarm (#3374)"

This reverts commit 764c4dcf54.

* Revert "make steel heal caustic for ipcs (#3206)"

This reverts commit 450ac82550.

* Revert "add missing ipc survival boxes (#3065)"

This reverts commit 888c9cdb00.

* Revert "make borgs use ipc repairing (#3064)"

This reverts commit f77a49dd0b.

* Revert "Update hud.yml to add ipcs to diagnostic hud (#3019)"

This reverts commit 7220643531.

* Revert "Tweak IPCs (#2979)"

This reverts commit 98b47476de.

* Revert "fix nukies ipc test fail (#2957)"

This reverts commit 4a1acbf863.

* Revert "fix ipc nukies not getting comms (#2884)"

This reverts commit 8a2254770e.

* Revert "fix ipc encryption key mispredict (#2879)"

This reverts commit f08726efc1.

* Revert "Merge pull request #2800 from Spielern/port-ipc"

This reverts commit 822fa4312c, reversing
changes made to fe4c23c702.

* Remove and Fix rest of IPC Hangons causing crashes

* Integration test Errors

* Expand migration file with removed IPC stuff

* IPC Leg was found and migrated to naught

* Revert "Merge pull request #2542 from deltanedas/shitmed-ops"

This reverts commit 83a8002922, reversing
changes made to baa89b0052.

* Revert "Set up surgical augments infrastructure & add tool panel augments (#3059)"

This reverts commit a40f0be6fd.

* Revert "Psionic Prosthetics (#4689)"

This reverts commit 2679bb238a.

* Revert "Add surgical cleanliness and sanitation (#2847)"

This reverts commit 64565ba4f7.

* Remove unremoved mentions

* Revert "Add autoclave to easily sanitize large amounts of items and faster (#2933)"

This reverts commit d0da90fa2e.

* Shit Med Removed

* Remove _ShitMed Folders and fix Errors in Console

* Add OrganAnimalBrain into the mirgraiton file

* Heads no Input Mover

* Monke

* Full migration file I guess

* oops

* shiv state fix

* Restore accidental deleted recipe

* Forgot one flt mention

* Fix more issues

* Comment out Damage Visual for motorkind for now

* Motorkind...

* Commenting stuff out for now

* thought there'd be more of this to gut

---------

Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
2026-05-21 20:27:04 -04:00

135 lines
5.7 KiB
C#

using Content.Shared.Database;
using Content.Shared.Humanoid;
using Content.Shared.Mobs.Components;
using Robust.Shared.Player;
namespace Content.Shared.Mobs.Systems;
public partial class MobStateSystem
{
#region Public API
/// <summary>
/// Check if an Entity can be set to a particular MobState
/// </summary>
/// <param name="entity">Target Entity</param>
/// <param name="mobState">MobState to check</param>
/// <param name="component">MobState Component owned by the target</param>
/// <returns>If the entity can be set to that MobState</returns>
public bool HasState(EntityUid entity, MobState mobState, MobStateComponent? component = null)
{
return _mobStateQuery.Resolve(entity, ref component, false) &&
component.AllowedStates.Contains(mobState);
}
/// <summary>
/// Run a MobState update check. This will trigger update events if the state has been changed.
/// </summary>
/// <param name="entity">Target Entity we want to change the MobState of</param>
/// <param name="component">MobState Component attached to the entity</param>
/// <param name="origin">Entity that caused the state update (if applicable)</param>
public void UpdateMobState(EntityUid entity, MobStateComponent? component = null, EntityUid? origin = null)
{
if (!_mobStateQuery.Resolve(entity, ref component))
return;
var ev = new UpdateMobStateEvent {Target = entity, Component = component, Origin = origin};
RaiseLocalEvent(entity, ref ev);
ChangeState(entity, component, ev.State, origin: origin);
}
/// <summary>
/// Change the MobState without triggering UpdateMobState events.
/// WARNING: use this sparingly when you need to override other systems (MobThresholds)
/// </summary>
/// <param name="entity">Target Entity we want to change the MobState of</param>
/// <param name="mobState">The new MobState we want to set</param>
/// <param name="component">MobState Component attached to the entity</param>
/// <param name="origin">Entity that caused the state update (if applicable)</param>
public void ChangeMobState(EntityUid entity, MobState mobState, MobStateComponent? component = null,
EntityUid? origin = null)
{
if (!_mobStateQuery.Resolve(entity, ref component))
return;
ChangeState(entity, component, mobState, origin: origin);
}
#endregion
#region Virtual API
/// <summary>
/// Called when a new MobState is entered.
/// </summary>
/// <param name="entity">The owner of the MobState Component</param>
/// <param name="component">MobState Component owned by the target</param>
/// <param name="state">The new MobState</param>
protected virtual void OnEnterState(EntityUid entity, MobStateComponent component, MobState state)
{
OnStateEnteredSubscribers(entity, component, state);
}
/// <summary>
/// Called when this entity changes MobState
/// </summary>
/// <param name="entity">The owner of the MobState Component</param>
/// <param name="component">MobState Component owned by the target</param>
/// <param name="oldState">The previous MobState</param>
/// <param name="newState">The new MobState</param>
protected virtual void OnStateChanged(EntityUid entity, MobStateComponent component, MobState oldState,
MobState newState)
{
}
/// <summary>
/// Called when a new MobState is exited.
/// </summary>
/// <param name="entity">The owner of the MobState Component</param>
/// <param name="component">MobState Component owned by the target</param>
/// <param name="state">The old MobState</param>
protected virtual void OnExitState(EntityUid entity, MobStateComponent component, MobState state)
{
OnStateExitSubscribers(entity, component, state);
}
#endregion
#region Private Implementation
//Actually change the MobState
private void ChangeState(EntityUid target, MobStateComponent component, MobState newState, EntityUid? origin = null)
{
var oldState = component.CurrentState;
//make sure we are allowed to enter the new state
if (oldState == newState || !component.AllowedStates.Contains(newState))
return;
OnExitState(target, component, oldState);
component.CurrentState = newState;
OnEnterState(target, component, newState);
var ev = new MobStateChangedEvent(target, component, oldState, newState, origin);
OnStateChanged(target, component, oldState, newState);
RaiseLocalEvent(target, ev, true);
if (origin != null && HasComp<ActorComponent>(origin) && HasComp<ActorComponent>(target) && oldState < newState)
_adminLogger.Add(LogType.Damaged, LogImpact.High, $"{ToPrettyString(origin):player} caused {ToPrettyString(target):player} state to change from {oldState} to {newState}");
else
_adminLogger.Add(LogType.Damaged, oldState == MobState.Alive ? LogImpact.Low : LogImpact.Medium, $"{ToPrettyString(target):user} state changed from {oldState} to {newState}");
Dirty(target, component);
}
#endregion
}
/// <summary>
/// Event that gets triggered when we want to update the mobstate. This allows for systems to override MobState changes
/// </summary>
/// <param name="Target">The Entity whose MobState is changing</param>
/// <param name="Component">The MobState Component owned by the Target</param>
/// <param name="State">The new MobState we want to set</param>
/// <param name="Origin">Entity that caused the state update (if applicable)</param>
[ByRefEvent]
public record struct UpdateMobStateEvent(EntityUid Target, MobStateComponent Component, MobState State,
EntityUid? Origin = null);