public BlueprintDetails(Blueprint print) { ItemId = print.ItemId; BlueprintId = print.TypeId; Me = print.MaterialEfficiency; Pe = print.TimeEfficiency; Runs = print.Runs; LastUpdated = DateTime.Now; }
public async Task<decimal> CalculateItemPrice(int typeId) { var bpInfo = await _dataService.GetBlueprintInfoByProductTypeIdAsync(typeId); if (bpInfo == null) return 0; // todo: Create indy job repository var indyHistory = await _apiService.GetApiResult<IndustryJobDto>(new Credential(), CallContext.Corp, CallEndPoint.IndustryJobsHistory); if (!indyHistory.Success) throw new Exception($"IndustryJob history failed... error: {indyHistory.Message}"); var job = indyHistory.Result.Where(p => p.ProductTypeId == typeId && p.ActivityId == 1).OrderByDescending(p => p.EndDate).FirstOrDefault(); if (job == null) return 0; var itemPrice = (decimal)job.Cost / job.Runs / (decimal)bpInfo.Manufacturing.Products.First(p => p.TypeId == typeId).Quantity; //var bp = await _blueprintRepository.FindBlueperintByItemIdAsync(job.BlueprintId) ?? var bp = await _blueprintRepository.FindBlueprintAsync(bpInfo.BlueprintId); if (bp == null) bp = new Blueprint(bpInfo.BlueprintId, 4, 4, 10); var jobInfo = new Domains.IndustryJob(bpInfo, bp); var materials = await jobInfo.GetMaterialNeeds(job.SuccesfulRuns); var matPrices = await _apiService.GetMarketStatistics(materials.Select(p => p.TypeId).ToList(), 30000142); // todo: Create Transaction Repository foreach (var mat in materials) { var used = mat.Quantity/(decimal)job.SuccesfulRuns; var matBp = await _dataService.GetBlueprintInfoByProductTypeIdAsync(mat.TypeId); if (matBp == null) { try { var matPrice = used * matPrices.FirstOrDefault(p => p.TypeId == mat.TypeId).Buy / (decimal)jobInfo.BlueprintInfo.Manufacturing.Products.First(p => p.TypeId == typeId).Quantity; itemPrice += matPrice; continue; } catch (Exception e) { throw new Exception($"Material {mat.TypeName} (ID: {mat.TypeId}) failed due to not being in price list"); } } itemPrice += (await CalculateItemPrice(mat.TypeId)) * mat.Quantity; } return itemPrice; }
private async Task CreateManufacturingViewModel(Blueprint blueprint) { var bpInfo = _bpInfo.FirstOrDefault(p => p.BlueprintId.Equals(blueprint.TypeId)); if (bpInfo == null || !bpInfo.Manufacturing.Products.Any() || bpInfo.Manufacturing.Products.First().MetaGroup < 2) return; var product = bpInfo.Manufacturing?.Products?.First(); if (product == null || !await PreManufacturingValidation(product)) return; var job = new Domains.IndustryJob(bpInfo, blueprint); var rawMaterials = await _manufacturingService.GetRawMaterials(job, 1); var marketStatIds = rawMaterials.Select(p => p.TypeId).ToList(); marketStatIds.Add(product.TypeId); var marketStats = await _apiService.GetMarketStatistics(marketStatIds, 30000142); var productCost = rawMaterials.Sum(mat => Convert.ToDecimal(mat.Quantity) * marketStats.First(p => p.TypeId.Equals(mat.TypeId)).Buy); productCost = productCost / Convert.ToDecimal(bpInfo.Manufacturing.Products.First().Quantity); var productPrice = marketStats.First(p => p.TypeId.Equals(product.TypeId)).Buy; if (productPrice <= productCost) return; var runs = 0; if (productCost < 8000000 && blueprint.Runs > 0) runs = blueprint.Runs; else if (productCost < 8000000 && blueprint.Runs == -1) runs = product.CategoryId == 6 ? 5 : 20; else if (productCost > 8000000 && productCost < 30000000 && blueprint.Runs > 0) runs = blueprint.Runs >= 10 ? 10 : blueprint.Runs; else if (productCost > 1500000000) return; else runs = 1; if (runs > 100) runs = 100; var manufTime = await _manufacturingService.GetTotalManufacturingTime(job, runs); var profitPerHour = (productPrice - productCost / (decimal)job.BlueprintInfo.Manufacturing.Products.First().Quantity) / manufTime * 60 * 60; var materials = await job.GetMaterialNeeds(runs); foreach (var mat in materials) { var bp = await _staticService.GetBlueprintInfoByProductTypeIdAsync(mat.TypeId); if (bp == null || bp.BlueprintId == 0) { _materials.Add(mat); continue; } _components.Add(new Component(mat.TypeId, mat.TypeName, (int)mat.Quantity)); } _products.Add(new Product(product.TypeId, product.TypeName, runs, profitPerHour, product.CategoryId)); }
public IndustryJob(BlueprintInfo info, Blueprint print) { BlueprintInfo = info; Blueprint = print; }