private async Task<InventionJob> GetInventionJob(Domains.IndustryJob job, BlueprintInfo t2Print, IEnumerable<Decryptor> decryptors, IEnumerable<MarketPrice> invMatPrices) { try { var types = new List<int> { t2Print.Manufacturing.Products.First().TypeId }; var rawMaterials = await _manufacturingService.GetRawMaterials(new Domains.IndustryJob(t2Print, new Blueprint(1, 0, 0, 1)), 1); types.AddRange(rawMaterials.Select(p => p.TypeId).ToList()); var marketStats = await _apiService.GetMarketStatistics(types, 30000142); var baseRuns = t2Print.Manufacturing.Products.First().CategoryId == 6 ? 1 : 10; var costOfInvention = job.BlueprintInfo.Invention.Materials.Sum(material => invMatPrices.First().Buy * Convert.ToDecimal(material.Quantity)); var t2Item = await _staticService.GetProductTypeAsync(t2Print.BlueprintId); var t1Item = await _staticService.GetProductTypeAsync(job.BlueprintInfo.BlueprintId); var tasks = decryptors.Select(p => CheckDecryptor(p, job, t2Print, costOfInvention, baseRuns, marketStats)).ToList(); var inventionJob = new InventionJob(t2Item.TypeId, t2Item.TypeName, t1Item.TypeId, t1Item.TypeName, 0, new List<Decryptor>()); while (tasks.Any()) { var task = await Task.WhenAny(tasks); inventionJob.Decryptors.Add(await task); tasks.Remove(task); } return inventionJob; } catch (Exception e) { throw new Exception($"Invention of {t2Print.Manufacturing.Products.First().TypeName} failed with message: {e.Message}"); } }
private async Task DoStuffToInvention(InventionJob job) { var decryptor = job.Decryptors.OrderByDescending(p => p.ProfitPerInvention).First(); if (decryptor.Price < 50000) return; var indyJob = new Domains.IndustryJob(await _staticService.GetBlueprintInfoAsync(job.ParentId), new Blueprint(job.ParentId, 0, 0, 1)); var runs = Math.Floor((double)60 * 60 * 24 / await indyJob.GetInventionTime() / 2); runs = runs > 0 ? runs : 1; _inventions.Add(new Invention(job.ParentId, job.ParentName, job.Name, decryptor.TypeName, decryptor.ProfitPerInvention, (int)runs)); if (decryptor.TypeId > 0) _materials.Add(new Material(decryptor.TypeId, decryptor.TypeName, (int)runs)); foreach (var p in indyJob.BlueprintInfo.Invention.Materials) _materials.Add(new Material(p.TypeId, p.TypeName, (int)(p.Quantity * runs))); }