public void requestInventory() { Console.WriteLine("inventory requested: " + inventoryRequested); if (!inventoryRequested) { inventoryRequested = true; TheTCPWrapper.Send(CommandCreator.SEND_MY_INVENTORY()); } }
private void INVENTORY_ITEM_TEXT(byte[] data) { if (GettingInventoryItems == false || Gambling) { return; } int i = 0; string ItemDescription = ""; string TempItemDescription = ""; TempItemDescription = System.Text.ASCIIEncoding.ASCII.GetString(data, 4, data.Length - 4).Trim(); TempItemDescription = TempItemDescription.Replace((char)10, ' '); // remove bad some chars (eg color tags) for (i = 0; i < TempItemDescription.Length; i++) { if (!(TempItemDescription[i] < 32 || TempItemDescription[i] > 126)) { ItemDescription = ItemDescription + TempItemDescription[i]; } } lock (TheInventory.SyncRoot) { for (i = 0; i < TheInventory.Count; i++) { inventory_item MyInventoryItem = (inventory_item)TheInventory[i]; if (MyInventoryItem.description == "") { ItemDescription = ItemDescription.Trim(); MyInventoryItem.description = ItemDescription; if (MyInventoryItem.description.ToLower().Contains("extract")) { MyInventoryItem.name = ItemDescription.Substring(0, ItemDescription.LastIndexOf(" - ")).Trim(); } else { MyInventoryItem.name = ItemDescription.Substring(0, ItemDescription.IndexOf(" - ")).Trim(); } MyInventoryItem.weight = int.Parse(ItemDescription.Substring(ItemDescription.IndexOf("Weight:") + 8, ItemDescription.Length - (ItemDescription.IndexOf("Weight:") + 8 + 4))); MyInventoryItem.SqlID = TheMySqlManager.SetSQLID(MyInventoryItem); //get the reserved amount MyInventoryItem.reservedQuantity = TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID); TheInventory[i] = MyInventoryItem; // get the knownitems id (setsqlid) // TheInventory[i] = SetSQLID((inventory_item)TheInventory[i]); //update the known item info on the table mostly for weight and imageid TheMySqlManager.updateknownitems(MyInventoryItem, MyInventoryItem.SqlID); // insert the row may only need this for debugging string dump = "INSERT INTO inventory (pos,quantity, knownitemsid, botid) VALUES "; dump += "(" + MyInventoryItem.pos + "," + MyInventoryItem.quantity + "," + MyInventoryItem.SqlID.ToString() + "," + Settings.botid.ToString() + ")"; dump += ";"; TheMySqlManager.raw_sql(dump); if (i + 1 < TheInventory.Count) //if this isn't the last one jump out of the loop { break; } // else { OnGotNewInventoryList(new GotNewInventoryListEventArgs(TheInventory)); TheLogger.Log("Got all inventory item names!"); inventoryRequested = false; GettingInventoryItems = false; if (firstTime) { MainClass.gettingPerks = true; TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#list_perks")); firstTime = false; } //TheTCPWrapper.Send(CommandCreator.SIT_DOWN(false)); } } } } }
private void HERE_YOUR_INVENTORY(byte[] data) { //ITEM_REAGENT = 1, /*!< can be used in magic */ //ITEM_RESOURCE = 2, /*!< can be used to manufacture */ //ITEM_STACKABLE = 4, /*!< the item is stackable */ //ITEM_INVENTORY_USABLE = 8, /*!< item can be used with inventory */ //ITEM_TILE_USABLE = 16, //ITEM_PLAYER_USABLE = 32, /*!< item is usable by players */ //ITEM_OBJECT_USABLE = 64, //ITEM_ON_OFF = 128, if (GettingInventoryItems) { return; } TheLogger.Log("Getting inventory item names!"); TheInventory.Clear(); TheMySqlManager.ClearInventoryList(Settings.botid); GettingInventoryItems = true; int total_items = data[3]; if (total_items == 0) { OnGotNewInventoryList(new GotNewInventoryListEventArgs(TheInventory)); TheLogger.Log("Got all inventory item names!"); inventoryRequested = false; GettingInventoryItems = false; if (firstTime) { MainClass.gettingPerks = true; TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#list_perks")); firstTime = false; } sizeOfPacket = 8; //TheTCPWrapper.Send(CommandCreator.SIT_DOWN(false)); } else { sizeOfPacket = (data.Length - 4) / total_items; Console.WriteLine(data.Length + " " + total_items + ":size of packets: " + sizeOfPacket); if (sizeOfPacket != 8) { for (int i = 0; i < total_items; i++) { inventory_item MyInventoryItem = new inventory_item(); byte pos = data[i * sizeOfPacket + 1 + 6 + 3]; MyInventoryItem.name = ""; MyInventoryItem.description = ""; MyInventoryItem.weight = 0; MyInventoryItem.SqlID = 0; MyInventoryItem.imageid = System.BitConverter.ToInt16(data, i * sizeOfPacket + 1 + 3); MyInventoryItem.quantity = System.BitConverter.ToUInt32(data, i * sizeOfPacket + 1 + 2 + 3); MyInventoryItem.pos = pos; int flags = data[i * sizeOfPacket + 1 + 7 + 3]; MyInventoryItem.is_resource = ((flags & 2) > 0); MyInventoryItem.is_reagent = ((flags & 1) > 0); MyInventoryItem.use_with_inventory = ((flags & 8) > 0); MyInventoryItem.is_stackable = ((flags & 4) > 0); TheInventory.Add(MyInventoryItem); TheTCPWrapper.Send(CommandCreator.LOOK_AT_INVENTORY_ITEM((byte)MyInventoryItem.pos)); } } else { TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#item_uid")); inventoryRequested = false; GettingInventoryItems = false; requestInventory(); } } //for (int i = 0; i < total_items; i++) //{ // inventory_item MyInventoryItem = new inventory_item(); // byte pos = data[i * 8 + 1 + 6 + 3]; // MyInventoryItem.name = ""; // MyInventoryItem.description = ""; // MyInventoryItem.weight = 0; // MyInventoryItem.SqlID = 0; // MyInventoryItem.imageid = System.BitConverter.ToInt16(data, i * 8 + 1 + 3); // MyInventoryItem.quantity = System.BitConverter.ToUInt32(data, i * 8 + 1 + 2 + 3); // MyInventoryItem.pos = pos; // int flags = data[i * 8 + 1 + 7 + 3]; // MyInventoryItem.is_resource = ((flags & 2) > 0); // MyInventoryItem.is_reagent = ((flags & 1) > 0); // MyInventoryItem.use_with_inventory = ((flags & 8) > 0); // MyInventoryItem.is_stackable = ((flags & 4) > 0); // TheInventory.Add(MyInventoryItem); // TheTCPWrapper.Send(CommandCreator.LOOK_AT_INVENTORY_ITEM((byte)MyInventoryItem.pos)); // System.Threading.Thread.Sleep(10); //} }