private static void ReplaceBag(WAEContainer bagToReplace, WAEItem newBag) { if (bagToReplace.EmptyBagInOtherBags()) { Logger.Log($"Replacing {bagToReplace.ThisBag.Name} with {newBag.Name}"); if (newBag.InBag == bagToReplace.Position) { newBag = AllItems.Find(b => b.ItemLink == newBag.ItemLink); } newBag.MoveToBag(bagToReplace.Position); WAELootFilter.ProtectFromFilter(newBag.ItemLink); Lua.LuaDoString($"EquipPendingItem(0);"); //Lua.LuaDoString($"StaticPopup1Button1:Click()"); } Scan(); }
public bool EmptyBagInOtherBags() { List <WAEContainerSlot> freeSlots = new List <WAEContainerSlot>(); // record free slots foreach (WAEContainer container in WAEContainers.ListContainers.Where(b => b.IsOriginalBackpack || !b.IsAmmoPouch && !b.IsQuiver)) { if (container != this) { freeSlots.AddRange(container.Slots.Where(slot => slot.OccupiedBy == null)); } } // Move Items if (freeSlots.Count > Items.Count) { Logger.Log($"Moving items out of {ThisBag.Name}"); for (int i = 0; i < Items.Count; i++) { WAEContainerSlot destination = freeSlots[i]; WAEItem smallBag = Items[i]; smallBag.PickupFromBag(); ToolBox.Sleep(100); smallBag.MoveToBag(destination.BagPosition, destination.Slot); ToolBox.Sleep(100); } } WAEContainers.Scan(); // Check if bag to move is actually empty if (GetContainerNbFreeSlots() == GetContainerNbSlots()) { return(true); } return(false); }
public static void BagEquip() { //Logger.LogDebug("*** Bag equip..."); DateTime dateBegin = DateTime.Now; if (AutoEquipSettings.CurrentSettings.AutoEquipBags) { bool ImHunterAndNeedAmmoBag = ObjectManager.Me.WowClass == WoWClass.Hunter && AutoEquipSettings.CurrentSettings.EquipQuiver; int maxAmountOfBags = ImHunterAndNeedAmmoBag ? 4 : 5; WAEContainer equippedQuiver = ListContainers.Find(bag => bag.IsQuiver); WAEContainer equippedAmmoPouch = ListContainers.Find(bag => bag.IsAmmoPouch); bool hasRangedWeaponEquipped = WAECharacterSheet.Ranged.Item != null; string equippedRanged = WAECharacterSheet.Ranged.Item?.ItemSubType; if (AutoEquipSettings.CurrentSettings.EquipQuiver) { // Move ammoContainer to position 4 if (equippedQuiver != null && equippedQuiver.Position != 4) { equippedQuiver.MoveToSlot(4); Scan(); equippedQuiver = ListContainers.Find(bag => bag.IsQuiver); } if (equippedAmmoPouch != null && equippedAmmoPouch.Position != 4) { equippedAmmoPouch.MoveToSlot(4); Scan(); equippedAmmoPouch = ListContainers.Find(bag => bag.IsAmmoPouch); } // We have an ammo container equipped if (ImHunterAndNeedAmmoBag && (equippedQuiver != null || equippedAmmoPouch != null)) { WAEContainer equippedAmmoContainer = equippedQuiver == null ? equippedAmmoPouch : equippedQuiver; WAEItem bestAmmoContainerInBags = GetBiggestAmmoContainerFromBags(); if (bestAmmoContainerInBags != null) { // Check we have the right type of ammo container if ((equippedRanged == TypeRanged.Bows.ToString() || equippedRanged == TypeRanged.Crossbows.ToString()) && !equippedAmmoContainer.IsQuiver) { ReplaceBag(equippedAmmoContainer, bestAmmoContainerInBags); } else if (equippedRanged == TypeRanged.Guns.ToString() && !equippedAmmoContainer.IsAmmoPouch) { ReplaceBag(equippedAmmoContainer, bestAmmoContainerInBags); } // Try to find a better one else if (bestAmmoContainerInBags.QuiverCapacity > equippedAmmoContainer.Capacity || bestAmmoContainerInBags.AmmoPouchCapacity > equippedAmmoContainer.Capacity) { ReplaceBag(equippedAmmoContainer, bestAmmoContainerInBags); } } } // We have no ammo container equipped if (ImHunterAndNeedAmmoBag && equippedQuiver == null && equippedAmmoPouch == null) { if (!hasRangedWeaponEquipped || equippedRanged == TypeRanged.Thrown.ToString()) { maxAmountOfBags = 5; } else { WAEItem bestAmmoContainerInBags = GetBiggestAmmoContainerFromBags(); // We found an ammo container to equip if (bestAmmoContainerInBags != null) { if (GetEmptyContainerSlots().Count > 0) { // There is an empty slot int availableSpot = GetEmptyContainerSlots().Last(); Logger.Log($"Equipping {bestAmmoContainerInBags.Name} in slot {availableSpot}"); bestAmmoContainerInBags.MoveToBag(availableSpot); Lua.LuaDoString($"EquipPendingItem(0);"); //Lua.LuaDoString($"StaticPopup1Button1:Click()"); WAELootFilter.ProtectFromFilter(bestAmmoContainerInBags.ItemLink); Scan(); } else { // No empty slot, we need to replace a bag by an ammo container WAEContainer smallestEquippedBag = GetSmallestEquippedBag(); ReplaceBag(smallestEquippedBag, bestAmmoContainerInBags); } } } } } else { // The user doesn't want to have quiver equipped, removing them if (equippedQuiver != null || equippedAmmoPouch != null) { WAEContainer equippedAmmoContainer = equippedQuiver == null ? equippedAmmoPouch : equippedQuiver; WAEItem biggestBagInBags = GetBiggestBagFromBags(); if (biggestBagInBags != null) { ReplaceBag(equippedAmmoContainer, biggestBagInBags); } } } // Bag equip if we have at least 1 empty slot if (GetNbBagEquipped() < maxAmountOfBags) { List <int> emptyContainerSlots = GetEmptyContainerSlots(); int nbEmpty = emptyContainerSlots.Count; int nbloop = emptyContainerSlots.Count; foreach (int emptySlotId in emptyContainerSlots) { WAEItem biggestBag = GetBiggestBagFromBags(); if (biggestBag != null) { Logger.Log($"Equipping {biggestBag.Name}"); int availableSpot = GetEmptyContainerSlots().First(); biggestBag.MoveToBag(availableSpot); Lua.LuaDoString($"EquipPendingItem(0);"); //Lua.LuaDoString($"StaticPopup1Button1:Click()"); WAELootFilter.ProtectFromFilter(biggestBag.ItemLink); Scan(); } if (GetNbBagEquipped() >= maxAmountOfBags) { break; } } } // Bag equip to replace one for better capacity if (GetNbBagEquipped() >= maxAmountOfBags) { WAEContainer smallestEquippedBag = GetSmallestEquippedBag(); WAEItem biggestBagInBags = GetBiggestBagFromBags(); if (smallestEquippedBag != null && biggestBagInBags != null && smallestEquippedBag.Capacity < biggestBagInBags.BagCapacity && smallestEquippedBag.Position != 0) { ReplaceBag(smallestEquippedBag, biggestBagInBags); } } } Logger.LogPerformance($"Bag Equip Process time : {(DateTime.Now.Ticks - dateBegin.Ticks) / 10000} ms"); }