Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disease stages #8405

Merged
merged 12 commits into from
Jun 22, 2022
1 change: 0 additions & 1 deletion Content.Client/Entry/IgnoredComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static class IgnoredComponents
"DiseaseVaccineCreator",
"ImmovableRod",
"DiseaseZombie",
"DiseaseBuildup",
"ZombieTransfer",
"RangedMagazine",
"RandomMetadata",
Expand Down
19 changes: 0 additions & 19 deletions Content.Server/Disease/Components/DiseaseBuildupComponent.cs

This file was deleted.

4 changes: 3 additions & 1 deletion Content.Server/Disease/DiseaseSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public override void Update(float frameTime)
}
foreach (var effect in disease.Effects)
{
if (_random.Prob(effect.Probability))
if (_random.Prob(effect.Probability)
&& disease.DiseaseSeverity >= effect.MinSeverity
&& disease.DiseaseSeverity <= effect.MaxSeverity)
effect.Effect(args);
}
}
Expand Down
22 changes: 22 additions & 0 deletions Content.Server/Disease/Effects/DiseaseAddComp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Content.Shared.Disease;
using JetBrains.Annotations;

namespace Content.Server.Disease.Effects;

[UsedImplicitly]
public sealed class DiseaseAddComp : DiseaseEffect
{
[DataField("comp")]
public string? Comp = null;
public override void Effect(DiseaseEffectArgs args)
{
if (Comp == null) return;

EntityUid uid = args.DiseasedEntity;
Component newComponent = (Component) IoCManager.Resolve<IComponentFactory>().GetComponent(Comp);
newComponent.Owner = uid;

if (!args.EntityManager.HasComponent(uid, newComponent.GetType()))
args.EntityManager.AddComponent(uid, newComponent);
}
}
25 changes: 3 additions & 22 deletions Content.Server/Disease/Effects/DiseaseProgression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
namespace Content.Server.Disease.Effects
{
/// <summary>
/// Handles a disease which incubates over a period of time
/// before adding another component to the infected entity
/// currently used for zombie virus
/// Handles any disease with stages
/// You are gonna need this if you want the stage to work
/// </summary>
[UsedImplicitly]
public sealed class DiseaseProgression : DiseaseEffect
Expand All @@ -19,27 +18,9 @@ public sealed class DiseaseProgression : DiseaseEffect
[ViewVariables(VVAccess.ReadWrite)]
public float Rate = 0.01f;

/// <summary>
/// The component that is added at the end of build up
/// </summary>
[DataField("comp")]
public string? Comp = null;

public override void Effect(DiseaseEffectArgs args)
{
args.EntityManager.EnsureComponent<DiseaseBuildupComponent>(args.DiseasedEntity, out var buildup);
if (buildup.Progression < 1) //increases steadily until 100%
{
buildup.Progression += Rate;
}
else if (Comp != null)//adds the component for the later stage of the disease.
{
EntityUid uid = args.DiseasedEntity;
var newComponent = (Component) IoCManager.Resolve<IComponentFactory>().GetComponent(Comp);
newComponent.Owner = uid;
if (!args.EntityManager.HasComponent(uid, newComponent.GetType()))
args.EntityManager.AddComponent(uid, newComponent);
}
args.Disease.DiseaseSeverity += Rate;
}
}
}
1 change: 0 additions & 1 deletion Content.Server/Disease/Zombie/DiseaseZombieSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private void OnComponentInit(EntityUid uid, DiseaseZombieComponent component, Co
return;

RemComp<DiseaseCarrierComponent>(uid);
RemComp<DiseaseBuildupComponent>(uid);
RemComp<RespiratorComponent>(uid);
RemComp<BarotraumaComponent>(uid);
RemComp<HungerComponent>(uid);
Expand Down
24 changes: 24 additions & 0 deletions Content.Shared/Disease/DiseaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ public abstract class DiseaseEffect
/// What effect the disease will have.
/// </summary>
public abstract void Effect(DiseaseEffectArgs args);

/// <summary>
/// What is the minimal severity needed for this effect to occur?
/// </summary>
[DataField("minSeverity")]
public float MinSeverity
{
get => _minSeverity;
set => _minSeverity = Math.Clamp(value, 0.0f, 1.0f);
}

private float _minSeverity = 0.0f;

/// <summary>
/// What is the maximum severity that this effect can occur?
/// </summary>
[DataField("maxSeverity")]
public float MaxSeverity
{
get => _maxSeverity;
set => _maxSeverity = Math.Clamp(value, 0.0f, 1.0f);
}

private float _maxSeverity = 1.0f;
}
/// <summary>
/// What you have to work with in any disease effect/cure.
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/Disease/DiseasePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public sealed class DiseasePrototype : IPrototype, IInheritingPrototype
/// it needs something to control its tickrate
/// </summary>
public float Accumulator = 0f;

/// <summary>
/// This controls the progression of the disease, used to stage disease effects
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float DiseaseSeverity
{
get => _diseaseServerity;
set => _diseaseServerity = Math.Clamp(value, 0f, 1f);
}
private float _diseaseServerity = 0f;
/// <summary>
/// List of effects the disease has that will
/// run every second (by default anyway)
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/Diseases/noninfectious.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
collection: Coughs
- !type:DiseaseProgression
probability: 0.33
- !type:DiseaseAddComp
minSeverity: 0.9
comp: DiseaseZombie
cures:
- !type:DiseaseReagentCure
Expand Down