Zombie SFX (#9976)

This commit is contained in:
Nemanja
2022-08-07 23:16:43 -04:00
committed by GitHub
parent 39ef4179d0
commit 123c631067
11 changed files with 127 additions and 7 deletions

View File

@@ -8,8 +8,11 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.MobState.Components;
using Content.Server.Disease;
using Content.Shared.Inventory;
using Content.Shared.MobState;
using Content.Server.Inventory;
using Robust.Shared.Prototypes;
using Content.Server.Speech;
using Content.Server.Chat.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Damage;
@@ -22,6 +25,8 @@ namespace Content.Server.Zombies
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
[Dependency] private readonly ZombifyOnDeathSystem _zombify = default!;
[Dependency] private readonly ServerInventorySystem _inv = default!;
[Dependency] private readonly VocalSystem _vocal = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
@@ -30,9 +35,25 @@ namespace Content.Server.Zombies
base.Initialize();
SubscribeLocalEvent<ZombieComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<ZombieComponent, MobStateChangedEvent>(OnMobState);
SubscribeLocalEvent<ActiveZombieComponent, DamageChangedEvent>(OnDamage);
SubscribeLocalEvent<ZombieComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshSpeed);
}
private void OnMobState(EntityUid uid, ZombieComponent component, MobStateChangedEvent args)
{
if (args.CurrentMobState == DamageState.Alive)
EnsureComp<ActiveZombieComponent>(uid);
else
RemComp<ActiveZombieComponent>(uid);
}
private void OnDamage(EntityUid uid, ActiveZombieComponent component, DamageChangedEvent args)
{
if (args.DamageIncreased)
DoGroan(uid, component);
}
private void OnRefreshSpeed(EntityUid uid, ZombieComponent component, RefreshMovementSpeedModifiersEvent args)
{
var mod = component.ZombieMovementSpeedDebuff;
@@ -96,13 +117,13 @@ namespace Content.Server.Zombies
if (HasComp<ZombieComponent>(entity))
args.BonusDamage = -args.BaseDamage * zombieComp.OtherZombieDamageCoefficient;
if ((mobState.IsDead() || mobState.IsCritical())
if ((mobState.CurrentState == DamageState.Dead || mobState.CurrentState == DamageState.Critical)
&& !HasComp<ZombieComponent>(entity))
{
_zombify.ZombifyEntity(entity);
args.BonusDamage = -args.BaseDamage;
}
else if (mobState.IsAlive()) //heals when zombies bite live entities
else if (mobState.CurrentState == DamageState.Alive) //heals when zombies bite live entities
{
var healingSolution = new Solution();
healingSolution.AddReagent("Bicaridine", 1.00); //if OP, reduce/change chem
@@ -110,5 +131,39 @@ namespace Content.Server.Zombies
}
}
}
public void DoGroan(EntityUid uid, ActiveZombieComponent component)
{
if (component.LastDamageGroanCooldown > 0)
return;
if (_robustRandom.Prob(0.5f)) //this message is never seen by players so it just says this for admins
_chat.TrySendInGameICMessage(uid, "[automated zombie groan]", InGameICChatType.Speak, false);
else
_vocal.TryScream(uid);
component.LastDamageGroanCooldown = component.GroanCooldown;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var zombiecomp in EntityQuery<ActiveZombieComponent>())
{
zombiecomp.Accumulator += frameTime;
zombiecomp.LastDamageGroanCooldown -= frameTime;
if (zombiecomp.Accumulator < zombiecomp.RandomGroanAttempt)
continue;
zombiecomp.Accumulator -= zombiecomp.RandomGroanAttempt;
if (!_robustRandom.Prob(zombiecomp.GroanChance))
continue;
//either do a random accent line or scream
DoGroan(zombiecomp.Owner, zombiecomp);
}
}
}
}