public void Push(SuitBuildableMyWorldObject item, EquippableSlotFlags slot) { cache[nextOpenCacheIndex].Piece = item; cache[nextOpenCacheIndex].Slot = slot; cache[nextOpenCacheIndex].SpellCount = item.SpellsToUseInSearch.Count; occupiedSlots |= slot; for (int i = 0; i < item.SpellsToUseInSearch.Count; i++) { spells[nextOpenSpellIndex] = item.SpellsToUseInSearch[i]; nextOpenSpellIndex++; } nextOpenCacheIndex++; if (item.ItemSetId != -1) armorSetCountById[item.ItemSetId]++; if (item.CalcedStartingArmorLevel > 0) TotalBaseArmorLevel += (item.CalcedStartingArmorLevel * slot.GetTotalBitsSet()); if (slot.IsBodyArmor()) TotalBodyArmorPieces++; }
public void Push(SuitBuildableMyWorldObject item, EquippableSlotFlags slot) { cache[nextOpenCacheIndex].Piece = item; cache[nextOpenCacheIndex].Slot = slot; cache[nextOpenCacheIndex].SpellCount = item.SpellsToUseInSearch.Count; occupiedSlots |= slot; for (int i = 0; i < item.SpellsToUseInSearch.Count; i++) { spells[nextOpenSpellIndex] = item.SpellsToUseInSearch[i]; nextOpenSpellIndex++; } nextOpenCacheIndex++; if (item.ItemSetId != -1) { armorSetCountById[item.ItemSetId]++; } if (item.CalcedStartingArmorLevel > 0) { TotalBaseArmorLevel += (item.CalcedStartingArmorLevel * slot.GetTotalBitsSet()); } if (slot.IsBodyArmor()) { TotalBodyArmorPieces++; } }
public LeanMyWorldObject(ExtendedMyWorldObject myWorldObject) { ExtendedMyWorldObject = myWorldObject; EquippableSlots = myWorldObject.EquippableSlots; Coverage = myWorldObject.Coverage; ItemSetId = myWorldObject.IntValues.ContainsKey(265) ? myWorldObject.IntValues[265] : 0; ObjectClass = myWorldObject.ObjectClass; Material = myWorldObject.Material; CalcedStartingArmorLevel = myWorldObject.CalcedStartingArmorLevel; damRating = myWorldObject.DamRating; damResistRating = myWorldObject.DamResistRating; critRating = myWorldObject.CritRating; critResistRating = myWorldObject.CritResistRating; critDamRating = myWorldObject.CritDamRating; critDamResistRating = myWorldObject.CritDamResistRating; healBoostRating = myWorldObject.HealBoostRating; vitalityRating = myWorldObject.VitalityRating; }
public static bool IsUnderwear(this EquippableSlotFlags value) { if (value == (EquippableSlotFlags.Feet | EquippableSlotFlags.PantsLowerLegs)) { return(false); } return(((int)value & 0x000000DE) != 0); }
public bool PutItemInBuckets(SuitBuildableMyWorldObject piece, EquippableSlotFlags slot) { bool foundBucket = false; foreach (Bucket bucket in this) { if ((slot & bucket.Slot) == bucket.Slot) { foundBucket = true; bucket.Add(piece); } } return(foundBucket); }
public void Pop() { occupiedSlots ^= cache[nextOpenCacheIndex - 1].Slot; nextOpenSpellIndex -= cache[nextOpenCacheIndex - 1].SpellCount; armorSetCountById[cache[nextOpenCacheIndex - 1].Piece.ItemSetId]--; if (cache[nextOpenCacheIndex - 1].Piece.CalcedStartingArmorLevel > 0) TotalBaseArmorLevel -= (cache[nextOpenCacheIndex - 1].Piece.CalcedStartingArmorLevel * cache[nextOpenCacheIndex - 1].Slot.GetTotalBitsSet()); if (cache[nextOpenCacheIndex - 1].Slot.IsBodyArmor()) TotalBodyArmorPieces--; nextOpenCacheIndex--; }
public static int GetTotalBitsSet(this EquippableSlotFlags value) { int slotFlags = (int)value; int bitsSet = 0; while (slotFlags != 0) { if ((slotFlags & 1) == 1) { bitsSet++; } slotFlags >>= 1; } return(bitsSet); }
public void Push(LeanMyWorldObject item, EquippableSlotFlags slot) { slotCache[nextOpenCacheIndex].Piece = item; slotCache[nextOpenCacheIndex].Slot = slot; //slotCache[nextOpenCacheIndex].SpellCount = item.SpellsToUseInSearch.Count; // Used for the old search compare method occupiedSlots |= slot; // Used for the old search compare method /*for (int i = 0; i < item.SpellsToUseInSearch.Count; i++) * { * spells[nextOpenSpellIndex] = item.SpellsToUseInSearch[i]; * nextOpenSpellIndex++; * }*/ if (nextOpenCacheIndex == 0) { spellBitmaps[nextOpenCacheIndex] = item.SpellBitmap; } else { spellBitmaps[nextOpenCacheIndex] = spellBitmaps[nextOpenCacheIndex - 1] | item.SpellBitmap; } nextOpenCacheIndex++; if (item.ItemSetId != -1) { armorSetCountById[item.ItemSetId]++; } if (item.CalcedStartingArmorLevel > 0) { TotalBaseArmorLevel += (item.CalcedStartingArmorLevel * slot.GetTotalBitsSet()); } if (slot.IsBodyArmor()) { TotalBodyArmorPieces++; } }
public void Pop() { occupiedSlots ^= cache[nextOpenCacheIndex - 1].Slot; nextOpenSpellIndex -= cache[nextOpenCacheIndex - 1].SpellCount; armorSetCountById[cache[nextOpenCacheIndex - 1].Piece.ItemSetId]--; if (cache[nextOpenCacheIndex - 1].Piece.CalcedStartingArmorLevel > 0) { TotalBaseArmorLevel -= (cache[nextOpenCacheIndex - 1].Piece.CalcedStartingArmorLevel * cache[nextOpenCacheIndex - 1].Slot.GetTotalBitsSet()); } if (cache[nextOpenCacheIndex - 1].Slot.IsBodyArmor()) { TotalBodyArmorPieces--; } nextOpenCacheIndex--; }
public void Pop() { occupiedSlots ^= slotCache[nextOpenCacheIndex - 1].Slot; //nextOpenSpellIndex -= slotCache[nextOpenCacheIndex - 1].SpellCount; // Used for the old search compare method armorSetCountById[slotCache[nextOpenCacheIndex - 1].Piece.ItemSetId]--; if (slotCache[nextOpenCacheIndex - 1].Piece.CalcedStartingArmorLevel > 0) { TotalBaseArmorLevel -= (slotCache[nextOpenCacheIndex - 1].Piece.CalcedStartingArmorLevel * slotCache[nextOpenCacheIndex - 1].Slot.GetTotalBitsSet()); } if (slotCache[nextOpenCacheIndex - 1].Slot.IsBodyArmor()) { TotalBodyArmorPieces--; } nextOpenCacheIndex--; }
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 == 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.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(); 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 (option == CoverageFlags.Feet && baseSuit[EquippableSlotFlags.Feet] == null) { slotFlag = EquippableSlotFlags.Feet; 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.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; }
public bool SlotIsOpen(EquippableSlotFlags slot) { return ((occupiedSlots & slot) == 0); }
public static bool IsShirt(this EquippableSlotFlags value) { return(((int)value & 0x0000001A) != 0); }
public static bool PutItemInBuckets(this ICollection <Bucket> value, LeanMyWorldObject piece, EquippableSlotFlags slot) { bool foundBucket = false; foreach (Bucket bucket in value) { if ((slot & bucket.Slot) == bucket.Slot) { foundBucket = true; bucket.Add(piece); } } return(foundBucket); }
public bool SlotIsOpen(EquippableSlotFlags slot) { return((occupiedSlots & slot) == 0); }
public static bool IsExtremityBodyArmor(this EquippableSlotFlags value) { return((value & (EquippableSlotFlags.Feet | EquippableSlotFlags.Hands | EquippableSlotFlags.Head)) != 0); }
public static bool IsCoreBodyArmor(this EquippableSlotFlags value) { return((value & (EquippableSlotFlags.Chest | EquippableSlotFlags.UpperArms | EquippableSlotFlags.LowerArms | EquippableSlotFlags.Abdomen | EquippableSlotFlags.UpperLegs | EquippableSlotFlags.LowerLegs)) != 0); }
// Some feet armor have EquippableSlotFlags.Feet | EquippableSlotFlags.PantsLowerLegs public static bool IsBodyArmor(this EquippableSlotFlags value) { return(((int)value & 0x00007F21) != 0); }
public Bucket(EquippableSlotFlags slot) { Slot = slot; }
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; }