diff --git a/Content.Server/Chat/ChatCommands.cs b/Content.Server/Chat/ChatCommands.cs index 9450fa45fc..a309a344f0 100644 --- a/Content.Server/Chat/ChatCommands.cs +++ b/Content.Server/Chat/ChatCommands.cs @@ -8,6 +8,7 @@ using Content.Server.Interfaces.GameObjects; using Content.Server.Interfaces; using Content.Server.Observer; using Content.Server.Players; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Damage; using Content.Shared.Interfaces; using Robust.Server.Interfaces.Console; @@ -190,30 +191,19 @@ namespace Content.Server.Chat } } } + // Default suicide, bite your tongue - PopupMessageOtherClientsInRange(owner, Loc.GetString("{0:theName} is attempting to bite {0:their} own tongue!", owner), 15); - _notifyManager.PopupMessage(owner, owner, Loc.GetString("You attempt to bite your own tongue!")); + var othersMessage = Loc.GetString("{0:theName} is attempting to bite {0:their} own tongue!", owner); + owner.PopupMessageOtherClients(othersMessage); + + var selfMessage = Loc.GetString("You attempt to bite your own tongue!"); + owner.PopupMessage(selfMessage); + dmgComponent.ChangeDamage(DamageType.Piercing, 500, true, owner); // Prevent the player from returning to the body. Yes, this is an ugly hack. var ghost = new Ghost(){CanReturn = false}; ghost.Execute(shell, player, Array.Empty()); } - private void PopupMessageOtherClientsInRange(IEntity source, string message, int maxReceiveDistance) - { - var viewers = _playerManager.GetPlayersInRange(source.Transform.GridPosition, maxReceiveDistance); - - foreach (var viewer in viewers) - { - var viewerEntity = viewer.AttachedEntity; - - if (viewerEntity == null || source == viewerEntity) - { - continue; - } - - source.PopupMessage(viewer.AttachedEntity, message); - } - } } } diff --git a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs index 5a5228cdbd..8987084e21 100644 --- a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs @@ -8,7 +8,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.GameObjects; -using Content.Server.GameObjects.EntitySystems.DoAfter; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Interactable; @@ -17,7 +17,6 @@ using Content.Shared.Interfaces; using Robust.Server.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; -using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -258,16 +257,31 @@ namespace Content.Server.GameObjects.Components.Interactable public SuicideKind Suicide(IEntity victim, IChatManager chat) { + string othersMessage; + string selfMessage; + if (TryWeld(5, victim, silent: true)) { PlaySoundCollection(WeldSoundCollection); - PopupMessageOtherClientsInRange(victim, Loc.GetString("{0:theName} welds {0:their} every orifice closed! It looks like {0:theyre} trying to commit suicide!", victim), 15); - _notifyManager.PopupMessage(victim, victim, Loc.GetString("You weld your every orifice closed!")); + + othersMessage = + Loc.GetString( + "{0:theName} welds {0:their} every orifice closed! It looks like {0:theyre} trying to commit suicide!", + victim); + victim.PopupMessageOtherClients(othersMessage); + + selfMessage = Loc.GetString("You weld your every orifice closed!"); + victim.PopupMessage(selfMessage); + return SuicideKind.Heat; } - PopupMessageOtherClientsInRange(victim, Loc.GetString("{0:theName} bashes themselves with the unlit welding torch!", victim), 15); - _notifyManager.PopupMessage(victim, victim, Loc.GetString("You bash yourself with the unlit welding torch!")); + othersMessage = Loc.GetString("{0:theName} bashes themselves with the unlit welding torch!", victim); + victim.PopupMessageOtherClients(othersMessage); + + selfMessage = Loc.GetString("You bash yourself with the unlit welding torch!"); + victim.PopupMessage(selfMessage); + return SuicideKind.Blunt; } @@ -275,22 +289,5 @@ namespace Content.Server.GameObjects.Components.Interactable { Dirty(); } - - private void PopupMessageOtherClientsInRange(IEntity source, string message, int maxReceiveDistance) - { - var viewers = _playerManager.GetPlayersInRange(source.Transform.GridPosition, maxReceiveDistance); - - foreach (var viewer in viewers) - { - var viewerEntity = viewer.AttachedEntity; - - if (viewerEntity == null || source == viewerEntity) - { - continue; - } - - source.PopupMessage(viewer.AttachedEntity, message); - } - } } } diff --git a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs index e3ba2687b3..c7ec8a84f1 100644 --- a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs @@ -500,29 +500,18 @@ namespace Content.Server.GameObjects.Components.Kitchen headCount++; } } - PopupMessageOtherClientsInRange(victim, Loc.GetString("{0:theName} is trying to cook {0:their} head!", victim), 15); - _notifyManager.PopupMessage(victim, victim, Loc.GetString("You cook your head!")); + + var othersMessage = Loc.GetString("{0:theName} is trying to cook {0:their} head!", victim); + victim.PopupMessageOtherClients(othersMessage); + + var selfMessage = Loc.GetString("You cook your head!"); + victim.PopupMessage(selfMessage); + _currentCookTimerTime = 10; ClickSound(); _uiDirty = true; wzhzhzh(); return SuicideKind.Heat; } - private void PopupMessageOtherClientsInRange(IEntity source, string message, int maxReceiveDistance) - { - var viewers = _playerManager.GetPlayersInRange(source.Transform.GridPosition, maxReceiveDistance); - - foreach (var viewer in viewers) - { - var viewerEntity = viewer.AttachedEntity; - - if (viewerEntity == null || source == viewerEntity) - { - continue; - } - - source.PopupMessage(viewer.AttachedEntity, message); - } - } } } diff --git a/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs b/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs index f04b50cff2..2b2cf18bbd 100644 --- a/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs @@ -17,6 +17,7 @@ using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; using System; +using Content.Server.Utility; namespace Content.Server.GameObjects.Components.Movement { @@ -207,8 +208,12 @@ namespace Content.Server.GameObjects.Components.Movement // we may potentially need additional logic since we're forcing a player onto a climbable // there's also the cases where the user might collide with the person they are forcing onto the climbable that i haven't accounted for - PopupMessageOtherClientsInRange(user, Loc.GetString("{0:theName} forces {1:theName} onto {2:theName}!", user, entityToMove, Owner), 15); - user.PopupMessage(user, Loc.GetString("You force {0:theName} onto {1:theName}!", entityToMove, Owner)); + var othersMessage = Loc.GetString("{0:theName} forces {1:theName} onto {2:theName}!", user, + entityToMove, Owner); + user.PopupMessageOtherClients(othersMessage); + + var selfMessage = Loc.GetString("You force {0:theName} onto {1:theName}!", entityToMove, Owner); + user.PopupMessage(selfMessage); } } @@ -243,25 +248,11 @@ namespace Content.Server.GameObjects.Components.Movement climbMode.TryMoveTo(user.Transform.WorldPosition, endPoint); - PopupMessageOtherClientsInRange(user, Loc.GetString("{0:theName} jumps onto {1:theName}!", user, Owner), 15); - user.PopupMessage(user, Loc.GetString("You jump onto {0:theName}!", Owner)); - } - } + var othersMessage = Loc.GetString("{0:theName} jumps onto {1:theName}!", user, Owner); + user.PopupMessageOtherClients(othersMessage); - private void PopupMessageOtherClientsInRange(IEntity source, string message, int maxReceiveDistance) - { - var viewers = _playerManager.GetPlayersInRange(source.Transform.GridPosition, maxReceiveDistance); - - foreach (var viewer in viewers) - { - var viewerEntity = viewer.AttachedEntity; - - if (viewerEntity == null || source == viewerEntity) - { - continue; - } - - source.PopupMessage(viewer.AttachedEntity, message); + var selfMessage = Loc.GetString("You jump onto {0:theName}!", Owner); + user.PopupMessage(selfMessage); } } diff --git a/Content.Server/Utility/NotifyExtensions.cs b/Content.Server/Utility/NotifyExtensions.cs new file mode 100644 index 0000000000..c617c25cbd --- /dev/null +++ b/Content.Server/Utility/NotifyExtensions.cs @@ -0,0 +1,37 @@ +using Content.Shared.Interfaces; +using Robust.Server.Interfaces.Player; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.IoC; + +namespace Content.Server.Utility +{ + public static class NotifyExtensions + { + /// + /// Pops up a message for every player around to see, + /// except for itself. + /// + /// The entity on which to popup the message. + /// The message to show. + /// + /// The range in which to search for players, defaulting to one screen. + /// + public static void PopupMessageOtherClients(this IEntity source, string message, int range = 15) + { + var playerManager = IoCManager.Resolve(); + var viewers = playerManager.GetPlayersInRange(source.Transform.GridPosition, range); + + foreach (var viewer in viewers) + { + var viewerEntity = viewer.AttachedEntity; + + if (viewerEntity == null || source == viewerEntity) + { + continue; + } + + source.PopupMessage(viewer.AttachedEntity, message); + } + } + } +} diff --git a/Content.Shared/Interfaces/ISharedNotifyManager.cs b/Content.Shared/Interfaces/ISharedNotifyManager.cs index 2dde0e7b50..c7d6adcd4f 100644 --- a/Content.Shared/Interfaces/ISharedNotifyManager.cs +++ b/Content.Shared/Interfaces/ISharedNotifyManager.cs @@ -35,9 +35,26 @@ namespace Content.Shared.Interfaces public static class NotifyManagerExt { + /// + /// Pops up a message at the location of for + /// alone to see. + /// + /// The entity above which the message will appear. + /// The entity that will see the message. + /// The message to show. public static void PopupMessage(this IEntity source, IEntity viewer, string message) { IoCManager.Resolve().PopupMessage(source, viewer, message); } + + /// + /// Pops up a message at the given entity's location for it alone to see. + /// + /// The entity that will see the message. + /// The message to be seen. + public static void PopupMessage(this IEntity viewer, string message) + { + viewer.PopupMessage(viewer, message); + } } }