void AddCompletedSuitToTreeView(CompletedSuit suit) { CompletedSuitTreeNode newNode = new CompletedSuitTreeNode(suit); TreeNodeCollection nodes = FindDeepestNode(treeView1.Nodes, suit); for (int i = 0; i <= nodes.Count; i++) { if (i == nodes.Count) { nodes.Add(newNode); break; } CompletedSuitTreeNode nodeAsSuit = (nodes[i] as CompletedSuitTreeNode); //if (nodeAsSuit != null && (nodeAsSuit.Suit.Count < suit.Count || (nodeAsSuit.Suit.Count == suit.Count && nodeAsSuit.Suit.TotalBaseArmorLevel < suit.TotalBaseArmorLevel))) if (nodeAsSuit != null) { if (nodeAsSuit.Suit.TotalBaseArmorLevel < suit.TotalBaseArmorLevel) { nodes.Insert(i, newNode); break; } if ((nodeAsSuit.Suit.TotalBaseArmorLevel == suit.TotalBaseArmorLevel) && ((nodeAsSuit.Suit.TotalEffectiveEpics < suit.TotalEffectiveEpics) || (nodeAsSuit.Suit.TotalEffectiveEpics == suit.TotalEffectiveEpics && nodeAsSuit.Suit.TotalEffectiveMajors < suit.TotalEffectiveMajors))) { nodes.Insert(i, newNode); break; } } } }
void accSearcher_SuitCreated(CompletedSuit obj) { if (!IsDisposed) { BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); } }
void armorSearcher_SuitCreated(CompletedSuit obj) { BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); lock (lockObject) { // We don't accessorise suits that have less items than our best suit if (obj.Count < armorSearcherHighestItemCount) { return; } if (obj.Count > armorSearcherHighestItemCount) { armorSearcherHighestItemCount = obj.Count; // Disable previous accessory searchers that have a lower initial item count foreach (var kvp in accessorySearchers) { if (kvp.Value < armorSearcherHighestItemCount && kvp.Key != null && kvp.Key.Running) { kvp.Key.Stop(); } } } } Interlocked.Increment(ref accessoryThreadQueueCounter); ThreadPool.QueueUserWorkItem(delegate { AccessorySearcher accSearcher; lock (lockObject) { if (abortedSearch || obj.Count < armorSearcherHighestItemCount) { Interlocked.Decrement(ref accessoryThreadQueueCounter); ThreadFinished(); return; } Interlocked.Increment(ref accessoryThreadRunningCounter); accSearcher = new AccessorySearcher(new SearcherConfiguration(), searchItems, obj); accessorySearchers.TryAdd(accSearcher, obj.Count); } accSearcher.SuitCreated += new Action <CompletedSuit>(accSearcher_SuitCreated); accSearcher.Start(); accSearcher.SuitCreated -= new Action <CompletedSuit>(accSearcher_SuitCreated); Interlocked.Decrement(ref accessoryThreadRunningCounter); Interlocked.Decrement(ref accessoryThreadQueueCounter); ThreadFinished(); }); }
public ArmorSearcher(SearcherConfiguration config, IEnumerable<SuitBuildableMyWorldObject> pieces, CompletedSuit startingSuit = null) : base(config, pieces, startingSuit) { // Sort the list with the highest armor first Equipment.Sort((a, b) => b.CalcedStartingArmorLevel.CompareTo(a.CalcedStartingArmorLevel)); // Remove any pieces that have no armor for (int i = Equipment.Count - 1 ; i >= 0 ; i--) { if (Equipment[i].CalcedStartingArmorLevel <= 0) Equipment.RemoveAt(i); } }
void armorSearcher_SuitCreated(CompletedSuit obj) { BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); ThreadPool.QueueUserWorkItem(delegate { AccessorySearcher accSearcher = new AccessorySearcher(new SearcherConfiguration(), boundList, obj); accessorySearchers.Add(accSearcher); accSearcher.SuitCreated += new Action <CompletedSuit>(accSearcher_SuitCreated); accSearcher.Start(); accSearcher.SuitCreated -= new Action <CompletedSuit>(accSearcher_SuitCreated); }); }
TreeNodeCollection FindDeepestNode(TreeNodeCollection nodes, CompletedSuit suit) { foreach (TreeNode node in nodes) { CompletedSuitTreeNode nodeAsSuit = (node as CompletedSuitTreeNode); if (nodeAsSuit != null && suit.IsProperSupersetOf(nodeAsSuit.Suit)) { return(FindDeepestNode(node.Nodes, suit)); } } return(nodes); }
public AccessorySearcher(SearcherConfiguration config, IEnumerable<SuitBuildableMyWorldObject> accessories, CompletedSuit startingSuit = null) : base(config, accessories, startingSuit) { // Sort the list with the highest amount of epics // As a temp fix we just sort based on spell count Equipment.Sort((a, b) => { if (a.CalcedStartingArmorLevel > 0 && b.CalcedStartingArmorLevel > 0) return b.CalcedStartingArmorLevel.CompareTo(a.CalcedStartingArmorLevel); if (a.CalcedStartingArmorLevel > 0 && b.CalcedStartingArmorLevel == 0) return -1; if (a.CalcedStartingArmorLevel == 0 && b.CalcedStartingArmorLevel > 0) return 1; return b.SpellsToUseInSearch.Count.CompareTo(a.SpellsToUseInSearch.Count); }); // Remove any pieces that have armor for (int i = Equipment.Count - 1; i >= 0; i--) { if (Equipment[i].CalcedStartingArmorLevel > 0) Equipment.RemoveAt(i); } }
private void PopulateFromEquipmentGroup(CompletedSuit suit) { if (suit == null) { return; } foreach (Control cntrl in tabPage1.Controls) { if (cntrl is EquipmentPieceControl) { EquipmentPieceControl coveragePiece = cntrl as EquipmentPieceControl; coveragePiece.SetEquipmentPiece(suit[coveragePiece.EquippableSlots] == null ? null : suit[coveragePiece.EquippableSlots].ExtendedMyWorldObject); cntrl.Refresh(); } } cntrlSuitCantrips.Clear(); // This method adds every spell for all the items of the suit foreach (var kvp in suit) { foreach (var spell in kvp.Value.ExtendedMyWorldObject.CachedSpells) { cntrlSuitCantrips.Add(spell); } } // This method only adds the spells that met our spell filter criteria //foreach (Spell spell in suit.EffectiveSpells) // cntrlSuitCantrips.Add(spell); cntrlSuitCantrips.Refresh(); }
void accSearcher_SuitCreated(CompletedSuit obj) { if (!IsDisposed) BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); }
void AddCompletedSuitToTreeView(CompletedSuit suit) { CompletedSuitTreeNode newNode = new CompletedSuitTreeNode(suit); TreeNodeCollection nodes = FindDeepestNode(treeView1.Nodes, suit); for (int i = 0; i <= nodes.Count; i++) { if (i == nodes.Count) { nodes.Add(newNode); break; } CompletedSuitTreeNode nodeAsSuit = (nodes[i] as CompletedSuitTreeNode); //if (nodeAsSuit != null && (nodeAsSuit.Suit.Count < suit.Count || (nodeAsSuit.Suit.Count == suit.Count && nodeAsSuit.Suit.TotalBaseArmorLevel < suit.TotalBaseArmorLevel))) if (nodeAsSuit != null) { if (nodeAsSuit.Suit.TotalBaseArmorLevel < suit.TotalBaseArmorLevel) { nodes.Insert(i, newNode); break; } if ((nodeAsSuit.Suit.TotalBaseArmorLevel == suit.TotalBaseArmorLevel) && ((nodeAsSuit.Suit.TotalEffectiveEpics < suit.TotalEffectiveEpics) || (nodeAsSuit.Suit.TotalEffectiveEpics == suit.TotalEffectiveEpics && nodeAsSuit.Suit.TotalEffectiveMajors < suit.TotalEffectiveMajors))) { nodes.Insert(i, newNode); break; } } } }
public CompletedSuitTreeNode(CompletedSuit suit) { Suit = suit; Text = suit.ToString(); }
void armorSearcher_SuitCreated(CompletedSuit obj) { BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); ThreadPool.QueueUserWorkItem(delegate { AccessorySearcher accSearcher = new AccessorySearcher(new SearcherConfiguration(), boundList, obj); accessorySearchers.Add(accSearcher); accSearcher.SuitCreated += new Action<CompletedSuit>(accSearcher_SuitCreated); accSearcher.Start(); accSearcher.SuitCreated -= new Action<CompletedSuit>(accSearcher_SuitCreated); }); }
protected virtual void OnSuitCreated(CompletedSuit obj) { Action<CompletedSuit> handler = SuitCreated; if (handler != null) handler(obj); }
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; }
protected Searcher(SearcherConfiguration config, IEnumerable<SuitBuildableMyWorldObject> equipment, CompletedSuit startingSuit = null) { Config = config; foreach (var piece in equipment) { if (!piece.Exclude) Equipment.Add(piece); } // Remove pieces that don't meet our minimum requirements for (int i = Equipment.Count - 1; i >= 0; i--) { if (!config.ItemPassesRules(Equipment[i])) Equipment.RemoveAt(i); } // Remove surpassed pieces for (int i = Equipment.Count - 1; i >= 0; i--) { if (Equipment.ItemIsSurpassed(Equipment[i])) Equipment.RemoveAt(i); } // If we were given a starting suit, lets start our SuitBuilder off with all those items if (startingSuit != null) { foreach (var o in startingSuit) SuitBuilder.Push(o.Value, o.Key); } // Remove pieces that can provide no beneficial spell for (int i = Equipment.Count - 1; i >= 0; i--) { if (!SuitBuilder.CanGetBeneficialSpellFrom(Equipment[i])) Equipment.RemoveAt(i); } // Remove pieces we can't add to our base suit for (int i = Equipment.Count - 1; i >= 0; i--) { if (!SuitBuilder.SlotIsOpen(Equipment[i].EquippableSlots)) { if (Equipment[i].EquippableSlots.GetTotalBitsSet() == 1) Equipment.RemoveAt(i); else { if (Equipment[i].EquippableSlots.IsBodyArmor()) { var reductionOptions = Equipment[i].Coverage.ReductionOptions(); foreach (var option in reductionOptions) { if (option == CoverageFlags.Chest && SuitBuilder.SlotIsOpen(EquippableSlotFlags.Chest)) goto end; if (option == CoverageFlags.UpperArms && SuitBuilder.SlotIsOpen(EquippableSlotFlags.UpperArms)) goto end; if (option == CoverageFlags.LowerArms && SuitBuilder.SlotIsOpen(EquippableSlotFlags.LowerArms)) goto end; if (option == CoverageFlags.Abdomen && SuitBuilder.SlotIsOpen(EquippableSlotFlags.Abdomen)) goto end; if (option == CoverageFlags.UpperLegs && SuitBuilder.SlotIsOpen(EquippableSlotFlags.UpperLegs)) goto end; if (option == CoverageFlags.LowerLegs && SuitBuilder.SlotIsOpen(EquippableSlotFlags.LowerLegs)) goto end; } Equipment.RemoveAt(i); } else { if ((Equipment[i].EquippableSlots.HasFlag(EquippableSlotFlags.LeftRing) || Equipment[i].EquippableSlots.HasFlag(EquippableSlotFlags.RightRing)) && !SuitBuilder.SlotIsOpen(EquippableSlotFlags.LeftRing) && !SuitBuilder.SlotIsOpen(EquippableSlotFlags.RightRing)) { Equipment.RemoveAt(i); goto end; } if ((Equipment[i].EquippableSlots.HasFlag(EquippableSlotFlags.LeftBracelet) || Equipment[i].EquippableSlots.HasFlag(EquippableSlotFlags.RightBracelet)) && !SuitBuilder.SlotIsOpen(EquippableSlotFlags.LeftBracelet) && !SuitBuilder.SlotIsOpen(EquippableSlotFlags.RightBracelet)) { Equipment.RemoveAt(i); goto end; } } } } end: ; } }
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; }
TreeNodeCollection FindDeepestNode(TreeNodeCollection nodes, CompletedSuit suit) { foreach (TreeNode node in nodes) { CompletedSuitTreeNode nodeAsSuit = (node as CompletedSuitTreeNode); if (nodeAsSuit != null && suit.IsProperSupersetOf(nodeAsSuit.Suit)) return FindDeepestNode(node.Nodes, suit); } return nodes; }
public CompletedSuitTreeNode(CompletedSuit suit) { Suit = suit; Text = suit.ToString(); }
private void PopulateFromEquipmentGroup(CompletedSuit suit) { if (suit == null) return; foreach (Control cntrl in tabPage1.Controls) { if (cntrl is EquipmentPieceControl) { EquipmentPieceControl coveragePiece = cntrl as EquipmentPieceControl; coveragePiece.SetEquipmentPiece(suit[coveragePiece.EquippableSlots]); cntrl.Refresh(); } } cntrlSuitCantrips.Clear(); // This method adds every spell for all the items of the suit foreach (var kvp in suit) { foreach (var spell in kvp.Value.CachedSpells) cntrlSuitCantrips.Add(spell); } // This method only adds the spells that met our spell filter criteria //foreach (Spell spell in suit.EffectiveSpells) // cntrlSuitCantrips.Add(spell); cntrlSuitCantrips.Refresh(); }
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; }