Zombie Mode [New Game Mode] (#8501)

Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Nemanja
2022-07-05 23:42:51 -04:00
committed by GitHub
parent ab12345168
commit 836c0bb1c4
43 changed files with 821 additions and 51 deletions

View File

@@ -7,6 +7,11 @@ using Content.Server.Weapon.Melee;
using Content.Shared.Chemistry.Components;
using Content.Shared.MobState.Components;
using Content.Server.Disease;
using Content.Shared.Inventory;
using Content.Server.Popups;
using Robust.Shared.Player;
using Content.Server.Inventory;
using Robust.Shared.Prototypes;
namespace Content.Server.Zombies
{
@@ -15,13 +20,52 @@ namespace Content.Server.Zombies
[Dependency] private readonly DiseaseSystem _disease = default!;
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
[Dependency] private readonly ZombifyOnDeathSystem _zombify = default!;
[Dependency] private readonly ServerInventorySystem _inv = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ZombieComponent, MeleeHitEvent>(OnMeleeHit);
}
private float GetZombieInfectionChance(EntityUid uid, ZombieComponent component)
{
float baseChance = component.MaxZombieInfectionChance;
if (!TryComp<InventoryComponent>(uid, out var inventoryComponent))
return baseChance;
var enumerator =
new InventorySystem.ContainerSlotEnumerator(uid, inventoryComponent.TemplateId, _protoManager, _inv,
SlotFlags.FEET |
SlotFlags.HEAD |
SlotFlags.EYES |
SlotFlags.GLOVES |
SlotFlags.MASK |
SlotFlags.NECK |
SlotFlags.INNERCLOTHING |
SlotFlags.OUTERCLOTHING);
var items = 0f;
var total = 0f;
while (enumerator.MoveNext(out var con))
{
total++;
if (con.ContainedEntity != null)
items++;
}
var max = component.MaxZombieInfectionChance;
var min = component.MinZombieInfectionChance;
//gets a value between the max and min based on how many items the entity is wearing
float chance = (max-min) * ((total - items)/total) + min;
return chance;
}
private void OnMeleeHit(EntityUid uid, ZombieComponent component, MeleeHitEvent args)
{
if (!EntityManager.TryGetComponent<ZombieComponent>(args.User, out var zombieComp))
@@ -38,11 +82,11 @@ namespace Content.Server.Zombies
if (!TryComp<MobStateComponent>(entity, out var mobState) || HasComp<DroneComponent>(entity))
continue;
if (_robustRandom.Prob(0.5f) && HasComp<DiseaseCarrierComponent>(entity))
if (HasComp<DiseaseCarrierComponent>(entity) && _robustRandom.Prob(GetZombieInfectionChance(entity, component)))
_disease.TryAddDisease(entity, "ActiveZombieVirus");
if (HasComp<ZombieComponent>(entity))
args.BonusDamage = args.BaseDamage * zombieComp.OtherZombieDamageCoefficient;
args.BonusDamage = -args.BaseDamage * zombieComp.OtherZombieDamageCoefficient;
if ((mobState.IsDead() || mobState.IsCritical())
&& !HasComp<ZombieComponent>(entity))