Пример #1
0
    public void getItem(Item.ItemInfo _item, int _amount)
    {
        bool haveIt = false;

        for (int i = 0; i < itemSlotInfos.Count; i++)
        {
            if (itemSlotInfos[i].GetItem().ID == _item.ID)
            {
                itemSlotInfos[i].get(_amount);
                haveIt = true;
                break;
            }
        }
        if (!haveIt)
        {
            ItemSlotInfo tmp = new ItemSlotInfo();

            tmp.SetItem(_item);
            tmp.SetNum(_amount);

            itemSlotInfos.Add(tmp);

            SortItemList();
        }
        removeSlots();
        setSlots();
    }
Пример #2
0
        private bool isItemInInventory(SunItem item, out ItemSlotInfo itemSlot)
        {
            itemSlot = null;
            foreach (var slot in invSlotsInfo)
            {
                if (slot != null && (uint)BitConverter.ToUInt16(slot.itemInfo.code, 0) == item.itemId)
                {
                    itemSlot = slot;
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public bool SplitItem(byte posFrom, byte posTo, byte amountLeft, byte amountMove)
        {
            TryGetSlotInfo(posFrom, GetSlots(1), out var orgSlot);

            var newSlot = new ItemSlotInfo(orgSlot.ToBytes());

            newSlot.position           = posTo;
            newSlot.itemInfo.itemCount = amountMove;
            var index = FindFreeInvSlot();

            GetSlots(1)[index] = newSlot;

            orgSlot.itemInfo.itemCount = amountLeft;
            inventoryItemCount++;
            return(true);
        }
Пример #4
0
        private bool TryGetSlotInfo(byte pos, ItemSlotInfo[] slots, out ItemSlotInfo slotInfo)
        {
            slotInfo = null;
            foreach (var slot in slots)
            {
                if (slot == null)
                {
                    continue;
                }
                if ((byte)slot.position != pos)
                {
                    continue;
                }
                slotInfo = slot;
                return(true);
            }

            return(false);
        }
Пример #5
0
        public bool AddItemToInv(SunItem item, out ItemSlotInfo slotInfo, int count = 1)
        {
            slotInfo = null;
            if (isItemInInventory(item, out var slot))
            {
                slot.itemInfo.itemCount++;
                slotInfo = slot;
                return(true);
            }
            var slotNum = FindFreeInvSlot();

            if (slotNum == -1)
            {
                return(false);
            }
            invSlotsInfo[slotNum] = new ItemSlotInfo((byte)slotNum, item, (byte)count);
            slotInfo = invSlotsInfo[slotNum];
            inventoryItemCount++;
            return(true);
        }
Пример #6
0
        public void SerializeInventoryByteStream()
        {
            equipItemCount = EquipItem[0];
            if (EquipItem.Length != equipItemCount * 28 + 1)
            {
                return;                                              //SlotInfo Size
            }
            for (int i = 0; i < equipItemCount; i++)
            {
                equipInfo[i] = new ItemSlotInfo(ByteUtils.SlicedBytes(EquipItem, i * 28 + 1, (i + 1) * 28 + 1));
                if (equipInfo[i].position == 0)
                {
                    //equipInfo[i].itemInfo.serial = new byte[] { 10, 0, 0, 0 };
                }
            }

            tempInventoryItemCount = TmpInventoryItem[0];
            if (TmpInventoryItem.Length != tempInventoryItemCount * 28 + 1)
            {
                return;                                                             //SlotInfo Size
            }
            for (int i = 0; i < tempInventoryItemCount; i++)
            {
                tempInventory[i] = new ItemSlotInfo(ByteUtils.SlicedBytes(TmpInventoryItem, i * 28 + 1, (i + 1) * 28 + 1));
            }

            inventoryItemCount = InventoryItem[0];
            if (InventoryItem.Length != inventoryItemCount * 28 + 1)
            {
                return;                                                      //SlotInfo Size
            }
            for (int i = 0; i < inventoryItemCount; i++)
            {
                invSlotsInfo[i] = new ItemSlotInfo(ByteUtils.SlicedBytes(InventoryItem, i * 28 + 1, (i + 1) * 28 + 1));
                if (invSlotsInfo[i].position == 0)
                {
                    //invSlotsInfo[i].itemInfo.serial=new byte[]{10,0,0,0};
                }
            }
        }