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)); }
public static void LoadNPCsQuestions() { lock (DatabaseProvider.Locker) { var sqlText = "SELECT * FROM npcs_questions"; var sqlCommand = new MySqlCommand(sqlText, DatabaseProvider.Connection); 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 Game.World.Conditions.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)); }