public void AddItem(AOItem item) { int nextfree = Low; bool free = false; while (nextfree < Low + Spots) { free = true; foreach (InventoryEntry ie in Entries) { if (nextfree == ie.Placement) { free = false; break; } } if (free) break; nextfree++; } if (free) { InventoryEntry newentry = new InventoryEntry(); newentry.Placement = nextfree; newentry.Item = item.ShallowCopy(); Entries.Add(newentry); } }
/// <summary> /// Add a Item to a Inventory page/place /// </summary> /// <param name="container">Number of Inventory page</param> /// <param name="place">Desired place</param> /// <param name="item">item to add</param> /// <returns>Success</returns> public InventoryEntry AddItem(int container, int place, AOItem item) { // Container ID's: // (x) 0065 Weaponpage // (x) 0066 Armorpage // (x) 0067 Implantpage // (x) 0068 Inventory (places 64-93) // (x) 0069 Bank // ( ) 006B Backpack - this will take some time // ( ) 006C (KnuBot) Trade Window // ( ) 006E Overflow window // (x) 006F Trade Window/Next free spot in 0x68 // (x) 0073 Socialpage // ( ) 0767 Shop Inventory // ( ) 0790 Playershop Inventory // (x) DEAD Bank (why FC, why???) switch (container) { // Equipment pages case 0x65: case 0x66: case 0x67: case 0x73: { if (GetInventoryEntryAt(container, place) == null) { InventoryEntry newentry = new InventoryEntry(); newentry.Item = item.ShallowCopy(); newentry.Placement = place; GetPage(container).Entries.Add(newentry); return newentry; } return null; } // Look for next free main inventory spot case 0x6f: { int nextfree = 64; while (nextfree < 94) { if (GetInventoryEntryAt(0x68, nextfree) == null) { InventoryEntry newentry = new InventoryEntry(); newentry.Item = item.ShallowCopy(); newentry.Placement = nextfree; GetPage(0x68).Entries.Add(newentry); return newentry; } nextfree++; } return null; } // Bank case 0xDEAD: case 0x69: // 0x69 probably not needed { container = 0x69; int nextfree = 0; while (nextfree < 102) { if (GetInventoryEntryAt(container, nextfree) == null) { InventoryEntry newentry = new InventoryEntry(); newentry.Item = item.ShallowCopy(); newentry.Placement = nextfree; GetPage(container).Entries.Add(newentry); return newentry; } nextfree++; } return null; } } return null; }