public virtual List<ComparisonCalculationBase> GetEnchantCalculations(ItemSlot slot, Character character, CharacterCalculationsBase currentCalcs, bool equippedOnly, bool forceSlotName=false) { ClearCache(); List<ComparisonCalculationBase> enchantCalcs = new List<ComparisonCalculationBase>(); CharacterCalculationsBase calcsEquipped = null; CharacterCalculationsBase calcsUnequipped = null; // only need to get unequipped value once not every time around the loop Character charUnequipped = character.Clone(); charUnequipped.SetEnchantBySlot(slot, null); calcsUnequipped = GetCharacterCalculations(charUnequipped, null, false, false, false); foreach (Enchant enchant in Enchant.FindEnchants(slot, character)) { bool isEquipped = character.GetEnchantBySlot(slot) == enchant; if (equippedOnly && !isEquipped) continue; Character charEquipped = character.Clone(); charEquipped.SetEnchantBySlot(slot, enchant); calcsEquipped = GetCharacterCalculations(charEquipped, null, false, false, false); ComparisonCalculationBase enchantCalc = CreateNewComparisonCalculation(); enchantCalc.Name = forceSlotName || equippedOnly ? string.Format("{0} ({1})", enchant.Name, slot) : enchant.Name; enchantCalc.Item = new Item(enchant.Name, ItemQuality.Temp, ItemType.None, -1 * (enchant.Id + ((int)AvailableItemIDModifiers.Enchants * (int)enchant.Slot)), null, ItemSlot.None, null, false, enchant.Stats, null, ItemSlot.None, ItemSlot.None, ItemSlot.None, 0, 0, ItemDamageType.Physical, 0, null); enchantCalc.Item.Name = forceSlotName || equippedOnly ? string.Format("{0} ({1})", enchant.Name, slot) : enchant.Name; enchantCalc.Item.Stats = enchant.Stats; enchantCalc.Equipped = isEquipped; enchantCalc.OverallPoints = calcsEquipped.OverallPoints - calcsUnequipped.OverallPoints; float[] subPoints = new float[calcsEquipped.SubPoints.Length]; for (int i = 0; i < calcsEquipped.SubPoints.Length; i++) { subPoints[i] = calcsEquipped.SubPoints[i] - calcsUnequipped.SubPoints[i]; } enchantCalc.SubPoints = subPoints; enchantCalc.ImageSource = enchant.IconSource; enchantCalcs.Add(enchantCalc); if (equippedOnly && isEquipped) break; } return enchantCalcs; }
public OptimizerResults(Character before, Character after, bool talents) { _before = before.Clone(); _after = after.Clone(); _talents = talents; }
public virtual ComparisonCalculationBase GetItemSetCalculations(ItemSet itemset, Character character) { bool useCache = character == _cachedCharacter; Character characterWithAllSlotsEmpty = null; if (!useCache) characterWithAllSlotsEmpty = character.Clone(); Character characterWithNewItemSet = character.Clone(); if (!useCache) { foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { characterWithAllSlotsEmpty[cs] = null; } } foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { characterWithNewItemSet[cs] = itemset[cs]; } CharacterCalculationsBase characterStatsWithAllSlotsEmpty; if (useCache && _cachedCharacterStatsWithAllSlotsEmpty != null) characterStatsWithAllSlotsEmpty = _cachedCharacterStatsWithAllSlotsEmpty; else { characterStatsWithAllSlotsEmpty = GetCharacterCalculations(characterWithAllSlotsEmpty, null, false, false, false); _cachedCharacter = character; _cachedCharacterStatsWithAllSlotsEmpty = characterStatsWithAllSlotsEmpty; } CharacterCalculationsBase characterStatsWithNewItemSet = GetCharacterCalculations(characterWithNewItemSet, null, false, false, false); ComparisonCalculationBase itemSetCalc = CreateNewComparisonCalculation(); itemSetCalc.ItemInstance = null; itemSetCalc.Item = null; itemSetCalc.Name = itemset.Name != null ? itemset.Name : string.Empty; //itemSetCalc.Description = itemset.ListAsDesc; itemSetCalc.ItemSet = itemset; itemSetCalc.Equipped = true; foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { if (character[cs] != itemset[cs]) { itemSetCalc.Equipped = false; break; } } itemSetCalc.OverallPoints = characterStatsWithNewItemSet.OverallPoints - characterStatsWithAllSlotsEmpty.OverallPoints; float[] subPoints = new float[characterStatsWithNewItemSet.SubPoints.Length]; for (int i = 0; i < characterStatsWithNewItemSet.SubPoints.Length; i++) { subPoints[i] = characterStatsWithNewItemSet.SubPoints[i] - characterStatsWithAllSlotsEmpty.SubPoints[i]; } itemSetCalc.SubPoints = subPoints; characterStatsWithNewItemSet.ToString(); return itemSetCalc; }
public virtual ComparisonCalculationBase GetItemCalculations(Item additionalItem, Character character, CharacterSlot slot) { bool useCache = character == _cachedCharacter && slot == _cachedSlot; Character characterWithSlotEmpty = null; if (!useCache) characterWithSlotEmpty = character.Clone(); Character characterWithNewItem = character.Clone(); CharacterCalculationsBase characterStatsWithSlotEmpty; if (useCache) characterStatsWithSlotEmpty = _cachedCharacterStatsWithSlotEmpty; else { characterStatsWithSlotEmpty = GetCharacterCalculations(characterWithSlotEmpty, null, false, false, false); _cachedCharacter = character; _cachedSlot = slot; _cachedCharacterStatsWithSlotEmpty = characterStatsWithSlotEmpty; } CharacterCalculationsBase characterStatsWithNewItem = GetCharacterCalculations(characterWithNewItem, additionalItem, false, false, false); ComparisonCalculationBase itemCalc = CreateNewComparisonCalculation(); itemCalc.Item = additionalItem; itemCalc.Name = additionalItem.Name; itemCalc.Equipped = false; itemCalc.ImageSource = additionalItem.IconPath; itemCalc.OverallPoints = characterStatsWithNewItem.OverallPoints - characterStatsWithSlotEmpty.OverallPoints; float[] subPoints = new float[characterStatsWithNewItem.SubPoints.Length]; for (int i = 0; i < characterStatsWithNewItem.SubPoints.Length; i++) { subPoints[i] = characterStatsWithNewItem.SubPoints[i] - characterStatsWithSlotEmpty.SubPoints[i]; } itemCalc.SubPoints = subPoints; characterStatsWithNewItem.ToString(); return itemCalc; }
public virtual ComparisonCalculationBase GetItemGemCalculations(Item gem, Character character, CharacterSlot slot, int gemIndex) { if (gemIndex == 0) { return GetItemCalculations(gem, character, CharacterSlot.Gems); } bool useCache = character == _cachedCharacter && slot == _cachedSlot && gemIndex == _cachedGemIndex; Character characterWithGemSlotEmpty = null; if (!useCache) characterWithGemSlotEmpty = character.Clone(); Character characterWithNewGem = character.Clone(); if (!useCache) { ItemInstance emptyItemInstance = characterWithGemSlotEmpty[slot]; if (emptyItemInstance != null) { emptyItemInstance = emptyItemInstance.Clone(); emptyItemInstance.SetGem(gemIndex, null); characterWithGemSlotEmpty[slot] = emptyItemInstance; } } ItemInstance newItemInstance = characterWithNewGem[slot]; if (newItemInstance != null) { newItemInstance = newItemInstance.Clone(); newItemInstance.SetGem(gemIndex, gem); characterWithNewGem[slot] = newItemInstance; } CharacterCalculationsBase characterStatsWithGemSlotEmpty; if (useCache && _cachedCharacterStatsWithGemSlotEmpty != null) characterStatsWithGemSlotEmpty = _cachedCharacterStatsWithGemSlotEmpty; else { characterStatsWithGemSlotEmpty = GetCharacterCalculations(characterWithGemSlotEmpty, null, false, false, false); _cachedCharacter = character; _cachedSlot = slot; _cachedGemIndex = gemIndex; _cachedCharacterStatsWithGemSlotEmpty = characterStatsWithGemSlotEmpty; } CharacterCalculationsBase characterStatsWithNewGem = GetCharacterCalculations(characterWithNewGem, (Properties.GeneralSettings.Default.ShowRelativeToEquipped ? character[slot].Item : null), false, false, false); ComparisonCalculationBase itemCalc = CreateNewComparisonCalculation(); itemCalc.Item = gem; itemCalc.Name = gem != null ? gem.Name : string.Empty; itemCalc.Equipped = (character[slot] != null && character[slot].GetGem(gemIndex) == gem); itemCalc.OverallPoints = characterStatsWithNewGem.OverallPoints - characterStatsWithGemSlotEmpty.OverallPoints; float[] subPoints = new float[characterStatsWithNewGem.SubPoints.Length]; for (int i = 0; i < characterStatsWithNewGem.SubPoints.Length; i++) { subPoints[i] = characterStatsWithNewGem.SubPoints[i] - characterStatsWithGemSlotEmpty.SubPoints[i]; } itemCalc.SubPoints = subPoints; characterStatsWithNewGem.ToString(); return itemCalc; }
public virtual ComparisonCalculationBase GetItemCalculations(ItemInstance item, Character character, CharacterSlot slot) { // Check if the last iteration has the same character and is in the same slot. // If it is, we'll use the same characterWithSlotEmpty to save processing time bool useCache = character == _cachedCharacter && slot == _cachedSlot; Character characterWithSlotEmpty = null; if (!useCache) characterWithSlotEmpty = character.Clone(); Character characterWithNewItem = character.Clone(); if (slot != CharacterSlot.Metas && slot != CharacterSlot.Gems && slot != CharacterSlot.Cogwheels && slot != CharacterSlot.Hydraulics) { // Show Relative to Equipped makes the Base version character with the original item value 0 // and every other calc relative to that if (!useCache) characterWithSlotEmpty[slot] = (Properties.GeneralSettings.Default.ShowRelativeToEquipped && character[slot] != null ? character[slot].Clone() : null); characterWithNewItem[slot] = item; } CharacterCalculationsBase characterStatsWithSlotEmpty; if (useCache && _cachedCharacterStatsWithSlotEmpty != null) characterStatsWithSlotEmpty = _cachedCharacterStatsWithSlotEmpty; else { characterStatsWithSlotEmpty = GetCharacterCalculations(characterWithSlotEmpty, null, false, false, false); _cachedCharacter = character; _cachedSlot = slot; _cachedCharacterStatsWithSlotEmpty = characterStatsWithSlotEmpty; } CharacterCalculationsBase characterStatsWithNewItem = GetCharacterCalculations(characterWithNewItem, null, false, false, false); ComparisonCalculationBase itemCalc = CreateNewComparisonCalculation(); itemCalc.ItemInstance = item; itemCalc.Item = item.Item; itemCalc.Name = item.Name; itemCalc.Equipped = character[slot] == item; itemCalc.OverallPoints = characterStatsWithNewItem.OverallPoints - characterStatsWithSlotEmpty.OverallPoints; float[] subPoints = new float[characterStatsWithNewItem.SubPoints.Length]; for (int i = 0; i < characterStatsWithNewItem.SubPoints.Length; i++) { subPoints[i] = characterStatsWithNewItem.SubPoints[i] - characterStatsWithSlotEmpty.SubPoints[i]; } itemCalc.SubPoints = subPoints; characterStatsWithNewItem.ToString(); return itemCalc; }
public virtual List<ComparisonCalculationBase> GetSetBonusCalculations(Character character, CharacterCalculationsBase currentCalcs) { ClearCache(); List<ComparisonCalculationBase> buffCalcs = new List<ComparisonCalculationBase>(); CharacterCalculationsBase calcsEquipped = null; CharacterCalculationsBase calcsUnequipped = null; Character charAutoActivated = character.Clone(); foreach (Buff autoBuff in currentCalcs.AutoActivatedBuffs) { if (!charAutoActivated.ActiveBuffs.Contains(autoBuff)) { charAutoActivated.ActiveBuffsAdd(autoBuff); RemoveConflictingBuffs(charAutoActivated.ActiveBuffs, autoBuff); } } charAutoActivated.DisableBuffAutoActivation = true; string filter = "Set Bonuses"; string[] multiFilter = filter.Split('|'); List<Buff> relevantBuffs = new List<Buff>(); Buff.cachedClass = character.Class; Buff.cachedPriProf = character.PrimaryProfession; Buff.cachedSecProf = character.SecondaryProfession; foreach (Buff buff in Buff.RelevantBuffs) { bool isinMultiFilter = false; if (multiFilter.Length > 0) { foreach (string mFilter in multiFilter) { if (buff.Group.Equals(mFilter, StringComparison.CurrentCultureIgnoreCase)) { isinMultiFilter = true; break; } } } if (filter == null || filter == "All" || filter == "Current" || buff.Group.Equals(filter, StringComparison.CurrentCultureIgnoreCase) || isinMultiFilter) { relevantBuffs.Add(buff); foreach (Buff imp in buff.Improvements) { if (Calculations.Instance.IsBuffRelevant(imp, character)) { relevantBuffs.Add(imp); } } } } foreach (Buff buff in relevantBuffs) { if (!"Current".Equals(filter, StringComparison.CurrentCultureIgnoreCase) || charAutoActivated.ActiveBuffs.Contains(buff)) { Character charUnequipped = charAutoActivated.Clone(); Character charEquipped = charAutoActivated.Clone(); charUnequipped.DisableBuffAutoActivation = true; charEquipped.DisableBuffAutoActivation = true; // find next lower set bonus count int maxCount = 0; foreach (Buff lowerSetBonus in relevantBuffs) { if (lowerSetBonus.SetName == buff.SetName && lowerSetBonus.SetThreshold < buff.SetThreshold) { if (lowerSetBonus.SetThreshold > maxCount) { maxCount = lowerSetBonus.SetThreshold; } } } charUnequipped.SetBonusCount[buff.SetName] = maxCount; charEquipped.SetBonusCount[buff.SetName] = buff.SetThreshold; RemoveConflictingBuffs(charEquipped.ActiveBuffs, buff); RemoveConflictingBuffs(charUnequipped.ActiveBuffs, buff); calcsUnequipped = GetCharacterCalculations(charUnequipped, null, false, false, false); calcsEquipped = GetCharacterCalculations(charEquipped, null, false, false, false); ComparisonCalculationBase buffCalc = CreateNewComparisonCalculation(); buffCalc.Name = buff.Name; buffCalc.Item = new Item() { Name = buff.Name, Stats = buff.Stats, Quality = ItemQuality.Temp }; buffCalc.Equipped = charAutoActivated.ActiveBuffs.Contains(buff); if (!buffCalc.Equipped && buff.ConflictingBuffs.Count > 0 && buff.ConflictingBuffs[0] != null) { bool hasConflictingMatch = false; foreach (String cb in buff.ConflictingBuffs) { foreach (Buff b in character.ActiveBuffs) { if (b.Name != buff.Name && b.ConflictingBuffs.Contains(cb)) { hasConflictingMatch = true; break; } } } buffCalc.PartEquipped = hasConflictingMatch; } buffCalc.OverallPoints = calcsEquipped.OverallPoints - calcsUnequipped.OverallPoints; float[] subPoints = new float[calcsEquipped.SubPoints.Length]; for (int i = 0; i < calcsEquipped.SubPoints.Length; i++) { subPoints[i] = calcsEquipped.SubPoints[i] - calcsUnequipped.SubPoints[i]; } buffCalc.SubPoints = subPoints; buffCalcs.Add(buffCalc); } } return buffCalcs; }
public virtual List<ComparisonCalculationBase> GetReforgeCalculations(CharacterSlot slot, Character character, CharacterCalculationsBase currentCalcs, bool equippedOnly) { ClearCache(); List<ComparisonCalculationBase> reforgeCalcs = new List<ComparisonCalculationBase>(); if (!equippedOnly) { CharacterCalculationsBase calcsEquipped = null; CharacterCalculationsBase calcsUnequipped = null; // only need to get unequipped value once not every time around the loop Character charUnequipped = character.Clone(); charUnequipped.SetReforgingBySlot(slot, null); calcsUnequipped = GetCharacterCalculations(charUnequipped, null, false, false, false); Item toReforge = character[slot] != null ? character[slot].Item : null; int toReforgeSuffix = character[slot] != null ? character[slot].RandomSuffixId : 0; if (toReforge == null) return reforgeCalcs; List<Reforging> possibleReforges = GetReforgingOptions(toReforge, toReforgeSuffix); foreach (Reforging reforge in possibleReforges) { Reforging origReforge = character.GetReforgingBySlot(slot); int id1 = origReforge != null ? origReforge.Id : 0; int id2 = reforge != null ? reforge.Id : 0; bool isEquipped = id1 == id2; Character charEquipped = character.Clone(); charEquipped.SetReforgingBySlot(slot, reforge); calcsEquipped = GetCharacterCalculations(charEquipped, null, false, false, false); ComparisonCalculationBase reforgeCalc = CreateNewComparisonCalculation(); if (reforge != null) { reforgeCalc.Name = reforge.ToString(); reforgeCalc.Item = new Item(reforge.ToString(), ItemQuality.Temp, ItemType.None, -(int)AvailableItemIDModifiers.Reforges - reforge.Id, null, ItemSlot.None, null, false, new Stats(), null, ItemSlot.None, ItemSlot.None, ItemSlot.None, 0, 0, ItemDamageType.Physical, 0, null); reforgeCalc.Item.Stats._rawAdditiveData[(int)reforge.ReforgeFrom] -= reforge.ReforgeAmount; reforgeCalc.Item.Stats._rawAdditiveData[(int)reforge.ReforgeTo] += reforge.ReforgeAmount; } else { reforgeCalc.Name = "Not Reforged"; reforgeCalc.Item = new Item("Not Reforged", ItemQuality.Temp, ItemType.None, -(int)AvailableItemIDModifiers.Reforges, null, ItemSlot.None, null, false, new Stats(), null, ItemSlot.None, ItemSlot.None, ItemSlot.None, 0, 0, ItemDamageType.Physical, 0, null); } reforgeCalc.Equipped = isEquipped; reforgeCalc.OverallPoints = calcsEquipped.OverallPoints - calcsUnequipped.OverallPoints; float[] subPoints = new float[calcsEquipped.SubPoints.Length]; for (int i = 0; i < calcsEquipped.SubPoints.Length; i++) { subPoints[i] = calcsEquipped.SubPoints[i] - calcsUnequipped.SubPoints[i]; } reforgeCalc.SubPoints = subPoints; reforgeCalcs.Add(reforgeCalc); } } else { CharacterCalculationsBase calcsEquipped = null; CharacterCalculationsBase calcsUnequipped = null; // only need to get unequipped value once not every time around the loop Character charUnequipped = character.Clone(); charUnequipped.SetReforgingBySlot(slot, null); calcsUnequipped = GetCharacterCalculations(charUnequipped, null, false, false, false); Item toReforge = character[slot] != null ? character[slot].Item : null; if (toReforge == null) return reforgeCalcs; Reforging reforge = character[slot].Reforging; Reforging origReforge = character.GetReforgingBySlot(slot); bool isEquipped = true; Character charEquipped = character; calcsEquipped = GetCharacterCalculations(charEquipped, null, false, false, false); ComparisonCalculationBase reforgeCalc = CreateNewComparisonCalculation(); if (reforge != null) { reforgeCalc.Name = reforge.ToString(); reforgeCalc.Item = new Item(reforge.ToString(), ItemQuality.Temp, ItemType.None, -(int)AvailableItemIDModifiers.Reforges - reforge.Id, null, ItemSlot.None, null, false, new Stats(), null, ItemSlot.None, ItemSlot.None, ItemSlot.None, 0, 0, ItemDamageType.Physical, 0, null); reforgeCalc.Item.Stats._rawAdditiveData[(int)reforge.ReforgeFrom] -= reforge.ReforgeAmount; reforgeCalc.Item.Stats._rawAdditiveData[(int)reforge.ReforgeTo] += reforge.ReforgeAmount; } else { reforgeCalc.Name = "Not Reforged"; reforgeCalc.Item = new Item("Not Reforged", ItemQuality.Temp, ItemType.None, -(int)AvailableItemIDModifiers.Reforges, null, ItemSlot.None, null, false, new Stats(), null, ItemSlot.None, ItemSlot.None, ItemSlot.None, 0, 0, ItemDamageType.Physical, 0, null); } reforgeCalc.Equipped = isEquipped; reforgeCalc.OverallPoints = calcsEquipped.OverallPoints - calcsUnequipped.OverallPoints; float[] subPoints = new float[calcsEquipped.SubPoints.Length]; for (int i = 0; i < calcsEquipped.SubPoints.Length; i++) { subPoints[i] = calcsEquipped.SubPoints[i] - calcsUnequipped.SubPoints[i]; } reforgeCalc.SubPoints = subPoints; reforgeCalcs.Add(reforgeCalc); } return reforgeCalcs; }
public virtual ComparisonCalculationBase GetBossCalculations(BossHandler boss, BossHandler easy, Character character, CharacterCalculationsBase currentCalcs) { ClearCache(); CharacterCalculationsBase calcsEquipped = null; CharacterCalculationsBase calcsUnequipped = null; // only need to get unequipped value once not every time around the loop Character charUnequipped = character.Clone(); charUnequipped.BossOptions = BossOptions.CloneBossHandler(easy); calcsUnequipped = GetCharacterCalculations(charUnequipped, null, false, false, false); // bool isEquipped = false; Character charEquipped = character.Clone(); charUnequipped.BossOptions = BossOptions.CloneBossHandler(boss); calcsEquipped = GetCharacterCalculations(charEquipped, null, false, false, false); ComparisonCalculationBase bossCalc = CreateNewComparisonCalculation(); bossCalc.Name = boss.Name + " (" + boss.ContentString + ")"; bossCalc.Item = new Item(boss.Name + " (" + boss.ContentString + ")", ItemQuality.Temp, ItemType.None, boss.GetHashCode(), null, ItemSlot.None, null, false, new Stats(), null, ItemSlot.None, ItemSlot.None, ItemSlot.None, 0, 0, ItemDamageType.Physical, 0, null); bossCalc.Equipped = isEquipped; bossCalc.OverallPoints = calcsEquipped.OverallPoints - calcsUnequipped.OverallPoints; float[] subPoints = new float[calcsEquipped.SubPoints.Length]; for (int i = 0; i < calcsEquipped.SubPoints.Length; i++) { subPoints[i] = calcsEquipped.SubPoints[i] - calcsUnequipped.SubPoints[i]; } bossCalc.SubPoints = subPoints; //bossCalc.ImageSource = boss.IconSource; // return bossCalc; }