mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description This significantly improves the quality of the language system by fixing the mistakes I've made almost a year ago while developing it. Mainly, this throws away the old half-broken way of networking in favor of the component state system provided by RT. Language speaker comp is now shared with SendOnlyToOwner = true, and its state is handled manually. In addition to that, this brings the following changes: - UniversalLanguageSpeaker and LanguageKnowledge are now server-side - DetermineLanguagesEvent and LanguagesUpdateEvent are now shared (so that future systems can be built in shared, if needed) - Everything now uses the ProtoId<LanguagePrototype> type instead of raw strings (god, I hated those so much) - The server-side language system now accepts Entity<T?> arguments instead of EntityUid + T - UniversalLanguageSpeaker is now based on DetermineEntityLanguagesEvent and gets an Enabled field, which allows to turn it off. This may have some use in the future. - Some minor cleanup <!-- TODO MEDIA <details><summary><h1>Media</h1></summary> <p>  </p> </details> --> # Changelog No cl --------- Co-authored-by: VMSolidus <evilexecutive@gmail.com>
75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using Content.Server.Administration;
|
|
using Content.Server.Language;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Emoting;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Language.Components;
|
|
using Content.Shared.Language.Systems;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Speech;
|
|
using Robust.Shared.Console;
|
|
|
|
namespace Content.Server.Mind.Commands
|
|
{
|
|
[AdminCommand(AdminFlags.Admin)]
|
|
public sealed class MakeSentientCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
|
|
public string Command => "makesentient";
|
|
public string Description => "Makes an entity sentient (able to be controlled by a player)";
|
|
public string Help => "makesentient <entity id>";
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length != 1)
|
|
{
|
|
shell.WriteLine("Wrong number of arguments.");
|
|
return;
|
|
}
|
|
|
|
if (!NetEntity.TryParse(args[0], out var entNet) || !_entManager.TryGetEntity(entNet, out var entId))
|
|
{
|
|
shell.WriteLine("Invalid argument.");
|
|
return;
|
|
}
|
|
|
|
if (!_entManager.EntityExists(entId))
|
|
{
|
|
shell.WriteLine("Invalid entity specified!");
|
|
return;
|
|
}
|
|
|
|
MakeSentient(entId.Value, _entManager, true, true);
|
|
}
|
|
|
|
public static void MakeSentient(EntityUid uid, IEntityManager entityManager, bool allowMovement = true, bool allowSpeech = true)
|
|
{
|
|
entityManager.EnsureComponent<MindContainerComponent>(uid);
|
|
if (allowMovement)
|
|
{
|
|
entityManager.EnsureComponent<InputMoverComponent>(uid);
|
|
entityManager.EnsureComponent<MobMoverComponent>(uid);
|
|
entityManager.EnsureComponent<MovementSpeedModifierComponent>(uid);
|
|
}
|
|
|
|
if (allowSpeech)
|
|
{
|
|
entityManager.EnsureComponent<SpeechComponent>(uid);
|
|
entityManager.EnsureComponent<EmotingComponent>(uid);
|
|
|
|
var language = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();
|
|
var speaker = entityManager.EnsureComponent<LanguageSpeakerComponent>(uid);
|
|
|
|
// If the entity already speaks some language (like monkey or robot), we do nothing else
|
|
// Otherwise, we give them the fallback language
|
|
if (speaker.SpokenLanguages.Count == 0)
|
|
language.AddLanguage(uid, SharedLanguageSystem.FallbackLanguagePrototype);
|
|
}
|
|
|
|
entityManager.EnsureComponent<ExaminerComponent>(uid);
|
|
}
|
|
}
|
|
}
|