Disease artifact cleanup (#7359)

This commit is contained in:
metalgearsloth
2022-04-04 15:37:08 +10:00
committed by GitHub
parent e7fae0fa6c
commit babb279dd1
3 changed files with 40 additions and 28 deletions

View File

@@ -332,9 +332,13 @@ namespace Content.Server.Disease
/// rolls the dice to see if they get
/// the disease.
/// </summary>
public void TryInfect(DiseaseCarrierComponent carrier, DiseasePrototype? disease, float chance = 0.7f)
/// <param name="carrier">The target of the disease</param>
/// <param name="disease">The disease to apply</param>
/// <param name="chance">% chance of the disease being applied, before considering resistance</param>
/// <param name="forced">Bypass the disease's infectious trait.</param>
public void TryInfect(DiseaseCarrierComponent carrier, DiseasePrototype? disease, float chance = 0.7f, bool forced = false)
{
if(disease is not { Infectious: true })
if(disease == null || !forced && !disease.Infectious)
return;
var infectionChance = chance - carrier.DiseaseResist;
if (infectionChance <= 0)

View File

@@ -8,14 +8,14 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
[RegisterComponent]
public sealed class DiseaseArtifactComponent : Component
{
public override string Name => "DiseaseArtifact";
/// <summary>
/// Disease the artifact will spawn
/// If empty, picks a random one from its list
/// </summary>
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))]
[DataField("disease")]
[ViewVariables(VVAccess.ReadWrite)]
public string SpawnDisease = string.Empty;
public DiseasePrototype? SpawnDisease;
/// <summary>
/// How far away it will check for people
/// If empty, picks a random one from its list
@@ -23,15 +23,4 @@ public sealed class DiseaseArtifactComponent : Component
[DataField("range")]
[ViewVariables(VVAccess.ReadWrite)]
public float Range = 5f;
[ViewVariables(VVAccess.ReadWrite)]
public DiseasePrototype ResolveDisease = default!;
[ViewVariables(VVAccess.ReadWrite)]
public readonly IReadOnlyList<string> ArtifactDiseases = new[]
{
"VanAusdallsRobovirus",
"OwOnavirus",
"BleedersBite",
"Ultragigacancer",
"AMIV"
};
}

View File

@@ -6,6 +6,7 @@ using Content.Server.Disease.Components;
using Robust.Shared.Random;
using Robust.Shared.Prototypes;
using Content.Shared.Interaction;
using Robust.Shared.Map;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
{
@@ -14,11 +15,23 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
/// </summary>
public sealed class DiseaseArtifactSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly DiseaseSystem _disease = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
// TODO: YAML Serializer won't catch this.
[ViewVariables(VVAccess.ReadWrite)]
public readonly IReadOnlyList<string> ArtifactDiseases = new[]
{
"VanAusdallsRobovirus",
"OwOnavirus",
"BleedersBite",
"Ultragigacancer",
"AMIV"
};
public override void Initialize()
{
base.Initialize();
@@ -31,31 +44,37 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
/// </summary>
private void OnMapInit(EntityUid uid, DiseaseArtifactComponent component, MapInitEvent args)
{
if (component.SpawnDisease == string.Empty && component.ArtifactDiseases.Count != 0)
{
var diseaseName = _random.Pick(component.ArtifactDiseases);
if (component.SpawnDisease != null || ArtifactDiseases.Count == 0) return;
var diseaseName = _random.Pick(ArtifactDiseases);
component.SpawnDisease = diseaseName;
if (!_prototypeManager.TryIndex<DiseasePrototype>(diseaseName, out var disease))
{
Logger.ErrorS("disease", $"Invalid disease {diseaseName} selected from random diseases.");
return;
}
if (_prototypeManager.TryIndex(component.SpawnDisease, out DiseasePrototype? disease) && disease != null)
component.ResolveDisease = disease;
component.SpawnDisease = disease;
}
/// <summary>
/// When activated, blasts everyone in LOS within 3 tiles
/// When activated, blasts everyone in LOS within n tiles
/// with a high-probability disease infection attempt
/// </summary>
private void OnActivate(EntityUid uid, DiseaseArtifactComponent component, ArtifactActivatedEvent args)
{
if (component.SpawnDisease == null) return;
var xform = Transform(uid);
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapID, xform.WorldPosition, 3f))
var carrierQuery = GetEntityQuery<DiseaseCarrierComponent>();
foreach (var entity in _lookup.GetEntitiesInRange(xform.Coordinates, component.Range))
{
if (!_interactionSystem.InRangeUnobstructed(uid, entity, 3f))
if (!carrierQuery.TryGetComponent(entity, out var carrier)) continue;
if (!_interactionSystem.InRangeUnobstructed(uid, entity, component.Range))
continue;
if (TryComp<DiseaseCarrierComponent>(entity, out var carrier))
EntitySystem.Get<DiseaseSystem>().TryInfect(carrier, component.ResolveDisease);
_disease.TryInfect(carrier, component.SpawnDisease, forced: true);
}
}
}