Example #1
0
    /// <summary>
    /// Processes a message to be used in the chat log and chat bubbles.
    /// 1. Detects which modifiers should be present in the messages.
    ///    - Some of the modifiers will come from the player being unconcious, being a clown, etc.
    ///    - Other modifiers are voluntary, such as shouting. They normally cannot override involuntary modifiers.
    ///    - Certain emotes override each other and will never be present at the same time.
    ///      - Emote overrides whispering, and whispering overrides yelling.
    /// 2. Modifies the message to match the previously detected modifiers.
    ///    - Stutters, honks, drunkenness, etc. are directly applied to the message.
    ///    - The chat log and chat bubble may add minor changes to the text, such as narration ("Player says, ...").
    /// </summary>
    /// <param name="sendByPlayer">The player sending the message. Used for detecting conciousness and occupation.</param>
    /// <param name="message">The chat message to process.</param>
    /// <returns>A tuple of the processed chat message and the detected modifiers.</returns>
    private static (string, ChatModifier) ProcessMessage(ConnectedPlayer sentByPlayer, string message)
    {
        ChatModifier   chatModifiers        = ChatModifier.None; // Modifier that will be returned in the end.
        ConsciousState playerConsciousState = ConsciousState.DEAD;

        if (sentByPlayer.Script == null)
        {
            return(message, chatModifiers);
        }

        if (sentByPlayer.Script.playerHealth != null)
        {
            playerConsciousState = sentByPlayer.Script.playerHealth.ConsciousState;
        }

        //Semi should be able to speak as health shouldnt affect them
        if (sentByPlayer.Script.IsPlayerSemiGhost)
        {
            playerConsciousState = ConsciousState.CONSCIOUS;
        }

        if (playerConsciousState == ConsciousState.UNCONSCIOUS || playerConsciousState == ConsciousState.DEAD)
        {
            // Only the Mute modifier matters if the player cannot speak. We can skip everything else.
            return(message, ChatModifier.Mute);
        }

        // Emote
        if (message.StartsWith("*") || message.StartsWith("/me ", true, CultureInfo.CurrentCulture))
        {
            //Note : This is stupid but it's the only way I could find a way to make this work
            //We shouldn't have to check twice in different functions just to have a reference of the player who did the emote.
            if (CheckForEmoteAction(message, Instance.emoteActionManager))
            {
                playerGameObject = sentByPlayer.GameObject;
            }
            message        = message.Replace("/me", ""); // note that there is no space here as compared to the above if
            message        = message.Substring(1);       // so that this substring can properly cut off both * and the space
            chatModifiers |= ChatModifier.Emote;
        }
        // Whisper
        else if (message.StartsWith("#") || message.StartsWith("/w ", true, CultureInfo.CurrentCulture))
        {
            message        = message.Replace("/w", "");
            message        = message.Substring(1);
            chatModifiers |= ChatModifier.Whisper;
        }
        // Sing
        else if (message.StartsWith("%") || message.StartsWith("/s ", true, CultureInfo.CurrentCulture))
        {
            message        = message.Replace("/s", "");
            message        = message.Substring(1);
            message        = Sing(message);
            chatModifiers |= ChatModifier.Sing;
        }
        // Involuntaly whisper due to not being fully concious
        else if (playerConsciousState == ConsciousState.BARELY_CONSCIOUS)
        {
            chatModifiers |= ChatModifier.Whisper;
        }
        // Yell
        else if ((message == message.ToUpper(CultureInfo.InvariantCulture) &&      // Is it all caps?
                  message.Any(char.IsLetter)))            // AND does it contain at least one letter?
        {
            chatModifiers |= ChatModifier.Yell;
        }
        // Question
        else if (message.EndsWith("?"))
        {
            chatModifiers |= ChatModifier.Question;
        }
        // Exclaim
        else if (message.EndsWith("!"))
        {
            chatModifiers |= ChatModifier.Exclaim;
        }

        // Assign character trait speech mods
        //TODO Assigning from character creation for now, they exclude each others
        chatModifiers |= Instance.CharacterSpeech[sentByPlayer.Script.characterSettings.Speech];

        //TODO Assign racial speech mods

        // Assign inventory speech mods
        chatModifiers |= sentByPlayer.Script.mind.inventorySpeechModifiers;

        /////// Process Speech mutations
        message = SpeechModManager.Instance.ApplyMod(chatModifiers, message);

        return(message, chatModifiers);
    }
Example #2
0
    /// <summary>
    /// Processes a message to be used in the chat log and chat bubbles.
    /// 1. Detects which modifiers should be present in the messages.
    ///    - Some of the modifiers will come from the player being unconcious, being a clown, etc.
    ///    - Other modifiers are voluntary, such as shouting. They normally cannot override involuntary modifiers.
    ///    - Certain emotes override each other and will never be present at the same time.
    ///      - Emote overrides whispering, and whispering overrides yelling.
    /// 2. Modifies the message to match the previously detected modifiers.
    ///    - Stutters, honks, drunkenness, etc. are directly applied to the message.
    ///    - The chat log and chat bubble may add minor changes to the text, such as narration ("Player says, ...").
    /// </summary>
    /// <param name="sendByPlayer">The player sending the message. Used for detecting conciousness and occupation.</param>
    /// <param name="message">The chat message to process.</param>
    /// <returns>A tuple of the processed chat message and the detected modifiers.</returns>
    private static (string, ChatModifier) ProcessMessage(ConnectedPlayer sentByPlayer, string message)
    {
        ChatModifier   chatModifiers        = ChatModifier.None; // Modifier that will be returned in the end.
        ConsciousState playerConsciousState = ConsciousState.DEAD;

        if (sentByPlayer.Script == null)
        {
            return(message, chatModifiers);
        }

        if (sentByPlayer.Script.playerHealth != null)
        {
            playerConsciousState = sentByPlayer.Script.playerHealth.ConsciousState;
        }

        if (playerConsciousState == ConsciousState.UNCONSCIOUS || playerConsciousState == ConsciousState.DEAD)
        {
            // Only the Mute modifier matters if the player cannot speak. We can skip everything else.
            return(message, ChatModifier.Mute);
        }

        // Emote
        if (message.StartsWith("/me "))
        {
            message        = message.Substring(4);
            chatModifiers |= ChatModifier.Emote;
        }
        // Whisper
        else if (message.StartsWith("#"))
        {
            message        = message.Substring(1);
            chatModifiers |= ChatModifier.Whisper;
        }
        // Involuntaly whisper due to not being fully concious
        else if (playerConsciousState == ConsciousState.BARELY_CONSCIOUS)
        {
            chatModifiers |= ChatModifier.Whisper;
        }
        // Yell
        else if ((message == message.ToUpper(CultureInfo.InvariantCulture) &&      // Is it all caps?
                  message.Any(char.IsLetter)))         // AND does it contain at least one letter?
        {
            chatModifiers |= ChatModifier.Yell;
        }
        // Question
        else if (message.EndsWith("?"))
        {
            chatModifiers |= ChatModifier.Question;
        }
        // Exclaim
        else if (message.EndsWith("!"))
        {
            chatModifiers |= ChatModifier.Exclaim;
        }

        // Clown
        if (sentByPlayer.Script.mind != null &&
            sentByPlayer.Script.mind.occupation != null &&
            sentByPlayer.Script.mind.occupation.JobType == JobType.CLOWN)
        {
            int intensity = UnityEngine.Random.Range(1, 4);
            for (int i = 0; i < intensity; i++)
            {
                message += " HONK!";
            }
            chatModifiers |= ChatModifier.Clown;
        }

        // TODO None of the followinger modifiers are currently in use.
        // They have been commented out to prevent compile warnings.

        // Stutter
        //if (false) // TODO Currently players can not stutter.
        //{
        //	//Stuttering people randomly repeat beginnings of words
        //	//Regex - find word boundary followed by non digit, non special symbol, non end of word letter. Basically find the start of words.
        //	Regex rx = new Regex(@"(\b)+([^\d\W])\B");
        //	message = rx.Replace(message, Stutter);
        //	chatModifiers |= ChatModifier.Stutter;
        //}
        //
        //// Hiss
        //if (false) // TODO Currently players can never speak like a snek.
        //{
        //	Regex rx = new Regex("s+|S+");
        //	message = rx.Replace(message, Hiss);
        //	chatModifiers |= ChatModifier.Hiss;
        //}
        //
        //// Drunk
        //if (false) // TODO Currently players can not get drunk.
        //{
        //	//Regex - find 1 or more "s"
        //	Regex rx = new Regex("s+|S+");
        //	message = rx.Replace(message, Slur);
        //	//Regex - find 1 or more whitespace
        //	rx = new Regex(@"\s+");
        //	message = rx.Replace(message, Hic);
        //	//50% chance to ...hic!... at end of sentance
        //	if (UnityEngine.Random.Range(1, 3) == 1)
        //	{
        //		message = message + " ...hic!...";
        //	}
        //	chatModifiers |= ChatModifier.Drunk;
        //}

        return(message, chatModifiers);
    }
    public static HealthConsciousMessage Send(GameObject recipient, GameObject entityToUpdate, ConsciousState consciousState)
    {
        HealthConsciousMessage msg = new HealthConsciousMessage
        {
            EntityToUpdate = entityToUpdate.GetComponent <NetworkIdentity>().netId,
            ConsciousState = consciousState
        };

        msg.SendTo(recipient);
        return(msg);
    }
 private void SyncConsciousState(ConsciousState oldConsciousState, ConsciousState newConsciousState)
 {
     consciousState = newConsciousState;
 }
 public void SetConsciousState(ConsciousState newConsciousState)
 {
     consciousState = newConsciousState;
 }
    public static HealthOverallMessage SendToAll(GameObject entityToUpdate, int overallHealth, ConsciousState consciousState, UI_PressureAlert.PressureChecker pressureStatus, UI_TempAlert.TempChecker tempStatus)
    {
        HealthOverallMessage msg = new HealthOverallMessage
        {
            EntityToUpdate = entityToUpdate.GetComponent <NetworkIdentity>().netId,
            OverallHealth  = overallHealth,
            ConsciousState = consciousState,
            PressureStatus = pressureStatus,
            TempStatus     = tempStatus,
        };

        msg.SendToAll();
        return(msg);
    }
Example #7
0
    public static HealthOverallMessage SendToAll(GameObject entityToUpdate, int overallHealth, ConsciousState consciousState)
    {
        HealthOverallMessage msg = new HealthOverallMessage
        {
            EntityToUpdate = entityToUpdate.GetComponent <NetworkIdentity>().netId,
            OverallHealth  = overallHealth,
            ConsciousState = consciousState
        };

        msg.SendToAll();
        return(msg);
    }
	private void OnConsciousStateChange(ConsciousState oldState, ConsciousState newState)
	{
		if (!CanPlayerStillProgress()) InterruptProgress("performer not conscious enough");
	}