Пример #1
0
    private void SendEntitySpeak(EntityUid source, string message, bool hideChat = false)
    {
        if (!_actionBlocker.CanSpeak(source))
        {
            return;
        }
        message = TransformSpeech(source, message);

        (message, var channel) = GetRadioPrefix(source, message);

        if (channel != null)
        {
            _listener.PingListeners(source, message, channel);
        }

        var messageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",
                                        ("entityName", Name(source)));

        SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat);

        var ev = new EntitySpokeEvent(message);

        RaiseLocalEvent(source, ev);
        _adminLogger.Add(LogType.Chat, LogImpact.Low, $"Say from {ToPrettyString(source):user}: {message}");
    }
Пример #2
0
    private void SendEntityWhisper(EntityUid source, string message, bool hideChat = false)
    {
        if (!_actionBlocker.CanSpeak(source))
        {
            return;
        }

        message = TransformSpeech(source, message);
        var obfuscatedMessage = ObfuscateMessageReadability(message, 0.2f);

        var transformSource = Transform(source);
        var sourceCoords    = transformSource.Coordinates;
        var messageWrap     = Loc.GetString("chat-manager-entity-whisper-wrap-message",
                                            ("entityName", Name(source)));

        var xforms = GetEntityQuery <TransformComponent>();
        var ghosts = GetEntityQuery <GhostComponent>();

        var sessions = new List <ICommonSession>();

        ClientDistanceToList(source, VoiceRange, sessions);

        // Whisper needs these special calculations, since it can obfuscate the message.
        foreach (var session in sessions)
        {
            if (session.AttachedEntity is not {
                Valid: true
            } playerEntity)
            {
                continue;
            }

            var transformEntity = xforms.GetComponent(playerEntity);

            if (sourceCoords.InRange(EntityManager, transformEntity.Coordinates, WhisperRange) ||
                ghosts.HasComponent(playerEntity))
            {
                _chatManager.ChatMessageToOne(ChatChannel.Whisper, message, messageWrap, source, hideChat, session.ConnectedClient);
            }
            else
            {
                _chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, messageWrap, source, hideChat,
                                              session.ConnectedClient);
            }
        }

        var ev = new EntitySpokeEvent(message);

        RaiseLocalEvent(source, ev, false);
        _adminLogger.Add(LogType.Chat, LogImpact.Low, $"Whisper from {ToPrettyString(source):user}: {message}");
    }
        private void OnEntitySpoke(EntityUid uid, SharedSpeechComponent component, EntitySpokeEvent args)
        {
            if (component.SpeechSounds == null)
            {
                return;
            }

            var currentTime = _gameTiming.CurTime;
            var cooldown    = TimeSpan.FromSeconds(component.SoundCooldownTime);

            // Ensure more than the cooldown time has passed since last speaking
            if (currentTime - component.LastTimeSoundPlayed < cooldown)
            {
                return;
            }

            // Play speech sound
            string contextSound;
            var    prototype = _protoManager.Index <SpeechSoundsPrototype>(component.SpeechSounds);
            var    message   = args.Message;

            // Different sounds for ask/exclaim based on last character
            switch (args.Message[^ 1])