Exemplo n.º 1
0
        /// <summary>
        /// Reads the TextResource tokens for this page record.
        /// </summary>
        /// <param name="page">Page index.</param>
        /// <returns>TextResource token array.</returns>
        public TextFile.Token[] GetPageTokens(int page)
        {
            if (page < 0 || page >= PageCount)
            {
                throw new IndexOutOfRangeException("BookFile: Invalid page index.");
            }

            byte[] buffer = bookFile.GetBytes();

            return(TextFile.ReadTokens(ref buffer, (int)header.PageOffsets[page], TextFile.Formatting.EndOfPage));
        }
Exemplo n.º 2
0
        private void AnswerAndPlayAnim(int choice)
        {
            if (animPlaying || questionsAnswered == questionCount)
            {
                return;
            }

            int weightIndex = GetWeightIndex(questionsAnswered, choice);

            weights[weightIndex]++;
            Debug.Log("CreateCharClassQuestions: Warrior: " + weights[0] + " Rogue: " + weights[1] + " Mage: " + weights[2]);
            if (questionsAnswered == questionCount - 1) // Final question was answered
            {
                // Compute class index
                FileProxy classFile = new FileProxy(Path.Combine(DaggerfallUnity.Instance.Arena2Path, classesFileName), FileUsage.UseDisk, true);
                if (classFile == null)
                {
                    throw new Exception("CreateCharClassQuestions: Could not load CLASSES.DAT.");
                }
                byte[] classData   = classFile.GetBytes();
                int    headerIndex = GetHeaderIndex(classData);
                if (headerIndex == -1)
                {
                    throw new Exception("CreateCharClassQuestions: Error reading CLASSES.DAT - could not find a results match. Warrior: " + weights[0] + " Rogue: " + weights[1] + " Mage: " + weights[2]);
                }
                classIndex = GetClassIndex(headerIndex, classData);
            }

            questionsAnswered++;
            switch (weightIndex)
            {
            case 0:
                warriorBlue += constellationBrightnessIncrement;
                warriorAnim.Start();
                break;

            case 1:
                rogueBlue += constellationBrightnessIncrement;
                rogueAnim.Start();
                break;

            case 2:
                mageBlue += constellationBrightnessIncrement;
                mageAnim.Start();
                break;
            }

            animPlaying = true;
            DaggerfallUI.Instance.PlayOneShot(SoundClips.Ignite);
        }
        public BiogFile(CharacterDocument characterDocument)
        {
            // Store reference to character document
            this.characterDocument = characterDocument;

            // Load text file
            string    fileName = "BIOG" + characterDocument.classIndex.ToString("D" + 2) + "T0.TXT";
            FileProxy txtFile  = new FileProxy(Path.Combine(DaggerfallUnity.Instance.Arena2Path, fileName), FileUsage.UseDisk, true);

            questionsStr = System.Text.Encoding.UTF8.GetString(txtFile.GetBytes());

            // Parse text into questions
            StringReader reader = new StringReader(questionsStr);

            for (int i = 0; i < questionCount; i++)
            {
                questions[i] = new Question();

                string curLine = reader.ReadLine();
                // Parse question text
                for (int j = 0; j < Question.lines; j++)
                {
                    // Check if the next line is part of the question
                    if (j == 0) // first question line should lead with a number followed by a '.'
                    {
                        questions[i].Text[j] = curLine.Split(new[] { '.' }, 2)[1].Trim();
                    }
                    else if (j > 0 && curLine.IndexOf(".") != 1 && curLine.IndexOf(".") != 2)
                    {
                        questions[i].Text[j] = curLine.Trim();
                    }
                    else
                    {
                        break;
                    }
                    curLine = reader.ReadLine();
                }
                // Parse answers to the current question
                while (curLine.Length > 1) // Line without 2-char preamble = Empty line = end of answers
                {
                    Answer ans = new Answer();
                    // Get Answer text
                    if (curLine.IndexOf(".") == 1)
                    {
                        ans.Text = curLine.Split('.')[1].Trim();
                        curLine  = reader.ReadLine();
                    }
                    // Add answer effects
                    while (curLine.IndexOf(".") != 1 && curLine.Length > 1)
                    {
                        ans.Effects.Add(curLine.Trim());
                        curLine = reader.ReadLine();
                    }
                    questions[i].Answers.Add(ans);
                }
            }
            reader.Close();

            // Initialize reputation changes
            for (int i = 0; i < changedReputations.Length; i++)
            {
                changedReputations[i] = 0;
            }

            // Initialize question token lists
            Q1Tokens  = new List <int>();
            Q2Tokens  = new List <int>();
            Q3Tokens  = new List <int>();
            Q4Tokens  = new List <int>();
            Q5Tokens  = new List <int>();
            Q6Tokens  = new List <int>();
            Q7Tokens  = new List <int>();
            Q8Tokens  = new List <int>();
            Q9Tokens  = new List <int>();
            Q10Tokens = new List <int>();
            Q11Tokens = new List <int>();
            Q12Tokens = new List <int>();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Read file.
 /// </summary>
 public byte[] Read(uint recordIndex)
 {
     return(managedFile.GetBytes(recordIndex * recordLength, recordLength));
 }
Exemplo n.º 5
0
        public BiogFile(CharacterDocument characterDocument)
        {
            // Store reference to character document
            this.characterDocument = characterDocument;

            // Load text file
            string    fileName = $"BIOG{characterDocument.classIndex:D2}T{characterDocument.biographyIndex}.TXT";
            FileProxy txtFile  = new FileProxy(Path.Combine(BiogFile.BIOGSourceFolder, fileName), FileUsage.UseDisk, true);

            questionsStr = System.Text.Encoding.UTF8.GetString(txtFile.GetBytes());

            // Parse text into questions
            StringReader reader  = new StringReader(questionsStr);
            string       curLine = reader.ReadLine();

            for (int i = 0; i < questionCount; i++)
            {
                questions[i] = new Question();

                // Skip through any blank lines
                while (curLine.Length <= 1)
                {
                    curLine = reader.ReadLine();
                }

                // If we haven't parsed the first question yet, allow users to specify a custom backstory string id
                if (i == 0)
                {
                    if (curLine[0] == '#')
                    {
                        string value = curLine.Substring(1);
                        if (!int.TryParse(value, out backstoryId))
                        {
                            Debug.LogError($"{fileName}: Invalid string id '{value}'");
                            backstoryId = defaultBackstoriesStart + characterDocument.classIndex;
                        }

                        // Find the next non-empty line, which should be question 1
                        do
                        {
                            curLine = reader.ReadLine();
                        } while (curLine.Length <= 1);
                    }
                    else
                    {
                        backstoryId = defaultBackstoriesStart + characterDocument.classIndex;
                    }
                }

                // Parse question text
                for (int j = 0; j < Question.lines; j++)
                {
                    // Check if the next line is part of the question
                    if (j == 0) // first question line should lead with a number followed by a '.'
                    {
                        questions[i].Text[j] = curLine.Split(new[] { '.' }, 2)[1].Trim();
                    }
                    else if (j > 0 && curLine.IndexOf(".") != 1 && curLine.IndexOf(".") != 2)
                    {
                        questions[i].Text[j] = curLine.Trim();
                    }
                    else
                    {
                        break;
                    }
                    curLine = reader.ReadLine();
                }
                // Parse answers to the current question
                while (curLine.IndexOf(".") == 1 && char.IsLetter(curLine[0])) // Line without 2-char preamble including letter = end of answers
                {
                    Answer ans = new Answer();
                    // Get Answer text
                    ans.Text = curLine.Split('.')[1].Trim();
                    curLine  = reader.ReadLine();

                    // Add answer effects
                    while (curLine.IndexOf(".") != 1 && curLine.Length > 1)
                    {
                        ans.Effects.Add(curLine.Trim());
                        curLine = reader.ReadLine();
                    }
                    questions[i].Answers.Add(ans);
                }
            }
            reader.Close();

            // Initialize reputation changes
            for (int i = 0; i < changedReputations.Length; i++)
            {
                changedReputations[i] = 0;
            }

            // Initialize question token lists
            Q1Tokens  = new List <int>();
            Q2Tokens  = new List <int>();
            Q3Tokens  = new List <int>();
            Q4Tokens  = new List <int>();
            Q5Tokens  = new List <int>();
            Q6Tokens  = new List <int>();
            Q7Tokens  = new List <int>();
            Q8Tokens  = new List <int>();
            Q9Tokens  = new List <int>();
            Q10Tokens = new List <int>();
            Q11Tokens = new List <int>();
            Q12Tokens = new List <int>();
        }