CluwneSystem.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Content.Server.Administration.Commands;
  2. using Content.Server.Popups;
  3. using Content.Shared.Popups;
  4. using Content.Shared.Mobs;
  5. using Content.Server.Chat;
  6. using Content.Server.Chat.Systems;
  7. using Content.Shared.Chat.Prototypes;
  8. using Robust.Shared.Random;
  9. using Content.Shared.Stunnable;
  10. using Content.Shared.Damage.Prototypes;
  11. using Content.Shared.Damage;
  12. using Robust.Shared.Prototypes;
  13. using Content.Server.Emoting.Systems;
  14. using Content.Server.Speech.EntitySystems;
  15. using Content.Shared.Cluwne;
  16. using Content.Shared.Interaction.Components;
  17. using Robust.Shared.Audio.Systems;
  18. using Content.Shared.NameModifier.EntitySystems;
  19. using Content.Shared.Clumsy;
  20. namespace Content.Server.Cluwne;
  21. public sealed class CluwneSystem : EntitySystem
  22. {
  23. [Dependency] private readonly PopupSystem _popupSystem = default!;
  24. [Dependency] private readonly SharedAudioSystem _audio = default!;
  25. [Dependency] private readonly IRobustRandom _robustRandom = default!;
  26. [Dependency] private readonly SharedStunSystem _stunSystem = default!;
  27. [Dependency] private readonly DamageableSystem _damageableSystem = default!;
  28. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  29. [Dependency] private readonly ChatSystem _chat = default!;
  30. [Dependency] private readonly AutoEmoteSystem _autoEmote = default!;
  31. [Dependency] private readonly NameModifierSystem _nameMod = default!;
  32. public override void Initialize()
  33. {
  34. base.Initialize();
  35. SubscribeLocalEvent<CluwneComponent, ComponentStartup>(OnComponentStartup);
  36. SubscribeLocalEvent<CluwneComponent, MobStateChangedEvent>(OnMobState);
  37. SubscribeLocalEvent<CluwneComponent, EmoteEvent>(OnEmote, before:
  38. new[] { typeof(VocalSystem), typeof(BodyEmotesSystem) });
  39. SubscribeLocalEvent<CluwneComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
  40. }
  41. /// <summary>
  42. /// On death removes active comps and gives genetic damage to prevent cloning, reduce this to allow cloning.
  43. /// </summary>
  44. private void OnMobState(EntityUid uid, CluwneComponent component, MobStateChangedEvent args)
  45. {
  46. if (args.NewMobState == MobState.Dead)
  47. {
  48. RemComp<CluwneComponent>(uid);
  49. RemComp<ClumsyComponent>(uid);
  50. RemComp<AutoEmoteComponent>(uid);
  51. var damageSpec = new DamageSpecifier(_prototypeManager.Index<DamageGroupPrototype>("Genetic"), 300);
  52. _damageableSystem.TryChangeDamage(uid, damageSpec);
  53. }
  54. }
  55. public EmoteSoundsPrototype? EmoteSounds;
  56. /// <summary>
  57. /// OnStartup gives the cluwne outfit, ensures clumsy, and makes sure emote sounds are laugh.
  58. /// </summary>
  59. private void OnComponentStartup(EntityUid uid, CluwneComponent component, ComponentStartup args)
  60. {
  61. if (component.EmoteSoundsId == null)
  62. return;
  63. _prototypeManager.TryIndex(component.EmoteSoundsId, out EmoteSounds);
  64. EnsureComp<AutoEmoteComponent>(uid);
  65. _autoEmote.AddEmote(uid, "CluwneGiggle");
  66. EnsureComp<ClumsyComponent>(uid);
  67. _popupSystem.PopupEntity(Loc.GetString("cluwne-transform", ("target", uid)), uid, PopupType.LargeCaution);
  68. _audio.PlayPvs(component.SpawnSound, uid);
  69. _nameMod.RefreshNameModifiers(uid);
  70. SetOutfitCommand.SetOutfit(uid, "CluwneGear", EntityManager);
  71. }
  72. /// <summary>
  73. /// Handles the timing on autoemote as well as falling over and honking.
  74. /// </summary>
  75. private void OnEmote(EntityUid uid, CluwneComponent component, ref EmoteEvent args)
  76. {
  77. if (args.Handled)
  78. return;
  79. args.Handled = _chat.TryPlayEmoteSound(uid, EmoteSounds, args.Emote);
  80. if (_robustRandom.Prob(component.GiggleRandomChance))
  81. {
  82. _audio.PlayPvs(component.SpawnSound, uid);
  83. _chat.TrySendInGameICMessage(uid, "honks", InGameICChatType.Emote, ChatTransmitRange.Normal);
  84. }
  85. else if (_robustRandom.Prob(component.KnockChance))
  86. {
  87. _audio.PlayPvs(component.KnockSound, uid);
  88. _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(component.ParalyzeTime), true);
  89. _chat.TrySendInGameICMessage(uid, "spasms", InGameICChatType.Emote, ChatTransmitRange.Normal);
  90. }
  91. }
  92. /// <summary>
  93. /// Applies "Cluwnified" prefix
  94. /// </summary>
  95. private void OnRefreshNameModifiers(Entity<CluwneComponent> entity, ref RefreshNameModifiersEvent args)
  96. {
  97. args.AddModifier("cluwne-name-prefix");
  98. }
  99. }