1
0

DevourSystem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Server.Body.Components;
  2. using Content.Server.Body.Systems;
  3. using Content.Shared.Chemistry.Components;
  4. using Content.Shared.Devour;
  5. using Content.Shared.Devour.Components;
  6. using Content.Shared.Humanoid;
  7. namespace Content.Server.Devour;
  8. public sealed class DevourSystem : SharedDevourSystem
  9. {
  10. [Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<DevourerComponent, DevourDoAfterEvent>(OnDoAfter);
  15. SubscribeLocalEvent<DevourerComponent, BeingGibbedEvent>(OnGibContents);
  16. }
  17. private void OnDoAfter(EntityUid uid, DevourerComponent component, DevourDoAfterEvent args)
  18. {
  19. if (args.Handled || args.Cancelled)
  20. return;
  21. var ichorInjection = new Solution(component.Chemical, component.HealRate);
  22. if (component.FoodPreference == FoodPreference.All ||
  23. (component.FoodPreference == FoodPreference.Humanoid && HasComp<HumanoidAppearanceComponent>(args.Args.Target)))
  24. {
  25. ichorInjection.ScaleSolution(0.5f);
  26. if (component.ShouldStoreDevoured && args.Args.Target is not null)
  27. {
  28. ContainerSystem.Insert(args.Args.Target.Value, component.Stomach);
  29. }
  30. _bloodstreamSystem.TryAddToChemicals(uid, ichorInjection);
  31. }
  32. //TODO: Figure out a better way of removing structures via devour that still entails standing still and waiting for a DoAfter. Somehow.
  33. //If it's not human, it must be a structure
  34. else if (args.Args.Target != null)
  35. {
  36. QueueDel(args.Args.Target.Value);
  37. }
  38. _audioSystem.PlayPvs(component.SoundDevour, uid);
  39. }
  40. private void OnGibContents(EntityUid uid, DevourerComponent component, ref BeingGibbedEvent args)
  41. {
  42. if (!component.ShouldStoreDevoured)
  43. return;
  44. // For some reason we have two different systems that should handle gibbing,
  45. // and for some another reason GibbingSystem, which should empty all containers, doesn't get involved in this process
  46. ContainerSystem.EmptyContainer(component.Stomach);
  47. }
  48. }