Skip to content

Commit

Permalink
Added factory detail export
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimencia committed Feb 12, 2021
1 parent aae5ffd commit 6d042c6
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 13 deletions.
58 changes: 58 additions & 0 deletions DU Industry Tool/IndustryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,64 @@ public void SaveOreValues()
File.WriteAllText("oreValues.json", JsonConvert.SerializeObject(Ores));
}


public List<IngredientRecipe> GetIngredientRecipes(string key, double quantity = 1)
{
var results = new List<IngredientRecipe>();

double inputMultiplier = 0;
double outputMultiplier = 0;
double outputAdder = 0;

var recipe = _recipes[key];

// Skip catalysts entirely tho.
if (Groups.Values.Where(g => g.Id == recipe.GroupId).FirstOrDefault()?.Name == "Catalyst")
return results;

foreach (var talent in Talents.Where(t => t.ApplicableRecipes.Contains(recipe.Key)))
{
if (talent.InputTalent)
{
inputMultiplier += talent.Multiplier * talent.Value;
//Console.WriteLine("Applying talent " + talent.Name + " to " + recipe.Name + " for input mult " + (talent.Multiplier * talent.Value));
}
else
{
//Console.WriteLine("Applying talent " + talent.Name + " to " + recipe.Name + " for output mult " + (talent.Multiplier * talent.Value) + " and adder " + (talent.Addition * talent.Value));
outputMultiplier += talent.Multiplier * talent.Value;
outputAdder += talent.Addition * talent.Value;
}
}

inputMultiplier += 1;
outputMultiplier += 1;

foreach (var ingredient in recipe.Ingredients)
{
if (_recipes[ingredient.Type].ParentGroupName == "Ore")
{
//Console.WriteLine(ingredient.Name + " value: " + Ores.Where(o => o.Key == ingredient.Type).First().Value + "; Requires " + ingredient.Quantity + " to make " + recipe.Products.First().Quantity + " for a total of " + ((Ores.Where(o => o.Key == ingredient.Type).First().Value * ingredient.Quantity) / recipe.Products.First().Quantity));

//Console.WriteLine("Talents: " + ingredient.Name + " value: " + Ores.Where(o => o.Key == ingredient.Type).First().Value + "; Requires " + (ingredient.Quantity * inputMultiplier) + " to make " + (recipe.Products.First().Quantity * outputMultiplier) + " for a total of " + ((Ores.Where(o => o.Key == ingredient.Type).First().Value * ingredient.Quantity * inputMultiplier) / (recipe.Products.First().Quantity * outputMultiplier + outputAdder)));
var resRecipe = new IngredientRecipe() { Key = ingredient.Type, Name = ingredient.Name, Quantity = (ingredient.Quantity * inputMultiplier / (recipe.Products.First().Quantity * outputMultiplier + outputAdder))*quantity, ParentGroupName = "Ore"};
results.Add(resRecipe);
}
else
{
var resRecipe = JsonConvert.DeserializeObject<IngredientRecipe>(JsonConvert.SerializeObject(_recipes[ingredient.Type]));
if (Groups.Values.Where(g => g.Id == resRecipe.GroupId).FirstOrDefault()?.Name != "Catalyst")
{
resRecipe.Quantity = (ingredient.Quantity * inputMultiplier / (recipe.Products.First().Quantity * outputMultiplier + outputAdder))*quantity;
results.Add(resRecipe);
results.AddRange(GetIngredientRecipes(ingredient.Type, resRecipe.Quantity));
}
}
}

return results;
}

public double GetBaseCost(string key)
{
// Just like the other one, but ignore talents.
Expand Down
32 changes: 21 additions & 11 deletions DU Industry Tool/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions DU Industry Tool/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,55 @@ private void exportToSpreadsheetToolStripMenuItem_Click(object sender, EventArgs
MessageBox.Show("Exported to " + "Item Export " + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx in the same folder as the exe");
}
}

private void factoryBreakdownForSelectedToolStripMenuItem_Click(object sender, EventArgs e)
{
// Exports an excel sheet with info about how to setup the factory for the selected recipe (aborts if no recipe selected)
if (treeView.SelectedNode != null && treeView.SelectedNode.Tag != null && treeView.SelectedNode.Tag is SchematicRecipe)
{
var recipe = treeView.SelectedNode.Tag as SchematicRecipe;
// Shows the amount of required components, amount per day required, amount per day per industry, and the number of industries you need of that component to provide for 1 of the parent
// The number of parent parts can be put in as a value
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("Factory");
worksheet.Cell(1, 1).Value = "Number of Industries producing " + recipe.Name;
worksheet.Cell(1, 2).Value = "Produced/Day";
worksheet.Cell(2, 1).Value = 1;
worksheet.Cell(2, 2).FormulaR1C1 = $"=R[0]C[-1]*(86400/{recipe.Time})";

worksheet.Cell(1, 3).Value = "Product";
worksheet.Cell(1, 4).Value = "Required/Day";
worksheet.Cell(1, 5).Value = "Produced/Day/Industry";
worksheet.Cell(1, 6).Value = "Num Industries Required";
worksheet.Cell(1, 7).Value = "Actual";

worksheet.Row(1).Style.Font.SetBold();

int row = 2;
var ingredients = Manager.GetIngredientRecipes(recipe.Key).OrderByDescending(i => i.Level).GroupBy(i => i.Key);
foreach(var group in ingredients)
{
worksheet.Cell(row, 3).Value = group.First().Name;
worksheet.Cell(row, 4).FormulaA1 = $"=B2*{group.Sum(g => g.Quantity)}";
double outputMult = 1;
var talents = Manager.Talents.Where(t => t.InputTalent == false && t.ApplicableRecipes.Contains(group.First().Key));
if (talents.Count() > 0)
outputMult += talents.Sum(t => t.Multiplier);
if (group.First().ParentGroupName != "Ore")
worksheet.Cell(row, 5).Value = (86400 / group.First().Time)*group.First().Products.First().Quantity*outputMult;
worksheet.Cell(row, 6).FormulaR1C1 = "=R[0]C[-2]/R[0]C[-1]";
worksheet.Cell(row, 7).FormulaR1C1 = "=ROUNDUP(R[0]C[-1])";

row++;
}

worksheet.ColumnsUsed().AdjustToContents();
workbook.SaveAs($"Factory Plan {recipe.Name} {DateTime.Now.ToString("yyyy-MM-dd")}.xlsx");
MessageBox.Show($"Exported to 'Factory Plan { recipe.Name} { DateTime.Now.ToString("yyyy-MM-dd")}.xlsx' in the same folder as the exe");
}
}

}
}
}
12 changes: 10 additions & 2 deletions DU Industry Tool/Recipe.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -33,14 +35,20 @@ public class SchematicRecipe
public Guid GroupId { get; set; }
public string ParentGroupName { get; set; }
public string Key { get; set; }
[JsonIgnore]
public TreeNode Node { get; set; }
public ulong NqId { get; set; } // Different from Id... for markets
}

public class IngredientRecipe : SchematicRecipe
{
public double Quantity { get; set; }
}

public class ProductDetail
{
public string Type { get; set; }
public float Quantity { get; set; }
public double Quantity { get; set; }
public string Name { get; set; }
}

Expand Down

0 comments on commit 6d042c6

Please sign in to comment.