The Rat King [Antag] (#8706)
* vending machine go spit * who's da rat, bozo * fixes * crown + fixes * aaaa * aa * lololol * removing vending shit + most annoying fix alive * paul review * moony fixes * sloth review * Minor diseasesystem fix * inverse moment * A * Also reduce args allocations Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Disease;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Disease.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
/// <summary>
|
||||
/// Allows the enity to be infected with diseases.
|
||||
/// Allows the entity to be infected with diseases.
|
||||
/// Please use only on mobs.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class DiseaseCarrierComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
@@ -15,22 +16,33 @@ namespace Content.Server.Disease.Components
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public List<DiseasePrototype> Diseases = new();
|
||||
|
||||
/// <summary>
|
||||
/// The carrier's resistance to disease
|
||||
/// </summary>
|
||||
[DataField("diseaseResist")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float DiseaseResist = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Diseases the carrier has had, used for immunity.
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public List<DiseasePrototype> PastDiseases = new();
|
||||
|
||||
/// <summary>
|
||||
/// All the diseases the carrier has or has had.
|
||||
/// Checked against when trying to add a disease
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public List<DiseasePrototype> AllDiseases => PastDiseases.Concat(Diseases).ToList();
|
||||
|
||||
/// <summary>
|
||||
/// A list of diseases which the entity does not
|
||||
/// exhibit direct symptoms from. They still transmit
|
||||
/// these diseases, just without symptoms.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("carrierDiseases", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<DiseasePrototype>))]
|
||||
public HashSet<string>? CarrierDiseases;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,17 +96,23 @@ namespace Content.Server.Disease
|
||||
for (var i = 0; i < carrierComp.Diseases.Count; i++) //this is a for-loop so that it doesn't break when new diseases are added
|
||||
{
|
||||
var disease = carrierComp.Diseases[i];
|
||||
|
||||
var args = new DiseaseEffectArgs(carrierComp.Owner, disease, EntityManager);
|
||||
disease.Accumulator += frameTime;
|
||||
if (disease.Accumulator >= disease.TickTime)
|
||||
|
||||
if (disease.Accumulator < disease.TickTime) continue;
|
||||
|
||||
// if the disease is on the silent disease list, don't do effects
|
||||
var doEffects = carrierComp.CarrierDiseases?.Contains(disease.ID) != true;
|
||||
var args = new DiseaseEffectArgs(carrierComp.Owner, disease, EntityManager);
|
||||
disease.Accumulator -= disease.TickTime;
|
||||
|
||||
foreach (var cure in disease.Cures)
|
||||
{
|
||||
if (cure.Cure(args))
|
||||
CureDisease(carrierComp, disease);
|
||||
}
|
||||
|
||||
if (doEffects)
|
||||
{
|
||||
disease.Accumulator -= disease.TickTime;
|
||||
foreach (var cure in disease.Cures)
|
||||
{
|
||||
if (cure.Cure(args))
|
||||
CureDisease(carrierComp, disease);
|
||||
}
|
||||
foreach (var effect in disease.Effects)
|
||||
{
|
||||
if (_random.Prob(effect.Probability))
|
||||
@@ -383,6 +389,14 @@ namespace Content.Server.Disease
|
||||
TryAddDisease(carrier.Owner, disease, carrier);
|
||||
}
|
||||
|
||||
public void TryInfect(DiseaseCarrierComponent carrier, string? disease, float chance = 0.7f, bool forced = false)
|
||||
{
|
||||
if (disease == null || !_prototypeManager.TryIndex<DiseasePrototype>(disease, out var d))
|
||||
return;
|
||||
|
||||
TryInfect(carrier, d, chance, forced);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plays a sneeze/cough popup if applicable
|
||||
/// and then tries to infect anyone in range
|
||||
|
||||
Reference in New Issue
Block a user