示例#1
0
        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);
            //}
        }