mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description Due to some inherent limitations of maintenance, code review, and me having both severely crippling ADHD and a lifelong adderal dependency, I've made the executive decision to break apart the Psionic Refactor into a multitude of smaller, bite sized PRs. I'm keeping the original Psionic Refactor PR open, because I'm going to need it for code reference to keep track of the changes I had originally worked on, but I need to essentially restart the entire refactor from scratch, and approach it from a new angle that's going to make everything actually way easier. I also need to be able to work on each available system individually wherever possible, and this fact is most readily shown by how the Lightning Refactor and Oracle Refactor were both done separately. To start off, this PR is ONLY moving all of the relevant psionics code to core folders, and nothing more. I'm doing this first so that I can immediately cut down massively on the "Files Changed" with the simplest, most basic change necessary to start my work. No changelog because this isn't player facing, and no media because there's literally nothing to show.
129 lines
5.0 KiB
C#
129 lines
5.0 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Administration.Managers;
|
|
using Content.Server.Chat.Managers;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Shared.Abilities.Psionics;
|
|
using Content.Shared.Bed.Sleep;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Drugs;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Psionics.Glimmer;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Random;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Content.Server.Chat
|
|
{
|
|
/// <summary>
|
|
/// Extensions for Telepathic chat stuff
|
|
/// </summary>
|
|
|
|
public sealed class TelepathicChatSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IAdminManager _adminManager = default!;
|
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly GlimmerSystem _glimmerSystem = default!;
|
|
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
|
private IEnumerable<INetChannel> GetPsionicChatClients()
|
|
{
|
|
return Filter.Empty()
|
|
.AddWhereAttachedEntity(IsEligibleForTelepathy)
|
|
.Recipients
|
|
.Select(p => p.ConnectedClient);
|
|
}
|
|
|
|
private IEnumerable<INetChannel> GetAdminClients()
|
|
{
|
|
return _adminManager.ActiveAdmins
|
|
.Select(p => p.ConnectedClient);
|
|
}
|
|
|
|
private List<INetChannel> GetDreamers(IEnumerable<INetChannel> removeList)
|
|
{
|
|
var filtered = Filter.Empty()
|
|
.AddWhereAttachedEntity(entity => HasComp<SleepingComponent>(entity) || HasComp<SeeingRainbowsComponent>(entity) && !HasComp<PsionicsDisabledComponent>(entity) && !HasComp<PsionicInsulationComponent>(entity))
|
|
.Recipients
|
|
.Select(p => p.ConnectedClient);
|
|
|
|
var filteredList = filtered.ToList();
|
|
|
|
foreach (var entity in removeList)
|
|
filteredList.Remove(entity);
|
|
|
|
return filteredList;
|
|
}
|
|
|
|
private bool IsEligibleForTelepathy(EntityUid entity)
|
|
{
|
|
return HasComp<PsionicComponent>(entity)
|
|
&& !HasComp<PsionicsDisabledComponent>(entity)
|
|
&& !HasComp<PsionicInsulationComponent>(entity)
|
|
&& (!TryComp<MobStateComponent>(entity, out var mobstate) || mobstate.CurrentState == MobState.Alive);
|
|
}
|
|
|
|
public void SendTelepathicChat(EntityUid source, string message, bool hideChat)
|
|
{
|
|
if (!IsEligibleForTelepathy(source))
|
|
return;
|
|
|
|
var clients = GetPsionicChatClients();
|
|
var admins = GetAdminClients();
|
|
string messageWrap;
|
|
string adminMessageWrap;
|
|
|
|
messageWrap = Loc.GetString("chat-manager-send-telepathic-chat-wrap-message",
|
|
("telepathicChannelName", Loc.GetString("chat-manager-telepathic-channel-name")), ("message", message));
|
|
|
|
adminMessageWrap = Loc.GetString("chat-manager-send-telepathic-chat-wrap-message-admin",
|
|
("source", source), ("message", message));
|
|
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Telepathic chat from {ToPrettyString(source):Player}: {message}");
|
|
|
|
_chatManager.ChatMessageToMany(ChatChannel.Telepathic, message, messageWrap, source, hideChat, true, clients.ToList(), Color.PaleVioletRed);
|
|
|
|
_chatManager.ChatMessageToMany(ChatChannel.Telepathic, message, adminMessageWrap, source, hideChat, true, admins, Color.PaleVioletRed);
|
|
|
|
if (_random.Prob(0.1f))
|
|
_glimmerSystem.Glimmer++;
|
|
|
|
if (_random.Prob(Math.Min(0.33f + ((float) _glimmerSystem.Glimmer / 1500), 1)))
|
|
{
|
|
float obfuscation = (0.25f + (float) _glimmerSystem.Glimmer / 2000);
|
|
var obfuscated = ObfuscateMessageReadability(message, obfuscation);
|
|
_chatManager.ChatMessageToMany(ChatChannel.Telepathic, obfuscated, messageWrap, source, hideChat, false, GetDreamers(clients), Color.PaleVioletRed);
|
|
}
|
|
|
|
foreach (var repeater in EntityQuery<TelepathicRepeaterComponent>())
|
|
{
|
|
_chatSystem.TrySendInGameICMessage(repeater.Owner, message, InGameICChatType.Speak, false);
|
|
}
|
|
}
|
|
|
|
private string ObfuscateMessageReadability(string message, float chance)
|
|
{
|
|
var modifiedMessage = new StringBuilder(message);
|
|
|
|
for (var i = 0; i < message.Length; i++)
|
|
{
|
|
if (char.IsWhiteSpace((modifiedMessage[i])))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (_random.Prob(1 - chance))
|
|
{
|
|
modifiedMessage[i] = '~';
|
|
}
|
|
}
|
|
|
|
return modifiedMessage.ToString();
|
|
}
|
|
}
|
|
}
|