Example #1
0
        public static ChatNode FromString(string input, out string remaining_input)
        {
            var node = new ChatNode();
            int i = input.IndexOf(':');
            string tag = input.Substring(0, i++).Trim();
            input = input.Substring(i, input.Length - i);

            node.Tag = tag;

            i = input.IndexOf('(') + 1;
            int k = input.IndexOf(')') - i;
            string line = input.Substring(i, k);
            input = input.Remove(i - 1, k + 2);

            node.Comment = Line.FromString(line);
            List<ChatNode> children = new List<ChatNode>();
            while ((input = input.Trim())[0] != ';')
            {
                string rem_input;
                children.Add(FromString(input, out rem_input));
                input = rem_input;
            }
            node.Children = children.ToArray();
            remaining_input = new String(input.Skip(1).ToArray());
            return node;
        }
Example #2
0
        public static ChatNode FromString(string input, out string remaining_input)
        {
            var    node = new ChatNode();
            int    i    = input.IndexOf(':');
            string tag  = input.Substring(0, i++).Trim();

            input = input.Substring(i, input.Length - i);

            node.Tag = tag;

            i = input.IndexOf('(') + 1;
            int    k    = input.IndexOf(')') - i;
            string line = input.Substring(i, k);

            input = input.Remove(i - 1, k + 2);

            node.Comment = Line.FromString(line);
            List <ChatNode> children = new List <ChatNode>();

            while ((input = input.Trim())[0] != ';')
            {
                string rem_input;
                children.Add(FromString(input, out rem_input));
                input = rem_input;
            }
            node.Children   = children.ToArray();
            remaining_input = new String(input.Skip(1).ToArray());
            return(node);
        }
Example #3
0
        static void Main(string[] args)
        {
            SpVoice voice = new SpVoice();

            foreach (SpObjectToken sp in voice.GetVoices())
            {
                Console.WriteLine(sp.GetDescription());
            }

            Stack <Interest> Dialogue = new Stack <Interest>();
            Queue <Voice>    talkers  = new Queue <Voice>();

            talkers.Enqueue(new Voice {
                Name = "Bao Dur", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Bao-Dur.txt"))
            });
            talkers.Enqueue(new Voice {
                Name = "Kreia", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Kreia.txt"))
            });
            talkers.Enqueue(new Voice {
                Name = "Exile", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Exile.txt"))
            });
            //talkers.Enqueue(new Voice { Name = "WHO", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Who.txt")) });
            Voice[] ppl = talkers.ToArray();

            Random rand = new Random();

            /* Add a point of Interest.  These could be raised by finding items, doing quests, ect. */
            Dialogue.Push(new Interest {
                Tags = new string[1] {
                    "Greeting"
                }
            });


            Module.GetString = (path) =>
            {
                var arpath = path.ToLower().Split('/');
                if (arpath[0] == "last")
                {
                    var ln = Dialogue.Peek() as Line;
                    if (ln != null)
                    {
                        return(ln.Author.GetString(arpath[1]));
                    }
                }
                return("");
            };
            string[] current_topic = null;
            string   response_name = null;
            Line     response      = null;

            while (
                //TODO -- Find the Person with the highest level of interest.
                talkers.Any(talker =>
                            talker.HasInterest(current_topic = Dialogue.Peek().Tags, TOLERANCE) &&
                            !Dialogue.Contains(response = talker._root.VoiceInterest(current_topic)) &&
                            (response_name = talker.Name) != null && /*OH MY GOD YOU LAZY GIT*/
                            (response.Author = talker) != null
                            )
                )
            {
                var strng = response.Output.Select(l => l.Resolve()).Aggregate((a, b) => a + b);
                Console.WriteLine(String.Format("{0}: {1}", response_name, strng));
                voice.Speak(strng);
                Dialogue.Push(response);
                // Oh god, Stop me, please.
                // Just re-queues the talkers in random order
                // I really don't need a Queue anymore, I should just access an enumerable in a random fashion
                talkers.Enqueue(talkers.Dequeue());

                /*talkers.Clear();
                 * var numbs = Enumerable.Range(0, ppl.Length).ToList();
                 * while (numbs.Any())
                 * {
                 *  int i = rand.Next(numbs.Count());
                 *  int ind = numbs.ElementAt(i);
                 *  numbs.RemoveAt(i);
                 *  talkers.Enqueue(ppl[ind]);
                 * }*/
            }
            Console.ReadLine();
        }