Ejemplo n.º 1
0
    void OnSlotClicked(PointerEventData eventData)
    {
        InventorySlotUI slotUI = eventData.pointerPress.GetComponent <InventorySlotUI>();

        this.itemToDisplay = slotUI.itemToDisplay;
        Refresh();
    }
Ejemplo n.º 2
0
    protected virtual void OnDropAreaDrop(PointerEventData eventData)
    {
        // This can work only with InventorySlotUI objects.
        InventorySlotUI slotDropped = eventData.pointerDrag.GetComponent <InventorySlotUI>();

        if (slotDropped != null)
        {
            // If the slot is of an item from elsewhere, take it into this display window,
            // provided its underlying inventory has the space for the item.
            SKSItem itemDropped = slotDropped.itemToDisplay;
            if (!inventory.Contains(itemDropped) && inventory.itemCount < inventory.capacity)
            {
                SKSInventory otherInventory = itemDropped.belongsTo as SKSInventory;
                if (otherInventory != null)
                {
                    otherInventory.Remove(itemDropped);
                }
                inventory.Add(itemDropped);

                // Destroy the slot; a new one should be made in its place thanks to
                // the moving around of items.
                Destroy(slotDropped.gameObject);
            }
            else
            {
                // This slot was inside this window, so just put it back where it belongs.
                slotDropped.ResetParent();
            }
        }

        base.OnDrop(eventData);
    }
Ejemplo n.º 3
0
    bool TryToBuySomething()
    {
        bool boughtSomething = false;

        if (shopsToBuyFrom != null && shopsToBuyFrom.Length > 0)
        {
            // Pick a random shop.
            int     shopCount = shopsToBuyFrom.Length;
            int     shopIndex = Random.Range(0, shopCount);
            SKSShop toBuyFrom = shopsToBuyFrom[shopIndex];

            // Buy the first item this NPC can afford.
            SKSItem itemToBuy = null;
            foreach (SKSItem item in toBuyFrom.storefront.items)
            {
                if (item.price <= cash)
                {
                    itemToBuy = item;
                    break;
                }
            }

            if (itemToBuy != null)
            {
                toBuyFrom.SellItem(itemToBuy, this);
                boughtSomething = true;
            }
        }

        return(boughtSomething);
    }
Ejemplo n.º 4
0
    public static SKSItem Copy(SKSItem original)
    {
        SKSItem itemCopy = ScriptableObject.CreateInstance <SKSItem>();

        CopyBaseAttributes(original, itemCopy);
        itemCopy.price       = original.price;
        itemCopy.description = original.description;

        return(itemCopy);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Return true if selling was successful, false otherwise.
    /// </summary>
    public bool SellItem(SKSItem itemToSell, ICustomer toSellTo)
    {
        if (toSellTo.cash >= itemToSell.price)
        {
            toSellTo.cash -= itemToSell.price;
            storefront.Remove(itemToSell);
            owner.cash += itemToSell.price;
            SoldSomething.Invoke();
            return(true);
        }

        Debug.Log(toSellTo.name + " doesn't have enough cash to buy " + itemToSell.name);
        return(false);
    }
Ejemplo n.º 6
0
    void ObserveSlots()
    {
        InventorySlotUI slotUI = null;

        // Watch for when any of the inventory slots are clicked, so this displays the item last clicked.
        foreach (Transform slot in displayWindow.slotHolder)
        {
            slotUI = slot.GetComponent <InventorySlotUI>();
            slotUI.events.PointerClicked.RemoveListener(slotClickAction);
            // ^ In case this panel was already watching this slot.

            slotUI.events.PointerClicked.AddListener(slotClickAction);
        }

        itemToDisplay = null;
        HideOwnContents();
    }