Пример #1
0
    public static void DropActive(PlayerController player, InventoriesController invController, int count)
    {
        var tempItem = new Item {
            itemType = invController.activeItem.itemType, amount = count
        };

        WorldItem.DropItem(player.transform.position, tempItem, player.facingRight);

        if (invController.activeItem.amount == count)
        {
            invController.DestroyActive();
        }
        else
        {
            invController.activeItem.amount--;

            if (invController.activeItem.amount <= 0)
            {
                invController.DestroyActive();
            }
            else
            {
                invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
            }
        }
    }
Пример #2
0
    private static void PutDown(UI_Inventory ui, InventoriesController invController)
    {
        if (ui.isHovering && invController.activeItem != null && invController.activeItem.itemType != ItemType.Empty)
        {
            // place
            if (ui.hoverSlot.item == null)
            {
                ui.inventory.SetItem(invController.activeItem, ui.hoverSlot.index);
                invController.DestroyActive();
            }
            else
            {
                var tempItem = ui.hoverSlot.item;

                // combine
                if (tempItem.itemType == invController.activeItem.itemType)
                {
                    var totalAmount = tempItem.amount + invController.activeItem.amount;

                    if (totalAmount <= Item.MaxAmount)
                    {
                        ui.inventory.SetItem(new Item {
                            itemType = tempItem.itemType, amount = totalAmount
                        }, ui.hoverSlot.index);
                        invController.DestroyActive();
                    }
                    else
                    {
                        ui.inventory.SetItem(new Item {
                            itemType = tempItem.itemType, amount = Item.MaxAmount
                        }, ui.hoverSlot.index);
                        invController.activeItem = new Item {
                            itemType = tempItem.itemType, amount = totalAmount - Item.MaxAmount
                        };
                        invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
                    }
                }
                // switch
                else
                {
                    ui.inventory.SetItem(invController.activeItem, ui.hoverSlot.index);
                    invController.activeItem = new Item {
                        itemType = tempItem.itemType, amount = tempItem.amount
                    };
                    invController.activeTransform.GetComponent <Image>().sprite = invController.activeItem.GetSprite();
                    invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
                }
            }
        }
    }
Пример #3
0
    private static void Drag(UI_Inventory ui, InventoriesController invController)
    {
        if (invController.slotList.Count > 1)
        {
            var itemsPerSlot = invController.activeItem.amount / invController.slotList.Count;
            var itemsHeld    = invController.activeItem.amount % invController.slotList.Count;

            foreach (var slot in invController.slotList)
            {
                if (slot.item != null)
                {
                    var totalAmount = slot.item.amount + itemsPerSlot;
                    if (totalAmount > Item.MaxAmount)
                    {
                        slot.ui.inventory.SetItem(new Item {
                            itemType = invController.activeItem.itemType, amount = Item.MaxAmount
                        }, slot.index);
                        itemsHeld += totalAmount - Item.MaxAmount;
                    }
                    else
                    {
                        slot.ui.inventory.SetItem(new Item {
                            itemType = invController.activeItem.itemType, amount = totalAmount
                        }, slot.index);
                    }
                }
                else
                {
                    slot.ui.inventory.SetItem(new Item {
                        itemType = invController.activeItem.itemType, amount = itemsPerSlot
                    }, slot.index);
                }
            }

            if (itemsHeld == 0)
            {
                invController.DestroyActive();
            }
            else
            {
                invController.activeItem.amount = itemsHeld;
                invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
            }
        }
        else
        {
            PutDown(ui, invController);
        }
    }