示例#1
0
 public override bool SetItemAt(Vector2 pos, ItemStack stack)
 {
     foreach (var slot in inventoryData.inventoryContent)
     {
         if (slot.pos == pos)
         {
             if (slot.itemStack.data == stack.data)
             {
                 lastSlot = new InventoryData.InventorySlot(pos, stack);
                 slot.itemStack.sizeStack += stack.sizeStack;
                 NotifyUpdate(slot);
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     InventoryData.InventorySlot _slot = new InventoryData.InventorySlot(pos, stack);
     lastSlot = _slot;
     inventoryData.inventoryContent.Add(_slot);
     NotifyUpdate(_slot);
     return(true);
 }
示例#2
0
 void NotifyUpdate(InventoryData.InventorySlot cursor)
 {
     if (showInventory || (cursor.pos.y == 0))
     {
         if (callbackList.ContainsKey(cursor.pos))
         {
             callbackList[cursor.pos] (cursor.itemStack);
         }
     }
 }
示例#3
0
    public bool AddItems(ItemStack stack)
    {
        Vector2 emptySlot = Vector2.one * -1;

        for (int y = 0; y < sizeInventory / sizeInventoryBar; y++)
        {
            for (int x = 0; x < sizeRowInventory && x + y * sizeInventoryBar < sizeInventory; x++)
            {
                Vector2 cursor          = new Vector2(x, y);
                bool    findInInventory = false;
                foreach (var slot in inventoryData.inventoryContent)
                {
                    if (slot.pos == cursor)
                    {
                        if (slot.itemStack.data.itemName == stack.data.itemName)
                        {
                            slot.itemStack.sizeStack += stack.sizeStack;
                            NotifyUpdate(slot);
                            return(true);
                        }
                        else
                        {
                            findInInventory = true;
                            break;
                        }
                    }
                }
                if (emptySlot == Vector2.one * -1 && !findInInventory)
                {
                    emptySlot = cursor;
                }
            }
        }
        if (emptySlot != Vector2.one * -1)
        {
            InventoryData.InventorySlot slot = new InventoryData.InventorySlot(emptySlot, stack);
            inventoryData.inventoryContent.Add(slot);
            NotifyUpdate(slot);
            return(true);
        }
        return(false);
    }
示例#4
0
    public static void setSavedInventory(SavableInventoryData savedData)
    {
        InventoryData data = InventoryData.CreateInstance <InventoryData> ();

        data.gold = savedData.gold;
        foreach (var _slot in savedData.inventoryContent)
        {
            ItemData item = ItemFactory.Instance.MakeItem(_slot.itemStack.data);
            if (item)
            {
                ItemStack stack = new ItemStack(item, _slot.itemStack.sizeStack);
                InventoryData.InventorySlot slot = new InventoryData.InventorySlot(_slot.pos, stack);
                data.inventoryContent.Add(slot);
            }
        }
        inventoryData = data;
        if (_instance != null)
        {
            _instance.NotifyAll();
        }
    }
示例#5
0
 public void RewindLastItem()
 {
     InventoryData.InventorySlot rewindSlot = new InventoryData.InventorySlot(lastSlot.pos, null);
     foreach (var slot in inventoryData.inventoryContent)
     {
         if (slot.pos == lastSlot.pos)
         {
             Debug.LogFormat("Rewind item: {0} x{1}", slot.itemStack.data.itemName, slot.itemStack.sizeStack);
             if (slot.itemStack.sizeStack == lastSlot.itemStack.sizeStack)
             {
                 inventoryData.inventoryContent.Remove(slot);
             }
             else
             {
                 slot.itemStack.sizeStack -= lastSlot.itemStack.sizeStack;
                 rewindSlot = slot;
             }
             break;
         }
     }
     NotifyUpdate(rewindSlot);
 }