예제 #1
0
 /// <summary>
 /// Initialize all vendor data on load
 /// </summary>
 protected virtual void InitializeVendor()
 {
     if (canRollBackItems)
     {
         rollBackButton.SetActive(true);
     }
     else
     {
         rollBackButton.SetActive(false);
     }
     _itemDetails  = Object.FindObjectOfType <InventoryDetailsExtended>();
     _inputManager = Object.FindObjectOfType <InventoryInputManagerExtended>();
     SetVendorInventoryName();
     vendorInventory.ResizeArray(vendorColumns * vendorRows);
     vendorRollBackInventory.ResizeArray(vendorRollBackColumns * vendorRollBackRows);
 }
예제 #2
0
        /// <summary>
        /// Buy item or items from vendor
        /// </summary>
        public virtual void BuyItem()
        {
            Vendor openedVendor = null;

            Vendor[] vendors = FindObjectsOfType <Vendor>();
            foreach (Vendor vendor in vendors)
            {
                if (vendor.enabled && vendor.isOpen)
                {
                    openedVendor = vendor;
                }
            }
            if (openedVendor != null)
            {
                InventorySlot            slot      = CurrentlySelectedInventorySlot;
                Inventory                inventory = slot.ParentInventoryDisplay.TargetInventory;
                int                      index     = slot.Index;
                InventoryItem            item      = inventory.Content[index];
                InventoryDetailsExtended ide       = FindObjectOfType <InventoryDetailsExtended>();
                if (ide != null && item != null && ide.disabledItems.Contains(item) == false && (inventory.name == openedVendor.vendorInventory.name || inventory.name == openedVendor.vendorRollBackInventory.name))
                {
                    int quantity = Int32.Parse(ide.vendorQuantity.text);
                    int price    = Int32.Parse(ide.vendorPrice.text);
                    int cash     = openedVendor.GetPlayerCash();
                    if (cash >= price)
                    {
                        int freeSlot = FindFirstFreeSlot(openedVendor.mainInventory);
                        if (freeSlot != -1)
                        {
                            openedVendor.PayForItem(price);
                            openedVendor.mainInventory.Content[freeSlot]          = item.Copy();
                            openedVendor.mainInventory.Content[freeSlot].Quantity = quantity;
                            MMInventoryEvent.Trigger(MMInventoryEventType.ContentChanged, null, openedVendor.mainInventory.name, null, 0, 0);
                        }
                        if (inventory.name == openedVendor.vendorInventory.name)
                        {
                            //vendor has limited stock
                            if (openedVendor.limitedStock)
                            {
                                if (quantity < item.Quantity)
                                {
                                    item.Quantity -= quantity;
                                }
                                else
                                {
                                    openedVendor.vendorInventory.DestroyItem(index);
                                }
                                MMInventoryEvent.Trigger(MMInventoryEventType.ContentChanged, null, openedVendor.vendorInventory.name, null, 0, 0);
                            }
                        }
                        else if (inventory.name == openedVendor.vendorRollBackInventory.name)
                        {
                            if (quantity < item.Quantity)
                            {
                                item.Quantity -= quantity;
                            }
                            else
                            {
                                openedVendor.vendorRollBackInventory.DestroyItem(index);
                            }
                            MMInventoryEvent.Trigger(MMInventoryEventType.ContentChanged, null, openedVendor.vendorRollBackInventory.name, null, 0, 0);
                        }
                    }
                }
            }
        }
예제 #3
0
 protected virtual void Awake()
 {
     _itemDetails = FindObjectOfType <InventoryDetailsExtended>();
 }
예제 #4
0
        /// <summary>
        /// Sell item or items to vendor
        /// </summary>
        public virtual void SellItem()
        {
            Vendor openedVendor = null;

            Vendor[] vendors = FindObjectsOfType <Vendor>();
            foreach (Vendor vendor in vendors)
            {
                if (vendor.enabled && vendor.isOpen)
                {
                    openedVendor = vendor;
                }
            }
            if (openedVendor != null)
            {
                InventorySlot            slot      = CurrentlySelectedInventorySlot;
                Inventory                inventory = slot.ParentInventoryDisplay.TargetInventory;
                int                      index     = slot.Index;
                InventoryItem            item      = inventory.Content[index];
                InventoryDetailsExtended ide       = FindObjectOfType <InventoryDetailsExtended>();
                if (ide != null && item != null && inventory.name == openedVendor.mainInventory.name)
                {
                    foreach (InventoryItem disabled in ide.disabledItems)
                    {
                        if (item.name == disabled.name)
                        {
                            return;
                        }
                    }
                    int quantity = Int32.Parse(ide.vendorQuantity.text);
                    int price    = Int32.Parse(ide.vendorPrice.text);
                    //we can buy back items from vendor
                    if (openedVendor.canRollBackItems)
                    {
                        if (openedVendor.vendorRollBackInventory.AddItem(item, quantity))
                        {
                            if (openedVendor.mainInventory.AddItem(openedVendor.currencyItem, price))
                            {
                                //openedVendor.vendorRollBackInventory.AddItem(item, quantity);
                                MMInventoryEvent.Trigger(MMInventoryEventType.ContentChanged, null, openedVendor.vendorRollBackInventory.name, null, 0, 0);
                                if (quantity < item.Quantity)
                                {
                                    item.Quantity -= quantity;
                                }
                                else
                                {
                                    openedVendor.mainInventory.DestroyItem(index);
                                }
                                //openedVendor.GetCashForItem(price);
                                MMInventoryEvent.Trigger(MMInventoryEventType.ContentChanged, null, openedVendor.mainInventory.name, null, 0, 0);
                            }
                        }
                    }
                    //we can't buy back items from vendor
                    else
                    {
                        if (openedVendor.mainInventory.AddItem(openedVendor.currencyItem, price))
                        {
                            if (quantity < item.Quantity)
                            {
                                item.Quantity -= quantity;
                            }
                            else
                            {
                                openedVendor.mainInventory.DestroyItem(index);
                            }
                            //openedVendor.GetCashForItem(price);
                            MMInventoryEvent.Trigger(MMInventoryEventType.ContentChanged, null, openedVendor.mainInventory.name, null, 0, 0);
                        }
                    }
                }
            }
        }