Пример #1
0
        public static Storage GiveTotalSoldProduct(ISeller seller, Product product)
        {
            var res = new Storage(product);

            foreach (var deal in seller.AllSellDeals().Where(x => x.Value.Product == product))
            {
                // Key is a market, Value is a Storage
                var market       = deal.Key;
                var sentToMarket = deal.Value;
                if (sentToMarket.get() > 0f)
                {
                    Value DSB = new Value(market.getDemandSupplyBalance(sentToMarket.Product, false));
                    if (DSB.get() == Options.MarketInfiniteDSB)
                    {
                        DSB.SetZero(); // real DSB is unknown
                    }
                    else if (DSB.get() > Options.MarketEqualityDSB)
                    {
                        DSB.Set(Options.MarketEqualityDSB);
                    }

                    var realSold = sentToMarket.Multiply(DSB);

                    if (realSold.isNotZero())
                    {
                        res.Add(realSold);
                    }
                }
            }
            return(res);
        }
Пример #2
0
        /// <summary>
        /// Brings money for sold product
        /// </summary>
        public static void GiveMoneyForSoldProduct(ISeller seller)
        {
            foreach (var deal in seller.AllSellDeals())
            {
                // Key is a market, Value is a Storage
                var market       = deal.Key;
                var sentToMarket = deal.Value;
                if (sentToMarket.get() > 0f)
                {
                    Value DSB = new Value(market.getDemandSupplyBalance(sentToMarket.Product, false));
                    if (DSB.get() == Options.MarketInfiniteDSB)
                    {
                        DSB.SetZero(); // real DSB is unknown
                    }
                    else if (DSB.get() > Options.MarketEqualityDSB)
                    {
                        DSB.Set(Options.MarketEqualityDSB);
                    }

                    decimal realSold = (decimal)sentToMarket.get();
                    realSold *= (decimal)DSB.get();

                    if (realSold > 0m)
                    {
                        MoneyView cost = market.getCost(sentToMarket.Product).Copy().Multiply(realSold);

                        // adding unsold product
                        // assuming gainGoodsThisTurn & realSold have same product
                        //if (storage.isExactlySameProduct(gainGoodsThisTurn))
                        //    storage.add(gainGoodsThisTurn);
                        //else
                        //    storage = new Storage(gainGoodsThisTurn);
                        //storage.Subtract((float)realSold);


                        if (market.CanPay(cost)) //&& Country.market.tmpMarketStorage.has(realSold))
                        {
                            market.Pay(seller as Agent, cost, Register.Account.MarketOperations);
                        }
                        else
                        {
                            if (Game.devMode)// && Country.market.HowMuchLacksMoneyIncludingDeposits(cost).Get() > 10m)
                            {
                                Debug.Log("Failed market - lacks " + market.HowMuchLacksMoneyIncludingDeposits(cost)
                                          + " for " + realSold + " " + sentToMarket.Product + " " + seller + " trade: " + cost); // money in market ended... Only first lucky get money
                            }
                            market.PayAllAvailableMoney(seller as Agent, Register.Account.MarketOperations);
                        }
                    }
                }
            }
        }