mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-20 15:08:46 +03:00
# Description Implements the softcrit functionality. Similiar to critical state but spessmen will be able to communicate and crawl around, but not pick up items. Also supports configuring what is and isn't allowed in different MobStates (per mob prototype): you can enable picking up items while in softcrit so people can pick up their lasgun and continue shooting after taking a 40x46mm to their ass cheeks from the guest nukies while being dragged to safety.  <details> <summary><h1>Technical details</h1></summary> New prototype type: "mobStateParams" (`MobStateParametersPrototype`) Used to specify what can and can't be done when in a certain mobstate. Of note that they are not actually bound to any `MobState` by themselves. To assign a params prototype to a mobstate, use `InitMobStateParams` in `MobStateComponent`. It has to be a prototype because if I just did something akin to `Dictionary<MobState, Dictionary<string, bool>>`, you'd have to check the parent and copy every flag besides the one you wish to modify. That is, if I understand how the prototype system works correctly, which I frankly doubt. <!-- Working on softcrit made me hate prototypes. --> MobStateComponent now has: - `Dictionary<string, string> InitMobStateParams`, for storing "mobstate - parameter prototype" pairs. `<string, string>` because it has to be editable via mob prototypes. Named "mobStateParams" for mob prototypes. - `public Dictionary<MobState, MobStateParametersPrototype> MobStateParams` for actually storing the params for each state - `public Dictionary<MobState, MobStateParametersOverride> MobStateParamsOverrides` for storing overrides. `MobStateParametersOverride` is a struct which mirrors all `MobStateParametersPrototype`'s fields, except they're all nullable. This is meant for code which wants to temporarily override some setting, like a spell which allows dead people to talk. This is not the best solution, but it should do at first. A better option would be tracking each change separately, instead of hoping different systems overriding the same flag will play nicely with eachother. - a shitton of getter methods TraitModifyMobState now has: - `public Dictionary<string, string> Params` to specify a new prototype to use. - Important note: All values of `MobStateParametersPrototype` are nullable, which is a hack to support `TraitModifyMobState`. This trait takes one `MobStateParametersPrototype` per mobstate and applies all of its non-null values. This way, a params prototype can be created which will only have `pointing: true` and the trait can apply it (e.g. to critstate, so we can spam pointing while dying like it's a game of turbo dota) - The above is why that wall of getters exists: They check the relevant override struct, then the relevant prototype. If both are null, they default to false (0f for floats.) The only exception is OxyDamageOverlay, because it's used both for oxy damage overlay (if null) and as a vision-limiting black void in crit.. MobStateSystem now has: - a bunch of new "IsSomething"/"CanDoSomething" methods to check the various flags, alongside rewritten old ones. -  lookin ahh predicate factory </details> --- # TODO done: - [x] Make proper use of `MobStateSystem.IsIncapacitated()`. done: some checks were changed, some left as they did what was (more or less) intended. <details>Previous `IsIncapacitated()` implementation simply checked if person was in crit or dead. Now there is a `IsIncapacitated` flag in the parameters, but it's heavily underutilized. I may need some help on this one, since I don't know where would be a good place to check for it and I absolutely will not just scour the entire build in search for them. </details> - [x] Separate force-dropping items from being downed done: dropItemsOnEntering bool field. If true, will drop items upon entering linked mobstate. - [x] Don't drop items if `ForceDown` is true but `PickingUp` is also true. done: dropItemsOnEntering bool field. If true, will drop items upon entering linked mobstate. - [x] Actually check what are "conscious attempts" are used for done: whether or not mob is conscious. Renamed the bool field accordingly. - [x] Look into adding a way to make people choke "slowly" in softcrit as opposed to choking at "regular speed" in crit. Make that into a param option? Make that into a float so the speed can be finetuned? done: `BreathingMultiplier` float field added. <details> 1f is regular breathing, 0.25 is "quarter-breathing". Air taken is multiplied by `BreathingMultiplier` and suffocation damage taken (that is dealt by RespiratorSystem, not all oxy damage) is multiplied by `1-BreathingMultiplier`. </details> - [x] make sure the serializer actually does its job done: it doesn't. Removed. - [x] Make an option to prohibit using radio headsets while in softcrit done: Requires Incapacitated parameter to be false to be able to use headset radio. - [x] Make sure it at least compiles not done: - [ ] probably move some other stuff to Params if it makes sense. Same thing as with `IsIncapacitated` though: I kinda don't want to, at least for now. --- <details><summary><h1>No media</h1></summary> <p> :p </p> </details> --- # Changelog 🆑 - add: Soft critical state. Crawl to safety, or to your doom - whatever is closer. --------- Signed-off-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com> (cherry picked from commit 9a357c1774f1a783844a07b5414f504ca574d84c)
262 lines
8.4 KiB
C#
262 lines
8.4 KiB
C#
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Standing;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Mobs.Systems;
|
|
|
|
[Virtual]
|
|
public partial class MobStateSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] private readonly StandingStateSystem _standing = default!;
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly ILogManager _logManager = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
private ISawmill _sawmill = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
_sawmill = _logManager.GetSawmill("MobState");
|
|
base.Initialize();
|
|
SubscribeEvents();
|
|
}
|
|
|
|
#region Public API
|
|
|
|
/// <summary>
|
|
/// Check if a Mob is Alive
|
|
/// </summary>
|
|
/// <param name="target">Target Entity</param>
|
|
/// <param name="component">The MobState component owned by the target</param>
|
|
/// <returns>If the entity is alive</returns>
|
|
public bool IsAlive(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CurrentState == MobState.Alive;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if a Mob is Critical
|
|
/// </summary>
|
|
/// <param name="target">Target Entity</param>
|
|
/// <param name="component">The MobState component owned by the target</param>
|
|
/// <returns>If the entity is Critical</returns>
|
|
public bool IsCritical(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CurrentState.IsCrit();
|
|
}
|
|
|
|
public bool IsCriticalOrDead(EntityUid target, MobStateComponent? component = null) => IsCriticalOrDead(target, true, component);
|
|
public bool IsCriticalOrDead(EntityUid target, bool countSoftCrit = true, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CurrentState.IsCritOrDead(countSoftCrit);
|
|
}
|
|
|
|
public bool IsHardCritical(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CurrentState == MobState.Critical;
|
|
}
|
|
|
|
public bool IsSoftCritical(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CurrentState == MobState.SoftCritical;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if a Mob is Dead
|
|
/// </summary>
|
|
/// <param name="target">Target Entity</param>
|
|
/// <param name="component">The MobState component owned by the target</param>
|
|
/// <returns>If the entity is Dead</returns>
|
|
public bool IsDead(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
|
|
return component.CurrentState == MobState.Dead;
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Check if a Mob is in an Invalid state
|
|
/// </summary>
|
|
/// <param name="target">Target Entity</param>
|
|
/// <param name="component">The MobState component owned by the target</param>
|
|
/// <returns>If the entity is in an Invalid State</returns>
|
|
public bool IsInvalidState(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, true)) // i think this one should log it
|
|
return false;
|
|
return component.CurrentState.IsValid();
|
|
}
|
|
|
|
|
|
public bool CanMove(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanMove();
|
|
}
|
|
|
|
public bool CanSpeak(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanTalk();
|
|
}
|
|
|
|
public bool CanEmote(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanEmote();
|
|
}
|
|
|
|
public bool CanThrow(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanThrow();
|
|
}
|
|
|
|
public bool CanPickUp(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanPickUp();
|
|
}
|
|
|
|
public bool CanPull(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanPull();
|
|
}
|
|
|
|
public bool CanAttack(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanAttack();
|
|
}
|
|
|
|
public bool CanUse(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanUse();
|
|
}
|
|
|
|
public bool CanPoint(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanPoint();
|
|
}
|
|
|
|
public bool ConsciousAttemptAllowed(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.IsConscious();
|
|
}
|
|
|
|
public bool IsDown(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.IsDowned();
|
|
}
|
|
|
|
public bool IsConscious(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.IsConscious();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Check if a Mob is incapacitated in its current MobState.
|
|
/// </summary>
|
|
/// <param name="target">Target Entity</param>
|
|
/// <param name="component">The MobState component owned by the target</param>
|
|
/// <returns>If the entity is Critical or Dead</returns>
|
|
public bool IsIncapacitated(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.IsIncapacitated();
|
|
}
|
|
|
|
public bool CanEquipSelf(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanEquipSelf();
|
|
}
|
|
|
|
public bool CanUnequipSelf(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanUnequipSelf();
|
|
}
|
|
|
|
public bool CanEquipOther(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanEquipOther();
|
|
}
|
|
|
|
public bool CanUnequipOther(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.CanUnequipOther();
|
|
}
|
|
|
|
|
|
|
|
public bool IsThreatening(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return false;
|
|
return component.IsThreatening();
|
|
}
|
|
/// <summary>
|
|
/// Clamped to [0,1]. Use <see cref="MobStateComponent.GetBreathingMultiplier"/> to get unclamped value.
|
|
/// </summary>
|
|
public float BreatheMultiplier(EntityUid target, MobStateComponent? component = null)
|
|
{
|
|
if (!Resolve(target, ref component, false))
|
|
return 0f;
|
|
return Math.Clamp(component.GetBreathingMultiplier(), 0, 1);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Private Implementation
|
|
|
|
#endregion
|
|
}
|