public static bool HasBetterBag() { GItem[] Items = GObjectList.GetItems(); foreach (GItem Item in Items) { if (Item.Type.ToString() == "Container" && !IsEquippedBag(Item.GUID)) { GContainer bag = (GContainer)GObjectList.FindObject(Item.GUID); if (bag != null) { long[] AllBags = GPlayerSelf.Me.Bags; foreach (long CurrentBag in AllBags) { GContainer cbag = (GContainer)GObjectList.FindObject(CurrentBag); if (cbag != null) { if (cbag.SlotCount < bag.SlotCount && !cbag.Name.ToString().ToLower().Contains("ammo") && !cbag.Name.ToString().ToLower().Contains("quiver")) { return(true); } } } } } } return(false); }
public static bool EquipNewBag(GItem Item) { BagManager bm = new BagManager(); GContainer bag = (GContainer)GObjectList.FindObject(Item.GUID); if (bag != null) { bm.ClickItem(Item, true); for (int p = 1; p <= 4; p++) { if (Popup.IsVisible(p)) { String text = Popup.GetText(p); PPather.WriteLine("Inventory: Got a popup ('" + text + "')"); if (text.Contains("will bind it to you")) { Popup.ClickButton(p, 1); } else { Popup.ClickButton(p, 2); } } } bm.CloseAllBags(); return(true); } bm.CloseAllBags(); return(false); }
/// <summary> /// Retrieves the quantities of all distinct items in all of your bags. /// </summary> /// <param name="useCache">Whether to use cached data, if possible</param> /// <returns> /// A Dictionary with keys corresponding to the names /// of each distinct item in your inventory and values corresponding /// to the number of that item across all of your bags. /// </returns> public static Dictionary <string, int> CreateItemCount(bool useCache) { // only check it every 30 seconds to try to reduce // overhead if (curItemsCache != null && !curItemCacheTimer.IsReady && useCache) { return(curItemsCache); } Dictionary <string, int> items = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase); long[] AllBags = GPlayerSelf.Me.Bags; for (int bagNr = 0; bagNr < 5; bagNr++) { long[] Contents; int SlotCount; if (bagNr == 0) { Contents = GContext.Main.Me.BagContents; SlotCount = GContext.Main.Me.SlotCount; } else { GContainer bag = (GContainer)GObjectList.FindObject(AllBags[bagNr - 1]); if (bag != null) { Contents = bag.BagContents; SlotCount = bag.SlotCount; } else { SlotCount = 0; Contents = null; } } for (int i = 0; i < SlotCount; i++) { if (Contents[i] == 0) { continue; } GItem CurItem = (GItem)GObjectList.FindObject(Contents[i]); if (CurItem != null) { string ItemName = CurItem.Name; int ItemCount = CurItem.StackSize; int OldCount = 0; items.TryGetValue(ItemName, out OldCount); items.Remove(ItemName); items.Add(ItemName, OldCount + ItemCount); } } } curItemCacheTimer.Reset(); curItemsCache = items; return(curItemsCache); }
public static void GetEquippedItems() { GItemHelper GIH = new GItemHelper(); if (CharacterSlots == null) { CharacterSlots = GetCharacterSlots(); } CharacterFrame.ShowFrame(); foreach (string slot in CharacterSlots) { string tooltipName = "none"; PPather.Debug("\n\n == SLOT LOOKUP FOR {0} START ==", slot); List <string> tooltip = CharacterFrame.GetTooltip(slot); if (tooltip != null && tooltip.Count > 0) { //foreach (string tip in tooltip) // PPather.WriteLine("Character: Tooltip[{0}]\t=>\t{1}", slot, tip); tooltipName = tooltip[tooltip.Count - 1]; } PPather.Debug("Character: Name for {0} = {1}", slot, tooltipName); if (tooltip == null || IsEmptySlotName(tooltipName)) { AddNullSlot(slot); } else { Item i = ItemManager.get(tooltipName); if (i == null) { AddNullSlot(slot); } else { GItem Item = (GItem)GObjectList.FindObject(GIH.GetEquippedGUID(slot)); if (Item == null) { continue; } EasyItem E = new EasyItem(Item, i, Item.GUID, tooltipName); try { CurrentlyEquipped.Add(slot, E); PPather.WriteLine(LOG_CATEGORY.INFORMATION, "Character: Item [{0}] equipped in '{1}'", tooltipName, slot); PPather.Debug(String.Format("ToolTip[{0}]: {1}", i.Name, CleanToolTip(tooltip))); } catch (ArgumentException) { PPather.Debug("Character: " + tooltipName + " is already added to CurrentlyEquipped (skipping)"); } } } PPather.Debug("\n=== SLOT LOOKUP FOR {0} END ===\n", slot); } CharacterFrame.HideFrame(); }
/*public BagManager() { * // make sure all bags are closed * * CloseAllBags(); * UpdateItems(); * * // check all contents * }*/ public void UpdateItemsSorted() { //PPather.WriteLine("UpdateItemsSorted()"); int[] count = new int[5] { 0, 0, 0, 0, 0 }; UpdateItems(); for (int i = 0; i < BagItems.Length; i++) { BagItem it = BagItems[i]; //PPather.WriteLine("UpdateItemsSorted: Adding {0} to Bag {1} (count = {2})", it.item.Name, it.bag, count[it.bag] + 1); count[it.bag]++; } int bags = GPlayerSelf.Me.Bags.Length + 1; long[] AllBags = GPlayerSelf.Me.Bags; for (int bagNr = 0; bagNr < 5; bagNr++) { int SlotCount; if (bagNr == 0) { SlotCount = GContext.Main.Me.SlotCount; } else { GContainer bag = (GContainer)GObjectList.FindObject(AllBags[bagNr - 1]); if (bag != null) { SlotCount = bag.SlotCount; } else { SlotCount = 0; } } count[bagNr] = SlotCount; } //PPather.WriteLine("UpdateItemsSorted: Creating new Bag array of size {0}", bags); Bags = new Bag[bags]; for (int i = 0; i < bags; i++) { //PPather.WriteLine("UpdateItemsSorted: Creating new GItem array of size {0} to Bag {1}", count[i], i); GItem[] gits = new GItem[count[i]]; //PPather.WriteLine("UpdateItemsSorted: Adding gits to Bag {0}", i); Bags[i] = new Bag(i, gits); } for (int i = 0; i < BagItems.Length; i++) { BagItem it = BagItems[i]; //PPather.WriteLine("UpdateItemsSorted: Bag[{0}].Add({1}, {2})", it.bag, it.item.Name, it.slot-1); Bags[it.bag].Add(it.item, it.slot - 1); } }
/*public BagManager() { * // make sure all bags are closed * * CloseAllBags(); * UpdateItems(); * * // check all contents * }*/ public void UpdateItems() { List <GItem> ItemList = new List <GItem>(); List <BagItem> BagItemList = new List <BagItem>(); long[] AllBags = GPlayerSelf.Me.Bags; long[] Contents; int SlotCount; for (int bag = 0; bag <= 4; bag++) { SlotCount = 0; if (bag == 0) { Contents = GContext.Main.Me.BagContents; SlotCount = GContext.Main.Me.SlotCount; } else { GContainer container = (GContainer)GObjectList.FindObject(AllBags[bag - 1]); if (container != null) { Contents = container.BagContents; SlotCount = container.SlotCount; } else { Contents = null; } } if (Contents != null) { for (int i = 0; i < Contents.Length; i++) { GItem CurItem = (GItem)GObjectList.FindObject(Contents[i]); if (CurItem != null) { ItemList.Add(CurItem); BagItem bi = new BagItem(bag, SlotCount - i, CurItem); BagItemList.Add(bi); } } } } Items = ItemList.ToArray(); BagItems = BagItemList.ToArray(); }
public static bool EquipBetterBag() { GItem[] Items = GObjectList.GetItems(); foreach (GItem Item in Items) { if (Item.Type.ToString() == "Container" && !IsEquippedBag(Item.GUID)) { GContainer bag = (GContainer)GObjectList.FindObject(Item.GUID); if (bag != null) { long[] AllBags = GPlayerSelf.Me.Bags; for (int i = 0; i < AllBags.Length; i++) { GContainer cbag = (GContainer)GObjectList.FindObject(AllBags[i]); if (cbag != null) { if (cbag.SlotCount < bag.SlotCount && !cbag.Name.ToString().ToLower().Contains("ammo") && !cbag.Name.ToString().ToLower().Contains("quiver")) { GInterfaceObject OldBag = GContext.Main.Interface.GetByName("CharacterBag" + i + "Slot"); BagManager bm = new BagManager(); bm.ClickItem(Item, false); Functions.Click(OldBag, false); for (int p = 1; p <= 4; p++) { if (Popup.IsVisible(p)) { String text = Popup.GetText(p); PPather.WriteLine("Inventory: Got a popup ('" + text + "')"); if (text.Contains("will bind it to you")) { Popup.ClickButton(p, 1); } else { Popup.ClickButton(p, 2); } } } return(true); } } } } } } return(true); }
public static Value MyBagNames() { Dictionary <String, int> dic = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase); long[] AllBags = GPlayerSelf.Me.Bags; for (int bag = 1; bag <= 4; bag++) { GContainer container = (GContainer)GObjectList.FindObject(AllBags[bag - 1]); if (container != null) { string ItemName = container.Name; int OldCount = 0; dic.TryGetValue(ItemName, out OldCount); dic.Remove(ItemName); dic.Add(ItemName, OldCount + 1); } } return(new Value(dic)); }
public static bool HasFreeBagSlot() { int count = 0; long[] AllBags = GPlayerSelf.Me.Bags; foreach (long CurrentBag in AllBags) { GContainer bag = (GContainer)GObjectList.FindObject(CurrentBag); if (bag != null) { count++; } } if (count == 4) { return(false); } return(true); }
public static bool EquipBetterBag(GItem Item, string BagSlotName) { GContainer bag = (GContainer)GObjectList.FindObject(Item.GUID); if (bag != null) { long[] AllBags = GPlayerSelf.Me.Bags; for (int i = 0; i < AllBags.Length; i++) { GContainer cbag = (GContainer)GObjectList.FindObject(AllBags[i]); if (cbag != null) { GInterfaceObject OldBag = GContext.Main.Interface.GetByName(BagSlotName); BagManager bm = new BagManager(); bm.ClickItem(Item, false); Functions.Click(OldBag, false); for (int p = 1; p <= 4; p++) { if (Popup.IsVisible(p)) { String text = Popup.GetText(p); PPather.WriteLine("Inventory: Got a popup ('" + text + "')"); if (text.Contains("will bind it to you")) { Popup.ClickButton(p, 1); } else { Popup.ClickButton(p, 2); } } } bm.CloseAllBags(); return(true); } } } return(false); }
public static bool EquipNewBag() { if (HasFreeBagSlot()) { GItem[] Items = GObjectList.GetItems(); foreach (GItem Item in Items) { if (Item.Type.ToString() == "Container" && !IsEquippedBag(Item.GUID)) { GContainer bag = (GContainer)GObjectList.FindObject(Item.GUID); if (bag != null) { BagManager bm = new BagManager(); bm.ClickItem(Item, true); for (int p = 1; p <= 4; p++) { if (Popup.IsVisible(p)) { String text = Popup.GetText(p); PPather.WriteLine("Inventory: Got a popup ('" + text + "')"); if (text.Contains("will bind it to you")) { Popup.ClickButton(p, 1); } else { Popup.ClickButton(p, 2); } } } bm.CloseAllBags(); return(true); } } } } return(false); }
public static Value FreeBagSlots() { int count = 0; int totalslots = 0; long[] AllBags = GPlayerSelf.Me.Bags; for (int bagNr = 0; bagNr < 5; bagNr++) { long[] Contents; int SlotCount; if (bagNr == 0) { Contents = GContext.Main.Me.BagContents; SlotCount = GContext.Main.Me.SlotCount; } else { GContainer bag = (GContainer)GObjectList.FindObject(AllBags[bagNr - 1]); if (bag != null) { // The slots in quivers and ammo pouches shouldn't count. // Apparently, there's no way to determine what kind of container // we're dealing with so I just added all the containers in the game // that hold arrows or ammo as of 2.4.2. if (bag.ItemDefID != 34106 && bag.ItemDefID != 34099 && bag.ItemDefID != 29118 && bag.ItemDefID != 19320 && bag.ItemDefID != 8218 && bag.ItemDefID != 2663 && bag.ItemDefID != 7372 && bag.ItemDefID != 3604 && bag.ItemDefID != 3574 && bag.ItemDefID != 11363 && bag.ItemDefID != 5441 && bag.ItemDefID != 7279 && bag.ItemDefID != 2102 && bag.ItemDefID != 34105 && bag.ItemDefID != 34100 && bag.ItemDefID != 18714 && bag.ItemDefID != 29143 && bag.ItemDefID != 29144 && bag.ItemDefID != 19319 && bag.ItemDefID != 8217 && bag.ItemDefID != 2662 && bag.ItemDefID != 7371 && bag.ItemDefID != 3605 && bag.ItemDefID != 11362 && bag.ItemDefID != 3573 && bag.ItemDefID != 5439 && bag.ItemDefID != 7278 && bag.ItemDefID != 2101) { SlotCount = bag.SlotCount; Contents = bag.BagContents; } else { SlotCount = 0; Contents = null; } } else { SlotCount = 0; Contents = null; } } totalslots += SlotCount; for (int i = 0; i < SlotCount; i++) { if (Contents[i] == 0) { count++; } } } return(new Value(count)); }
public static void CompareAndEquipBags(EasyItem[] C) { RankedBag[] RankedBags = new RankedBag[C.Length + 4]; //PPather.WriteLine(String.Format("AutoEquip: RankedBags.Length = {0}", RankedBags.Length)); //PPather.WriteLine(String.Format("AutoEquip: containers.Count = {0}", C.Length)); //PPather.WriteLine(String.Format("AutoEquip: GPlayerSelf.Me.Bags.Length = {0}", 4)); /* add bags found in inventory */ GItem[] Items = GObjectList.GetItems(); List <long> added = new List <long>(); int nr = 0; for (nr = 0; nr < C.Length; nr++) { if (!Inventory.IsEquippedBag(C[nr].GUID) && !added.Contains(C[nr].GUID)) { GContainer bag = (GContainer)GObjectList.FindObject(C[nr].GUID); string SlotName = Inventory.GetBagSlotName(C[nr].GItem); RankedBag b = new RankedBag(1, bag.SlotCount, bag, C[nr].GItem, SlotName); RankedBags[nr] = b; //PPather.WriteLine("AutoEquip: (inventory) RankedBags[{0}] = {1} (SlotCount={2}, GUID={3})", nr, C[nr].Item.Name, bag.SlotCount, C[nr].GUID); added.Add(C[nr].GUID); } } /* add already equipped bags */ nr = C.Length; foreach (GItem Item in Items) { if (Item.Type.ToString() == "Container" && Inventory.IsEquippedBag(Item.GUID) && !added.Contains(Item.GUID)) { GContainer bag = (GContainer)GObjectList.FindObject(Item.GUID); string SlotName = Inventory.GetBagSlotName(Item); RankedBag b = new RankedBag(0, bag.SlotCount, bag, Item, SlotName); RankedBags[nr] = b; //PPather.WriteLine("AutoEquip: (eqiupped) RankedBags[{0}] = {1} (SlotCount={2}, GUID={3})", nr, Item.Name, bag.SlotCount, Item.GUID); added.Add(Item.GUID); nr++; } } /* add the empty slots */ int freeslots = 0; while (nr < (C.Length + 4)) { RankedBag b = new RankedBag(0, 0, null, null, null); RankedBags[nr] = b; nr++; freeslots++; } /* sort bags on slotcount */ Array.Sort(RankedBags); /* DEBUG print of ranks */ //for (int k = 0; k < RankedBags.Length; k++) //{ // RankedBag rb = RankedBags[k]; // if (rb != null) // { // string name = "null"; // if (rb.item != null) name = rb.item.Name; // PPather.WriteLine(String.Format("AutoEquip: Rank {0} => {1}({2})", k, name, rb.slots)); // } //} /* get the bag slot names to replace (reverse sort) */ List <string> slots = new List <string>(); for (int j = RankedBags.Length - 1; j >= 0; j--) { RankedBag r = RankedBags[j]; if (r == null) { continue; } if (r.slotname == null) { continue; } string name = "null"; if (r.item != null) { name = r.item.Name; } slots.Add(r.slotname); //PPather.WriteLine("AutoEquip: Rank {0} of BagSlot to replace is {1} ({2})", slots.Count, r.slotname, name); } String[] BagSlots = slots.ToArray(); int ReplaceSlotIndex = 0; /* go through RankedBags and make sure the top 4 ranked bags are equipped */ int index = 0; int equipped = 0; while (index < 4) { //PPather.WriteLine("AutoEquip: index={0}, equipped={1}, freeslots={2}", index, equipped, freeslots); RankedBag r = RankedBags[index]; if (r != null) { string name = "null"; if (r.item != null) { name = r.item.Name; } if (r.location == 0) { //PPather.WriteLine("AutoEquip: {0} rank[{1}] is equipped", name, index); } else if (freeslots > 0) { //PPather.WriteLine("AutoEquip: {0} rank[{1}] is new bag", name, index); EquipBag(r.item, true, null); equipped++; freeslots--; } else { //PPather.WriteLine("AutoEquip: {0} rank[{1}] is better bag", name, index); EquipBag(r.item, false, BagSlots[ReplaceSlotIndex]); equipped++; ReplaceSlotIndex++; } } index++; } }