Files
tbd-station-14/Content.Server/EntityEffects/Effects/WearableReaction.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

49 lines
1.6 KiB
C#

using Content.Shared.Inventory;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.EntityEffects;
using Robust.Shared.Prototypes;
namespace Content.Server.EntityEffects.Effects.Effects;
/// <summary>
/// A reaction effect that spawns a PrototypeID in the entity's Slot, and attempts to consume the reagent if EntityEffectReagentArgs.
/// Used to implement the water droplet effect for arachnids.
/// </summary>
public sealed partial class WearableReaction : EntityEffect
{
/// <summary>
/// Minimum quantity of reagent required to trigger this effect.
/// Only used with EntityEffectReagentArgs.
/// </summary>
[DataField]
public float AmountThreshold = 1f;
/// <summary>
/// Slot to spawn the item into.
/// </summary>
[DataField(required: true)]
public string Slot;
/// <summary>
/// Prototype ID of item to spawn.
/// </summary>
[DataField(required: true)]
public string PrototypeID;
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => null;
public override void Effect(EntityEffectBaseArgs args)
{
// SpawnItemInSlot returns false if slot is already occupied
if (args.EntityManager.System<InventorySystem>().SpawnItemInSlot(args.TargetEntity, Slot, PrototypeID))
{
if (args is EntityEffectReagentArgs reagentArgs)
{
if (reagentArgs.Reagent == null || reagentArgs.Quantity < AmountThreshold)
return;
reagentArgs.Source?.RemoveReagent(reagentArgs.Reagent.ID, AmountThreshold);
}
}
}
}