Ejemplo n.º 1
0
        public static void LoadNPCsQuestions()
        {
            var sqlText    = "SELECT * FROM npcs_questions";
            var sqlCommand = new MySqlCommand(sqlText, Program.DBHelper.Use());

            var sqlReader = sqlCommand.ExecuteReader();

            while (sqlReader.Read())
            {
                var question = new Models.NPC.NPCsQuestion()
                {
                    QuestionID       = sqlReader.GetInt32("questionID"),
                    RescueQuestionID = sqlReader.GetInt32("rescueQuestion"),
                };

                foreach (var answer in sqlReader.GetString("answers").Split(';'))
                {
                    if (answer == "")
                    {
                        continue;
                    }

                    question.Answers.Add(AnswersList.First(x => x.AnswerID == int.Parse(answer)));
                }

                foreach (var condi in sqlReader.GetString("conditions").Split('&'))
                {
                    if (condi == "")
                    {
                        continue;
                    }

                    var condiInfos  = condi.Split(';');
                    var condiObject = new NPCConditions();

                    condiObject.CondiID = int.Parse(condiInfos[0]);
                    condiObject.Args    = condiInfos[1];

                    question.Conditions.Add(condiObject);
                }

                question.Params = sqlReader.GetString("params").Split(',').ToList();

                QuestionsList.Add(question);
            }

            sqlReader.Close();

            foreach (var question in QuestionsList.Where(x => x.RescueQuestionID != -1))
            {
                question.RescueQuestion = QuestionsList.First(x => x.QuestionID == question.RescueQuestionID);
            }

            Utilities.Loggers.Status.Write(string.Format("Loaded '{0}' npcsQuestions from the database !", QuestionsList.Count));
        }
Ejemplo n.º 2
0
        public static void LoadNPCsAnswers()
        {
            var sqlText    = "SELECT * FROM npcs_answers";
            var sqlCommand = new MySqlCommand(sqlText, Program.DBHelper.Use());

            var sqlReader = sqlCommand.ExecuteReader();

            while (sqlReader.Read())
            {
                var answer = new Models.NPC.NPCsAnswer()
                {
                    AnswerID = sqlReader.GetInt32("answerID"),
                    Effects  = sqlReader.GetString("effects"),
                };

                foreach (var condi in sqlReader.GetString("conditions").Split('&'))
                {
                    if (condi == "")
                    {
                        continue;
                    }

                    var condiInfos  = condi.Split(';');
                    var condiObject = new NPCConditions();

                    condiObject.CondiID = int.Parse(condiInfos[0]);
                    condiObject.Args    = condiInfos[1];

                    answer.Conditions.Add(condiObject);
                }

                AnswersList.Add(answer);
            }

            sqlReader.Close();

            Utilities.Loggers.Status.Write(string.Format("Loaded '{0}' npcsAnswers from the database !", AnswersList.Count));
        }