mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 14:07:53 +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)
301 lines
12 KiB
C#
301 lines
12 KiB
C#
using System.Linq;
|
|
using Content.Server.Actions;
|
|
using Content.Server.Body.Systems;
|
|
using Content.Server.Chat;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Emoting.Systems;
|
|
using Content.Server.Speech.EntitySystems;
|
|
using Content.Shared._White.Blocking;
|
|
using Content.Shared.Bed.Sleep;
|
|
using Content.Shared.Cloning;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.NameModifier.EntitySystems;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Weapons.Melee.Events;
|
|
using Content.Shared.Zombies;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Zombies
|
|
{
|
|
public sealed partial class ZombieSystem : SharedZombieSystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly ActionsSystem _actions = default!;
|
|
[Dependency] private readonly AutoEmoteSystem _autoEmote = default!;
|
|
[Dependency] private readonly EmoteOnDamageSystem _emoteOnDamage = default!;
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly NameModifierSystem _nameMod = default!;
|
|
|
|
public const SlotFlags ProtectiveSlots =
|
|
SlotFlags.FEET |
|
|
SlotFlags.HEAD |
|
|
SlotFlags.EYES |
|
|
SlotFlags.GLOVES |
|
|
SlotFlags.MASK |
|
|
SlotFlags.NECK |
|
|
SlotFlags.INNERCLOTHING |
|
|
SlotFlags.OUTERCLOTHING;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ZombieComponent, ComponentStartup>(OnStartup);
|
|
SubscribeLocalEvent<ZombieComponent, EmoteEvent>(OnEmote, before:
|
|
new[] { typeof(VocalSystem), typeof(BodyEmotesSystem) });
|
|
|
|
SubscribeLocalEvent<ZombieComponent, MeleeHitEvent>(OnMeleeHit,
|
|
after: new[] {typeof(MeleeBlockSystem)}); // WD EDIT
|
|
SubscribeLocalEvent<ZombieComponent, MobStateChangedEvent>(OnMobState);
|
|
SubscribeLocalEvent<ZombieComponent, CloningEvent>(OnZombieCloning);
|
|
SubscribeLocalEvent<ZombieComponent, TryingToSleepEvent>(OnSleepAttempt);
|
|
SubscribeLocalEvent<ZombieComponent, GetCharactedDeadIcEvent>(OnGetCharacterDeadIC);
|
|
|
|
SubscribeLocalEvent<PendingZombieComponent, MapInitEvent>(OnPendingMapInit);
|
|
|
|
SubscribeLocalEvent<IncurableZombieComponent, MapInitEvent>(OnPendingMapInit);
|
|
|
|
SubscribeLocalEvent<ZombifyOnDeathComponent, MobStateChangedEvent>(OnDamageChanged);
|
|
}
|
|
|
|
private void OnPendingMapInit(EntityUid uid, IncurableZombieComponent component, MapInitEvent args)
|
|
{
|
|
_actions.AddAction(uid, ref component.Action, component.ZombifySelfActionPrototype);
|
|
}
|
|
|
|
private void OnPendingMapInit(EntityUid uid, PendingZombieComponent component, MapInitEvent args)
|
|
{
|
|
if (_mobState.IsDead(uid))
|
|
{
|
|
ZombifyEntity(uid);
|
|
return;
|
|
}
|
|
|
|
component.NextTick = _timing.CurTime + TimeSpan.FromSeconds(1f);
|
|
component.GracePeriod = _random.Next(component.MinInitialInfectedGrace, component.MaxInitialInfectedGrace);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
var curTime = _timing.CurTime;
|
|
|
|
// Hurt the living infected
|
|
var query = EntityQueryEnumerator<PendingZombieComponent, DamageableComponent, MobStateComponent>();
|
|
while (query.MoveNext(out var uid, out var comp, out var damage, out var mobState))
|
|
{
|
|
// Process only once per second
|
|
if (comp.NextTick > curTime)
|
|
continue;
|
|
|
|
comp.NextTick = curTime + TimeSpan.FromSeconds(1f);
|
|
|
|
comp.GracePeriod -= TimeSpan.FromSeconds(1f);
|
|
if (comp.GracePeriod > TimeSpan.Zero)
|
|
continue;
|
|
|
|
if (_random.Prob(comp.InfectionWarningChance))
|
|
_popup.PopupEntity(Loc.GetString(_random.Pick(comp.InfectionWarnings)), uid, uid);
|
|
|
|
var multiplier = _mobState.IsCritical(uid, mobState)
|
|
? comp.CritDamageMultiplier
|
|
: 1f;
|
|
|
|
_damageable.TryChangeDamage(uid, comp.Damage * multiplier, true, false, damage);
|
|
}
|
|
|
|
// Heal the zombified
|
|
var zombQuery = EntityQueryEnumerator<ZombieComponent, DamageableComponent, MobStateComponent>();
|
|
while (zombQuery.MoveNext(out var uid, out var comp, out var damage, out var mobState))
|
|
{
|
|
// Process only once per second
|
|
if (comp.NextTick + TimeSpan.FromSeconds(1) > curTime)
|
|
continue;
|
|
|
|
comp.NextTick = curTime;
|
|
|
|
if (_mobState.IsDead(uid, mobState))
|
|
continue;
|
|
|
|
var multiplier = _mobState.IsCritical(uid, mobState)
|
|
? comp.PassiveHealingCritMultiplier
|
|
: 1f;
|
|
|
|
// Gradual healing for living zombies.
|
|
_damageable.TryChangeDamage(uid, comp.PassiveHealing * multiplier, true, false, damage);
|
|
}
|
|
}
|
|
|
|
private void OnSleepAttempt(EntityUid uid, ZombieComponent component, ref TryingToSleepEvent args)
|
|
{
|
|
args.Cancelled = true;
|
|
}
|
|
|
|
private void OnGetCharacterDeadIC(EntityUid uid, ZombieComponent component, ref GetCharactedDeadIcEvent args)
|
|
{
|
|
args.Dead = true;
|
|
}
|
|
|
|
private void OnStartup(EntityUid uid, ZombieComponent component, ComponentStartup args)
|
|
{
|
|
if (component.EmoteSoundsId == null)
|
|
return;
|
|
_protoManager.TryIndex(component.EmoteSoundsId, out component.EmoteSounds);
|
|
}
|
|
|
|
private void OnEmote(EntityUid uid, ZombieComponent component, ref EmoteEvent args)
|
|
{
|
|
// always play zombie emote sounds and ignore others
|
|
if (args.Handled)
|
|
return;
|
|
args.Handled = _chat.TryPlayEmoteSound(uid, component.EmoteSounds, args.Emote);
|
|
}
|
|
|
|
private void OnMobState(EntityUid uid, ZombieComponent component, MobStateChangedEvent args)
|
|
{
|
|
if (args.IsAlive())
|
|
{
|
|
// Groaning when damaged
|
|
EnsureComp<EmoteOnDamageComponent>(uid);
|
|
_emoteOnDamage.AddEmote(uid, "Scream");
|
|
|
|
// Random groaning
|
|
EnsureComp<AutoEmoteComponent>(uid);
|
|
_autoEmote.AddEmote(uid, "ZombieGroan");
|
|
}
|
|
else
|
|
{
|
|
// Stop groaning when damaged
|
|
_emoteOnDamage.RemoveEmote(uid, "Scream");
|
|
|
|
// Stop random groaning
|
|
_autoEmote.RemoveEmote(uid, "ZombieGroan");
|
|
}
|
|
}
|
|
|
|
private float GetZombieInfectionChance(EntityUid uid, ZombieComponent component)
|
|
{
|
|
var max = component.MaxZombieInfectionChance;
|
|
|
|
if (!_inventory.TryGetContainerSlotEnumerator(uid, out var enumerator, ProtectiveSlots))
|
|
return max;
|
|
|
|
var items = 0f;
|
|
var total = 0f;
|
|
while (enumerator.MoveNext(out var con))
|
|
{
|
|
total++;
|
|
if (con.ContainedEntity != null)
|
|
items++;
|
|
}
|
|
|
|
if (total == 0)
|
|
return max;
|
|
|
|
// Everyone knows that when it comes to zombies, socks & sandals provide just as much protection as an
|
|
// armored vest. Maybe these should be weighted per-item. I.e. some kind of coverage/protection component.
|
|
// Or at the very least different weights per slot.
|
|
|
|
var min = component.MinZombieInfectionChance;
|
|
//gets a value between the max and min based on how many items the entity is wearing
|
|
var chance = (max - min) * ((total - items) / total) + min;
|
|
return chance;
|
|
}
|
|
|
|
private void OnMeleeHit(EntityUid uid, ZombieComponent component, MeleeHitEvent args)
|
|
{
|
|
if (args.Handled) // WD EDIT
|
|
return;
|
|
|
|
if (!TryComp<ZombieComponent>(args.User, out _))
|
|
return;
|
|
|
|
if (!args.HitEntities.Any())
|
|
return;
|
|
|
|
foreach (var entity in args.HitEntities)
|
|
{
|
|
if (args.User == entity)
|
|
continue;
|
|
|
|
if (!TryComp<MobStateComponent>(entity, out var mobState))
|
|
continue;
|
|
|
|
if (HasComp<ZombieComponent>(entity))
|
|
{
|
|
args.BonusDamage = -args.BaseDamage;
|
|
}
|
|
else
|
|
{
|
|
if (!HasComp<ZombieImmuneComponent>(entity) && !HasComp<NonSpreaderZombieComponent>(args.User) && _random.Prob(GetZombieInfectionChance(entity, component)))
|
|
{
|
|
EnsureComp<PendingZombieComponent>(entity);
|
|
EnsureComp<ZombifyOnDeathComponent>(entity);
|
|
}
|
|
}
|
|
|
|
if (_mobState.IsCriticalOrDead(entity, false, mobState) && !HasComp<ZombieComponent>(entity) && !HasComp<ZombieImmuneComponent>(entity))
|
|
{
|
|
ZombifyEntity(entity);
|
|
args.BonusDamage = -args.BaseDamage;
|
|
}
|
|
else if (_mobState.IsAlive(entity, mobState)) //heals when zombies bite live entities
|
|
{
|
|
_damageable.TryChangeDamage(uid, component.HealingOnBite, true, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This is the function to call if you want to unzombify an entity.
|
|
/// </summary>
|
|
/// <param name="source">the entity having the ZombieComponent</param>
|
|
/// <param name="target">the entity you want to unzombify (different from source in case of cloning, for example)</param>
|
|
/// <param name="zombiecomp"></param>
|
|
/// <remarks>
|
|
/// this currently only restore the name and skin/eye color from before zombified
|
|
/// TODO: completely rethink how zombies are done to allow reversal.
|
|
/// </remarks>
|
|
public bool UnZombify(EntityUid source, EntityUid target, ZombieComponent? zombiecomp)
|
|
{
|
|
if (!Resolve(source, ref zombiecomp))
|
|
return false;
|
|
|
|
foreach (var (layer, info) in zombiecomp.BeforeZombifiedCustomBaseLayers)
|
|
{
|
|
_humanoidAppearance.SetBaseLayerColor(target, layer, info.Color);
|
|
_humanoidAppearance.SetBaseLayerId(target, layer, info.Id);
|
|
}
|
|
if (TryComp<HumanoidAppearanceComponent>(target, out var appcomp))
|
|
{
|
|
appcomp.EyeColor = zombiecomp.BeforeZombifiedEyeColor;
|
|
}
|
|
_humanoidAppearance.SetSkinColor(target, zombiecomp.BeforeZombifiedSkinColor, false);
|
|
_bloodstream.ChangeBloodReagent(target, zombiecomp.BeforeZombifiedBloodReagent);
|
|
|
|
_nameMod.RefreshNameModifiers(target);
|
|
return true;
|
|
}
|
|
|
|
private void OnZombieCloning(EntityUid uid, ZombieComponent zombiecomp, ref CloningEvent args)
|
|
{
|
|
if (UnZombify(args.Source, args.Target, zombiecomp))
|
|
args.NameHandled = true;
|
|
}
|
|
}
|
|
}
|