public SpQuest(QuestData data, List<Npc> npcList = null, int visiblitySwitch = 1, bool countersComplete = true) { QuestData = data; NpcList = npcList ?? new List<Npc>(); VisiblitySwitch = visiblitySwitch; CountersComplete = countersComplete; }
public void AddQuest(Player player, QuestData questdata) { string SQL = "SELECT * FROM `quests` WHERE " + "`questid` = ?qid AND `characterid` = ?pid"; MySqlCommand cmd = new MySqlCommand(SQL, QuestDAOConnection); cmd.Parameters.AddWithValue("?qid", questdata.QuestId); cmd.Parameters.AddWithValue("?pid", player.Id); MySqlDataReader AddQuestReader = cmd.ExecuteReader(); bool isExists = AddQuestReader.HasRows; AddQuestReader.Close(); if (!isExists) { SQL = "INSERT INTO `quests` " + "(`characterid`, `questid`, `status`, `step`, `counters`) " + "VALUES (?pid, ?qid, ?status, ?step, ?counter);"; cmd = new MySqlCommand(SQL, QuestDAOConnection); cmd.Parameters.AddWithValue("?pid", player.Id); cmd.Parameters.AddWithValue("?qid", questdata.QuestId); cmd.Parameters.AddWithValue("?status", questdata.Status.ToString()); cmd.Parameters.AddWithValue("?step", questdata.Step); cmd.Parameters.AddWithValue("?counter", string.Join(",", questdata.Counters)); } else { SQL = "UPDATE `quests` SET " + "`status` = ?status, `step` = ?step, `counters` = ?counter " + "WHERE `questid` = ?qid AND `characterid` = ?pid"; cmd = new MySqlCommand(SQL, QuestDAOConnection); cmd.Parameters.AddWithValue("?status", questdata.Status.ToString()); cmd.Parameters.AddWithValue("?step", questdata.Step); cmd.Parameters.AddWithValue("?counter", string.Join(",", questdata.Counters)); cmd.Parameters.AddWithValue("?qid", questdata.QuestId); cmd.Parameters.AddWithValue("?pid", player.Id); } try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Logger.WriteLine(LogState.Exception, "DAO: ADD QUEST ERROR!" + ex.Message); } AddQuestReader.Close(); }
public QuestData LoadQuest(Player player, int questid) { string SQL = "SELECT * FROM `quests` WHERE " + "`questid` = ?qid AND `characterid` = ?pid"; MySqlCommand cmd = new MySqlCommand(SQL, QuestDAOConnection); cmd.Parameters.AddWithValue("?qid", questid); cmd.Parameters.AddWithValue("?pid", player.Id); MySqlDataReader LoadQuestReader = cmd.ExecuteReader(); QuestData quest = new QuestData(questid); if (LoadQuestReader.HasRows) { while (LoadQuestReader.Read()) { quest = new QuestData(questid) { QuestId = LoadQuestReader.GetInt32(1), Status = (QuestStatus)Enum.Parse(typeof(QuestStatus), LoadQuestReader.GetString(2)), Step = LoadQuestReader.GetInt32(3), Counters = LoadQuestReader.GetString(4).Split(',').Select(n => int.Parse(n)).ToList() }; } } LoadQuestReader.Close(); return quest; }
public Dictionary<int, QuestData> LoadQuests(Player player) { string SQL = "SELECT * FROM `quests` WHERE `characterid` = ?pid"; MySqlCommand cmd = new MySqlCommand(SQL, QuestDAOConnection); cmd.Parameters.AddWithValue("?pid", player.Id); MySqlDataReader LoadQuestsReader = cmd.ExecuteReader(); Dictionary<int, QuestData> questlist = new Dictionary<int, QuestData>(); if (LoadQuestsReader.HasRows) { while (LoadQuestsReader.Read()) { QuestData quest = new QuestData(0) { QuestId = LoadQuestsReader.GetInt32(2), Status = (QuestStatus)Enum.Parse(typeof(QuestStatus), LoadQuestsReader.GetString(3)), Step = LoadQuestsReader.GetInt32(4), Counters = LoadQuestsReader.GetString(5).Split(',').Select(n => int.Parse(n)).ToList() }; questlist.Add(quest.QuestId, quest); } } LoadQuestsReader.Close(); return questlist; }
public void StartQuest(Player player) { int nowQuests = 0; foreach (var questData in player.Quests.Values) if (questData.Status != QuestStatus.Complete) nowQuests++; if (nowQuests > 30) return; QuestData data = new QuestData(Quest.QuestId); player.Quests.Add(Quest.QuestId, data); InitNowStep(player); new SpQuest(data, null, 1, GetNowStep(player).IsCountersComplete(player)).Send(player.Connection); SystemMessages.NewQuest("@quest:" + Quest.QuestId + "001").Send(player.Connection); UpdateAroundIcons(player); }