Disease artifact cleanup (#7359)
This commit is contained in:
@@ -332,9 +332,13 @@ namespace Content.Server.Disease
|
|||||||
/// rolls the dice to see if they get
|
/// rolls the dice to see if they get
|
||||||
/// the disease.
|
/// the disease.
|
||||||
/// </summary>
|
/// </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;
|
return;
|
||||||
var infectionChance = chance - carrier.DiseaseResist;
|
var infectionChance = chance - carrier.DiseaseResist;
|
||||||
if (infectionChance <= 0)
|
if (infectionChance <= 0)
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class DiseaseArtifactComponent : Component
|
public sealed class DiseaseArtifactComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "DiseaseArtifact";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disease the artifact will spawn
|
/// Disease the artifact will spawn
|
||||||
/// If empty, picks a random one from its list
|
/// If empty, picks a random one from its list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))]
|
[DataField("disease")]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string SpawnDisease = string.Empty;
|
public DiseasePrototype? SpawnDisease;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How far away it will check for people
|
/// How far away it will check for people
|
||||||
/// If empty, picks a random one from its list
|
/// If empty, picks a random one from its list
|
||||||
@@ -23,15 +23,4 @@ public sealed class DiseaseArtifactComponent : Component
|
|||||||
[DataField("range")]
|
[DataField("range")]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float Range = 5f;
|
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"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Content.Server.Disease.Components;
|
|||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
|
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
|
||||||
{
|
{
|
||||||
@@ -14,11 +15,23 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DiseaseArtifactSystem : EntitySystem
|
public sealed class DiseaseArtifactSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = 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!;
|
[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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -31,31 +44,37 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnMapInit(EntityUid uid, DiseaseArtifactComponent component, MapInitEvent args)
|
private void OnMapInit(EntityUid uid, DiseaseArtifactComponent component, MapInitEvent args)
|
||||||
{
|
{
|
||||||
if (component.SpawnDisease == string.Empty && component.ArtifactDiseases.Count != 0)
|
if (component.SpawnDisease != null || ArtifactDiseases.Count == 0) return;
|
||||||
{
|
var diseaseName = _random.Pick(ArtifactDiseases);
|
||||||
var diseaseName = _random.Pick(component.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.SpawnDisease = disease;
|
||||||
component.ResolveDisease = disease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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
|
/// with a high-probability disease infection attempt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnActivate(EntityUid uid, DiseaseArtifactComponent component, ArtifactActivatedEvent args)
|
private void OnActivate(EntityUid uid, DiseaseArtifactComponent component, ArtifactActivatedEvent args)
|
||||||
{
|
{
|
||||||
|
if (component.SpawnDisease == null) return;
|
||||||
|
|
||||||
var xform = Transform(uid);
|
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;
|
continue;
|
||||||
|
|
||||||
if (TryComp<DiseaseCarrierComponent>(entity, out var carrier))
|
_disease.TryInfect(carrier, component.SpawnDisease, forced: true);
|
||||||
EntitySystem.Get<DiseaseSystem>().TryInfect(carrier, component.ResolveDisease);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user