Beispiel #1
0
        public static decimal PriceAdjust(decimal price, decimal onhand, PricingBias bias)
        {
            //
            // Summary:
            //     Takes specified price, and adjusts it based on given stock on hand using reactive price rules to
            //     give us a market buy or sell price that has reacted to overstocked or understocked goods.
            //     Can be called when buying(done), selling(done) or displaying prices on lcds(done) or /pricelist command(done) or /value(done) possibly /worth too (possible issues with performance)
            //     Bias favours price changes on sell or buy (done), need to factor in transaction size or item price somehow to avoid exploiting price points

            /* desired logic:
             * 0: presumably we run this server side since the player is unlikely to have the price file, if no file found create one
             * 1: either load the price adjust table from the pricetable file OR use a list/array which already contains the table
             * 2: compare the on hand value supplied with the values in the table if it matches a criteria adjust price and any other bias/protection we add
             * 3: repeat this until all table entries have been checked and/or applied as appropriate to slide the price up or down
             * 4: return the calculated price for output to player price list or for buy/sell transactions
             *** We also apply transport tycoon style subsides in here too.
             */



            //here is the meat and bones of the reactive pricing.  Any logic we use to slide the price up or down goes here
            //This should prevent the sell (to player) price dropping below any possible reactive price change to the buy (from player) price
            //Ths should be all this logic needs to be production server safe.
            var x = 0;

            do
            {
                if ((onhand > EconomyScript.Instance.ReactivePricing.Prices[x].PricePoint) && (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange < 1))  //price goes down
                {
                    if (bias == PricingBias.Buy)
                    {
                        price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange - 0.05m);
                    }                                                                                                                        // Buy from player price bias too much stock
                    //else { price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange); } // Sell to player price disabled as this can potentially allow players to cheat
                }
                else
                {
                    if ((onhand <= EconomyScript.Instance.ReactivePricing.Prices[x].PricePoint) && (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange > 1)) //price goes up
                    {
                        if (bias == PricingBias.Sell)
                        {
                            price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange + 0.05m);
                        }                                                                                                                         //Sell to player price bias low stock
                        //else { price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange); } // Buy from player price disabled as this can potentially allow players to cheat
                    }
                }
                x++;
            } while (x < EconomyScript.Instance.ReactivePricing.Prices.Count); //Avoid out of bounds errors

            return(price);
        }
        public static decimal PriceAdjust(decimal price, decimal onhand, PricingBias bias)
        {
            //
            // Summary:
            //     Takes specified price, and adjusts it based on given stock on hand using reactive price rules to
            //     give us a market buy or sell price that has reacted to overstocked or understocked goods.
            //     Can be called when buying(done), selling(done) or displaying prices on lcds(done) or /pricelist command(done) or /value(done) possibly /worth too (possible issues with performance)
            //     Bias favours price changes on sell or buy (done), need to factor in transaction size or item price somehow to avoid exploiting price points

            /* desired logic:
            0: presumably we run this server side since the player is unlikely to have the price file, if no file found create one
            1: either load the price adjust table from the pricetable file OR use a list/array which already contains the table
            2: compare the on hand value supplied with the values in the table if it matches a criteria adjust price and any other bias/protection we add
            3: repeat this until all table entries have been checked and/or applied as appropriate to slide the price up or down
            4: return the calculated price for output to player price list or for buy/sell transactions
            *** We also apply transport tycoon style subsides in here too.
            */

            //here is the meat and bones of the reactive pricing.  Any logic we use to slide the price up or down goes here
            //This should prevent the sell (to player) price dropping below any possible reactive price change to the buy (from player) price
            //Ths should be all this logic needs to be production server safe.
            var x = 0;
            do
            {
                if ((onhand > EconomyScript.Instance.ReactivePricing.Prices[x].PricePoint) && (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange < 1))  //price goes down
                {
                    if (bias == PricingBias.Buy) { price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange - 0.05m); } // Buy from player price bias too much stock
                     //else { price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange); } // Sell to player price disabled as this can potentially allow players to cheat
                }
                else
                {
                    if ((onhand <= EconomyScript.Instance.ReactivePricing.Prices[x].PricePoint) && (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange > 1)) //price goes up
                    {
                        if (bias == PricingBias.Sell) { price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange + 0.05m); } //Sell to player price bias low stock
                        //else { price = price * (EconomyScript.Instance.ReactivePricing.Prices[x].PriceChange); } // Buy from player price disabled as this can potentially allow players to cheat
                    }
                }
                x++;
            } while (x < EconomyScript.Instance.ReactivePricing.Prices.Count); //Avoid out of bounds errors

            return price;
        }