1
0

VentriloquistPuppetSystem.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Content.Server.Ghost.Roles.Components;
  2. using Content.Server.Popups;
  3. using Content.Shared.Interaction.Events;
  4. using Content.Shared.Puppet;
  5. using Content.Server.Speech.Muting;
  6. using Content.Shared.CombatMode;
  7. using Content.Shared.Hands;
  8. using Content.Shared.Speech.Muting;
  9. namespace Content.Server.Puppet
  10. {
  11. public sealed class VentriloquistPuppetSystem : SharedVentriloquistPuppetSystem
  12. {
  13. [Dependency] private readonly PopupSystem _popupSystem = default!;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. SubscribeLocalEvent<VentriloquistPuppetComponent, DroppedEvent>(OnDropped);
  18. SubscribeLocalEvent<VentriloquistPuppetComponent, UseInHandEvent>(OnUseInHand);
  19. SubscribeLocalEvent<VentriloquistPuppetComponent, GotUnequippedHandEvent>(OnUnequippedHand);
  20. }
  21. /// <summary>
  22. /// When used user inserts hand into dummy and the dummy can speak, when used again the user removes hand
  23. /// from dummy and the dummy cannot speak.
  24. /// </summary>
  25. private void OnUseInHand(EntityUid uid, VentriloquistPuppetComponent component, UseInHandEvent args)
  26. {
  27. if (args.Handled)
  28. return;
  29. // TODO stop using mute component as a toggle for this component's functionality.
  30. // TODO disable dummy when the user dies or cannot interact.
  31. // Then again, this is all quite cursed code, so maybe its a cursed ventriloquist puppet.
  32. if (!RemComp<MutedComponent>(uid))
  33. {
  34. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-remove-hand"), uid, args.User);
  35. MuteDummy(uid, component);
  36. return;
  37. }
  38. // TODO why does this need a combat component???
  39. EnsureComp<CombatModeComponent>(uid);
  40. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-insert-hand"), uid, args.User);
  41. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-inserted-hand"), uid, uid);
  42. if (!HasComp<GhostTakeoverAvailableComponent>(uid))
  43. {
  44. AddComp<GhostTakeoverAvailableComponent>(uid);
  45. var ghostRole = EnsureComp<GhostRoleComponent>(uid);
  46. ghostRole.RoleName = Loc.GetString("ventriloquist-puppet-role-name");
  47. ghostRole.RoleDescription = Loc.GetString("ventriloquist-puppet-role-description");
  48. }
  49. args.Handled = true;
  50. }
  51. /// <summary>
  52. /// When dropped the dummy is muted again.
  53. /// </summary>
  54. private void OnDropped(EntityUid uid, VentriloquistPuppetComponent component, DroppedEvent args)
  55. {
  56. if (HasComp<MutedComponent>(uid))
  57. return;
  58. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-remove-hand"), uid, args.User);
  59. MuteDummy(uid, component);
  60. }
  61. /// <summary>
  62. /// When unequipped from a hand slot the dummy is muted again.
  63. /// </summary>
  64. private void OnUnequippedHand(EntityUid uid, VentriloquistPuppetComponent component, GotUnequippedHandEvent args)
  65. {
  66. if (HasComp<MutedComponent>(uid))
  67. return;
  68. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-remove-hand"), uid, args.User);
  69. MuteDummy(uid, component);
  70. }
  71. /// <summary>
  72. /// Mutes the dummy.
  73. /// </summary>
  74. private void MuteDummy(EntityUid uid, VentriloquistPuppetComponent component)
  75. {
  76. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-removed-hand"), uid, uid);
  77. EnsureComp<MutedComponent>(uid);
  78. RemComp<CombatModeComponent>(uid);
  79. RemComp<GhostTakeoverAvailableComponent>(uid);
  80. }
  81. }
  82. }