Ejemplo n.º 1
0
        /// <summary>
        /// Стоимость покупки за основную валюту
        /// </summary>
        public decimal?GetBuyCost(Data data)
        {
            if (!CraftItems.Any())
            {
                return(null);
            }

            var sum = 0m;

            foreach (var craftItem in CraftItems)
            {
                var cost = craftItem.GetBuyPrice(data);
                if (cost == null)
                {
                    return(null);
                }

                var value = cost.Value;
                if (craftItem.ItemId == Item.WorkScoreId)
                {
                    var pro = data.Professions.FirstOrDefault(p => p.Id == ProfessionId);
                    if (pro != null && pro.Level > 0)
                    {
                        var oldCount = craftItem.Count;
                        try
                        {
                            craftItem.Count = Math.Round(craftItem.Count * pro.GetRatio());
                            value           = craftItem.GetBuyPrice(data).Value;
                        }
                        finally
                        {
                            craftItem.Count = oldCount;
                        }
                    }
                }

                sum += value;
            }
            return(sum);
        }