forked from SerbiaStrong-220/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ss220 telepathy (SerbiaStrong-220#1233)
* 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
1 parent
69bb814
commit 3988f32
Showing
14 changed files
with
249 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Content.Server/SS220/Chat/Command/Telepathy/TelepathyCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Content.Shared/SS220/Telepathy/TelepathyChannelPrototype.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- type: telepathyChannel | ||
id: TelepathyChannelYogSothothCult | ||
name: chat-telepathy-yogsothothcult |