Skip to content

Commit

Permalink
Ss220 telepathy (SerbiaStrong-220#1233)
Browse files Browse the repository at this point in the history
* Add basic telepathy action

* Add action handler

* Fix action init

* Add telepathy chanel

* Add telepathy chanel

* Renamed event

* Add tests entities

* Add check if sender can send message

* Delete action

* Only right entities receive message

* Add command to do announce in telepathy channel

* Delete command

* Finals fixes

* fix

* Add localization for telepathy channel

* Change message wrapping for telepathy

* Delete testing stuff

* Add chat-box local for telepathy
  • Loading branch information
NailMinnigalin authored Jul 5, 2024
1 parent 69bb814 commit 3988f32
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Content.Client/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public void SendMessage(string text, ChatSelectChannel channel)
_consoleHost.ExecuteCommand($"whisper \"{CommandParsing.Escape(str)}\"");
break;

//ss220-telepathy-begin
case ChatSelectChannel.Telepathy:
_consoleHost.ExecuteCommand($"telepathy \"{CommandParsing.Escape(str)}\"");
break;
//ss220-telepathy-end

default:
throw new ArgumentOutOfRangeException(nameof(channel), channel, null);
}
Expand Down
17 changes: 15 additions & 2 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Content.Shared.Decals;
using Content.Shared.Input;
using Content.Shared.Radio;
using Content.Shared.SS220.Telepathy;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
Expand Down Expand Up @@ -79,7 +80,9 @@ public sealed class ChatUIController : UIController
{SharedChatSystem.EmotesAltPrefix, ChatSelectChannel.Emotes},
{SharedChatSystem.AdminPrefix, ChatSelectChannel.Admin},
{SharedChatSystem.RadioCommonPrefix, ChatSelectChannel.Radio},
{SharedChatSystem.DeadPrefix, ChatSelectChannel.Dead}
{SharedChatSystem.DeadPrefix, ChatSelectChannel.Dead},
//ss220-telepathy
{SharedChatSystem.TelepathyChannelPrefix, ChatSelectChannel.Telepathy}
};

public static readonly Dictionary<ChatSelectChannel, char> ChannelPrefixes = new()
Expand All @@ -92,7 +95,9 @@ public sealed class ChatUIController : UIController
{ChatSelectChannel.Emotes, SharedChatSystem.EmotesPrefix},
{ChatSelectChannel.Admin, SharedChatSystem.AdminPrefix},
{ChatSelectChannel.Radio, SharedChatSystem.RadioCommonPrefix},
{ChatSelectChannel.Dead, SharedChatSystem.DeadPrefix}
{ChatSelectChannel.Dead, SharedChatSystem.DeadPrefix},
//ss220-telepathy
{ChatSelectChannel.Telepathy, SharedChatSystem.TelepathyChannelPrefix}
};

/// <summary>
Expand Down Expand Up @@ -554,6 +559,14 @@ private void UpdateChannelPermissions()
CanSendChannels |= ChatSelectChannel.Admin;
}

//ss220-telepathy-begin
if (_ent.HasComponent<TelepathyComponent>(_player.LocalEntity))
{
FilterableChannels |= ChatChannel.Telepathy;
CanSendChannels |= ChatSelectChannel.Telepathy;
}
//ss220-telepathy-end

SelectableChannels = CanSendChannels;

// Necessary so that we always have a channel to fall back to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public sealed partial class ChannelFilterPopup : Popup
ChatChannel.Whisper,
ChatChannel.Emotes,
ChatChannel.Radio,
//ss220-telepathy
ChatChannel.Telepathy,
ChatChannel.Notifications,
ChatChannel.LOOC,
ChatChannel.OOC,
Expand Down
12 changes: 11 additions & 1 deletion Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Content.Shared.Players;
using Content.Shared.Radio;
using Content.Shared.Speech;
using Content.Shared.SS220.Telepathy;
using Content.Shared.Whitelist;
using Robust.Server.Player;
using Robust.Shared.Audio;
Expand Down Expand Up @@ -260,6 +261,13 @@ public void TrySendInGameICMessage(
case InGameICChatType.Emote:
SendEntityEmote(source, message, range, nameOverride, hideLog: hideLog, ignoreActionBlocker: ignoreActionBlocker);
break;

//ss220-telepathy-begin
case InGameICChatType.Telepathy:
if (TryComp(source, out TelepathyComponent? telepathyComponent) && telepathyComponent.CanSend)
RaiseLocalEvent(source, new TelepathySendEvent() { Message = message });
break;
//ss220-telepathy-end
}
}

Expand Down Expand Up @@ -971,7 +979,9 @@ public enum InGameICChatType : byte
{
Speak,
Emote,
Whisper
Whisper,
//ss220-telepathy
Telepathy
}

/// <summary>
Expand Down
51 changes: 51 additions & 0 deletions Content.Server/SS220/Chat/Command/Telepathy/TelepathyCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Server.Chat.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.Enums;

namespace Content.Server.SS220.Chat.Command.Telepathy;

[AnyCommand]
public sealed class TelepathyCommand : IConsoleCommand
{
public string Command => "telepathy";
public string Description => "Send message through the power of mind";
public string Help => $"{Command} <text>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player is not { } player)
{
shell.WriteError("This command cannot be run from the server.");
return;
}

if (player.Status != SessionStatus.InGame)
return;

if (player.AttachedEntity is not {} playerEntity)
{
shell.WriteError("You don't have an entity!");
return;
}

if (args.Length < 1)
return;

var message = string.Join(" ", args).Trim();
if (string.IsNullOrEmpty(message))
return;

IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>()
.TrySendInGameICMessage(
playerEntity,
message,
InGameICChatType.Telepathy,
ChatTransmitRange.HideChat,
false,
shell,
player
);
}
}
93 changes: 93 additions & 0 deletions Content.Server/SS220/Telepathy/TelepathySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Server.Chat.Systems;
using Content.Shared.Chat;
using Content.Shared.SS220.Telepathy;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Utility;

namespace Content.Server.SS220.Telepathy;

/// <summary>
/// This handles events related to sending messages over the telepathy channel
/// </summary>
public sealed class TelepathySystem : EntitySystem
{
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TelepathyComponent, TelepathySendEvent>(OnTelepathySend);
SubscribeLocalEvent<TelepathyComponent, TelepathyAnnouncementSendEvent>(OnTelepathyAnnouncementSend);
}

private void OnTelepathyAnnouncementSend(EntityUid uid, TelepathyComponent component, TelepathyAnnouncementSendEvent args)
{
SendMessageToEveryoneWithRightChannel(args.TelepathyChannel, args.Message, null);
}

private void OnTelepathySend(EntityUid senderUid, TelepathyComponent component, TelepathySendEvent args)
{
if (!HasComp<TelepathyComponent>(senderUid))
return;

SendMessageToEveryoneWithRightChannel(component.TelepathyChannelPrototype, args.Message, senderUid);
}

private void SendMessageToEveryoneWithRightChannel(string rightTelepathyChanel, string message, EntityUid? senderUid)
{
var telepathyQuery = EntityQueryEnumerator<TelepathyComponent>();
while (telepathyQuery.MoveNext(out var receiverUid, out var receiverTelepathy))
{
if (rightTelepathyChanel == receiverTelepathy.TelepathyChannelPrototype)
SendMessageToChat(receiverUid, message, senderUid);
}
}


private void SendMessageToChat(EntityUid receiverUid, string messageString, EntityUid? senderUid)
{
var name = GetSenderName(senderUid);

var netSource = _entityManager.GetNetEntity(receiverUid);
var wrappedMessage = GetWrappedTelepathyMessage(receiverUid, messageString, senderUid);
var message = new ChatMessage(
ChatChannel.Telepathy,
messageString,
wrappedMessage,
netSource,
null
);
if (TryComp(receiverUid, out ActorComponent? actor))
_netMan.ServerSendMessage(new MsgChatMessage() {Message = message}, actor.PlayerSession.Channel);
}

private string GetWrappedTelepathyMessage(EntityUid receiverUid, string messageString, EntityUid? senderUid)
{
if (senderUid == null)
{
return Loc.GetString(
"chat-manager-send-telepathy-announce",
("announce", FormattedMessage.EscapeText(messageString))
);
}

return Loc.GetString(
"chat-manager-send-telepathy-message",
("message", FormattedMessage.EscapeText(messageString)),
("senderName", GetSenderName(senderUid))
);
}

private string GetSenderName(EntityUid? senderUid)
{
var nameEv = new TransformSpeakerNameEvent(senderUid!.Value, Name(senderUid.Value));
RaiseLocalEvent(senderUid.Value, nameEv);
var name = nameEv.Name;
return name;
}
}
5 changes: 4 additions & 1 deletion Content.Shared/Chat/ChatChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public enum ChatChannel : ushort
/// </summary>
Unspecified = 1 << 14,

//ss220-telepathy
Telepathy = 1 << 15,

/// <summary>
/// Channels considered to be IC.
/// </summary>
IC = Local | Whisper | Radio | Dead | Emotes | Damage | Visual | Notifications,
IC = Local | Whisper | Radio | Dead | Emotes | Damage | Visual | Notifications | Telepathy,

AdminRelated = Admin | AdminAlert | AdminChat,
}
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/Chat/ChatSelectChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public enum ChatSelectChannel : ushort
/// </summary>
Admin = ChatChannel.AdminChat,

//ss220-telepathy
Telepathy = ChatChannel.Telepathy,

Console = ChatChannel.Unspecified
}
}
2 changes: 2 additions & 0 deletions Content.Shared/Chat/SharedChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public abstract class SharedChatSystem : EntitySystem
public const char WhisperPrefix = ',';
public const char EmotesAltPrefix = '*';
public const char DefaultChannelKey = 'р';
//ss220-telepathy
public const char TelepathyChannelPrefix = '|';

[ValidatePrototypeId<RadioChannelPrototype>]
public const string CommonChannel = "Common";
Expand Down
25 changes: 25 additions & 0 deletions Content.Shared/SS220/Telepathy/TelepathyChannelPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Robust.Shared.Prototypes;

namespace Content.Shared.SS220.Telepathy;

[Prototype("telepathyChannel")]
public sealed partial class TelepathyChannelPrototype : IPrototype
{
/// <summary>
/// Human-readable name for the channel.
/// </summary>
[DataField("name")]
public string Name { get; private set; } = string.Empty;

[ViewVariables(VVAccess.ReadOnly)]
public string LocalizedName => Loc.GetString(Name);


[DataField("color")]
public Color Color { get; private set; } = Color.Lime;

[IdDataField, ViewVariables]
public string ID { get; } = default!;
}
30 changes: 30 additions & 0 deletions Content.Shared/SS220/Telepathy/TelepathyComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Shared.Actions;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.SS220.Telepathy;

/// <summary>
/// This is used for giving telepathy ability
/// </summary>
[RegisterComponent]
public sealed partial class TelepathyComponent : Component
{
[DataField("canSend", required: true)]
public bool CanSend;

[DataField("telepathyChannelPrototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<TelepathyChannelPrototype>))]
public string TelepathyChannelPrototype;
}

public sealed partial class TelepathySendEvent : InstantActionEvent
{
public string Message { get; init; }
}

public sealed partial class TelepathyAnnouncementSendEvent : InstantActionEvent
{
public string Message { get; init; }
public string TelepathyChannel { get; init; }
}
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/chat/managers/chat-manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ chat-manager-send-admin-dead-chat-wrap-message = { $adminChannelName }: [bold]([
chat-manager-send-admin-chat-wrap-message = { $adminChannelName }: [bold]{ $playerName }:[/bold] { $message }
chat-manager-send-admin-announcement-wrap-message = [bold]{ $adminChannelName }: { $message }[/bold]
chat-manager-send-hook-ooc-wrap-message = OOC: [bold](D){ $senderName }:[/bold] { $message }
chat-manager-send-telepathy-message = [color=purple]Эхо разума { $senderName }: { $message }[/color]
chat-manager-send-telepathy-announce = [color=purple]Эхо разума: { $announce }[/color]
chat-manager-dead-channel-name = МЁРТВЫЕ
chat-manager-admin-channel-name = АДМИН
chat-manager-rate-limited = Вы отправляете сообщения слишком быстро!
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/chat/ui/chat-box.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ hud-chatbox-select-channel-OOC = OOC
hud-chatbox-select-channel-Damage = Повреждения
hud-chatbox-select-channel-Visual = Действия
hud-chatbox-select-channel-Radio = Рация
hud-chatbox-select-channel-Telepathy = Телепатия
hud-chatbox-channel-Admin = Админ Разное
hud-chatbox-channel-AdminAlert = Админ Уведомления
hud-chatbox-channel-AdminChat = Админ Чат
hud-chatbox-channel-Telepathy = Телепатия
hud-chatbox-channel-Dead = Мёртвые
hud-chatbox-channel-Emotes = Эмоции
hud-chatbox-channel-Local = Рядом
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/SS220/telepahy_channels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- type: telepathyChannel
id: TelepathyChannelYogSothothCult
name: chat-telepathy-yogsothothcult

0 comments on commit 3988f32

Please sign in to comment.