Add popup message extension for players in range except for the source (#1962)

This commit is contained in:
DrSmugleaf
2020-08-30 11:28:46 +02:00
committed by GitHub
parent 827eab17d0
commit 9ec3ddf368
6 changed files with 100 additions and 79 deletions

View File

@@ -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<string>());
}
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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}

View File

@@ -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
{
/// <summary>
/// Pops up a message for every player around <see cref="source"/> to see,
/// except for <see cref="source"/> itself.
/// </summary>
/// <param name="source">The entity on which to popup the message.</param>
/// <param name="message">The message to show.</param>
/// <param name="range">
/// The range in which to search for players, defaulting to one screen.
/// </param>
public static void PopupMessageOtherClients(this IEntity source, string message, int range = 15)
{
var playerManager = IoCManager.Resolve<IPlayerManager>();
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);
}
}
}
}

View File

@@ -35,9 +35,26 @@ namespace Content.Shared.Interfaces
public static class NotifyManagerExt
{
/// <summary>
/// Pops up a message at the location of <see cref="source"/> for
/// <see cref="viewer"/> alone to see.
/// </summary>
/// <param name="source">The entity above which the message will appear.</param>
/// <param name="viewer">The entity that will see the message.</param>
/// <param name="message">The message to show.</param>
public static void PopupMessage(this IEntity source, IEntity viewer, string message)
{
IoCManager.Resolve<ISharedNotifyManager>().PopupMessage(source, viewer, message);
}
/// <summary>
/// Pops up a message at the given entity's location for it alone to see.
/// </summary>
/// <param name="viewer">The entity that will see the message.</param>
/// <param name="message">The message to be seen.</param>
public static void PopupMessage(this IEntity viewer, string message)
{
viewer.PopupMessage(viewer, message);
}
}
}