1
0

WearableReaction.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Shared.Inventory;
  2. using Content.Shared.Chemistry.Reagent;
  3. using Content.Shared.EntityEffects;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Server.EntityEffects.Effects.Effects;
  6. /// <summary>
  7. /// A reaction effect that spawns a PrototypeID in the entity's Slot, and attempts to consume the reagent if EntityEffectReagentArgs.
  8. /// Used to implement the water droplet effect for arachnids.
  9. /// </summary>
  10. public sealed partial class WearableReaction : EntityEffect
  11. {
  12. /// <summary>
  13. /// Minimum quantity of reagent required to trigger this effect.
  14. /// Only used with EntityEffectReagentArgs.
  15. /// </summary>
  16. [DataField]
  17. public float AmountThreshold = 1f;
  18. /// <summary>
  19. /// Slot to spawn the item into.
  20. /// </summary>
  21. [DataField(required: true)]
  22. public string Slot;
  23. /// <summary>
  24. /// Prototype ID of item to spawn.
  25. /// </summary>
  26. [DataField(required: true)]
  27. public string PrototypeID;
  28. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => null;
  29. public override void Effect(EntityEffectBaseArgs args)
  30. {
  31. // SpawnItemInSlot returns false if slot is already occupied
  32. if (args.EntityManager.System<InventorySystem>().SpawnItemInSlot(args.TargetEntity, Slot, PrototypeID))
  33. {
  34. if (args is EntityEffectReagentArgs reagentArgs)
  35. {
  36. if (reagentArgs.Reagent == null || reagentArgs.Quantity < AmountThreshold)
  37. return;
  38. reagentArgs.Source?.RemoveReagent(reagentArgs.Reagent.ID, AmountThreshold);
  39. }
  40. }
  41. }
  42. }