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>
/// The disease to add.
/// </summary>
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))]
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>), required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public string Disease = string.Empty;
public string Disease = default!;
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
{
[RegisterComponent]
/// <summary>
/// For disease vaccines
/// </summary>
[RegisterComponent]
public sealed class DiseaseVaccineComponent : Component
{
/// <summary>

View File

@@ -15,6 +15,7 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
using Content.Shared.Inventory.Events;
using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Utility;
namespace Content.Server.Disease
{
@@ -43,7 +44,7 @@ namespace Content.Server.Disease
SubscribeLocalEvent<DiseaseProtectionComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<DiseaseVaccineComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<DiseaseVaccineComponent, ExaminedEvent>(OnExamined);
/// Private events stuff
// Private events stuff
SubscribeLocalEvent<TargetVaxxSuccessfulEvent>(OnTargetVaxxSuccessful);
SubscribeLocalEvent<VaxxCancelledEvent>(OnVaxxCancelled);
}
@@ -60,7 +61,10 @@ namespace Content.Server.Disease
{
base.Update(frameTime);
foreach (var entity in AddQueue)
{
EnsureComp<DiseasedComponent>(entity);
}
AddQueue.Clear();
foreach (var tuple in CureQueue)
@@ -72,16 +76,19 @@ namespace Content.Server.Disease
}
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 (_random.Prob(0.005f * frameTime)) //Mean time to remove is 200 seconds per disease
CureDisease(carrierComp, _random.Pick(carrierComp.Diseases));
continue;
}
foreach(var disease in carrierComp.Diseases)
foreach (var disease in carrierComp.Diseases)
{
var args = new DiseaseEffectArgs(carrierComp.Owner, disease, EntityManager);
disease.Accumulator += frameTime;
@@ -139,16 +146,16 @@ namespace Content.Server.Disease
/// </summary>
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))
return;
/// Is the clothing in its actual slot?
// Is the clothing in its actual slot?
if (!clothing.SlotFlags.HasFlag(args.SlotFlags))
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))
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;
}
@@ -159,7 +166,7 @@ namespace Content.Server.Disease
/// </summary>
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)
return;
if(TryComp<DiseaseCarrierComponent>(args.Equipee, out var carrier))
@@ -282,12 +289,9 @@ namespace Content.Server.Disease
/// to not be guaranteed you are looking
/// for TryInfect.
/// </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))
addedDisease = diseaseProto;
if (!TryComp(host, out target))
if (!Resolve(host, ref target, false))
return;
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
return;
}
var freshDisease = _serializationManager.CreateCopy(addedDisease) ?? default!;
var freshDisease = _serializationManager.CreateCopy(addedDisease);
if (freshDisease == null) return;
target.Diseases.Add(freshDisease);
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>
/// Pits the infection chance against the
/// person's disease resistance and
@@ -314,7 +330,7 @@ namespace Content.Server.Disease
if (infectionChance <= 0)
return;
if (_random.Prob(infectionChance))
TryAddDisease(carrier, disease);
TryAddDisease(carrier.Owner, disease, carrier);
}
/// <summary>

View File

@@ -27,17 +27,10 @@ namespace Content.Server.Medical.Components
public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
/// <summary>
/// Is this actually going to give people the disease below
/// </summary>
[DataField("fake")]
[ViewVariables(VVAccess.ReadWrite)]
public bool Fake = false;
/// <summary>
/// The disease this will give people if Fake == true
/// The disease this will give people.
/// </summary>
[DataField("disease", customTypeSerializer: typeof(PrototypeIdSerializer<DiseasePrototype>))]
[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
{
[Dependency] private readonly DiseaseSystem _disease = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -68,13 +69,13 @@ namespace Content.Server.Medical
{
args.Component.CancelToken = null;
UpdateScannedUser(args.Component.Owner, args.User, args.Target, args.Component);
/// Below is for the traitor item
/// Piggybacking off another component's doafter is complete CBT so I gave up
/// and put it on the same component
if (!args.Component.Fake || args.Component.Disease == string.Empty || args.Target == null)
// Below is for the traitor item
// Piggybacking off another component's doafter is complete CBT so I gave up
// and put it on the same component
if (string.IsNullOrEmpty(args.Component.Disease) || args.Target == null)
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)
{

View File

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

View File

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