mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-19 14:38:36 +03:00
# Description UniversalLanguageSpeakerComponent has NUMEROUS issues, which previously were easy to ignore since it was a language only obtainable by Admins. But now that it's both a Psionic Power(And a trait that adds said power), the issues with it have been highlighted. Here's just a FEW 1. UniversalLanguageSpeaker overwrites all known languages, preventing you from speaking anything else 2. It overwrites the ability to use sign language. 3. It also overwrites the Mute trait. To fix that, I've made it follow *MOSTLY* the logic all the other languages use, so that it's less of a special snowflake case. Now if you have access to it, it will appear in your language list alongside other languages, rather than fully replacing the entire list. That way you can intentionally choose not to speak in a language understood by all. Fuck it, I also added the ability for the TraitSystem to just call LanguageSystem and directly add arbitrarily any desired language, rather than needing a component to do so. # Changelog 🆑 - fix: UniversalLanguageSpeaker(And Xenoglossy by extension) will now appear in your language menu alongside other known languages, rather than replace all known languages. You can effectively now choose whether or not to speak it, or to use a normal language. - add: Traits can now add Languages directly. - add: Traits can now remove Languages directly. --------- Signed-off-by: VMSolidus <evilexecutive@gmail.com> Co-authored-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Co-authored-by: FoxxoTrystan <45297731+FoxxoTrystan@users.noreply.github.com> Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using Content.Server.Language.Events;
|
|
using Content.Server.Mind;
|
|
using Content.Shared.Language;
|
|
using Content.Shared.Language.Components;
|
|
using Content.Shared.Language.Events;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mind.Components;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.Language;
|
|
|
|
public sealed partial class LanguageSystem
|
|
{
|
|
[Dependency] private readonly MindSystem _mind = default!;
|
|
|
|
|
|
public void InitializeNet()
|
|
{
|
|
SubscribeNetworkEvent<LanguagesSetMessage>(OnClientSetLanguage);
|
|
SubscribeNetworkEvent<RequestLanguagesMessage>((_, session) => SendLanguageStateToClient(session.SenderSession));
|
|
|
|
SubscribeLocalEvent<LanguageSpeakerComponent, LanguagesUpdateEvent>((uid, comp, _) => SendLanguageStateToClient(uid, comp));
|
|
|
|
// Refresh the client's state when its mind hops to a different entity
|
|
SubscribeLocalEvent<MindContainerComponent, MindAddedMessage>((uid, _, _) => SendLanguageStateToClient(uid));
|
|
SubscribeLocalEvent<MindComponent, MindGotRemovedEvent>((_, _, args) =>
|
|
{
|
|
if (args.Mind.Comp.Session != null)
|
|
SendLanguageStateToClient(args.Mind.Comp.Session);
|
|
});
|
|
}
|
|
|
|
|
|
private void OnClientSetLanguage(LanguagesSetMessage message, EntitySessionEventArgs args)
|
|
{
|
|
if (args.SenderSession.AttachedEntity is not { Valid: true } uid)
|
|
return;
|
|
|
|
var language = GetLanguagePrototype(message.CurrentLanguage);
|
|
if (language == null || !CanSpeak(uid, language.ID))
|
|
return;
|
|
|
|
SetLanguage(uid, language.ID);
|
|
}
|
|
|
|
private void SendLanguageStateToClient(EntityUid uid, LanguageSpeakerComponent? comp = null)
|
|
{
|
|
// Try to find a mind inside the entity and notify its session
|
|
if (!_mind.TryGetMind(uid, out _, out var mindComp) || mindComp.Session == null)
|
|
return;
|
|
|
|
SendLanguageStateToClient(uid, mindComp.Session, comp);
|
|
}
|
|
|
|
private void SendLanguageStateToClient(ICommonSession session, LanguageSpeakerComponent? comp = null)
|
|
{
|
|
// Try to find an entity associated with the session and resolve the languages from it
|
|
if (session.AttachedEntity is not { Valid: true } entity)
|
|
return;
|
|
|
|
SendLanguageStateToClient(entity, session, comp);
|
|
}
|
|
|
|
// TODO this is really stupid and can be avoided if we just make everything shared...
|
|
private void SendLanguageStateToClient(EntityUid uid, ICommonSession session, LanguageSpeakerComponent? component = null)
|
|
{
|
|
var message = !Resolve(uid, ref component, logMissing: false)
|
|
? new LanguagesUpdatedMessage(UniversalPrototype, [UniversalPrototype], [UniversalPrototype])
|
|
: new LanguagesUpdatedMessage(component.CurrentLanguage, component.SpokenLanguages, component.UnderstoodLanguages);
|
|
|
|
RaiseNetworkEvent(message, session);
|
|
}
|
|
}
|