Ejemplo n.º 1
0
        public void Update(StringTable table, int numEntries, byte[] data)
        {
            using (var stream = Bitstream.CreateWith(data)) {
                bool option = stream.ReadBool();
                if (option)
                {
                    throw new ArgumentException("Unknown option " + option);
                }

                List <string> keyHistory = new List <string>();

                uint entryId = UInt32.MaxValue;
                uint read    = 0;

                while (read < numEntries)
                {
                    if (!stream.ReadBool())
                    {
                        entryId = stream.ReadBits(table.EntryBits);
                    }
                    else
                    {
                        entryId = unchecked (entryId + 1);
                    }

                    Preconditions.CheckArgument(entryId < table.MaxEntries);

                    string key   = ReadKeyIfIncluded(stream, keyHistory);
                    byte[] value = ReadValueIfIncluded(stream, table.UserDataFixedSize,
                                                       table.UserDataSizeBits);

                    if (entryId < table.Count)
                    {
                        StringTable.Entry entry = table.Get(entryId);

                        if (key != null)
                        {
                            Preconditions.CheckArgument(key.Equals(entry.Key));
                        }

                        if (value != null)
                        {
                            entry.Value = value;
                        }
                    }
                    else
                    {
                        table.Put(entryId, new StringTable.Entry(key, value));
                    }

                    ++read;
                }
            }
        }
Ejemplo n.º 2
0
        private static void PrintNode(Conversation conversation, FlowChartLink parentLink, bool playAudio)
        {
            FlowChartNode node            = conversation.Nodes[parentLink.ToNodeID];
            var           dialogueNode    = node as DialogueNode;
            bool          keepParentBrief = (parentLink.PointsToGhost && dialogueNode != null && dialogueNode.IsQuestionNode);
            FlowChartNode briefNode       = (keepParentBrief ? conversation.Nodes[parentLink.FromNodeID] : node);

            Console.WriteLine("{0}", briefNode.GetBrief());

            FileInfo audioFile = ResourceLocator.FindVocalization(conversation.Tag, briefNode.NodeID);

            if (audioFile != null)
            {
                Console.Write("[audio] ");
            }

            StringTable.Entry text = conversation.FindText(briefNode.NodeID);
            if (text != null)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("{0}", text.Format());
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            Console.WriteLine("\n\n");

            if (node.Links.Count + node.ChildIDs.Count == 0)
            {
                if (node is TriggerConversationNode)
                {
                    Console.WriteLine("(End. Hit BACKSPACE to rewind or ENTER to load target conversation)");
                }
                else if (node.ContainerNodeID != -1)
                {
                    Console.WriteLine("(Hit BACKSPACE to rewind into container node)");
                }
                else
                {
                    Console.WriteLine("(End. Hit BACKSPACE to rewind)");
                }
            }
            else
            {
                for (int i = 0; i < node.Links.Count + node.ChildIDs.Count; i++)
                {
                    FlowChartNode targetNode;
                    bool          pointsToGhost = false;

                    if (i < node.Links.Count)
                    {
                        FlowChartLink link = node.Links[i];
                        pointsToGhost = link.PointsToGhost;
                        targetNode    = conversation.FindNode(link.ToNodeID);
                        Console.Write("({0}) {1} -> {2}", i + 1, link.GetBrief(), targetNode.GetBrief());
                    }
                    else
                    {
                        targetNode = conversation.FindNode(node.ChildIDs[i - node.Links.Count]);
                        Console.Write("({0}) [ child ] -> {1}", i + 1, targetNode.GetBrief());
                    }

                    if (targetNode is PlayerResponseNode && targetNode.Links.Count == 1)
                    {
                        Console.WriteLine(" -> {0}", conversation.FindNode(targetNode.Links[0].ToNodeID).GetBrief());
                    }
                    else
                    {
                        Console.WriteLine();
                    }

                    string condition = targetNode.Conditionals.Format();
                    if (condition.Length > 0)
                    {
                        Console.WriteLine("  if : {0}", condition);
                    }
                    foreach (var script in targetNode.OnEnterScripts)
                    {
                        Console.WriteLine("  on enter  : {0}", script.Format());
                    }
                    foreach (var script in targetNode.OnExitScripts)
                    {
                        Console.WriteLine("  on exit   : {0}", script.Format());
                    }
                    foreach (var script in targetNode.OnUpdateScripts)
                    {
                        Console.WriteLine("  on update : {0}", script.Format());
                    }

                    if (!pointsToGhost)
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    if (node.Links.Count + node.ChildIDs.Count == 1)
                    {
                        Console.WriteLine("[continue]");
                    }
                    else
                    {
                        if (ResourceLocator.FindVocalization(conversation.Tag, targetNode.NodeID) != null)
                        {
                            Console.Write("[audio] ");
                        }
                        text = conversation.FindText(targetNode.NodeID);
                        Console.WriteLine(text.Format());
                    }
                    if (!pointsToGhost)
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    Console.WriteLine("\n");
                }
            }

            if ((audioFile != null) && playAudio && (briefNode == node))
            {
                AudioServer.Play(audioFile);
            }
        }