Esempio n. 1
0
        /// <summary>
        /// Reads the values for this NPCChatDialogItemBase from an IValueReader.
        /// </summary>
        /// <param name="reader">IValueReader to read the values from.</param>
        protected void Read(IValueReader reader)
        {
            var id       = reader.ReadNPCChatDialogItemID("ID");
            var title    = reader.ReadString("Title");
            var text     = reader.ReadString("Text");
            var isBranch = reader.ReadBool("IsBranch");

            var responses = reader.ReadManyNodes("Responses", CreateResponse);

            NPCChatConditionalCollectionBase conditionals = null;

            if (isBranch)
            {
                var cReader         = reader.ReadNode("Conditionals");
                var hasConditionals = cReader.ReadBool("HasConditionals");
                if (hasConditionals)
                {
                    conditionals = CreateConditionalCollection();
                    if (conditionals != null)
                    {
                        conditionals.Read(cReader);
                    }
                }
            }

            SetReadValues(id, title, text, isBranch, responses, conditionals);

            AssertBranchHasTwoResponses();
            AssertNonBranchHasNoConditionals();
            AssertResponsesHaveValidValues();
        }
        /// <summary>
        /// Copies the values of this NPCChatConditionalCollectionBase to another NPCChatConditionalCollectionBase.
        /// </summary>
        /// <param name="dest">The NPCChatConditionalCollectionBase to copy the values into.</param>
        public void CopyValuesTo(NPCChatConditionalCollectionBase dest)
        {
            var stream = new BitStream(256);

            using (var writer = BinaryValueWriter.Create(stream))
            {
                Write(writer);
            }

            stream.PositionBits = 0;

            var reader = BinaryValueReader.Create(stream);

            dest.Read(reader);
        }
        /// <summary>
        /// Copies the values of this NPCChatConditionalCollectionBase to another NPCChatConditionalCollectionBase.
        /// </summary>
        /// <param name="dest">The NPCChatConditionalCollectionBase to copy the values into.</param>
        public void CopyValuesTo(NPCChatConditionalCollectionBase dest)
        {
            var stream = new BitStream(256);

            using (var writer = BinaryValueWriter.Create(stream))
            {
                Write(writer);
            }

            stream.PositionBits = 0;

            var reader = BinaryValueReader.Create(stream);

            dest.Read(reader);
        }
        /// <summary>
        /// Reads the values for this NPCChatResponseBase from an IValueReader.
        /// </summary>
        /// <param name="reader">IValueReader to read the values from.</param>
        protected void Read(IValueReader reader)
        {
            var value       = reader.ReadByte("Value");
            var page        = reader.ReadNPCChatDialogItemID("Page");
            var text        = reader.ReadString("Text");
            var actionNames = reader.ReadMany("Actions", ((r, name) => r.ReadString(name)));
            var actions     = GetActionsFromNames(actionNames);

            var cReader         = reader.ReadNode("Conditionals");
            var hasConditionals = cReader.ReadBool("HasConditionals");
            NPCChatConditionalCollectionBase conditionals = null;

            if (hasConditionals)
            {
                conditionals = CreateConditionalCollection();
                if (conditionals != null)
                {
                    conditionals.Read(cReader);
                }
            }

            SetReadValues(value, page, text, conditionals, actions);
        }