Esempio n. 1
0
        private void QuestView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int    i = e.RowIndex;
            IQuest q = IQuest.QuestID(Int32.Parse(QuestView.Rows[i].Cells[3].Value.ToString()));

            if (_player.Inventory.FirstOrDefault(itm => itm.Itm == q.ItemToComplete.Item) != null)
            {
                InventoryItem qItm = _player.Inventory.FirstOrDefault(itm => itm.Itm == q.ItemToComplete.Item);
                if (qItm.ItmQty >= q.ItemToComplete.ReqdQty)
                {
                    try
                    {
                        if (_player.PlayerLocation.NpcHere.GiveQuests.Contains(q))
                        {
                            if (qItm.ItmQty > q.ItemToComplete.ReqdQty)
                            {
                                _player.Inventory[_player.Inventory.IndexOf(qItm)].ItmQty -= q.ItemToComplete.ReqdQty;
                            }
                            else
                            {
                                _player.Inventory.Remove(qItm);
                            }
                            UpdateInventory();


                            _player.Xp += q.RewardXp;

                            if (q.RewardGold > 0)
                            {
                                _player.Gold += q.RewardGold;
                                infoBox.Text  = "Quest Completed: " + q.QuestName + "\n\n\"" + q.RewardDialogue + "\"\n\nYou receive " + q.RewardXp
                                                + " experience and " + q.RewardGold + " gold.";
                            }
                            else
                            {
                                infoBox.Text = "Quest Completed: " + q.QuestName + "\n\n\"" + q.RewardDialogue + "\"\n\nYou receive " + q.RewardXp
                                               + " experience.";
                            }

                            if (q.RewardItem != null)
                            {
                                AddInventoryItem(q.RewardItem);
                            }


                            int questIndex = _player.QuestLog.IndexOf(q);

                            _player.QuestLog[questIndex].Completed = true;

                            _player.PlayerLocation.NpcHere.GiveQuests.Remove(q);

                            UpdateQuests();
                        }
                    }
                    catch { }
                }
            }
        }
Esempio n. 2
0
        private void UpdateQuests()
        {
            QuestView.Rows.Clear();
            foreach (IQuest q in _player.QuestLog)
            {
                if (!q.Completed)
                {
                    IItem  reqdItm = q.ItemToComplete.Item;
                    string playerQty;
                    try
                    {
                        playerQty = _player.Inventory.FirstOrDefault(i => i.Itm == reqdItm).ItmQty.ToString();
                    }
                    catch
                    {
                        playerQty = "0";
                    }

                    int reqdQty = q.ItemToComplete.ReqdQty;
                    QuestView.Rows.Add(new[] { q.QuestName, q.QuestDesc, q.ItemToComplete.Item.ItmName.ToString() + " " + playerQty + " / " + reqdQty, q.ID.ToString() });
                }
            }

            for (int i = 0; i < QuestView.RowCount; i++)
            {
                IQuest q      = IQuest.QuestID(Int32.Parse(QuestView.Rows[i].Cells[3].Value.ToString()));
                int    qIndex = _player.QuestLog.IndexOf(q);

                if (_player.Inventory.FirstOrDefault(itm => itm.Itm == q.ItemToComplete.Item) != null)
                {
                    InventoryItem qItm = _player.Inventory.FirstOrDefault(itm => itm.Itm == q.ItemToComplete.Item);
                    if (qItm.ItmQty >= q.ItemToComplete.ReqdQty)
                    {
                        try
                        {
                            if (_player.PlayerLocation.NpcHere.GiveQuests.Contains(q))
                            {
                                QuestView.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Green;
                            }
                            else
                            {
                                QuestView.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Yellow;
                            }
                        }
                        catch
                        {
                            QuestView.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Yellow;
                        }
                    }
                }
            }
        }