List<Searcher> accessorySearchers = new List<Searcher>(); // We use this list to stop accessory searchers when the user stops the build. private void btnCalculatePossibilities_Click(object sender, System.EventArgs e) { btnCalculatePossibilities.Enabled = false; treeView1.Nodes.Clear(); PopulateFromEquipmentGroup(null); if (armorSearcher != null) { armorSearcher.SuitCreated -= new Action<CompletedSuit>(armorSearcher_SuitCreated); armorSearcher.SearchCompleted -= new Action(armorSearcher_SearchCompleted); } accessorySearchers.Clear(); SearcherConfiguration config = new SearcherConfiguration(); config.CantripsToLookFor = filtersControl1.CantripsToLookFor; config.PrimaryArmorSet = filtersControl1.PrimaryArmorSetId; config.SecondaryArmorSet = filtersControl1.SecondaryArmorSetId; // Go through our Equipment and remove/disable any extra spells that we're not looking for foreach (var piece in boundList) { piece.SpellsToUseInSearch.Clear(); foreach (Spell spell in piece.CachedSpells) { if (config.SpellPassesRules(spell) && !spell.IsOfSameFamilyAndGroup(Spell.GetSpell("Epic Impenetrability"))) piece.SpellsToUseInSearch.Add(spell); } } // Build our base suit from locked in pieces CompletedSuit baseSuit = new CompletedSuit(); // Add locked pieces in order of slots covered, starting with the fewest for (int slotCount = 1; slotCount <= 5; slotCount++) { foreach (SuitBuildableMyWorldObject item in boundList) { // Don't add items that we don't care about if (item.EquippableSlots == EquippableSlotFlags.None || item.EquippableSlots == EquippableSlotFlags.MeleeWeapon || item.EquippableSlots == EquippableSlotFlags.MissileWeapon || item.EquippableSlots == EquippableSlotFlags.TwoHandWeapon || item.EquippableSlots == EquippableSlotFlags.Wand || item.EquippableSlots == EquippableSlotFlags.MissileAmmo) continue; if (item.EquippableSlots == EquippableSlotFlags.Cloak || item.EquippableSlots == EquippableSlotFlags.BlueAetheria || item.EquippableSlots == EquippableSlotFlags.YellowAetheria || item.EquippableSlots == EquippableSlotFlags.RedAetheria) continue; if (item.Locked && item.EquippableSlots.GetTotalBitsSet() == slotCount) { try { if (item.EquippableSlots.GetTotalBitsSet() > 1 && item.EquippableSlots.IsBodyArmor() && MessageBox.Show(item.Name + " covers multiple slots. Would you like to reduce it?", "Add Item", MessageBoxButtons.YesNo) == DialogResult.Yes) { var reductionOptions = item.Coverage.ReductionOptions(); EquippableSlotFlags slotFlag = EquippableSlotFlags.None; foreach (var option in reductionOptions) { if (option == CoverageFlags.Chest && baseSuit[EquippableSlotFlags.Chest] == null) { slotFlag = EquippableSlotFlags.Chest; break; } if (option == CoverageFlags.UpperArms && baseSuit[EquippableSlotFlags.UpperArms] == null) { slotFlag = EquippableSlotFlags.UpperArms; break; } if (option == CoverageFlags.LowerArms && baseSuit[EquippableSlotFlags.LowerArms] == null) { slotFlag = EquippableSlotFlags.LowerArms; break; } if (option == CoverageFlags.Abdomen && baseSuit[EquippableSlotFlags.Abdomen] == null) { slotFlag = EquippableSlotFlags.Abdomen; break; } if (option == CoverageFlags.UpperLegs && baseSuit[EquippableSlotFlags.UpperLegs] == null) { slotFlag = EquippableSlotFlags.UpperLegs; break; } if (option == CoverageFlags.LowerLegs && baseSuit[EquippableSlotFlags.LowerLegs] == null) { slotFlag = EquippableSlotFlags.LowerLegs; break; } } if (slotFlag == EquippableSlotFlags.None) MessageBox.Show("Unable to reduce " + item + " into an open single slot." + Environment.NewLine + "Reduction coverage option not expected or not open."); else baseSuit.AddItem(slotFlag, item); } else if (!baseSuit.AddItem(item)) MessageBox.Show("Failed to add " + item.Name + " to base suit of armor."); } catch (ArgumentException) // Item failed to add { MessageBox.Show("Failed to add " + item.Name + " to base suit of armor. It overlaps another piece"); } } } } if (baseSuit.Count > 0) AddCompletedSuitToTreeView(baseSuit); armorSearcher = new ArmorSearcher(config, boundList, baseSuit); armorSearcher.SuitCreated += new Action<CompletedSuit>(armorSearcher_SuitCreated); armorSearcher.SearchCompleted += new Action(armorSearcher_SearchCompleted); new Thread(() => { //DateTime startTime = DateTime.Now; // Do the actual search here armorSearcher.Start(); //DateTime endTime = DateTime.Now; //MessageBox.Show((endTime - startTime).TotalSeconds.ToString()); }).Start(); btnStopCalculating.Enabled = true; progressBar1.Style = ProgressBarStyle.Marquee; }
public CompletedSuit CreateCompletedSuit() { CompletedSuit suit = new CompletedSuit(); for (int i = 0; i < nextOpenCacheIndex; i++) suit.AddItem(cache[i].Slot, cache[i].Piece); return suit; }
private void btnCalculatePossibilities_Click(object sender, System.EventArgs e) { if (filtersControl1.CantripsToLookFor.Count == 0) { if (MessageBox.Show("You have no spells selected. Your search results won't be very useful. Would you like to go ahead anyway?" + Environment.NewLine + Environment.NewLine + "To select spells, load defsults or click the spells you want on the bottom of the filters group on Tab labeled 'Step 1. Add Inventory'", "No Spells Selected", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { return; } } btnCalculatePossibilities.Enabled = false; treeView1.Nodes.Clear(); PopulateFromEquipmentGroup(null); if (armorSearcher != null) { armorSearcher.SuitCreated -= new Action <CompletedSuit>(armorSearcher_SuitCreated); armorSearcher.SearchCompleted -= new Action(ThreadFinished); } accessorySearchers.Clear(); abortedSearch = false; SearcherConfiguration config = new SearcherConfiguration(); config.CantripsToLookFor = filtersControl1.CantripsToLookFor; config.PrimaryArmorSet = filtersControl1.PrimaryArmorSetId; config.SecondaryArmorSet = filtersControl1.SecondaryArmorSetId; // Build the list of items we're going to use in our search searchItems = new List <LeanMyWorldObject>(); // Only add items that meet our minimum requirements foreach (var piece in boundList) { if (piece.Locked || (!piece.Exclude && config.ItemPassesRules(piece))) { searchItems.Add(new LeanMyWorldObject(piece)); } } var possibleSpells = new List <Spell>(); // Go through our Equipment and remove/disable any extra spells that we're not looking for foreach (var piece in searchItems) { piece.SpellsToUseInSearch.Clear(); foreach (Spell spell in piece.ExtendedMyWorldObject.CachedSpells) { if (config.SpellPassesRules(spell) && !spell.IsOfSameFamilyAndGroup(SpellTools.GetSpell(4667))) // Epic Impenetrability { piece.SpellsToUseInSearch.Add(spell); if (!possibleSpells.Contains(spell)) { possibleSpells.Add(spell); } } } } // Go through our possible spells and make sure they are all unique. This will also keep the lowest level spell that passed our rules for (int i = possibleSpells.Count - 1; i >= 0; i--) { for (int j = 0; j < i; j++) { if (possibleSpells[j].IsOfSameFamilyAndGroup(possibleSpells[i])) { if (possibleSpells[j].Surpasses(possibleSpells[i])) { possibleSpells.RemoveAt(j); } else { possibleSpells.RemoveAt(j); } goto next; } } next :; } // Now, we create our bitmapped spell map if (possibleSpells.Count > 32) { MessageBox.Show("Too many spells."); btnCalculatePossibilities.Enabled = true; return; } Dictionary <Spell, int> spellMap = new Dictionary <Spell, int>(); for (int i = 0; i < possibleSpells.Count; i++) { spellMap.Add(possibleSpells[i], 1 << i); } // Now, we update each item with the new spell map foreach (var piece in searchItems) { piece.SpellBitmap = 0; foreach (var spell in piece.SpellsToUseInSearch) { foreach (var kvp in spellMap) { if (spell.IsOfSameFamilyAndGroup(kvp.Key)) { piece.SpellBitmap |= kvp.Value; } } } } // Build our base suit from locked in pieces CompletedSuit baseSuit = new CompletedSuit(); // Add locked pieces in order of slots covered, starting with the fewest for (int slotCount = 1; slotCount <= 5; slotCount++) { foreach (var item in searchItems) { // Don't add items that we don't care about if (item.EquippableSlots == EquipMask.None || item.EquippableSlots == EquipMask.MeleeWeapon || item.EquippableSlots == EquipMask.MissileWeapon || item.EquippableSlots == EquipMask.TwoHanded || item.EquippableSlots == EquipMask.Held || item.EquippableSlots == EquipMask.MissileAmmo) { continue; } if (item.EquippableSlots == EquipMask.Cloak || item.EquippableSlots == EquipMask.SigilOne || item.EquippableSlots == EquipMask.SigilTwo || item.EquippableSlots == EquipMask.SigilThree) { continue; } if (item.ExtendedMyWorldObject.Locked && item.EquippableSlots.GetTotalBitsSet() == slotCount) { try { if (item.EquippableSlots.GetTotalBitsSet() > 1 && item.EquippableSlots.IsBodyArmor() && MessageBox.Show(item.ExtendedMyWorldObject.Name + " covers multiple slots. Would you like to reduce it?", "Add Item", MessageBoxButtons.YesNo) == DialogResult.Yes) { var reductionOptions = item.Coverage.ReductionOptions(); EquipMask slotFlag = EquipMask.None; foreach (var option in reductionOptions) { if (option == CoverageMask.OuterwearChest && baseSuit[EquipMask.ChestArmor] == null) { slotFlag = EquipMask.ChestArmor; break; } if (option == CoverageMask.OuterwearUpperArms && baseSuit[EquipMask.UpperArmArmor] == null) { slotFlag = EquipMask.UpperArmArmor; break; } if (option == CoverageMask.OuterwearLowerArms && baseSuit[EquipMask.LowerArmArmor] == null) { slotFlag = EquipMask.LowerArmArmor; break; } if (option == CoverageMask.OuterwearAbdomen && baseSuit[EquipMask.AbdomenArmor] == null) { slotFlag = EquipMask.AbdomenArmor; break; } if (option == CoverageMask.OuterwearUpperLegs && baseSuit[EquipMask.UpperLegArmor] == null) { slotFlag = EquipMask.UpperLegArmor; break; } if (option == CoverageMask.OuterwearLowerLegs && baseSuit[EquipMask.LowerLegArmor] == null) { slotFlag = EquipMask.LowerLegArmor; break; } if (option == CoverageMask.Feet && baseSuit[EquipMask.FootWear] == null) { slotFlag = EquipMask.FootWear; break; } } if (slotFlag == EquipMask.None) { MessageBox.Show("Unable to reduce " + item + " into an open single slot." + Environment.NewLine + "Reduction coverage option not expected or not open."); } else { baseSuit.AddItem(slotFlag, item); } } else if (!baseSuit.AddItem(item)) { MessageBox.Show("Failed to add " + item.ExtendedMyWorldObject.Name + " to base suit of armor."); } } catch (ArgumentException) // Item failed to add { MessageBox.Show("Failed to add " + item.ExtendedMyWorldObject.Name + " to base suit of armor. It overlaps another piece"); } } } } if (baseSuit.Count > 0) { AddCompletedSuitToTreeView(baseSuit); } armorSearcher = new ArmorSearcher(config, searchItems, baseSuit); armorSearcherHighestItemCount = 0; armorSearcher.SuitCreated += new Action <CompletedSuit>(armorSearcher_SuitCreated); armorSearcher.SearchCompleted += new Action(ThreadFinished); startTime = DateTime.Now; armorThreadCounter = 1; accessoryThreadQueueCounter = 0; accessoryThreadRunningCounter = 0; timerCalculatorUpdator.Start(); new Thread(() => { // Do the actual search here armorSearcher.Start(); Interlocked.Decrement(ref armorThreadCounter); ThreadFinished(); }).Start(); btnStopCalculating.Enabled = true; progressBar1.Style = ProgressBarStyle.Marquee; }
List <Searcher> accessorySearchers = new List <Searcher>(); // We use this list to stop accessory searchers when the user stops the build. private void btnCalculatePossibilities_Click(object sender, System.EventArgs e) { btnCalculatePossibilities.Enabled = false; treeView1.Nodes.Clear(); PopulateFromEquipmentGroup(null); if (armorSearcher != null) { armorSearcher.SuitCreated -= new Action <CompletedSuit>(armorSearcher_SuitCreated); armorSearcher.SearchCompleted -= new Action(armorSearcher_SearchCompleted); } accessorySearchers.Clear(); SearcherConfiguration config = new SearcherConfiguration(); config.CantripsToLookFor = filtersControl1.CantripsToLookFor; config.PrimaryArmorSet = filtersControl1.PrimaryArmorSetId; config.SecondaryArmorSet = filtersControl1.SecondaryArmorSetId; // Go through our Equipment and remove/disable any extra spells that we're not looking for foreach (var piece in boundList) { piece.SpellsToUseInSearch.Clear(); foreach (Spell spell in piece.CachedSpells) { if (config.SpellPassesRules(spell) && !spell.IsOfSameFamilyAndGroup(Spell.GetSpell("Epic Impenetrability"))) { piece.SpellsToUseInSearch.Add(spell); } } } // Build our base suit from locked in pieces CompletedSuit baseSuit = new CompletedSuit(); // Add locked pieces in order of slots covered, starting with the fewest for (int slotCount = 1; slotCount <= 5; slotCount++) { foreach (SuitBuildableMyWorldObject item in boundList) { // Don't add items that we don't care about if (item.EquippableSlots == EquippableSlotFlags.None || item.EquippableSlots == EquippableSlotFlags.MeleeWeapon || item.EquippableSlots == EquippableSlotFlags.MissileWeapon || item.EquippableSlots == EquippableSlotFlags.TwoHandWeapon || item.EquippableSlots == EquippableSlotFlags.Wand || item.EquippableSlots == EquippableSlotFlags.MissileAmmo) { continue; } if (item.EquippableSlots == EquippableSlotFlags.Cloak || item.EquippableSlots == EquippableSlotFlags.BlueAetheria || item.EquippableSlots == EquippableSlotFlags.YellowAetheria || item.EquippableSlots == EquippableSlotFlags.RedAetheria) { continue; } if (item.Locked && item.EquippableSlots.GetTotalBitsSet() == slotCount) { try { if (item.EquippableSlots.GetTotalBitsSet() > 1 && item.EquippableSlots.IsBodyArmor() && MessageBox.Show(item.Name + " covers multiple slots. Would you like to reduce it?", "Add Item", MessageBoxButtons.YesNo) == DialogResult.Yes) { var reductionOptions = item.Coverage.ReductionOptions(); EquippableSlotFlags slotFlag = EquippableSlotFlags.None; foreach (var option in reductionOptions) { if (option == CoverageFlags.Chest && baseSuit[EquippableSlotFlags.Chest] == null) { slotFlag = EquippableSlotFlags.Chest; break; } if (option == CoverageFlags.UpperArms && baseSuit[EquippableSlotFlags.UpperArms] == null) { slotFlag = EquippableSlotFlags.UpperArms; break; } if (option == CoverageFlags.LowerArms && baseSuit[EquippableSlotFlags.LowerArms] == null) { slotFlag = EquippableSlotFlags.LowerArms; break; } if (option == CoverageFlags.Abdomen && baseSuit[EquippableSlotFlags.Abdomen] == null) { slotFlag = EquippableSlotFlags.Abdomen; break; } if (option == CoverageFlags.UpperLegs && baseSuit[EquippableSlotFlags.UpperLegs] == null) { slotFlag = EquippableSlotFlags.UpperLegs; break; } if (option == CoverageFlags.LowerLegs && baseSuit[EquippableSlotFlags.LowerLegs] == null) { slotFlag = EquippableSlotFlags.LowerLegs; break; } } if (slotFlag == EquippableSlotFlags.None) { MessageBox.Show("Unable to reduce " + item + " into an open single slot." + Environment.NewLine + "Reduction coverage option not expected or not open."); } else { baseSuit.AddItem(slotFlag, item); } } else if (!baseSuit.AddItem(item)) { MessageBox.Show("Failed to add " + item.Name + " to base suit of armor."); } } catch (ArgumentException) // Item failed to add { MessageBox.Show("Failed to add " + item.Name + " to base suit of armor. It overlaps another piece"); } } } } if (baseSuit.Count > 0) { AddCompletedSuitToTreeView(baseSuit); } armorSearcher = new ArmorSearcher(config, boundList, baseSuit); armorSearcher.SuitCreated += new Action <CompletedSuit>(armorSearcher_SuitCreated); armorSearcher.SearchCompleted += new Action(armorSearcher_SearchCompleted); new Thread(() => { //DateTime startTime = DateTime.Now; // Do the actual search here armorSearcher.Start(); //DateTime endTime = DateTime.Now; //MessageBox.Show((endTime - startTime).TotalSeconds.ToString()); }).Start(); btnStopCalculating.Enabled = true; progressBar1.Style = ProgressBarStyle.Marquee; }