void OnSlotClicked(PointerEventData eventData) { InventorySlotUI slotUI = eventData.pointerPress.GetComponent <InventorySlotUI>(); this.itemToDisplay = slotUI.itemToDisplay; Refresh(); }
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); }
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); }
public static SKSItem Copy(SKSItem original) { SKSItem itemCopy = ScriptableObject.CreateInstance <SKSItem>(); CopyBaseAttributes(original, itemCopy); itemCopy.price = original.price; itemCopy.description = original.description; return(itemCopy); }
/// <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); }
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(); }