Turn ReagentEffects into generic EntityEffects (#28168)
* Oh the possibilities * Merge fixes * Forgot to remote LavaSystem oops * Changed EntityEffectArgs to EntityEffectBaseArgs and EntityEffectReagentArgs * Throw exception for unimplemented effectargs * Remove Json and overrideable datafields * Fix test issues * Actually fix the compiling issue * Fix comments and remove EntityEffectArgs (no longer used, replaced with EntityEffectBaseArgs)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
/// <summary>
|
||||
/// Requires the target entity to be above or below a certain temperature.
|
||||
/// Used for things like cryoxadone and pyroxadone.
|
||||
/// </summary>
|
||||
public sealed partial class Temperature : EntityEffectCondition
|
||||
{
|
||||
[DataField]
|
||||
public float Min = 0;
|
||||
|
||||
[DataField]
|
||||
public float Max = float.PositiveInfinity;
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.TargetEntity, out TemperatureComponent? temp))
|
||||
{
|
||||
if (temp.CurrentTemperature > Min && temp.CurrentTemperature < Max)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-body-temperature",
|
||||
("max", float.IsPositiveInfinity(Max) ? (float) int.MaxValue : Max),
|
||||
("min", Min));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Tag;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed partial class HasTag : EntityEffectCondition
|
||||
{
|
||||
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<TagPrototype>))]
|
||||
public string Tag = default!;
|
||||
|
||||
[DataField]
|
||||
public bool Invert = false;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent<TagComponent>(args.TargetEntity, out var tag))
|
||||
return args.EntityManager.System<TagSystem>().HasTag(tag, Tag) ^ Invert;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
// this should somehow be made (much) nicer.
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-has-tag", ("tag", Tag), ("invert", Invert));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Localizations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Content.Shared.Station;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
public sealed partial class JobCondition : EntityEffectCondition
|
||||
{
|
||||
[DataField(required: true)] public List<ProtoId<JobPrototype>> Job;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
args.EntityManager.TryGetComponent<MindContainerComponent>(args.TargetEntity, out var mindContainer);
|
||||
if (mindContainer != null && mindContainer.Mind != null)
|
||||
{
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
if (args.EntityManager.TryGetComponent<JobComponent>(mindContainer?.Mind, out var comp) && prototypeManager.TryIndex(comp.Prototype, out var prototype))
|
||||
{
|
||||
foreach (var jobId in Job)
|
||||
{
|
||||
if (prototype.ID == jobId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
var localizedNames = Job.Select(jobId => prototype.Index(jobId).LocalizedName).ToList();
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-job-condition", ("job", ContentLocalizationManager.FormatListToOr(localizedNames)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
public sealed partial class MobStateCondition : EntityEffectCondition
|
||||
{
|
||||
[DataField]
|
||||
public MobState Mobstate = MobState.Alive;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.TargetEntity, out MobStateComponent? mobState))
|
||||
{
|
||||
if (mobState.CurrentState == Mobstate)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-mob-state-condition", ("state", Mobstate));
|
||||
}
|
||||
}
|
||||
|
||||
53
Content.Server/EntityEffects/EffectConditions/OrganType.cs
Normal file
53
Content.Server/EntityEffects/EffectConditions/OrganType.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Body.Prototypes;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
/// <summary>
|
||||
/// Requires that the metabolizing organ is or is not tagged with a certain MetabolizerType
|
||||
/// </summary>
|
||||
public sealed partial class OrganType : EntityEffectCondition
|
||||
{
|
||||
[DataField(required: true, customTypeSerializer: typeof(PrototypeIdSerializer<MetabolizerTypePrototype>))]
|
||||
public string Type = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Does this condition pass when the organ has the type, or when it doesn't have the type?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool ShouldHave = true;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args is EntityEffectReagentArgs reagentArgs)
|
||||
{
|
||||
if (reagentArgs.OrganEntity == null)
|
||||
return false;
|
||||
|
||||
return Condition(reagentArgs.OrganEntity.Value, reagentArgs.EntityManager);
|
||||
}
|
||||
|
||||
// TODO: Someone needs to figure out how to do this for non-reagent effects.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Condition(Entity<MetabolizerComponent?> metabolizer, IEntityManager entMan)
|
||||
{
|
||||
metabolizer.Comp ??= entMan.GetComponentOrNull<MetabolizerComponent>(metabolizer.Owner);
|
||||
if (metabolizer.Comp != null
|
||||
&& metabolizer.Comp.MetabolizerTypes != null
|
||||
&& metabolizer.Comp.MetabolizerTypes.Contains(Type))
|
||||
return ShouldHave;
|
||||
return !ShouldHave;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-organ-type",
|
||||
("name", prototype.Index<MetabolizerTypePrototype>(Type).LocalizedName),
|
||||
("shouldhave", ShouldHave));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
/// <summary>
|
||||
/// Used for implementing reagent effects that require a certain amount of reagent before it should be applied.
|
||||
/// For instance, overdoses.
|
||||
///
|
||||
/// This can also trigger on -other- reagents, not just the one metabolizing. By default, it uses the
|
||||
/// one being metabolized.
|
||||
/// </summary>
|
||||
public sealed partial class ReagentThreshold : EntityEffectCondition
|
||||
{
|
||||
[DataField]
|
||||
public FixedPoint2 Min = FixedPoint2.Zero;
|
||||
|
||||
[DataField]
|
||||
public FixedPoint2 Max = FixedPoint2.MaxValue;
|
||||
|
||||
// TODO use ReagentId
|
||||
[DataField]
|
||||
public string? Reagent;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args is EntityEffectReagentArgs reagentArgs)
|
||||
{
|
||||
var reagent = Reagent ?? reagentArgs.Reagent?.ID;
|
||||
if (reagent == null)
|
||||
return true; // No condition to apply.
|
||||
|
||||
var quant = FixedPoint2.Zero;
|
||||
if (reagentArgs.Source != null)
|
||||
quant = reagentArgs.Source.GetTotalPrototypeQuantity(reagent);
|
||||
|
||||
return quant >= Min && quant <= Max;
|
||||
}
|
||||
|
||||
// TODO: Someone needs to figure out how to do this for non-reagent effects.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
ReagentPrototype? reagentProto = null;
|
||||
if (Reagent is not null)
|
||||
prototype.TryIndex(Reagent, out reagentProto);
|
||||
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-reagent-threshold",
|
||||
("reagent", reagentProto?.LocalizedName ?? Loc.GetString("reagent-effect-condition-guidebook-this-reagent")),
|
||||
("max", Max == FixedPoint2.MaxValue ? (float) int.MaxValue : Max.Float()),
|
||||
("min", Min.Float()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Content.Shared.EntityEffects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
/// <summary>
|
||||
/// Requires the solution to be above or below a certain temperature.
|
||||
/// Used for things like explosives.
|
||||
/// </summary>
|
||||
public sealed partial class SolutionTemperature : EntityEffectCondition
|
||||
{
|
||||
[DataField]
|
||||
public float Min = 0.0f;
|
||||
|
||||
[DataField]
|
||||
public float Max = float.PositiveInfinity;
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args is EntityEffectReagentArgs reagentArgs)
|
||||
{
|
||||
if (reagentArgs.Source == null)
|
||||
return false;
|
||||
if (reagentArgs.Source.Temperature < Min)
|
||||
return false;
|
||||
if (reagentArgs.Source.Temperature > Max)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Someone needs to figure out how to do this for non-reagent effects.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-solution-temperature",
|
||||
("max", float.IsPositiveInfinity(Max) ? (float) int.MaxValue : Max),
|
||||
("min", Min));
|
||||
}
|
||||
}
|
||||
34
Content.Server/EntityEffects/EffectConditions/TotalDamage.cs
Normal file
34
Content.Server/EntityEffects/EffectConditions/TotalDamage.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
public sealed partial class TotalDamage : EntityEffectCondition
|
||||
{
|
||||
[DataField]
|
||||
public FixedPoint2 Max = FixedPoint2.MaxValue;
|
||||
|
||||
[DataField]
|
||||
public FixedPoint2 Min = FixedPoint2.Zero;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.TargetEntity, out DamageableComponent? damage))
|
||||
{
|
||||
var total = damage.TotalDamage;
|
||||
if (total > Min && total < Max)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-total-damage",
|
||||
("max", Max == FixedPoint2.MaxValue ? (float) int.MaxValue : Max.Float()),
|
||||
("min", Min.Float()));
|
||||
}
|
||||
}
|
||||
34
Content.Server/EntityEffects/EffectConditions/TotalHunger.cs
Normal file
34
Content.Server/EntityEffects/EffectConditions/TotalHunger.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.EntityEffects.EffectConditions;
|
||||
|
||||
public sealed partial class Hunger : EntityEffectCondition
|
||||
{
|
||||
[DataField]
|
||||
public float Max = float.PositiveInfinity;
|
||||
|
||||
[DataField]
|
||||
public float Min = 0;
|
||||
|
||||
public override bool Condition(EntityEffectBaseArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.TargetEntity, out HungerComponent? hunger))
|
||||
{
|
||||
var total = hunger.CurrentHunger;
|
||||
if (total > Min && total < Max)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GuidebookExplanation(IPrototypeManager prototype)
|
||||
{
|
||||
return Loc.GetString("reagent-effect-condition-guidebook-total-hunger",
|
||||
("max", float.IsPositiveInfinity(Max) ? (float) int.MaxValue : Max),
|
||||
("min", Min));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user