Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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.pid);
            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.pid);
                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.pid);
            }

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Log.ErrorException("DAO: ADD QUEST ERROR!", e);
            }

            AddQuestReader.Close();
        }
Ejemplo n.º 3
0
        public void AddQuest(Player player, QuestData questdata)
        {
            string cmdString = "SELECT * FROM questdata WHERE QuestId=?qid AND PlayerId=?pid";
            MySqlCommand command = new MySqlCommand(cmdString, QuestDAOConnection);
            command.Parameters.AddWithValue("?qid", questdata.QuestId);
            command.Parameters.AddWithValue("?pid", player.Id);
            MySqlDataReader reader = command.ExecuteReader();
            bool isExists = reader.HasRows;
            reader.Close();

            if (!isExists)
            {
                cmdString = "INSERT INTO questdata "
                + "(`PlayerId`,`QuestId`,`Status`,`Step`,`Counters`) "
                + "VALUES (?pid, ?qid, ?qstatus, ?qstep, ?qcounter);";
                command = new MySqlCommand(cmdString, QuestDAOConnection);
                command.Parameters.AddWithValue("?pid", player.Id);
                command.Parameters.AddWithValue("?qid", questdata.QuestId);
                command.Parameters.AddWithValue("?qstatus", questdata.Status.ToString());
                command.Parameters.AddWithValue("?qstep", questdata.Step);
                command.Parameters.AddWithValue("?qcounter", string.Join(",", questdata.Counters));
            }
            else
            {
                cmdString = "UPDATE questdata SET"
                + "`Status`=?qstatus,`Step`=?qstep,`Counters`=?qcounter WHERE QuestId=?qid AND PlayerId=?pid";
                command = new MySqlCommand(cmdString, QuestDAOConnection);
                command.Parameters.AddWithValue("?qstatus", questdata.Status.ToString());
                command.Parameters.AddWithValue("?qstep", questdata.Step);
                command.Parameters.AddWithValue("?qcounter", string.Join(",", questdata.Counters));
                command.Parameters.AddWithValue("?qid", questdata.QuestId);
                command.Parameters.AddWithValue("?pid", player.Id);
            }

            try
            {
                command.ExecuteNonQuery();
            }
            catch (MySqlException ex)
            {
                Log.ErrorException("SaveQuest Error", ex);
            }
        }
Ejemplo n.º 4
0
        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.pid);
            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;
        }
Ejemplo n.º 5
0
        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.pid);
            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;
        }
Ejemplo n.º 6
0
        public QuestData LoadQuest(Player player, int questId)
        {
            string cmdString = "SELECT * FROM questdata WHERE QuestId=?qid AND PlayerId=?pid";
            MySqlCommand command = new MySqlCommand(cmdString, QuestDAOConnection);
            command.Parameters.AddWithValue("?qid", questId);
            command.Parameters.AddWithValue("?pid", player.Id);
            MySqlDataReader reader = command.ExecuteReader();

            QuestData quest = new QuestData(questId);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    quest = new QuestData(questId)
                    {
                        QuestId = reader.GetInt32(1),
                        Status = (QuestStatus)Enum.Parse(typeof(QuestStatus), reader.GetString(2)),
                        Step = reader.GetInt32(3),
                        Counters = reader.GetString(4).Split(',').Select(n => int.Parse(n)).ToList()
                    };
                }
            }
            reader.Close();

            return quest;
        }
Ejemplo n.º 7
0
        public Dictionary<int, QuestData> LoadQuests(Player player)
        {
            string cmdString = "SELECT * FROM questdata WHERE PlayerId=?pid";
            MySqlCommand command = new MySqlCommand(cmdString, QuestDAOConnection);
            command.Parameters.AddWithValue("?pid", player.Id);
            MySqlDataReader reader = command.ExecuteReader();

            Dictionary<int, QuestData> questlist = new Dictionary<int, QuestData>();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    QuestData quest = new QuestData(0)
                    {
                        QuestId = reader.GetInt32(2),
                        Status = (QuestStatus)Enum.Parse(typeof(QuestStatus), reader.GetString(3)),
                        Step = reader.GetInt32(4),
                        Counters = reader.GetString(5).Split(',').Select(n => int.Parse(n)).ToList()
                    };
                    questlist.Add(quest.QuestId, quest);
                }
            }
            reader.Close();

            return questlist;
        }
Ejemplo n.º 8
0
        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);
        }