예제 #1
0
        /// <summary>
        /// What will the merchant buy this item for
        /// </summary>
        /// <param name="item">the item in question</param>
        /// <returns>the price, -1 indicates they wont buy it</returns>
        public int HaggleCheck(IInanimate item)
        {
            decimal value = -1;

            if (item != null)
            {
                IInanimateTemplate template = item.Template <IInanimateTemplate>();
                if (WillPurchase.Any(merch => merch.Item.Id == item.TemplateId))
                {
                    DataStructure.Gaia.IEconomy theEconomy = CurrentLocation.CurrentZone.GetWorld().Macroeconomy;

                    if (theEconomy != null)
                    {
                        DataStructure.Gaia.IEconomicBasis priceBasis = theEconomy.Bases.FirstOrDefault(basis => basis.ItemType.Id == item.TemplateId);

                        if (priceBasis != null)
                        {
                            value = priceBasis.Basis * priceBasis.Adjustment;
                        }
                        else
                        {
                            value = theEconomy.MakeValuation(template);
                        }

                        foreach (IQuality quality in item.Qualities)
                        {
                            DataStructure.Gaia.IEconomicTrend trend = theEconomy.Trends.FirstOrDefault(trnd => trnd.Quality.Equals(quality.Name, StringComparison.InvariantCultureIgnoreCase));

                            if (trend != null)
                            {
                                value += trend.Basis * trend.Adjustment;
                            }
                            else
                            {
                                value += theEconomy.MakeValuation(template);
                            }
                        }

                        decimal myAdjustments = 1;

                        foreach (IMerchandise adjustment in WillPurchase.Where(merch => merch.Item.Id == item.TemplateId))
                        {
                            if (string.IsNullOrWhiteSpace(adjustment.Quality) || item.Qualities.Any(quality => quality.Name.Equals(adjustment.Quality) &&
                                                                                                    quality.Value.IsBetweenOrEqual(adjustment.QualityRange.Low, adjustment.QualityRange.High)))
                            {
                                myAdjustments += adjustment.MarkRate;
                            }
                        }

                        value += value * myAdjustments;
                    }
                }
            }

            return((int)Math.Truncate(value));
        }
예제 #2
0
        /// <summary>
        /// Check the price this will be sold for
        /// </summary>
        /// <param name="item">The item in question</param>
        /// <returns>the price, -1 indicates it wont be sold or isn't in stock</returns>
        public int PriceCheck(IInanimate item, bool mustBeInStock)
        {
            decimal value = -1;

            //If we need it in stock but don't have it it's sell price is invalid
            if (item != null && (!mustBeInStock || Inventory.Contains(item)))
            {
                if (WillSell.Any(merch => merch.Item.Id == item.TemplateId))
                {
                    DataStructure.Gaia.IEconomy theEconomy = CurrentLocation.CurrentZone.GetWorld().Macroeconomy;

                    if (theEconomy != null)
                    {
                        DataStructure.Gaia.IEconomicBasis priceBasis = theEconomy.Bases.FirstOrDefault(basis => basis.ItemType.Id == item.TemplateId);

                        if (priceBasis != null)
                        {
                            value = priceBasis.Basis * priceBasis.Adjustment;
                        }
                        else
                        {
                            value = theEconomy.MakeValuation(item.Template <IInanimateTemplate>());
                        }

                        foreach (IQuality quality in item.Qualities)
                        {
                            DataStructure.Gaia.IEconomicTrend trend = theEconomy.Trends.FirstOrDefault(trnd => trnd.Quality.Equals(quality.Name, StringComparison.InvariantCultureIgnoreCase));

                            if (trend != null)
                            {
                                value += trend.Basis * trend.Adjustment;
                            }
                            else
                            {
                                value += theEconomy.MakeValuation(item.Template <IInanimateTemplate>());
                            }
                        }

                        decimal myAdjustments = 1;

                        foreach (IMerchandise adjustment in WillSell.Where(merch => merch.Item.Id == item.TemplateId))
                        {
                            if (string.IsNullOrWhiteSpace(adjustment.Quality) || item.Qualities.Any(quality => quality.Name.Equals(adjustment.Quality) &&
                                                                                                    quality.Value.IsBetweenOrEqual(adjustment.QualityRange.Low, adjustment.QualityRange.High)))
                            {
                                myAdjustments *= adjustment.MarkRate;
                            }
                        }

                        value *= myAdjustments;
                    }
                }
            }

            return((int)Math.Truncate(value));
        }