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 But Epic #9043

Merged
merged 38 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1c46b73
Merge branch 'space-wizards-master'
EmoGarbage404 Apr 25, 2022
404cb6d
Merge branch 'space-wizards:master' into master
EmoGarbage404 Apr 27, 2022
bc28856
Merge branch 'space-wizards:master' into master
EmoGarbage404 Apr 28, 2022
b78709a
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 1, 2022
c8f849f
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 5, 2022
6ba6110
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 7, 2022
968f756
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 9, 2022
52cca51
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 11, 2022
71d3cb9
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 12, 2022
0a39235
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 13, 2022
f240894
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 13, 2022
df20146
Merge branch 'master' of https://github.com/space-wizards/space-stati…
EmoGarbage404 May 27, 2022
1442766
Merge branch 'space-wizards-master'
EmoGarbage404 May 27, 2022
fa7b5dd
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 29, 2022
9e8e4f8
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 29, 2022
63178a8
Merge branch 'space-wizards:master' into master
EmoGarbage404 May 30, 2022
0188a18
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 1, 2022
7afc2d0
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 2, 2022
78ec269
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 4, 2022
5b6f1b4
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 5, 2022
4abc44a
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 7, 2022
431e114
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 9, 2022
288a562
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 12, 2022
06edbd1
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 15, 2022
3b8f2cb
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 17, 2022
5ba338d
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 19, 2022
a5d9bcd
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 19, 2022
b56ac01
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 22, 2022
d6592c2
Merge branch 'space-wizards:master' into master
EmoGarbage404 Jun 22, 2022
a028567
first pass
EmoGarbage404 Jun 23, 2022
63a7b6a
Update DiseaseSystem.cs
EmoGarbage404 Jun 23, 2022
ed08c63
list now
EmoGarbage404 Jun 23, 2022
d5f1dc9
Merge remote-tracking branch 'origin/stages' into stages
EmoGarbage404 Jun 23, 2022
9d051e1
tf
EmoGarbage404 Jun 23, 2022
e30bd55
Update Content.Shared/Disease/DiseasePrototype.cs
EmoGarbage404 Jun 28, 2022
6c70f1b
sloth review
EmoGarbage404 Jun 28, 2022
40f10f5
Merge remote-tracking branch 'upstream/master' into stages
metalgearsloth Jul 8, 2022
3513d80
Adds that test I forgot about
metalgearsloth Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Content.IntegrationTests/Tests/DiseaseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Threading.Tasks;
using Content.Shared.Disease;
using NUnit.Framework;
using Robust.Shared.Prototypes;

namespace Content.IntegrationTests.Tests;

[TestFixture]
public sealed class DiseaseTest
{
/// <summary>
/// Asserts that a disease prototype has valid stages for its effects and cures.
/// </summary>
[Test]
public async Task Stages()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true});
var server = pairTracker.Pair.Server;

var protoManager = server.ResolveDependency<IPrototypeManager>();

await server.WaitAssertion(() =>
{
foreach (var proto in protoManager.EnumeratePrototypes<DiseasePrototype>())
{
var stages = proto.Stages;

foreach (var effect in proto.Effects)
{
for (var i = 0; i < effect.Stages.Length; i++)
{
Assert.That(stages.Contains(i), $"Disease {proto.ID} has an effect with an incorrect stage, {i}!");
}
}

foreach (var cure in proto.Cures)
{
for (var i = 0; i < cure.Stages.Length; i++)
{
Assert.That(stages.Contains(i), $"Disease {proto.ID} has a cure with an incorrect stage, {i}!");
}
}
}
});

await pairTracker.CleanReturnAsync();
}
}
17 changes: 15 additions & 2 deletions Content.Server/Disease/DiseaseSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public override void Update(float frameTime)
{
var disease = carrierComp.Diseases[i];
disease.Accumulator += frameTime;
disease.TotalAccumulator += frameTime;

if (disease.Accumulator < disease.TickTime) continue;

Expand All @@ -107,17 +108,29 @@ public override void Update(float frameTime)
var args = new DiseaseEffectArgs(carrierComp.Owner, disease, EntityManager);
disease.Accumulator -= disease.TickTime;

int stage = 0; //defaults to stage 0 because you should always have one
float lastThreshold = 0;
for (var j = 0; j < disease.Stages.Count; j++)
{
if (disease.TotalAccumulator >= disease.Stages[j] &&
disease.Stages[j] > lastThreshold)
{
lastThreshold = disease.Stages[j];
stage = j;
}
}

foreach (var cure in disease.Cures)
{
if (cure.Cure(args))
if (cure.Stages.AsSpan().Contains(stage) && cure.Cure(args))
CureDisease(carrierComp, disease);
}

if (doEffects)
{
foreach (var effect in disease.Effects)
{
if (_random.Prob(effect.Probability))
if (effect.Stages.AsSpan().Contains(stage) && _random.Prob(effect.Probability))
effect.Effect(args);
}
}
Expand Down
7 changes: 6 additions & 1 deletion Content.Shared/Disease/DiseaseCure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public abstract class DiseaseCure
/// and false otherwise
/// </summary>
public abstract bool Cure(DiseaseEffectArgs args);

/// <summary>
/// What stages the cure applies to.
/// probably should be all, but go wild
/// </summary>
[DataField("stages")]
public readonly int[] Stages = { 0 };
/// <summary>
/// This is used by the disease diangoser machine
/// to generate reports to tell people all of a disease's
Expand Down
5 changes: 5 additions & 0 deletions Content.Shared/Disease/DiseaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public abstract class DiseaseEffect
[DataField("probability")]
public float Probability = 1.0f;
/// <summary>
/// What stages this effect triggers on
/// </summary>
[DataField("stages")]
public readonly int[] Stages = { 0 };
/// <summary>
/// What effect the disease will have.
/// </summary>
public abstract void Effect(DiseaseEffectArgs args);
Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/Disease/DiseasePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public sealed class DiseasePrototype : IPrototype, IInheritingPrototype
/// </summary>
public float Accumulator = 0f;
/// <summary>
/// Since accumulator is reset with TickTime, this just tracks
/// the total amount of time a disease has been present.
/// </summary>
public float TotalAccumulator = 0f;
/// <summary>
/// Stores all the separate stages of the disease plus the time
/// thresholds for their activation
/// int: the disease stage (0 for baseline, 1, 2, etc.)
/// float: the time it takes for the stage to begin.
/// </summary>
[DataField("stages", serverOnly: true)]
public readonly List<float> Stages = new() { 0f };
/// <summary>
/// List of effects the disease has that will
/// run every second (by default anyway)
/// </summary>
Expand Down