Пример #1
0
    private void RebuildInventory()
    {
        //first remove all existing griditems in the backpack
        List <GridItem> backpackCopy = new List <GridItem>(BackpackGrid.Items);

        foreach (GridItem item in backpackCopy)
        {
            BackpackGrid.Items.Remove(item);
            DestroyItem(item);
        }

        //then load player party inventory's selected member's partyMemberInventory
        List <GridItemData> datas = GameManager.Inst.PlayerControl.Party.SelectedMember.Inventory.Backpack;

        foreach (GridItemData data in datas)
        {
            BackpackGrid.AddGridItem(data.Item, data.ColumnPos, data.RowPos, data.Orientation, data.Quantity);
        }
    }
Пример #2
0
    public void RefreshSellBuyTotalPrice()
    {
        //clear rubles in buy grid
        float buyPrice = 0;

        List <GridItem> buyGridCopy = new List <GridItem>(BuyGrid.Items);

        foreach (GridItem gItem in buyGridCopy)
        {
            gItem.PriceTag = _targetTrader.GetSellPrice(gItem.Item);

            if (gItem.Item.ID == "rubles")
            {
                BuyGrid.RemoveGridItem(gItem);
                GameManager.Inst.UIManager.WindowPanel.InventoryPanel.DestroyItem(gItem);
            }
            else
            {
                buyPrice += gItem.PriceTag * gItem.GetQuantity();
            }
        }

        int buyPriceInt = Mathf.CeilToInt(buyPrice);



        float sellPrice = 0;

        foreach (GridItem gItem in SellGrid.Items)
        {
            gItem.PriceTag = _targetTrader.GetBuyPrice(gItem.Item);
            sellPrice     += gItem.PriceTag * gItem.GetQuantity();
        }
        int sellPriceInt = Mathf.CeilToInt(sellPrice);

        SellPrice           = sellPriceInt;
        SellPriceLabel.text = sellPriceInt.ToString() + " RU";


        //automatically generate rubles in buy grid if player's item worth more than sells item
        if (sellPriceInt >= buyPriceInt)
        {
            int quantity = sellPriceInt - buyPriceInt;
            if (quantity > _targetTrader.Cash)
            {
                quantity = _targetTrader.Cash;
            }

            buyPriceInt += quantity;
            if (quantity > 0)
            {
                Item           rubleItem = GameManager.Inst.ItemManager.LoadItem("rubles");
                int            colPos;
                int            rowPos;
                GridItemOrient orientation;
                if (BuyGrid.FitItemInGrid(rubleItem, out colPos, out rowPos, out orientation))
                {
                    GridItem gItem = BuyGrid.AddGridItem(rubleItem, colPos, rowPos, orientation, quantity);
                    if (gItem != null)
                    {
                        gItem.PriceTag = 1;
                    }
                }
            }
        }

        BuyPrice           = buyPriceInt;
        BuyPriceLabel.text = buyPriceInt.ToString() + " RU";
    }
Пример #3
0
    public void OnTradeButtonPress()
    {
        //check if trading is possible
        int playerMoney = GameManager.Inst.UIManager.WindowPanel.InventoryPanel.BackpackGrid.GetItemQuantityByID("rubles");

        if (BuyPrice > SellPrice)
        {
            int difference = BuyPrice - SellPrice;

            if (playerMoney < difference)
            {
                return;
            }
            else
            {
                GameManager.Inst.UIManager.WindowPanel.InventoryPanel.BackpackGrid.RemoveItemsByID("rubles", difference);
                _targetTrader.Cash += difference;
            }
        }

        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Trade"), 0.2f);


        //update inventory panel to player inventory
        HumanCharacter player = GameManager.Inst.PlayerControl.SelectedPC;

        GameManager.Inst.UIManager.WindowPanel.InventoryPanel.SaveInventoryData(player);

        //first remove all items from sell
        List <GridItem> sellCopy = new List <GridItem>(SellGrid.Items);

        foreach (GridItem item in sellCopy)
        {
            SellGrid.Items.Remove(item);
            GameManager.Inst.UIManager.WindowPanel.InventoryPanel.DestroyItem(item);
        }


        //then take each one of the bought items and insert into backpack;
        //if anything won't fit, place it in the sell grid
        List <GridItem> buyCopy = new List <GridItem>(BuyGrid.Items);

        foreach (GridItem item in buyCopy)
        {
            int            colPos;
            int            rowPos;
            GridItemOrient orientation;

            if (player.Inventory.FitItemInBackpack(item.Item, out colPos, out rowPos, out orientation))
            {
                Debug.Log("Found backpack fit " + colPos + ", " + rowPos + " orientation " + orientation);

                GameManager.Inst.UIManager.WindowPanel.InventoryPanel.BackpackGrid.AddGridItem(item.Item, colPos, rowPos, orientation, item.GetQuantity());
                GameManager.Inst.UIManager.WindowPanel.InventoryPanel.SaveInventoryData(player);
            }
            else
            {
                SellGrid.AddGridItem(item.Item, item.ColumnPos, item.RowPos, item.Orientation, item.GetQuantity());
            }

            //if it's rubles then reduce trader cash
            if (item.Item.ID == "rubles")
            {
                _targetTrader.Cash -= item.GetQuantity();
            }

            BuyGrid.Items.Remove(item);
            GameManager.Inst.UIManager.WindowPanel.InventoryPanel.DestroyItem(item);
        }

        BuyPriceLabel.text  = "0 RU";
        SellPriceLabel.text = "0 RU";
        GameManager.Inst.UIManager.WindowPanel.InventoryPanel.RefreshTotalWeight();

        UpdateTraderMoneyDisplay();
    }