mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-14 21:01:14 +03:00
Signed-off-by: Prole <172158352+Prole0@users.noreply.github.com> Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com> Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Co-authored-by: Samuka-C <47865393+Samuka-C@users.noreply.github.com> Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com> Co-authored-by: Partmedia <kevinz5000@gmail.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: themias <89101928+themias@users.noreply.github.com> Co-authored-by: Victor Shen <71985089+Vexerot@users.noreply.github.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: Milon <milonpl.git@proton.me> Co-authored-by: Kirus59 <145689588+Kirus59@users.noreply.github.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: Stomf <5dorkydorks@gmail.com> Co-authored-by: drakewill-CRL <46307022+drakewill-CRL@users.noreply.github.com> Co-authored-by: PraxisMapper <praxismapper@gmail.com> Co-authored-by: EmoGarbage404 <retron404@gmail.com> Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: IProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com> Co-authored-by: TytosB <54259736+TytosB@users.noreply.github.com> Co-authored-by: abadaba695 <spacestation13thingy@gmail.com> Co-authored-by: kosticia <kosticia46@gmail.com> Co-authored-by: Thinbug <101073555+Thinbug0@users.noreply.github.com> Co-authored-by: pathetic meowmeow <uhhadd@gmail.com> Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Co-authored-by: Boaz1111 <149967078+Boaz1111@users.noreply.github.com> Co-authored-by: ActiveMammmoth <140334666+ActiveMammmoth@users.noreply.github.com> Co-authored-by: Myra <vasilis@pikachu.systems> Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: K-Dynamic <20566341+K-Dynamic@users.noreply.github.com> Co-authored-by: Gentleman-Bird <dcgreen406@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: BIGZi0348 <svalker0348@gmail.com> Co-authored-by: LaCumbiaDelCoronavirus <90893484+LaCumbiaDelCoronavirus@users.noreply.github.com> Co-authored-by: imatsoup <93290208+imatsoup@users.noreply.github.com> Co-authored-by: Matthew Herber <32679887+happyrobot33@users.noreply.github.com> Co-authored-by: Ertanic <36124833+Ertanic@users.noreply.github.com> Co-authored-by: MissKay1994 <15877268+MissKay1994@users.noreply.github.com> Co-authored-by: Errant <35878406+Errant-4@users.noreply.github.com> Co-authored-by: eoineoineoin <helloworld@eoinrul.es> Co-authored-by: Tiniest Shark <head.rebel@yahoo.com> Co-authored-by: nikitosych <boriszyn@gmail.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> Co-authored-by: YoungThug <ramialanbagy@gmail.com> Co-authored-by: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Southbridge <7013162+southbridge-fur@users.noreply.github.com> Co-authored-by: Vladislav Suchkov <20380250+murolem@users.noreply.github.com> Co-authored-by: Prole <172158352+Prole0@users.noreply.github.com> Co-authored-by: Unkn0wn_Gh0st <shadowstalkermll@gmail.com> Co-authored-by: 3nderall <101940324+3nderall@users.noreply.github.com> Co-authored-by: Radezolid <snappednexus@gmail.com> Co-authored-by: J <billsmith116@gmail.com> Co-authored-by: Ghagliiarghii <68826635+Ghagliiarghii@users.noreply.github.com> Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com> Co-authored-by: youtissoum <51883137+youtissoum@users.noreply.github.com> Co-authored-by: Minemoder5000 <minemoder50000@gmail.com> Co-authored-by: Spanky <scott@wearejacob.com> Co-authored-by: Spessmann <156740760+Spessmann@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: brainfood1183 <113240905+brainfood1183@users.noreply.github.com> Co-authored-by: Deerstop <edainturner@gmail.com> Co-authored-by: B_Kirill <153602297+B-Kirill@users.noreply.github.com> Co-authored-by: archee1 <archee3@hotmail.co.uk> Co-authored-by: Cojoke <83733158+Cojoke-dot@users.noreply.github.com> Co-authored-by: Quantum-cross <7065792+Quantum-cross@users.noreply.github.com> Co-authored-by: poklj <compgeek223@gmail.com> Co-authored-by: Krunklehorn <42424291+Krunklehorn@users.noreply.github.com> Co-authored-by: OnyxTheBrave <131422822+OnyxTheBrave@users.noreply.github.com> Co-authored-by: UpAndLeaves <92269094+Alpha-Two@users.noreply.github.com> Co-authored-by: Flareguy <78941145+Flareguy@users.noreply.github.com> Co-authored-by: Zalycon <84675130+Zalycon@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: Verm <32827189+Vermidia@users.noreply.github.com> Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com> Co-authored-by: ScarKy0 <scarky0@onet.eu> Co-authored-by: Dmitry <57028746+dimm00n@users.noreply.github.com>
328 lines
14 KiB
C#
328 lines
14 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.Server.Roles;
|
|
using Content.Shared.Anomaly.Components;
|
|
using Content.Shared.Armor;
|
|
using Content.Shared.Bed.Sleep;
|
|
using Content.Shared.Cloning.Events;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Roles;
|
|
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 SharedRoleSystem _role = 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);
|
|
SubscribeLocalEvent<ZombieComponent, MobStateChangedEvent>(OnMobState);
|
|
SubscribeLocalEvent<ZombieComponent, CloningEvent>(OnZombieCloning);
|
|
SubscribeLocalEvent<ZombieComponent, TryingToSleepEvent>(OnSleepAttempt);
|
|
SubscribeLocalEvent<ZombieComponent, GetCharactedDeadIcEvent>(OnGetCharacterDeadIC);
|
|
SubscribeLocalEvent<ZombieComponent, GetCharacterUnrevivableIcEvent>(OnGetCharacterUnrevivableIC);
|
|
SubscribeLocalEvent<ZombieComponent, MindAddedMessage>(OnMindAdded);
|
|
SubscribeLocalEvent<ZombieComponent, MindRemovedMessage>(OnMindRemoved);
|
|
|
|
SubscribeLocalEvent<PendingZombieComponent, MapInitEvent>(OnPendingMapInit);
|
|
SubscribeLocalEvent<PendingZombieComponent, BeforeRemoveAnomalyOnDeathEvent>(OnBeforeRemoveAnomalyOnDeath);
|
|
|
|
SubscribeLocalEvent<IncurableZombieComponent, MapInitEvent>(OnPendingMapInit);
|
|
|
|
SubscribeLocalEvent<ZombifyOnDeathComponent, MobStateChangedEvent>(OnDamageChanged);
|
|
}
|
|
|
|
private void OnBeforeRemoveAnomalyOnDeath(Entity<PendingZombieComponent> ent, ref BeforeRemoveAnomalyOnDeathEvent args)
|
|
{
|
|
// Pending zombies (e.g. infected non-zombies) do not remove their hosted anomaly on death.
|
|
// Current zombies DO remove the anomaly on death.
|
|
args.Cancelled = true;
|
|
}
|
|
|
|
private void OnPendingMapInit(EntityUid uid, IncurableZombieComponent component, MapInitEvent args)
|
|
{
|
|
_actions.AddAction(uid, ref component.Action, component.ZombifySelfActionPrototype);
|
|
|
|
if (HasComp<ZombieComponent>(uid) || HasComp<ZombieImmuneComponent>(uid))
|
|
return;
|
|
|
|
EnsureComp<PendingZombieComponent>(uid, out PendingZombieComponent pendingComp);
|
|
|
|
pendingComp.GracePeriod = _random.Next(pendingComp.MinInitialInfectedGrace, pendingComp.MaxInitialInfectedGrace);
|
|
}
|
|
|
|
private void OnPendingMapInit(EntityUid uid, PendingZombieComponent component, MapInitEvent args)
|
|
{
|
|
if (_mobState.IsDead(uid))
|
|
{
|
|
ZombifyEntity(uid);
|
|
return;
|
|
}
|
|
|
|
component.NextTick = _timing.CurTime + TimeSpan.FromSeconds(1f);
|
|
}
|
|
|
|
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 OnGetCharacterUnrevivableIC(EntityUid uid, ZombieComponent component, ref GetCharacterUnrevivableIcEvent args)
|
|
{
|
|
args.Unrevivable = 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.NewMobState == MobState.Alive)
|
|
{
|
|
// 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 zombieComponent)
|
|
{
|
|
var chance = zombieComponent.BaseZombieInfectionChance;
|
|
|
|
var armorEv = new CoefficientQueryEvent(ProtectiveSlots);
|
|
RaiseLocalEvent(uid, armorEv);
|
|
foreach (var resistanceEffectiveness in zombieComponent.ResistanceEffectiveness.DamageDict)
|
|
{
|
|
if (armorEv.DamageModifiers.Coefficients.TryGetValue(resistanceEffectiveness.Key, out var coefficient))
|
|
{
|
|
// Scale the coefficient by the resistance effectiveness, very descriptive I know
|
|
// For example. With 30% slash resist (0.7 coeff), but only a 60% resistance effectiveness for slash,
|
|
// you'll end up with 1 - (0.3 * 0.6) = 0.82 coefficient, or a 18% resistance
|
|
var adjustedCoefficient = 1 - ((1 - coefficient) * resistanceEffectiveness.Value.Float());
|
|
chance *= adjustedCoefficient;
|
|
}
|
|
}
|
|
|
|
var zombificationResistanceEv = new ZombificationResistanceQueryEvent(ProtectiveSlots);
|
|
RaiseLocalEvent(uid, zombificationResistanceEv);
|
|
chance *= zombificationResistanceEv.TotalCoefficient;
|
|
|
|
return MathF.Max(chance, zombieComponent.MinZombieInfectionChance);
|
|
}
|
|
|
|
private void OnMeleeHit(EntityUid uid, ZombieComponent component, MeleeHitEvent args)
|
|
{
|
|
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.IsIncapacitated(entity, mobState) && !HasComp<ZombieComponent>(entity) && !HasComp<ZombieImmuneComponent>(entity))
|
|
{
|
|
ZombifyEntity(entity);
|
|
args.BonusDamage = -args.BaseDamage;
|
|
}
|
|
else if (mobState.CurrentState == MobState.Alive) //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 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);
|
|
|
|
return true;
|
|
}
|
|
|
|
private void OnZombieCloning(Entity<ZombieComponent> ent, ref CloningEvent args)
|
|
{
|
|
UnZombify(ent.Owner, args.CloneUid, ent.Comp);
|
|
}
|
|
|
|
// Make sure players that enter a zombie (for example via a ghost role or the mind swap spell) count as an antagonist.
|
|
private void OnMindAdded(Entity<ZombieComponent> ent, ref MindAddedMessage args)
|
|
{
|
|
if (!_role.MindHasRole<ZombieRoleComponent>(args.Mind))
|
|
_role.MindAddRole(args.Mind, "MindRoleZombie", mind: args.Mind.Comp);
|
|
}
|
|
|
|
// Remove the role when getting cloned, getting gibbed and borged, or leaving the body via any other method.
|
|
private void OnMindRemoved(Entity<ZombieComponent> ent, ref MindRemovedMessage args)
|
|
{
|
|
_role.MindRemoveRole<ZombieRoleComponent>((args.Mind.Owner, args.Mind.Comp));
|
|
}
|
|
}
|
|
}
|