forked from frzyc/genshin-rounding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
84 lines (80 loc) · 4.38 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Text.Json;
using System.IO;
namespace genshin_rounding
{
public class ReliquaryAffixExcelConfigData
{
public int id { get; set; }
public int depotId { get; set; }
public int groupId { get; set; }
public string propType { get; set; }
public float propValue { get; set; }
}
class Program
{
static readonly string[] flatList = { "FIGHT_PROP_HP", "FIGHT_PROP_ATTACK", "FIGHT_PROP_DEFENSE", "FIGHT_PROP_ELEMENT_MASTERY" };
static void Main(string[] args)
{
var docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var dirName = $"{docPath}/GenshinData";
if (Directory.Exists(dirName)) {
string fileName = $"{dirName}/ExcelBinOutput/ReliquaryAffixExcelConfigData.json";
string fileStr = File.ReadAllText(fileName);
var reliquaryAffixExcelConfigDataArr = JsonSerializer.Deserialize<List<ReliquaryAffixExcelConfigData>>(fileStr);
if (reliquaryAffixExcelConfigDataArr == null) {
return;
}
var data = new Dictionary<int, Dictionary<string, List<float>>>();
foreach (var rdata in reliquaryAffixExcelConfigDataArr) {
int rank = rdata.depotId / 100;
if (rank > 5) continue;
data.TryAdd(rank, new Dictionary<string, List<float>>());
var dict = data[rank];
dict.TryAdd(rdata.propType, new List<float>());
var list = dict[rdata.propType];
list.Add(rdata.propValue);
}
string outDir = $"{docPath}/GenshinGenerated";
if (!Directory.Exists(outDir)) Directory.CreateDirectory(outDir);
File.WriteAllText($"{outDir}/subStatsRolls.json", JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true }));
var table = new Dictionary<int, Dictionary<string, Dictionary<string, List<List<float>>>>>();
foreach (var rankDict in data) {
var rank = rankDict.Key;
var dict = rankDict.Value;
table.TryAdd(rank, new Dictionary<string, Dictionary<string, List<List<float>>>>());
var tableRank = table[rank];
foreach (var propTypeList in dict) {
var propType = propTypeList.Key;
var list = propTypeList.Value;
tableRank.TryAdd(propType, new Dictionary<string, List<List<float>>>());
var tableProp = tableRank[propType];
var numUpgrades = rank == 2 ? 2 : rank + 1;
var combs = getAllCombsAndPerms(list, numUpgrades);
foreach (var rolls in combs) {
var sum = rolls.Sum();
var rounded = flatList.Contains(propType) ? string.Format("{0:#,0}", sum) : string.Format("{0:0.0}", sum * 100);
tableProp.TryAdd(rounded, new List<List<float>>());
var roundedList = tableProp[rounded];
roundedList.Add(rolls.ToList());
}
}
}
File.WriteAllText($"{outDir}/rollTable.json", JsonSerializer.Serialize(table, new JsonSerializerOptions { WriteIndented = true }));
} else Console.WriteLine($@"Expect Directory at '{dirName}'");
}
static IEnumerable<IEnumerable<T>> getAllCombsAndPerms<T>(IEnumerable<T> list, int length) where T : IComparable
{
IEnumerable<IEnumerable<T>> values = new IEnumerable<T>[] { };
IEnumerable<IEnumerable<T>> GetKCombsWithRept<T>(IEnumerable<T> list, int length, ref IEnumerable<IEnumerable<T>> all) where T : IComparable
{
if (length == 1) return list.Select(t => new T[] { t });
var combs = GetKCombsWithRept(list, length - 1, ref all);
all = all.Concat(combs);
return combs.SelectMany(t => list.Where(o => o.CompareTo(t.Last()) >= 0), (t1, t2) => t1.Concat(new T[] { t2 }));
}
var combs = GetKCombsWithRept(list, length, ref values);
values = values.Concat(combs);
return values;
}
}
}