mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-21 23:48:15 +03:00
# Description The language PR was merged early and OH GOD I ALREADY REGRET IT This PR is intended to provide the missing refactors and address the issues that were missed due to the early merge. --- # TODO - [X] Introduced a polymorphic obfuscation property to the LanguagePrototype - now it supports more than just 2 hardcoded methods, and each method can be configured per-language. Currently there are 3 obfuscation methods: replacement (same as replacement accent), obuscation by syllables and obfuscation by phrases. - [X] Refactored the existing obfuscation methods to not be a big hardcoded mess. - [X] Updated the existing languages accordingly: animalistic languages are now less of an unreadable mess and include less syllables. Certain languages like binary and snake seriously benefit from that. - [X] Refactored the existing commands in response to the never-addressed review (it got lost among hundreds of others) - [X] Refactored the commands to be more user-friendly (you can now use the number of the language in saylang and languageselect which can allow using keybinds to switch between languages) - [X] Moved a lot of obfuscation-related stuff from server to shared. The actual obfuscation process, however, is still done on the server. That may or may not be subject to change, too. - [X] Refactored the entire process of resolution of entities' languages. Instead of raising an event every time it's required to learn what languages an entity knows, the lists of ALL languages available to the entity (including via translators) is stored in LanguageSpeakerComponent and only updated when necessary (e.g. when a translator gets toggled). The list of languages the entity knows on its own is now stored in LanguageKnowledgeComponent. - [X] Made handheld translators automatically change your current language when activated. - [X] Rewrote the translator implanter system, now using the real implants and implanters - [ ] Rebalance science stuff (translators are incredibly expensive for what they're worth) - [ ] Uhhh stuff --- <details><summary><h1>Media</h1></summary> <p> N/A for now </p> </details> --- # Changelog 🆑 - tweak: Translator implants are now proper implants that can be removed. - tweak: Animalistic languages should now look less messy. - fix: Hopefully fixed language menu desync and other issues. --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com>
127 lines
4.4 KiB
C#
127 lines
4.4 KiB
C#
using Content.Server.Chat.Systems;
|
|
using Content.Server.Emp;
|
|
using Content.Server.Language;
|
|
using Content.Server.Radio.Components;
|
|
using Content.Server.Speech;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Radio;
|
|
using Content.Shared.Radio.Components;
|
|
using Content.Shared.Radio.EntitySystems;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
public sealed class HeadsetSystem : SharedHeadsetSystem
|
|
{
|
|
[Dependency] private readonly INetManager _netMan = default!;
|
|
[Dependency] private readonly RadioSystem _radio = default!;
|
|
[Dependency] private readonly LanguageSystem _language = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<HeadsetComponent, RadioReceiveEvent>(OnHeadsetReceive);
|
|
SubscribeLocalEvent<HeadsetComponent, EncryptionChannelsChangedEvent>(OnKeysChanged);
|
|
|
|
SubscribeLocalEvent<WearingHeadsetComponent, EntitySpokeEvent>(OnSpeak);
|
|
|
|
SubscribeLocalEvent<HeadsetComponent, EmpPulseEvent>(OnEmpPulse);
|
|
}
|
|
|
|
private void OnKeysChanged(EntityUid uid, HeadsetComponent component, EncryptionChannelsChangedEvent args)
|
|
{
|
|
UpdateRadioChannels(uid, component, args.Component);
|
|
}
|
|
|
|
private void UpdateRadioChannels(EntityUid uid, HeadsetComponent headset, EncryptionKeyHolderComponent? keyHolder = null)
|
|
{
|
|
// make sure to not add ActiveRadioComponent when headset is being deleted
|
|
if (!headset.Enabled || MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
|
|
return;
|
|
|
|
if (!Resolve(uid, ref keyHolder))
|
|
return;
|
|
|
|
if (keyHolder.Channels.Count == 0)
|
|
RemComp<ActiveRadioComponent>(uid);
|
|
else
|
|
EnsureComp<ActiveRadioComponent>(uid).Channels = new(keyHolder.Channels);
|
|
}
|
|
|
|
private void OnSpeak(EntityUid uid, WearingHeadsetComponent component, EntitySpokeEvent args)
|
|
{
|
|
if (args.Channel != null
|
|
&& TryComp(component.Headset, out EncryptionKeyHolderComponent? keys)
|
|
&& keys.Channels.Contains(args.Channel.ID))
|
|
{
|
|
_radio.SendRadioMessage(uid, args.Message, args.Channel, component.Headset);
|
|
args.Channel = null; // prevent duplicate messages from other listeners.
|
|
}
|
|
}
|
|
|
|
protected override void OnGotEquipped(EntityUid uid, HeadsetComponent component, GotEquippedEvent args)
|
|
{
|
|
base.OnGotEquipped(uid, component, args);
|
|
if (component.IsEquipped && component.Enabled)
|
|
{
|
|
EnsureComp<WearingHeadsetComponent>(args.Equipee).Headset = uid;
|
|
UpdateRadioChannels(uid, component);
|
|
}
|
|
}
|
|
|
|
protected override void OnGotUnequipped(EntityUid uid, HeadsetComponent component, GotUnequippedEvent args)
|
|
{
|
|
base.OnGotUnequipped(uid, component, args);
|
|
component.IsEquipped = false;
|
|
RemComp<ActiveRadioComponent>(uid);
|
|
RemComp<WearingHeadsetComponent>(args.Equipee);
|
|
}
|
|
|
|
public void SetEnabled(EntityUid uid, bool value, HeadsetComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (component.Enabled == value)
|
|
return;
|
|
|
|
if (!value)
|
|
{
|
|
RemCompDeferred<ActiveRadioComponent>(uid);
|
|
|
|
if (component.IsEquipped)
|
|
RemCompDeferred<WearingHeadsetComponent>(Transform(uid).ParentUid);
|
|
}
|
|
else if (component.IsEquipped)
|
|
{
|
|
EnsureComp<WearingHeadsetComponent>(Transform(uid).ParentUid).Headset = uid;
|
|
UpdateRadioChannels(uid, component);
|
|
}
|
|
}
|
|
|
|
private void OnHeadsetReceive(EntityUid uid, HeadsetComponent component, ref RadioReceiveEvent args)
|
|
{
|
|
var parent = Transform(uid).ParentUid;
|
|
if (TryComp(parent, out ActorComponent? actor))
|
|
{
|
|
var canUnderstand = _language.CanUnderstand(parent, args.Language.ID);
|
|
var msg = new MsgChatMessage
|
|
{
|
|
Message = canUnderstand ? args.OriginalChatMsg : args.LanguageObfuscatedChatMsg
|
|
};
|
|
_netMan.ServerSendMessage(msg, actor.PlayerSession.Channel);
|
|
}
|
|
}
|
|
|
|
private void OnEmpPulse(EntityUid uid, HeadsetComponent component, ref EmpPulseEvent args)
|
|
{
|
|
if (component.Enabled)
|
|
{
|
|
args.Affected = true;
|
|
args.Disabled = true;
|
|
}
|
|
}
|
|
}
|