Files
tbd-station-14/Content.Server/EntityEffects/Effects/SatiateHunger.cs
SlamBamActionman b9fa941ca6 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)
2024-06-30 13:43:43 +10:00

44 lines
1.8 KiB
C#

using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.EntityEffects;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Robust.Shared.Prototypes;
namespace Content.Server.EntityEffects.Effects
{
/// <summary>
/// Attempts to find a HungerComponent on the target,
/// and to update it's hunger values.
/// </summary>
public sealed partial class SatiateHunger : EntityEffect
{
private const float DefaultNutritionFactor = 3.0f;
/// <summary>
/// How much hunger is satiated.
/// Is multiplied by quantity if used with EntityEffectReagentArgs.
/// </summary>
[DataField("factor")] public float NutritionFactor { get; set; } = DefaultNutritionFactor;
//Remove reagent at set rate, satiate hunger if a HungerComponent can be found
public override void Effect(EntityEffectBaseArgs args)
{
var entman = args.EntityManager;
if (!entman.TryGetComponent(args.TargetEntity, out HungerComponent? hunger))
return;
if (args is EntityEffectReagentArgs reagentArgs)
{
entman.System<HungerSystem>().ModifyHunger(reagentArgs.TargetEntity, NutritionFactor * (float) reagentArgs.Quantity, hunger);
}
else
{
entman.System<HungerSystem>().ModifyHunger(args.TargetEntity, NutritionFactor, hunger);
}
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
=> Loc.GetString("reagent-effect-guidebook-satiate-hunger", ("chance", Probability), ("relative", NutritionFactor / DefaultNutritionFactor));
}
}