Пример #1
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";
    }