Skip to content

Commit 0e54796

Browse files
committed
Create CSV drop tables
1 parent e923de7 commit 0e54796

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

XbTool/XbTool/Xb1De/Drops/DropTableGen.cs

+178
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7+
using CsvHelper;
8+
using CsvHelper.Configuration;
79
using XbTool.BdatString;
810
using XbTool.CodeGen;
911

@@ -18,6 +20,8 @@ public static void GenerateDropTables(BdatStringCollection bdats, string outputF
1820
var enemies = ReadBdatTables(bdats);
1921
CalculateDropRates(enemies);
2022

23+
PrintCsv(enemies, $"{outputFile}.csv");
24+
2125
string html = PrintDropTables(enemies);
2226
File.WriteAllText(outputFile, html, Encoding.UTF8);
2327
}
@@ -59,6 +63,18 @@ private static void CalculateDropRates(List<Enemy> enemies)
5963
}
6064
}
6165

66+
private static void PrintCsv(List<Enemy> enemies, string fileName)
67+
{
68+
List<CsvEnemyEntry> entries = GetCsvEntries(enemies);
69+
70+
using (var writer = new StreamWriter(fileName))
71+
using (var csv = new CsvWriter(writer, true))
72+
{
73+
csv.Configuration.RegisterClassMap<CsvEnemyEntryMap>();
74+
csv.WriteRecords(entries);
75+
}
76+
}
77+
6278
private static string PrintDropTables(List<Enemy> enemies)
6379
{
6480
var sb = new Indenter(2);
@@ -693,6 +709,168 @@ private static DropEntry<ArtBookItemEntry> GetArtBookEntry(BdatStringItem row, i
693709

694710
return entry;
695711
}
712+
713+
private static List<CsvEnemyEntry> GetCsvEntries(List<Enemy> enemies)
714+
{
715+
var csvList = new List<CsvEnemyEntry>();
716+
717+
foreach (Enemy enemy in enemies)
718+
{
719+
csvList.Add(GetCsvEntry(enemy));
720+
}
721+
722+
return csvList;
723+
}
724+
725+
private static CsvEnemyEntry GetCsvEntry(Enemy enemy)
726+
{
727+
var entry = new CsvEnemyEntry();
728+
entry.EnemyId = enemy.Id;
729+
entry.EnemyName = enemy.Name;
730+
731+
entry.NormalDropPer = enemy.NormalRate;
732+
entry.RareDropPer = enemy.RareRate;
733+
entry.SuperRareDropPer = enemy.SuperRareRate;
734+
735+
entry.NaturalNormalDropPer = enemy.NormalDropRate;
736+
entry.NaturalRareDropPer = enemy.RareDropRate;
737+
entry.NaturalSuperRareDropPer = enemy.SuperRareDropRate;
738+
739+
enemy.NormalDrops.MaterialsSingle.CopyTo(entry.NormalMatSingle);
740+
enemy.NormalDrops.MaterialsDouble.CopyTo(entry.NormalMatDouble);
741+
742+
enemy.RareDrops.Crystals.CopyTo(entry.RareCrystals);
743+
enemy.RareDrops.Weapons.CopyTo(entry.RareWeapons);
744+
enemy.RareDrops.Armor.CopyTo(entry.RareArmor);
745+
enemy.RareDrops.ArtBooks.CopyTo(entry.RareArtBooks);
746+
747+
enemy.SuperRareDrops.Weapons.CopyTo(entry.SprWeapons);
748+
enemy.SuperRareDrops.UniqueWeapons.CopyTo(entry.SprUniqueWeapons);
749+
enemy.SuperRareDrops.UniqueArmor.CopyTo(entry.SprUniqueArmor);
750+
enemy.SuperRareDrops.ArtBooks.CopyTo(entry.SprArtBooks);
751+
752+
return entry;
753+
}
754+
}
755+
756+
internal sealed class CsvEnemyEntryMap : ClassMap<CsvEnemyEntry>
757+
{
758+
public CsvEnemyEntryMap()
759+
{
760+
Map(m => m.EnemyId);
761+
Map(m => m.EnemyName);
762+
763+
Map(m => m.NormalDropPer);
764+
Map(m => m.RareDropPer);
765+
Map(m => m.SuperRareDropPer);
766+
767+
Map(m => m.NaturalNormalDropPer);
768+
Map(m => m.NaturalRareDropPer);
769+
Map(m => m.NaturalSuperRareDropPer);
770+
771+
for (int i = 0; i < 2; i++)
772+
{
773+
int i2 = i;
774+
Map(m => m.NormalMatSingle, false).Name($"NormalMatSingleName{i}").ConvertUsing(x => x.NormalMatSingle[i2]?.Item.Name ?? "");
775+
Map(m => m.NormalMatSingle, false).Name($"NormalMatSingleRate{i}").ConvertUsing(x => x.NormalMatSingle[i2]?.TotalDropRate.ToString("F4") ?? "");
776+
}
777+
778+
for (int i = 0; i < 2; i++)
779+
{
780+
int i2 = i;
781+
Map(m => m.NormalMatDouble, false).Name($"NormalMatDoubleName{i}").ConvertUsing(x => x.NormalMatDouble[i2]?.Item.Name ?? "");
782+
Map(m => m.NormalMatDouble, false).Name($"NormalMatDoubleRate{i}").ConvertUsing(x => x.NormalMatDouble[i2]?.TotalDropRate.ToString("F4") ?? "");
783+
}
784+
785+
for (int i = 0; i < 2; i++)
786+
{
787+
int i2 = i;
788+
Map(m => m.RareCrystals, false).Name($"RareCrystalSkill1Name{i}").ConvertUsing(x => x.RareCrystals[i2]?.Item.Skill1Name ?? "");
789+
Map(m => m.RareCrystals, false).Name($"RareCrystalSkill2Name{i}").ConvertUsing(x => x.RareCrystals[i2]?.Item.Skill2Name ?? "");
790+
Map(m => m.RareCrystals, false).Name($"RareCrystalRank{i}").ConvertUsing(x => x.RareCrystals[i2]?.Item.Rank.ToString() ?? "");
791+
Map(m => m.RareCrystals, false).Name($"RareCrystalIsCylinder{i}").ConvertUsing(x => x.RareCrystals[i2]?.Item.IsCylinder.ToString() ?? "");
792+
Map(m => m.RareCrystals, false).Name($"RareCrystalRate{i}").ConvertUsing(x => x.RareCrystals[i2]?.TotalDropRate.ToString("F4") ?? "");
793+
}
794+
795+
for (int i = 0; i < 4; i++)
796+
{
797+
int i2 = i;
798+
Map(m => m.RareWeapons, false).Name($"RareWeaponName{i}").ConvertUsing(x => x.RareWeapons[i2]?.Item.Name ?? "");
799+
Map(m => m.RareWeapons, false).Name($"RareWeaponSlots{i}").ConvertUsing(x => x.RareWeapons[i2]?.SlotCount.ToString() ?? "");
800+
Map(m => m.RareWeapons, false).Name($"RareWeaponRate{i}").ConvertUsing(x => x.RareWeapons[i2]?.TotalDropRate.ToString("F4") ?? "");
801+
}
802+
803+
for (int i = 0; i < 4; i++)
804+
{
805+
int i2 = i;
806+
Map(m => m.RareArmor, false).Name($"RareArmorName{i}").ConvertUsing(x => x.RareArmor[i2]?.Item.Name ?? "");
807+
Map(m => m.RareArmor, false).Name($"RareArmorSlots{i}").ConvertUsing(x => x.RareArmor[i2]?.SlotCount.ToString() ?? "");
808+
Map(m => m.RareArmor, false).Name($"RareArmorRate{i}").ConvertUsing(x => x.RareArmor[i2]?.TotalDropRate.ToString("F4") ?? "");
809+
}
810+
811+
for (int i = 0; i < 0; i++)
812+
{
813+
int i2 = i;
814+
Map(m => m.RareArtBooks, false).Name($"RareArtBooksName{i}").ConvertUsing(x => x.RareArtBooks[i2]?.Item.Name ?? "");
815+
Map(m => m.RareArtBooks, false).Name($"RareArtBooksRate{i}").ConvertUsing(x => x.RareArtBooks[i2]?.TotalDropRate.ToString("F4") ?? "");
816+
}
817+
818+
for (int i = 0; i < 4; i++)
819+
{
820+
int i2 = i;
821+
Map(m => m.SprWeapons, false).Name($"SuperRareWeaponName{i}").ConvertUsing(x => x.SprWeapons[i2]?.Item.Name ?? "");
822+
Map(m => m.SprWeapons, false).Name($"SuperRareWeaponSlots{i}").ConvertUsing(x => x.SprWeapons[i2]?.SlotCount.ToString() ?? "");
823+
Map(m => m.SprWeapons, false).Name($"SuperRareWeaponRate{i}").ConvertUsing(x => x.SprWeapons[i2]?.TotalDropRate.ToString("F4") ?? "");
824+
}
825+
826+
for (int i = 0; i < 5; i++)
827+
{
828+
int i2 = i;
829+
Map(m => m.SprUniqueWeapons, false).Name($"SuperRareUniqueWeaponName{i}").ConvertUsing(x => x.SprUniqueWeapons[i2]?.Item.Name ?? "");
830+
Map(m => m.SprUniqueWeapons, false).Name($"SuperRareUniqueWeaponRate{i}").ConvertUsing(x => x.SprUniqueWeapons[i2]?.TotalDropRate.ToString("F4") ?? "");
831+
}
832+
833+
for (int i = 0; i < 5; i++)
834+
{
835+
int i2 = i;
836+
Map(m => m.SprUniqueArmor, false).Name($"SuperRareUniqueArmorName{i}").ConvertUsing(x => x.SprUniqueArmor[i2]?.Item.Name ?? "");
837+
Map(m => m.SprUniqueArmor, false).Name($"SuperRareUniqueArmorRate{i}").ConvertUsing(x => x.SprUniqueArmor[i2]?.TotalDropRate.ToString("F4") ?? "");
838+
}
839+
840+
for (int i = 0; i < 4; i++)
841+
{
842+
int i2 = i;
843+
Map(m => m.SprArtBooks, false).Name($"SuperRareArtBookName{i}").ConvertUsing(x => x.SprArtBooks[i2]?.Item.Name ?? "");
844+
Map(m => m.SprArtBooks, false).Name($"SuperRareArtBookRate{i}").ConvertUsing(x => x.SprArtBooks[i2]?.TotalDropRate.ToString("F4") ?? "");
845+
}
846+
}
847+
}
848+
849+
internal class CsvEnemyEntry
850+
{
851+
public int EnemyId { get; set; }
852+
public string EnemyName { get; set; }
853+
854+
public int NormalDropPer { get; set; }
855+
public int RareDropPer { get; set; }
856+
public int SuperRareDropPer { get; set; }
857+
858+
public double NaturalNormalDropPer { get; set; }
859+
public double NaturalRareDropPer { get; set; }
860+
public double NaturalSuperRareDropPer { get; set; }
861+
862+
public DropEntry<MaterialEntry>[] NormalMatSingle { get; set; } = new DropEntry<MaterialEntry>[2];
863+
public DropEntry<MaterialEntry>[] NormalMatDouble { get; set; } = new DropEntry<MaterialEntry>[2];
864+
865+
public DropEntry<CrystalItemEntry>[] RareCrystals { get; set; } = new DropEntry<CrystalItemEntry>[2];
866+
public DropEntry<WeaponItemEntry>[] RareWeapons { get; set; } = new DropEntry<WeaponItemEntry>[4];
867+
public DropEntry<EquipItemEntry>[] RareArmor { get; set; } = new DropEntry<EquipItemEntry>[4];
868+
public DropEntry<ArtBookItemEntry>[] RareArtBooks { get; set; } = new DropEntry<ArtBookItemEntry>[8];
869+
870+
public DropEntry<WeaponItemEntry>[] SprWeapons { get; set; } = new DropEntry<WeaponItemEntry>[4];
871+
public DropEntry<WeaponItemEntry>[] SprUniqueWeapons { get; set; } = new DropEntry<WeaponItemEntry>[8];
872+
public DropEntry<EquipItemEntry>[] SprUniqueArmor { get; set; } = new DropEntry<EquipItemEntry>[8];
873+
public DropEntry<ArtBookItemEntry>[] SprArtBooks { get; set; } = new DropEntry<ArtBookItemEntry>[8];
696874
}
697875

698876
[DebuggerDisplay("{Name}")]

0 commit comments

Comments
 (0)