Skip to content

Commit

Permalink
adcionando doenças de volta
Browse files Browse the repository at this point in the history
  • Loading branch information
Crono209ggg committed Dec 13, 2024
1 parent c7a91ed commit a06b88f
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Backmen.Disease;
using Content.Shared.Backmen.Disease;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
Expand All @@ -11,8 +12,10 @@ namespace Content.Server.Backmen.Chemistry.ReagentEffects;
/// Default metabolism for medicine reagents.
/// </summary>
[UsedImplicitly]
public sealed partial class ChemCauseDisease : ReagentEffect
public sealed partial class ChemCauseDisease : EntityEffect
{
public override bool ShouldLog => true;

protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
=> Loc.GetString("reagent-effect-guidebook-chem-cause-disease", ("chance", Probability),
("disease", prototype.Index<DiseasePrototype>(Disease).Name));
Expand All @@ -30,11 +33,11 @@ public sealed partial class ChemCauseDisease : ReagentEffect
[ViewVariables(VVAccess.ReadWrite)]
public string Disease = default!;

public override void Effect(ReagentEffectArgs args)
public override void Effect(EntityEffectBaseArgs args)
{
if (args.Scale != 1f)
if (args is EntityEffectReagentArgs reagentArgs && reagentArgs.Scale != 1f)
return;

args.EntityManager.System<DiseaseSystem>().TryAddDisease(args.SolutionEntity, Disease);
args.EntityManager.System<DiseaseSystem>().TryAddDisease(args.TargetEntity, Disease);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Atmos.Rotting;
using Content.Server.Backmen.Disease;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;

Expand All @@ -12,18 +13,18 @@ namespace Content.Server.Backmen.Chemistry.ReagentEffects;
/// For things ingested by one person, you probably want ChemCauseRandomDisease instead.
/// </summary>
[UsedImplicitly]
public sealed partial class ChemMiasmaPoolSource : ReagentEffect
public sealed partial class ChemMiasmaPoolSource : EntityEffect
{
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
=> Loc.GetString("reagent-effect-guidebook-chem-miasma-pool", ("chance", Probability));

public override void Effect(ReagentEffectArgs args)
public override void Effect(EntityEffectBaseArgs args)
{
if (args.Scale < 0.1f)
if (args is EntityEffectReagentArgs reagentArgs && reagentArgs.Scale != 1f)
return;

var disease = args.EntityManager.System<BkRottingSystem>().RequestPoolDisease();

args.EntityManager.System<DiseaseSystem>().TryAddDisease(args.SolutionEntity, disease);
args.EntityManager.System<DiseaseSystem>().TryAddDisease(args.TargetEntity, disease);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ public sealed partial class DiseaseVaccineCreatorComponent : Component
/// </summary>
public int BiomassCost = 4;

/// <summary>
/// The machine part that reduces biomass cost.
/// </summary>
[DataField("machinePartCost", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartCost = "Manipulator";

/// <summary>
/// Current vaccines queued.
/// </summary>
public int Queued = 0;

[DataField("runningSound")]
public SoundSpecifier RunningSoundPath = new SoundPathSpecifier("/Audio/Machines/vaccinator_running.ogg");
}
}
8 changes: 4 additions & 4 deletions Content.Server/Backmen/Disease/DiseaseDiagnosisSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using Content.Server.Backmen.Disease.Components;
using Content.Server.Backmen.Disease.Server;
using Content.Server.Nutrition.Components;
using Content.Server.Paper;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Station.Systems;
using Content.Shared.Backmen.Disease;
Expand All @@ -15,6 +13,8 @@
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Inventory;
using Content.Shared.Paper;
using Content.Shared.Power;
using Content.Shared.Tools.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -343,9 +343,9 @@ private void OnDiagnoserFinished(EntityUid uid, DiseaseDiagnoserComponent compon
}
_metaData.SetEntityName(printed,reportTitle);

_paperSystem.SetContent(printed, contents.ToMarkup(), paper);
_paperSystem.SetContent((printed,EnsureComp<PaperComponent>(printed)), contents.ToMarkup());
}

[ValidatePrototypeId<EntityPrototype>]
private const string ResearchDisk5000 = "ResearchDisk5000";
}
}
57 changes: 42 additions & 15 deletions Content.Server/Backmen/Disease/DiseaseSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Server.Backmen.Disease.Components;
using Content.Server.Body.Systems;
using Content.Server.Chat.Systems;
Expand Down Expand Up @@ -92,20 +92,26 @@ public override void Update(float frameTime)

foreach (var (carrier, disease) in _cureQueue)
{
if (carrier.Comp.Diseases.Count > 0) //This is reliable unlike testing Count == 0 right after removal for reasons I don't quite get
RemCompDeferred<DiseasedComponent>(carrier);
carrier.Comp.PastDiseases.Add(disease);
var d = carrier.Comp.Diseases.FirstOrDefault(x => x.ID == disease);
if (d != null)
{
carrier.Comp.Diseases.Remove(d);
if (d.Infectious)
{
carrier.Comp.PastDiseases.Add(disease);
}
}
if (carrier.Comp.Diseases.Count == 0) //This is reliable unlike testing Count == 0 right after removal for reasons I don't quite get
RemCompDeferred<DiseasedComponent>(carrier);
}
_cureQueue.Clear();

var q = EntityQueryEnumerator<DiseasedComponent, DiseaseCarrierComponent, MobStateComponent>();
while (q.MoveNext(out var owner, out _, out var carrierComp, out var mobState))
var q = EntityQueryEnumerator<DiseasedComponent, DiseaseCarrierComponent, MobStateComponent, MetaDataComponent>();
while (q.MoveNext(out var owner, out _, out var carrierComp, out var mobState, out var metaDataComponent))
{
if(Paused(owner, metaDataComponent))
continue;

if (carrierComp.Diseases.Count == 0)
{
continue;
Expand All @@ -124,34 +130,35 @@ public override void Update(float frameTime)
_parallel.ProcessNow(new DiseaseJob
{
System = this,
Owner = (owner, carrierComp),
Owner = (owner, carrierComp, mobState),
FrameTime = frameTime
}, carrierComp.Diseases.Count);
},
carrierComp.Diseases.Count);
}
}

private record struct DiseaseJob : IParallelRobustJob
{
public DiseaseSystem System { get; init; }
public Entity<DiseaseCarrierComponent> Owner { get; init; }
public Entity<DiseaseCarrierComponent, MobStateComponent> Owner { get; init; }
public float FrameTime { get; init; }
public void Execute(int index)
{
System.Process(Owner, FrameTime, index);
}
}

private void Process(Entity<DiseaseCarrierComponent> owner, float frameTime, int i)
private void Process(Entity<DiseaseCarrierComponent, MobStateComponent> owner, float frameTime, int i)
{
var disease = owner.Comp.Diseases[i];
var disease = owner.Comp1.Diseases[i];
disease.Accumulator += frameTime;
disease.TotalAccumulator += frameTime;

if (disease.Accumulator < disease.TickTime)
return;

// if the disease is on the silent disease list, don't do effects
var doEffects = owner.Comp.CarrierDiseases?.Contains(disease.ID) != true;
var doEffects = owner.Comp1.CarrierDiseases?.Contains(disease.ID) != true;
disease.Accumulator -= disease.TickTime;

var stage = 0; //defaults to stage 0 because you should always have one
Expand All @@ -169,17 +176,37 @@ private void Process(Entity<DiseaseCarrierComponent> owner, float frameTime, int
{
if (!cure.Stages.Contains(stage))
continue;
RaiseLocalEvent(owner, cure.GenerateEvent(owner,disease.ID));

try
{
RaiseLocalEvent(owner, cure.GenerateEvent(owner, disease.ID));
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}

if (_mobStateSystem.IsIncapacitated(owner, owner))
doEffects = false;

if (!doEffects)
return;

foreach (var effect in disease.Effects)
{
if (!effect.Stages.Contains(stage) || !_random.Prob(effect.Probability))
continue;
RaiseLocalEvent(owner, effect.GenerateEvent(owner,disease.ID));

try
{
RaiseLocalEvent(owner, effect.GenerateEvent(owner,disease.ID));
}
catch (Exception e)
{
Log.Error(e.ToString());
}

}
}
///
Expand Down Expand Up @@ -515,4 +542,4 @@ public enum SneezeCoughType
Sneeze,
Cough,
None
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Chemistry.ReagentEffects;
using Content.Shared.Backmen.Disease;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Backmen.Disease.Effects;

Expand Down Expand Up @@ -59,4 +56,4 @@ private void DiseaseAdjustReagent(Entity<DiseaseCarrierComponent> ent, ref Disea
if (args.DiseaseEffect.Amount > 0)
_solutionContainer.TryAddReagent(stream.Value, args.DiseaseEffect.Reagent.Value, args.DiseaseEffect.Amount, out _);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Station.Components;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Events;
using Content.Shared.Backmen.Disease;
using Content.Shared.GameTicking.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Random.Helpers;
Expand Down Expand Up @@ -63,4 +63,4 @@ protected override void Started(EntityUid uid, DiseaseOutbreakRuleComponent comp
stationsToNotify.Add((EntityUid) station);
}
}
}
}
20 changes: 12 additions & 8 deletions Content.Server/Backmen/Disease/VaccineSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Server.Backmen.Disease.Components;
using Content.Server.Backmen.Disease.Server;
using Content.Server.DoAfter;
Expand Down Expand Up @@ -43,8 +43,6 @@ public sealed class VaccineSystem : EntitySystem
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;

public override void Initialize()
Expand Down Expand Up @@ -177,7 +175,7 @@ private void OnSyncRequest(EntityUid uid, DiseaseVaccineCreatorComponent compone

private void OpenServerList(EntityUid uid, DiseaseVaccineCreatorComponent component, VaccinatorServerSelectionMessage args)
{
_uiSys.TryOpen(uid, ResearchClientUiKey.Key, args.Session);
_uiSys.TryOpenUi(uid, ResearchClientUiKey.Key, args.Actor);
}

private void AfterUIOpen(EntityUid uid, DiseaseVaccineCreatorComponent component, AfterActivatableUIOpenEvent args)
Expand Down Expand Up @@ -209,7 +207,7 @@ public void UpdateUserInterfaceState(EntityUid uid, DiseaseVaccineCreatorCompone
}

var state = new VaccineMachineUpdateState(biomass, component.BiomassCost, diseases, overrideLocked ?? HasComp<DiseaseMachineRunningComponent>(uid), hasServer);
_uiSys.TrySetUiState(uid, VaccineMachineUiKey.Key, state);
_uiSys.SetUiState(uid, VaccineMachineUiKey.Key, state);
}

/// <summary>
Expand Down Expand Up @@ -258,14 +256,20 @@ private void OnExamined(EntityUid uid, DiseaseVaccineComponent vaxx, ExaminedEve
/// past diseases to give them immunity
/// IF they don't already have the disease.
/// </summary>
public void Vaccinate(DiseaseCarrierComponent carrier, DiseasePrototype disease)
public bool Vaccinate(DiseaseCarrierComponent carrier, DiseasePrototype disease)
{
foreach (var currentDisease in carrier.Diseases)
{
if (currentDisease.ID == disease.ID) //ID because of the way protoypes work
return;
return false;
}

if (!disease.Infectious)
{
return false;
}
carrier.PastDiseases.Add(disease.ID);
return true;
}

private void OnDoAfter(EntityUid uid, DiseaseVaccineComponent component, VaccineDoAfterEvent args)
Expand Down Expand Up @@ -293,4 +297,4 @@ public DiseaseMachineFinishedEvent(DiseaseMachineComponent machine, bool dequeue
Machine = machine;
Dequeue = dequeue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ private void OnBlightAction(EntityUid uid, RevenantComponent component, Revenant
// TODO: When disease refactor is in.

// backmen-start: Disease
var disSys = EntityManager.System<Backmen.Disease.DiseaseSystem>();
var emo = GetEntityQuery<Shared.Backmen.Disease.DiseaseCarrierComponent>();
foreach (var ent in _lookup.GetEntitiesInRange(uid, component.BlightRadius))
{
if (emo.TryGetComponent(ent, out var comp))
EntityManager.System<Backmen.Disease.DiseaseSystem>().TryAddDisease(ent, component.BlightDiseasePrototypeId, comp);
if (emo.TryComp(ent, out var comp))
disSys.TryAddDisease(ent, component.BlightDiseasePrototypeId, comp);
}
EntityManager.System<Shared.Backmen.Abilities.Psionics.SharedPsionicAbilitiesSystem>().LogPowerUsed(uid, Loc.GetString("revenant-psionic-power"), 6, 10);
// backmen-end: Disease
}

Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/Backmen/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Robust.Shared.Configuration;

namespace Content.Shared.Backmen.CCVar;

// ReSharper disable once InconsistentNaming
[CVarDefs]
public sealed class CCVars
{
public static readonly CVarDef<bool>
GameDiseaseEnabled = CVarDef.Create("game.disease", true, CVar.SERVERONLY);

}
1 change: 0 additions & 1 deletion Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
components:
- type: Absorbable # Goobstation - changelings
- type: DiseaseCarrier # backmen
- type: Flashable
- type: Barotrauma
damage:
types:
Expand Down

0 comments on commit a06b88f

Please sign in to comment.