Fix sloth's disease shit (#7123)

This commit is contained in:
metalgearsloth
2022-03-15 07:51:42 +11:00
committed by GitHub
parent 4970a0ff71
commit 84225dde3d
7 changed files with 53 additions and 39 deletions

View File

@@ -21,12 +21,13 @@ namespace Content.Server.Chemistry.ReagentEffects
/// <summary> /// <summary>
/// The disease to add. /// The disease to add.
/// </summary> /// </summary>
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))] [DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>), required: true)]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public string Disease = string.Empty; public string Disease = default!;
public override void Effect(ReagentEffectArgs args) public override void Effect(ReagentEffectArgs args)
{ {
EntitySystem.Get<DiseaseSystem>().TryAddDisease(null, null, Disease, args.SolutionEntity); EntitySystem.Get<DiseaseSystem>().TryAddDisease(args.SolutionEntity, Disease);
} }
} }
} }

View File

@@ -3,10 +3,10 @@ using Content.Shared.Disease;
namespace Content.Server.Disease.Components namespace Content.Server.Disease.Components
{ {
[RegisterComponent]
/// <summary> /// <summary>
/// For disease vaccines /// For disease vaccines
/// </summary> /// </summary>
[RegisterComponent]
public sealed class DiseaseVaccineComponent : Component public sealed class DiseaseVaccineComponent : Component
{ {
/// <summary> /// <summary>

View File

@@ -15,6 +15,7 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager; using Robust.Shared.Serialization.Manager;
using Content.Shared.Inventory.Events; using Content.Shared.Inventory.Events;
using Content.Server.Nutrition.EntitySystems; using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Utility;
namespace Content.Server.Disease namespace Content.Server.Disease
{ {
@@ -43,7 +44,7 @@ namespace Content.Server.Disease
SubscribeLocalEvent<DiseaseProtectionComponent, GotUnequippedEvent>(OnUnequipped); SubscribeLocalEvent<DiseaseProtectionComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<DiseaseVaccineComponent, AfterInteractEvent>(OnAfterInteract); SubscribeLocalEvent<DiseaseVaccineComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<DiseaseVaccineComponent, ExaminedEvent>(OnExamined); SubscribeLocalEvent<DiseaseVaccineComponent, ExaminedEvent>(OnExamined);
/// Private events stuff // Private events stuff
SubscribeLocalEvent<TargetVaxxSuccessfulEvent>(OnTargetVaxxSuccessful); SubscribeLocalEvent<TargetVaxxSuccessfulEvent>(OnTargetVaxxSuccessful);
SubscribeLocalEvent<VaxxCancelledEvent>(OnVaxxCancelled); SubscribeLocalEvent<VaxxCancelledEvent>(OnVaxxCancelled);
} }
@@ -60,7 +61,10 @@ namespace Content.Server.Disease
{ {
base.Update(frameTime); base.Update(frameTime);
foreach (var entity in AddQueue) foreach (var entity in AddQueue)
{
EnsureComp<DiseasedComponent>(entity); EnsureComp<DiseasedComponent>(entity);
}
AddQueue.Clear(); AddQueue.Clear();
foreach (var tuple in CureQueue) foreach (var tuple in CureQueue)
@@ -72,16 +76,19 @@ namespace Content.Server.Disease
} }
CureQueue.Clear(); CureQueue.Clear();
foreach (var (diseasedComp, carrierComp, mobState) in EntityQuery<DiseasedComponent, DiseaseCarrierComponent, MobStateComponent>(false)) foreach (var (_, carrierComp, mobState) in EntityQuery<DiseasedComponent, DiseaseCarrierComponent, MobStateComponent>())
{ {
DebugTools.Assert(carrierComp.Diseases.Count > 0);
if (mobState.IsDead()) if (mobState.IsDead())
{ {
if (_random.Prob(0.005f * frameTime)) //Mean time to remove is 200 seconds per disease if (_random.Prob(0.005f * frameTime)) //Mean time to remove is 200 seconds per disease
CureDisease(carrierComp, _random.Pick(carrierComp.Diseases)); CureDisease(carrierComp, _random.Pick(carrierComp.Diseases));
continue; continue;
} }
foreach(var disease in carrierComp.Diseases) foreach (var disease in carrierComp.Diseases)
{ {
var args = new DiseaseEffectArgs(carrierComp.Owner, disease, EntityManager); var args = new DiseaseEffectArgs(carrierComp.Owner, disease, EntityManager);
disease.Accumulator += frameTime; disease.Accumulator += frameTime;
@@ -139,16 +146,16 @@ namespace Content.Server.Disease
/// </summary> /// </summary>
private void OnEquipped(EntityUid uid, DiseaseProtectionComponent component, GotEquippedEvent args) private void OnEquipped(EntityUid uid, DiseaseProtectionComponent component, GotEquippedEvent args)
{ {
/// This only works on clothing // This only works on clothing
if (!TryComp<ClothingComponent>(uid, out var clothing)) if (!TryComp<ClothingComponent>(uid, out var clothing))
return; return;
/// Is the clothing in its actual slot? // Is the clothing in its actual slot?
if (!clothing.SlotFlags.HasFlag(args.SlotFlags)) if (!clothing.SlotFlags.HasFlag(args.SlotFlags))
return; return;
/// Give the user the component's disease resist // Give the user the component's disease resist
if(TryComp<DiseaseCarrierComponent>(args.Equipee, out var carrier)) if(TryComp<DiseaseCarrierComponent>(args.Equipee, out var carrier))
carrier.DiseaseResist += component.Protection; carrier.DiseaseResist += component.Protection;
/// Set the component to active to the unequip check isn't CBT // Set the component to active to the unequip check isn't CBT
component.IsActive = true; component.IsActive = true;
} }
@@ -159,7 +166,7 @@ namespace Content.Server.Disease
/// </summary> /// </summary>
private void OnUnequipped(EntityUid uid, DiseaseProtectionComponent component, GotUnequippedEvent args) private void OnUnequipped(EntityUid uid, DiseaseProtectionComponent component, GotUnequippedEvent args)
{ {
/// Only undo the resistance if it was affecting the user // Only undo the resistance if it was affecting the user
if (!component.IsActive) if (!component.IsActive)
return; return;
if(TryComp<DiseaseCarrierComponent>(args.Equipee, out var carrier)) if(TryComp<DiseaseCarrierComponent>(args.Equipee, out var carrier))
@@ -282,12 +289,9 @@ namespace Content.Server.Disease
/// to not be guaranteed you are looking /// to not be guaranteed you are looking
/// for TryInfect. /// for TryInfect.
/// </summary> /// </summary>
public void TryAddDisease(DiseaseCarrierComponent? target, DiseasePrototype? addedDisease, string? diseaseName = null, EntityUid? host = null) public void TryAddDisease(EntityUid host, DiseasePrototype addedDisease, DiseaseCarrierComponent? target = null)
{ {
if (diseaseName != null && _prototypeManager.TryIndex(diseaseName, out DiseasePrototype? diseaseProto)) if (!Resolve(host, ref target, false))
addedDisease = diseaseProto;
if (!TryComp(host, out target))
return; return;
foreach (var disease in target.AllDiseases) foreach (var disease in target.AllDiseases)
@@ -295,11 +299,23 @@ namespace Content.Server.Disease
if (disease.ID == addedDisease?.ID) //ID because of the way protoypes work if (disease.ID == addedDisease?.ID) //ID because of the way protoypes work
return; return;
} }
var freshDisease = _serializationManager.CreateCopy(addedDisease) ?? default!;
var freshDisease = _serializationManager.CreateCopy(addedDisease);
if (freshDisease == null) return;
target.Diseases.Add(freshDisease); target.Diseases.Add(freshDisease);
AddQueue.Enqueue(target.Owner); AddQueue.Enqueue(target.Owner);
} }
public void TryAddDisease(EntityUid host, string? addedDisease, DiseaseCarrierComponent? target = null)
{
if (addedDisease == null || !_prototypeManager.TryIndex<DiseasePrototype>(addedDisease, out var added))
return;
TryAddDisease(host, added, target);
}
/// <summary> /// <summary>
/// Pits the infection chance against the /// Pits the infection chance against the
/// person's disease resistance and /// person's disease resistance and
@@ -314,7 +330,7 @@ namespace Content.Server.Disease
if (infectionChance <= 0) if (infectionChance <= 0)
return; return;
if (_random.Prob(infectionChance)) if (_random.Prob(infectionChance))
TryAddDisease(carrier, disease); TryAddDisease(carrier.Owner, disease, carrier);
} }
/// <summary> /// <summary>

View File

@@ -27,17 +27,10 @@ namespace Content.Server.Medical.Components
public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key); public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
/// <summary> /// <summary>
/// Is this actually going to give people the disease below /// The disease this will give people.
/// </summary>
[DataField("fake")]
[ViewVariables(VVAccess.ReadWrite)]
public bool Fake = false;
/// <summary>
/// The disease this will give people if Fake == true
/// </summary> /// </summary>
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))] [DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public string Disease = string.Empty; public string? Disease;
} }
} }

View File

@@ -14,6 +14,7 @@ namespace Content.Server.Medical
{ {
public sealed class HealthAnalyzerSystem : EntitySystem public sealed class HealthAnalyzerSystem : EntitySystem
{ {
[Dependency] private readonly DiseaseSystem _disease = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!; [Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -68,13 +69,13 @@ namespace Content.Server.Medical
{ {
args.Component.CancelToken = null; args.Component.CancelToken = null;
UpdateScannedUser(args.Component.Owner, args.User, args.Target, args.Component); UpdateScannedUser(args.Component.Owner, args.User, args.Target, args.Component);
/// Below is for the traitor item // Below is for the traitor item
/// Piggybacking off another component's doafter is complete CBT so I gave up // Piggybacking off another component's doafter is complete CBT so I gave up
/// and put it on the same component // and put it on the same component
if (!args.Component.Fake || args.Component.Disease == string.Empty || args.Target == null) if (string.IsNullOrEmpty(args.Component.Disease) || args.Target == null)
return; return;
EntitySystem.Get<DiseaseSystem>().TryAddDisease(null, null, args.Component.Disease, args.Target.Value); _disease.TryAddDisease(args.Target.Value, args.Component.Disease);
if (args.User == args.Target) if (args.User == args.Target)
{ {

View File

@@ -47,15 +47,17 @@ public sealed class DiseaseOutbreak : StationEvent
var diseaseName = _random.Pick(NotTooSeriousDiseases); var diseaseName = _random.Pick(NotTooSeriousDiseases);
if (!_prototypeManager.TryIndex(diseaseName, out DiseasePrototype? disease) || disease == null) if (!_prototypeManager.TryIndex(diseaseName, out DiseasePrototype? disease))
return; return;
var diseaseSystem = EntitySystem.Get<DiseaseSystem>();
foreach (var target in targetList) foreach (var target in targetList)
{ {
if (toInfect-- == 0) if (toInfect-- == 0)
break; break;
EntitySystem.Get<DiseaseSystem>().TryAddDisease(target, disease); diseaseSystem.TryAddDisease(target.Owner, disease, target);
} }
_chatManager.DispatchStationAnnouncement(Loc.GetString("station-event-disease-outbreak-announcement")); _chatManager.DispatchStationAnnouncement(Loc.GetString("station-event-disease-outbreak-announcement"));
} }

View File

@@ -1,11 +1,12 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
/// <summary>
/// Diseases encompass everything from viruses to cancers to heart disease.
/// It's not just a virology thing.
/// </summary>
namespace Content.Shared.Disease namespace Content.Shared.Disease
{ {
/// <summary>
/// Diseases encompass everything from viruses to cancers to heart disease.
/// It's not just a virology thing.
/// </summary>
[Prototype("disease")] [Prototype("disease")]
[DataDefinition] [DataDefinition]
public sealed class DiseasePrototype : IPrototype, IInheritingPrototype public sealed class DiseasePrototype : IPrototype, IInheritingPrototype