/// <summary>Downloads all of the quests <paramref name="thisChar"/> has started it hasn't already been.</summary> /// <param name="thisChar">The character being examined.</param> private void CharGetAllQuests(Characters thisChar) { int oldQuestCount = Program.questList.Count, oldItemCount = Program.itemList.Count; Cursor.Current = Cursors.WaitCursor; List <long> NewItemsList = new List <long>(); ConcurrentBag <QuestItem> NewItemsBag = new ConcurrentBag <QuestItem>(); StatusStripProgressBar.Maximum = thisChar.CharCollection.Count; StatusStripProgressBar.Value = 0; StatusStripProgressBar.Visible = true; foreach (long thisColl in thisChar.CharCollection.Keys) { if (!Program.questList.ContainsKey(thisColl)) { CollQuest TempQuest; try { TempQuest = new CollQuest(thisColl); } catch (Exception Err) { BadEnd(); throw Err; } Program.questList[TempQuest.DaybreakID] = TempQuest; _ = Parallel.ForEach(TempQuest.items, thisItem => { QuestItem TempItem; if (!Program.itemList.ContainsKey(thisItem)) { try { TempItem = new QuestItem(thisItem); } catch (Exception Err) { BadEnd(); throw Err; } if (!NewItemsBag.Contains(TempItem)) { NewItemsBag.Add(TempItem); } } }); } StatusStripProgressBar.Value++; } if (NewItemsBag.Count > 0) { foreach (QuestItem ThisItem in NewItemsBag) { Program.itemList[ThisItem.DaybreakID] = ThisItem; } } Cursor.Current = Cursors.Default; StatusStripProgressBar.Visible = false; CharQuestListBox.Refresh(); dirties[2] = (oldItemCount != Program.itemList.Count) || dirties[2]; dirties[3] = (oldQuestCount != Program.questList.Count) || dirties[3]; if (dirties[2] || dirties[3]) { StatusStripDirtyIndicator.Text = FloppyString; } }
private void CharQuestListBox_SelectedIndexChanged(object sender, EventArgs e) { CharQuestItemsCheckListBox.Items.Clear(); if (CharQuestListBox.SelectedIndex == -1) { CharQuestItemsCheckListBox.Refresh(); return; } if ((CharQuestListBox.SelectedIndex == 0) && (CharQuestListBox.SelectedItem is string)) { CharQuestItemsCheckListBox.Refresh(); return; } CollQuest thisQuest = (CollQuest)CharQuestListBox.SelectedItem; Characters thisChar = (Characters)CharListBox.SelectedItem; int OldCount = 0; if (thisChar == null) { CharQuestListBox.Items.Clear(); _ = CharListBox.Focus(); return; } if (thisChar.CharCollection.ContainsKey(thisQuest.DaybreakID)) { OldCount = thisChar.CharCollection[thisQuest.DaybreakID].Count; } if (thisChar.CharCollection.ContainsKey(thisQuest.DaybreakID) && (OldCount != thisChar.CharCollection[thisQuest.DaybreakID].Count)) { dirties[0] = true; UpdateDirtiesStatus(); } foreach (long thisItemID in thisQuest.items) { QuestItem thisItem = Program.itemList[thisItemID]; if (thisItem == null) { try { thisItem = new QuestItem(thisItemID); } catch (Exception Err) { BadEnd(); throw Err; } Program.itemList[thisItem.DaybreakID] = thisItem; dirties[2] = true; StatusStripDirtyIndicator.Text = FloppyString; } if (thisChar.IsComplete(thisQuest.DaybreakID)) { _ = CharQuestItemsCheckListBox.Items.Add(thisItem, true); } else { _ = CharQuestItemsCheckListBox.Items.Add(thisItem, thisChar.CharCollection[thisQuest.DaybreakID].Contains(thisItemID)); } } CharQuestItemsCheckListBox.Refresh(); }
private void PAItemList_SelectedIndexChanged(object sender, EventArgs e) { if ((PAItemList.SelectedIndex == -1) || ((PAItemList.SelectedIndex == 0) && (PAItemList.SelectedItem is string thisString) && (thisString == "Empty!"))) { SelectedItem = null; return; } const string Surplus = "This item is surplus. It may be sold."; PAListBoxResults.Items.Clear(); long ThisID; try { ThisID = (PAItemList.SelectedItem as ItemsFormat).ItemID; } catch (NullReferenceException) { PAListBoxResults.Items.Clear(); return; } int ThisQuant = (PAItemList.SelectedItem as ItemsFormat).ItemQuant; QuestItem ThisItem = Program.itemList[ThisID]; if (ThisQuant == 0) { PAIntroLabel.Text = Surplus; return; } else { Dictionary <long, WantResults> CharsWants = GetWants(ThisItem); if (CharsWants.Count == 0) { PAIntroLabel.Text = Surplus; return; } double biggestWant = CharsWants.Values.Select(p => p.GreedRate).Max(); List <long> WantingChars = new List <long>(); foreach (KeyValuePair <long, WantResults> ThisPair in CharsWants) { if (ThisPair.Value.GreedRate == biggestWant) { WantingChars.Add(ThisPair.Key); } } if (WantingChars.Contains(PAChosenChar)) { PAIntroLabel.Text = $"{Program.charList[PAChosenChar].name} may add {ThisItem.ItemName} to {Program.questList[CharsWants[PAChosenChar].QuestID].QuestName}."; } else if (WantingChars.Count == 1) { PAIntroLabel.Text = $"If possible, please mail {ServerMates[WantingChars[0]].name} {ThisItem.ItemName} for {Program.questList[CharsWants[WantingChars[0]].QuestID].QuestName}."; } else { PAIntroLabel.Text = "Multiple characters have equal want of this item. Please refer below."; } PAListBoxResults.Items.Clear(); foreach (KeyValuePair <long, WantResults> keyValuePair in CharsWants) { PAListBoxResults.Items.Add(new ResultsBoxItem(keyValuePair.Key, keyValuePair.Value.QuestID, keyValuePair.Value.GreedRate)); } SelectedItem = PAItemList.SelectedItem as ItemsFormat; PAListBoxResults.SelectedIndex = -1; } }
private Dictionary <long, WantResults> GetWants(QuestItem ThisItem) { Dictionary <long, WantResults> returnValue = new Dictionary <long, WantResults>(); // This will contain the charIDs as the key and the wantResults as the value. Dictionary <long, int> QuestDict = new Dictionary <long, int>(); // Contains each questID (key) that uses this item and the number of items required for those quests (value). foreach (CollQuest ThisQuest in Program.questList.Values) { if (ThisQuest.items.Contains(ThisItem.DaybreakID)) { QuestDict[ThisQuest.DaybreakID] = ThisQuest.items.Count; } } if (QuestDict.Count < 1) { FinalResult = DialogResult.Abort; ReturnedException = new Exception("No quests exist for the item being sought. This should never happen."); Close(); } foreach ((Characters ThisChar, KeyValuePair <long, int> ThisQuest) in from Characters ThisChar in ServerMates.Values from KeyValuePair <long, int> ThisQuest in QuestDict select(ThisChar, ThisQuest)) { if ((!returnValue.ContainsKey(ThisChar.DaybreakID)) && (!ThisChar.CharCollection.ContainsKey(ThisQuest.Key))) { returnValue[ThisChar.DaybreakID] = new WantResults() { QuestID = ThisQuest.Key, GreedRate = 0.0 }; } else if (!ThisChar.CharCollection.ContainsKey(ThisQuest.Key)) { continue; // A want already exists for this character and it is >= 0. } else if (!returnValue.ContainsKey(ThisChar.DaybreakID)) { int OldValue = ThisChar.CharCollection[ThisQuest.Key].Count; if (ThisChar.CharCollection[ThisQuest.Key].Contains(ThisItem.DaybreakID) || ThisChar.IsComplete(ThisQuest.Key)) { if ((OldValue != ThisChar.CharCollection[ThisQuest.Key].Count) && (FinalResult == DialogResult.Retry)) { FinalResult = DialogResult.OK; } continue; } if (Program.questList[ThisQuest.Key].ExpertColl) { returnValue[ThisChar.DaybreakID] = new WantResults() { QuestID = ThisQuest.Key, GreedRate = ((double)ThisChar.CharCollection[ThisQuest.Key].Count) / ThisQuest.Value * ExpertMult } } ; else { returnValue[ThisChar.DaybreakID] = new WantResults() { QuestID = ThisQuest.Key, GreedRate = ((double)ThisChar.CharCollection[ThisQuest.Key].Count) / ThisQuest.Value } }; } else if ((QuestDict.Count > 1) && (ThisQuest.Key != QuestDict.Keys.First())) { if (ThisChar.CharCollection[ThisQuest.Key].Contains(ThisItem.DaybreakID)) { continue; } double OldVal = returnValue[ThisChar.DaybreakID].GreedRate; double NewVal = ((double)ThisChar.CharCollection[ThisQuest.Key].Count) / ThisQuest.Value; if (Program.questList[ThisQuest.Key].ExpertColl) { NewVal *= ExpertMult; } if (OldVal < NewVal) { returnValue[ThisChar.DaybreakID] = new WantResults() { QuestID = ThisQuest.Key, GreedRate = NewVal }; } } } return(returnValue); }