Esempio n. 1
0
        private void btnLineDown_Click(object sender, EventArgs e)
        {
            ListViewItem lvi = lvLines.SelectedItems[0];
            QuestLine    ql  = (QuestLine)lvi.Tag;

            ListViewItem lvs = lvSteps.SelectedItems[0];
            QuestStep    qs  = (QuestStep)lvs.Tag;

            // Reorder in the array
            int index = qs.Lines.IndexOf(ql);

            qs.Lines.RemoveAt(index);
            qs.Lines.Insert(index + 1, ql);

            // Reorder in the list view
            index = lvLines.Items.IndexOf(lvi);
            lvLines.Items.Remove(lvi);
            lvLines.Items.Insert(index + 1, lvi);

            // mark the quest dirty
            SetDirty(true);

            // Fix the buttons
            FixLineButtons(ql);
        }
Esempio n. 2
0
        private void lvLines_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbIcon.Enabled        = false;
            cbStaticText.Enabled  = false;
            tbDynamicText.Enabled = false;
            btnDeleteLine.Enabled = false;
            btnLineUp.Enabled     = false;
            btnLineDown.Enabled   = false;

            if (lvLines.SelectedItems.Count > 0)
            {
                _selectingQuest = true;
                ListViewItem lvi = lvLines.SelectedItems[0];
                QuestLine    ql  = (QuestLine)lvi.Tag;

                cbIcon.Enabled        = true;
                cbStaticText.Enabled  = true;
                tbDynamicText.Enabled = true;

                cbIcon.SelectedItem       = Program.s_npcIcons.ContainsKey(ql.Icon) ? Program.s_npcIcons[ql.Icon] : null;
                cbStaticText.SelectedItem = Program.s_staticText.ContainsKey(ql.StaticText) ? Program.s_staticText[ql.StaticText] : null;
                tbDynamicText.Text        = ql.DynamicText;

                FixLineButtons(ql);
                btnDeleteLine.Enabled = true;
                _selectingQuest       = false;
            }
        }
Esempio n. 3
0
 public void DeleteLine(QuestLine ql)
 {
     Lines.Remove(ql);
     if (!ql.New)
     {
         DeletedLines.Add(ql);
     }
 }
Esempio n. 4
0
        void AddLineToDisplay(QuestLine ql)
        {
            string       icon = Program.s_npcIcons.ContainsKey(ql.Icon) ? Program.s_npcIcons[ql.Icon].ToString() : "None";
            string       text = Program.s_staticText.ContainsKey(ql.StaticText) ? Program.s_staticText[ql.StaticText].ToString() : ql.DynamicText;
            ListViewItem lvl  = lvLines.Items.Add(icon);

            lvl.SubItems.Add(text);
            lvl.Tag = ql;
        }
Esempio n. 5
0
        private void tbDynamicText_TextChanged(object sender, EventArgs e)
        {
            ListViewItem lvi = lvLines.SelectedItems[0];
            QuestLine    ql  = (QuestLine)lvi.Tag;

            ql.DynamicText       = tbDynamicText.Text;
            lvi.SubItems[1].Text = Program.s_staticText.ContainsKey(ql.StaticText) ? Program.s_staticText[ql.StaticText].ToString() : ql.DynamicText;

            SetDirty(true);
        }
Esempio n. 6
0
        void FixLineButtons(QuestLine ql)
        {
            btnLineUp.Enabled   = false;
            btnLineDown.Enabled = false;
            ListViewItem lvs   = lvSteps.SelectedItems[0];
            QuestStep    qs    = (QuestStep)lvs.Tag;
            int          index = qs.Lines.IndexOf(ql);

            btnLineUp.Enabled   = (index > 0);
            btnLineDown.Enabled = (index < (qs.Lines.Count - 1));
        }
Esempio n. 7
0
        private void cbStaticText_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvLines.SelectedItems.Count > 0)
            {
                ListViewItem lvi = lvLines.SelectedItems[0];
                QuestLine    ql  = (QuestLine)lvi.Tag;

                IntStrID staticText = (IntStrID)cbStaticText.SelectedItem;
                ql.StaticText        = (ushort)staticText.ID;
                lvi.SubItems[1].Text = Program.s_staticText.ContainsKey(ql.StaticText) ? Program.s_staticText[ql.StaticText].ToString() : ql.DynamicText;

                SetDirty(true);
            }
        }
Esempio n. 8
0
        private void cbIcon_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbIcon.SelectedItem != null)
            {
                ListViewItem lvi = lvLines.SelectedItems[0];
                QuestLine    ql  = (QuestLine)lvi.Tag;

                IntStrID icon = (IntStrID)cbIcon.SelectedItem;
                ql.Icon  = (ushort)icon.ID;
                lvi.Text = Program.s_npcIcons.ContainsKey(ql.Icon) ? Program.s_npcIcons[ql.Icon].ToString() : "None";

                SetDirty(true);
            }
        }
Esempio n. 9
0
        private void btnNewLine_Click(object sender, EventArgs e)
        {
            // Create a quest line
            QuestLine ql = new QuestLine(0, (ushort)(cbIcon.SelectedItem != null ? ((IntStrID)cbIcon.SelectedItem).ID : 0), (ushort)Math.Max(cbStaticText.SelectedIndex, 0), "", 0);

            ql.New = true;

            // Add it to the step
            ListViewItem lvs = lvSteps.SelectedItems[0];
            QuestStep    qs  = (QuestStep)lvs.Tag;

            qs.Lines.Add(ql);

            // Add it to the display
            AddLineToDisplay(ql);

            // Mark quest dirty
            SetDirty(true);
        }
Esempio n. 10
0
        private void btnDeleteLine_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this line?", "Delete Line", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                ListViewItem lvi = lvLines.SelectedItems[0];
                QuestLine    ql  = (QuestLine)lvi.Tag;

                // Deselect
                lvi.Selected = false;

                // Delete from step
                ListViewItem lvs = lvSteps.SelectedItems[0];
                QuestStep    qs  = (QuestStep)lvs.Tag;
                qs.DeleteLine(ql);

                // Delete from display
                lvLines.Items.Remove(lvi);

                SetDirty(true);
            }
        }
Esempio n. 11
0
        public static void SaveQuest(Quest q)
        {
            if (q.New)
            {
                // New quest, add it to the database now
                q.ID = (uint)AddQuest(q.Name, q.GiverID, q.GiverMapID);
            }
            else
            {
                // Update info
                ExecuteQuery(string.Format("UPDATE quest_info SET giver_id={0},giver_map_id={1} WHERE quest_id={2};", q.GiverID, q.GiverMapID, q.ID));

                // Update name
                ExecuteQuery(string.Format("UPDATE quest_names SET name=\"{0}\" WHERE quest_id={1};", q.Name, q.ID));
            }

            // Delete all the rewards for this quest
            ExecuteQuery(string.Format("DELETE FROM quest_rewards WHERE quest_id={0}", q.ID));

            // Finalize step order
            for (int i = 0; i < q.Steps.Count; i++)
            {
                QuestStep qs = q.Steps[i];
                string    sql;
                if (qs.New)
                {
                    sql = string.Format("INSERT INTO quest_steps SET step={0},type={1},count={2},target_id={3},owner_id={4},quest_id={5}; SELECT LAST_INSERT_ID();", i, (byte)qs.CompType, qs.CompCount, qs.CompTargetID, qs.OwnerID, q.ID);
                }
                else
                {
                    sql = string.Format("UPDATE quest_steps SET step={0},type={1},count={2},target_id={3},owner_id={4} WHERE quest_step_id={5};", i, (byte)qs.CompType, qs.CompCount, qs.CompTargetID, qs.OwnerID, qs.ID);
                }
                List <object[]> rows = ExecuteQuery(sql);
                if (rows.Count > 0)
                {
                    ulong id = (ulong)rows[0][0];
                    qs.ID = (uint)id;
                }
                qs.New = false;

                // Do Rewards
                foreach (QuestReward qr in qs.Rewards)
                {
                    sql = string.Format("INSERT INTO quest_rewards SET quest_id={0},step={1},type={2},context={3};", q.ID, i, (byte)qr.Type, qr.Context);
                    ExecuteQuery(sql);
                }

                // Do Lines
                for (int j = 0; j < qs.Lines.Count; j++)
                {
                    QuestLine ql = qs.Lines[j];
                    ql.Line = (byte)j;
                    if (ql.New)
                    {
                        sql = string.Format("INSERT INTO quest_lines SET quest_id={0},step={1},line={2},icon={3},static_text={4},text=\"{5}\"; SELECT LAST_INSERT_ID();", q.ID, i, ql.Line, ql.Icon, ql.StaticText, ql.DynamicText);
                    }
                    else
                    {
                        sql = string.Format("UPDATE quest_lines SET step={1},line={2},icon={3},static_text={4},text=\"{5}\" WHERE quest_line_id={0};", ql.ID, i, ql.Line, ql.Icon, ql.StaticText, ql.DynamicText);
                    }
                    rows = ExecuteQuery(sql);
                    if (rows.Count > 0)
                    {
                        ulong id = (ulong)rows[0][0];
                        ql.ID = (uint)id;
                    }
                    ql.New = false;
                }
            }

            // Kill any steps marked for deletion
            foreach (QuestStep qs in q.DeletedSteps)
            {
                if (!qs.New)
                {
                    string sql = string.Format("DELETE FROM quest_steps WHERE quest_step_id={0};", qs.ID);
                    ExecuteQuery(sql);
                }
            }

            // Save requirements
            foreach (QuestRequirement qr in q.Requirements)
            {
                string sql;
                if (qr.New)
                {
                    sql = string.Format("INSERT INTO quest_requirements SET quest_id={0},type={1},param={2}; SELECT LAST_INSERT_ID();", q.ID, qr.TheType, qr.Context);
                }
                else
                {
                    sql = string.Format("UPDATE quest_requirements SET type={0},param={1} WHERE quest_requirement_id={2};", qr.TheType, qr.Context, qr.ID);
                }
                List <object[]> rows = ExecuteQuery(sql);
                if (rows.Count > 0)
                {
                    ulong id = (ulong)rows[0][0];
                    qr.ID = (uint)id;
                }
                qr.New = false;
            }

            // Kill any requirements marked for deletion
            foreach (QuestRequirement qr in q.DeletedReqs)
            {
                if (!qr.New)
                {
                    string sql = string.Format("DELETE FROM quest_requirements WHERE quest_requirement_id={0};", qr.ID);
                    ExecuteQuery(sql);
                }
            }

            // Clear dirty flag
            q.Dirty = false;
        }
Esempio n. 12
0
        static public Quest[] FetchQuests()
        {
            List <Quest> quests = new List <Quest>();

            // Fetch Quests
            List <object[]> rows = ExecuteQuery("SELECT * FROM quest_info;");

            foreach (object[] row in rows)
            {
                Quest q = new Quest((uint)row[0], (uint)row[1], (ushort)row[2]);
                quests.Add(q);
            }

            // Go get subquest data
            foreach (Quest q in quests)
            {
                // Fetch Name
                string sql = string.Format("SELECT * FROM quest_names WHERE quest_id={0};", q.ID);
                rows = ExecuteQuery(sql);
                if (rows.Count > 0)
                {
                    q.Name = (string)rows[0][1];
                }

                // Fetch Requirements
                sql  = string.Format("SELECT * FROM quest_requirements WHERE quest_id={0};", q.ID);
                rows = ExecuteQuery(sql);
                foreach (object[] row in rows)
                {
                    uint             id   = (uint)row[0];
                    byte             type = (byte)row[2];
                    QuestRequirement qr   = new QuestRequirement(id, (QuestRequirement.Type)type, (uint)row[3]);
                    q.Requirements.Add(qr);
                }

                // Fetch Steps
                sql  = string.Format("SELECT * FROM quest_steps WHERE quest_id={0};", q.ID);
                rows = ExecuteQuery(sql);
                foreach (object[] row in rows)
                {
                    byte      type = (byte)row[2];
                    QuestStep qs   = new QuestStep((byte)row[1], (QuestStep.CompletionType)type, (uint)row[3], (uint)row[4], (uint)row[5], (uint)row[6]);
                    q.Steps.Add(qs);
                }

                // Process Steps
                foreach (QuestStep qs in q.Steps)
                {
                    // Fetch Rewards
                    sql  = string.Format("SELECT * FROM quest_rewards WHERE quest_id={0} AND step={1};", q.ID, qs.Step);
                    rows = ExecuteQuery(sql);
                    foreach (object[] row in rows)
                    {
                        // 0: quest_id	int(10) unsigned
                        // 1: step	tinyint(3) unsigned
                        // 2: type	tinyint(10) unsigned
                        // 3: context	int(10) unsigned
                        QuestReward qr = new QuestReward((byte)row[2], (uint)row[3]);
                        qs.Rewards.Add(qr);
                    }

                    // Fetch Lines
                    sql  = string.Format("SELECT * FROM quest_lines WHERE quest_id={0} AND step={1};", q.ID, qs.Step);
                    rows = ExecuteQuery(sql);
                    foreach (object[] row in rows)
                    {
                        string text = null;
                        if (row[6].GetType() != typeof(DBNull))
                        {
                            text = (string)row[6];
                        }
                        QuestLine ql = new QuestLine((byte)row[3], (ushort)row[4], (ushort)row[5], text, (uint)row[0]);
                        qs.Lines.Add(ql);
                    }

                    // Order Lines
                    qs.OrderLines();
                }

                // Order Steps
                q.OrderSteps();
            }
            return(quests.ToArray());
        }