Example #1
0
        /// <summary>
        /// Submits a keyword to generate a response from the current recipient
        /// Accessed by the UI
        /// </summary>
        /// <param name="keyword"></param>
        public void SubmitMessage(string keyword)
        {
            // make sure we are chatting with someone
            if (CurrentRecipient == null)
            {
                return;
            }

            // see if we can find the keyword in the auto fill
            string completedKeyword = autofill.Find(match => match.ToLower().StartsWith(keyword.ToLower()) == true);

            if (completedKeyword != null)
            {
                keyword = completedKeyword;
            }

            // find a tidbit containing the keyword
            Tidbit tidbit = CurrentRecipient.GetComponent <Customer>().GetKnownTidbit(keyword);

            // add our keyword to the history
            AddToHistory("Me: Know anything about " + keyword + "?");

            // build a response and also add it to our history
            AddToHistory(CurrentRecipient.name + ": " + BuildResponse(keyword, tidbit));

            // disable the input box if we have no more turns left
            inputTextBox.SetActive(!clock.Tick());
        }
Example #2
0
        /// <summary>
        /// Finds a tidbit containing data
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Matching tidbit</returns>
        public Tidbit GetKnownTidbit(string data)
        {
            // create a list of all matching tidbits
            var matchingTidbits = knownTidbits.FindAll(tidbit => tidbit.AttributeName.ToLower() == data.ToLower() ||
                                                       tidbit.AttributeType.ToLower() == data.ToLower() ||
                                                       tidbit.AttributePreference.ToString().ToLower() == data.ToLower() ||
                                                       tidbit.CustomerName.ToLower() == data.ToLower());

            // if we can't find any matches, output an empty tidbit
            if (matchingTidbits.Count == 0)
            {
                return(Tidbit.Empty());
            }

            // pick a random one to output
            return(matchingTidbits[Random.Range(0, matchingTidbits.Count - 1)]);
        }
Example #3
0
        /// <summary>
        /// Builds a response with the given keyword and tidbit
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="tidbit"></param>
        /// <returns></returns>
        string BuildResponse(string keyword, Tidbit tidbit)
        {
            // allow a bit of variation when we don't have any information to share
            string[] emptyResponses = new string[] { "No idea", "Nope", "I don't know", "Haven't got a clue", "Not sure about that one" };

            if (keyword == CurrentRecipient.name)
            {
                return("That's me!");
            }
            else if (tidbit.IsEmpty())
            {
                return(emptyResponses[Random.Range(0, emptyResponses.Length - 1)]);
            }
            else
            {
                return(tidbit.CustomerName + " " + tidbit.AttributePreference + " " + tidbit.AttributeName + ".");
            }
        }