SharedBodySystem.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Shared.Damage;
  2. using Content.Shared.Movement.Systems;
  3. using Content.Shared.Standing;
  4. using Robust.Shared.Containers;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Timing;
  7. namespace Content.Shared.Body.Systems;
  8. public abstract partial class SharedBodySystem : EntitySystem
  9. {
  10. /*
  11. * See the body partial for how this works.
  12. */
  13. /// <summary>
  14. /// Container ID prefix for any body parts.
  15. /// </summary>
  16. public const string PartSlotContainerIdPrefix = "body_part_slot_";
  17. /// <summary>
  18. /// Container ID for the ContainerSlot on the body entity itself.
  19. /// </summary>
  20. public const string BodyRootContainerId = "body_root_part";
  21. /// <summary>
  22. /// Container ID prefix for any body organs.
  23. /// </summary>
  24. public const string OrganSlotContainerIdPrefix = "body_organ_slot_";
  25. [Dependency] private readonly IGameTiming _timing = default!;
  26. [Dependency] protected readonly IPrototypeManager Prototypes = default!;
  27. [Dependency] protected readonly DamageableSystem Damageable = default!;
  28. [Dependency] protected readonly MovementSpeedModifierSystem Movement = default!;
  29. [Dependency] protected readonly SharedContainerSystem Containers = default!;
  30. [Dependency] protected readonly SharedTransformSystem SharedTransform = default!;
  31. [Dependency] protected readonly StandingStateSystem Standing = default!;
  32. public override void Initialize()
  33. {
  34. base.Initialize();
  35. InitializeBody();
  36. InitializeParts();
  37. }
  38. /// <summary>
  39. /// Inverse of <see cref="GetPartSlotContainerId"/>
  40. /// </summary>
  41. protected static string? GetPartSlotContainerIdFromContainer(string containerSlotId)
  42. {
  43. // This is blursed
  44. var slotIndex = containerSlotId.IndexOf(PartSlotContainerIdPrefix, StringComparison.Ordinal);
  45. if (slotIndex < 0)
  46. return null;
  47. var slotId = containerSlotId.Remove(slotIndex, PartSlotContainerIdPrefix.Length);
  48. return slotId;
  49. }
  50. /// <summary>
  51. /// Gets the container Id for the specified slotId.
  52. /// </summary>
  53. public static string GetPartSlotContainerId(string slotId)
  54. {
  55. return PartSlotContainerIdPrefix + slotId;
  56. }
  57. /// <summary>
  58. /// Gets the container Id for the specified slotId.
  59. /// </summary>
  60. public static string GetOrganContainerId(string slotId)
  61. {
  62. return OrganSlotContainerIdPrefix + slotId;
  63. }
  64. }