internal async Task CheckInventionJob(IndustryJobDto job) { var printInfo = _printInfos.FirstOrDefault(p => p.BlueprintId == job.BlueprintTypeId); if (printInfo == null) throw new InvalidOperationException("Trying to invent something that can't be invented..."); var mats = printInfo.Invention.Materials; foreach (var mat in mats) { var m = _stock.FirstOrDefault(p => p.TypeId == mat.TypeId); if (m == null) continue; if (m.Quantity <= mat.Quantity) _stock.Remove(m); else m.DecreaseQuantity(m.Quantity * job.Runs); } var inv = _inventions.FirstOrDefault(p => p.InputTypeId == job.BlueprintTypeId); if (inv != null) await Task.Run(() => _inventions.Remove(inv)); }
internal async Task CheckManufacturingJob(IndustryJobDto job) { var print = _blueprints.First(p => p.ItemId == job.BlueprintId); if (print == null) return; var printInfo = _printInfos.FirstOrDefault(p => p.BlueprintId == job.BlueprintTypeId); if (printInfo == null) throw new InvalidOperationException("It seems there was an item that has no blueprint being built... sort it out."); var indyJob = new Domains.IndustryJob(printInfo, print); var mats = await indyJob.GetMaterialNeeds(job.Runs); foreach (var mat in mats) { var m = _stock.FirstOrDefault(p => p.TypeId == mat.TypeId); if (m == null) continue; if (m.Quantity <= mat.Quantity) _stock.Remove(m); else m.DecreaseQuantity(mat.Quantity); } var comp = _components.FirstOrDefault(p => p.TypeId == job.ProductTypeId); if (comp != null) { if (comp.Quantity <= job.Runs) _components.Remove(comp); else comp.DecreaseQuantity(job.Runs); return; } var prod = _products.FirstOrDefault(p => p.TypeId == job.ProductTypeId); if (prod == null) return; if (prod.Quantity <= job.Runs) _products.Remove(prod); else prod.DecreaseQuantity(job.Runs); }