Skip to content

Placed the AvailableSheets foreach loop of InvokeAsync in SqlExport i… #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
99 changes: 53 additions & 46 deletions SaintCoinach.Cmd/Commands/SqlExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,56 +179,63 @@ public override async Task InvokeAsync(string[] paramList)
// .Where(n => !n.Contains("quest/") && !n.Contains("custom/"))
foreach (var name in _Realm.GameData.AvailableSheets)
{
var sheet = _Realm.GameData.GetSheet(name);
var variant = sheet.Header.Variant;
var sheet2 = sheet as XivSheet2<XivSubRow>;

Console.WriteLine($"Sheet: {name}, variant: {variant}");

if (sheet.Count == 0)
continue;

var sb = new StringBuilder();

sb.AppendLine($"CREATE TABLE {GetTableName(sheet)} (");

// key meme
if (sheet.Header.Variant == 1)
{
sb.AppendLine($" `_Key` INT NOT NULL,");
}
else
{
sb.AppendLine($" `_Key` INT NOT NULL,");
sb.AppendLine($" `_SubKey` INT NOT NULL,");
}

// add cols
foreach (var column in sheet.Header.Columns)
{
var colName = column.Name;
if (string.IsNullOrEmpty(colName))
colName = $"unk{column.Index}";

sb.AppendLine($" `{colName}` {GetSqlType(column.Reader.Type)},");
}

// primary key
if (sheet.Header.Variant == 1)
try
{
sb.AppendLine($" PRIMARY KEY (`_Key`)");
var sheet = _Realm.GameData.GetSheet(name);
var variant = sheet.Header.Variant;
var sheet2 = sheet as XivSheet2<XivSubRow>;

Console.WriteLine($"Sheet: {name}, variant: {variant}");

if (sheet.Count == 0)
continue;

var sb = new StringBuilder();

sb.AppendLine($"CREATE TABLE {GetTableName(sheet)} (");

// key meme
if (sheet.Header.Variant == 1)
{
sb.AppendLine($" `_Key` INT NOT NULL,");
}
else
{
sb.AppendLine($" `_Key` INT NOT NULL,");
sb.AppendLine($" `_SubKey` INT NOT NULL,");
}

// add cols
foreach (var column in sheet.Header.Columns)
{
var colName = column.Name;
if (string.IsNullOrEmpty(colName))
colName = $"unk{column.Index}";

sb.AppendLine($" `{colName}` {GetSqlType(column.Reader.Type)},");
}

// primary key
if (sheet.Header.Variant == 1)
{
sb.AppendLine($" PRIMARY KEY (`_Key`)");
}
else
{
sb.AppendLine($" PRIMARY KEY (`_Key`, `_SubKey`)");
}

sb.AppendLine(") COLLATE='utf8mb4_unicode_ci' ENGINE=MyISAM;");
sb.AppendLine();

WriteRows(sheet, sb);

imports.Add(sb.ToString());
}
else
catch (Exception e)
{
sb.AppendLine($" PRIMARY KEY (`_Key`, `_SubKey`)");
Console.WriteLine($"Failed to export {name}: {e}");
}

sb.AppendLine(") COLLATE='utf8mb4_unicode_ci' ENGINE=MyISAM;");
sb.AppendLine();

WriteRows(sheet, sb);

imports.Add(sb.ToString());
}

File.WriteAllText("schema.sql", string.Join(Environment.NewLine, imports));
Expand Down
33 changes: 33 additions & 0 deletions SaintCoinach/Xiv/InclusionShop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SaintCoinach.Ex.Relational;

namespace SaintCoinach.Xiv;

public class InclusionShop: XivRow
{
private List<InclusionShopCategory> _Categories;

public IEnumerable<InclusionShopCategory> Categories => _Categories ??= BuildCategories();

public bool IsValid => Categories.Any();

public byte UknownByte => As<byte>(1);

private List<InclusionShopCategory> BuildCategories()
{
var list = new List<InclusionShopCategory>();
for (var i = 0; i < 30; i++)
{
var cat = As<InclusionShopCategory>($"Category[{i}]");
if (cat.Key != 0)
list.Add(cat);
}
return list;
}

public InclusionShop(IXivSheet sheet, IRelationalRow sourceRow) : base(sheet, sourceRow)
{
}
}
36 changes: 36 additions & 0 deletions SaintCoinach/Xiv/InclusionShopCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SaintCoinach.Ex.Relational;

namespace SaintCoinach.Xiv;

public class InclusionShopCategory : XivRow
{
public string Name => AsString("Name");

public ClassJobCategory ClassJobCategory => As<ClassJobCategory>();

public IEnumerable<InclusionShopSeries> Series => AsSubRows<InclusionShopSeries>();

private IEnumerable<T> AsSubRows<T>() where T : XivSubRow
{
return AsSubRows<T>(typeof(T).Name);
}
private IEnumerable<T> AsSubRows<T>(string rowName) where T :XivSubRow
{
var sheetName = typeof(T).Name;
var key = (ushort)GetRaw(rowName);

var sheet = Sheet.Collection.GetSheet2<T>(sheetName)
.Cast<T>()
.Where(r => r.ParentKey == key)
.ToArray();

return sheet;
}

public InclusionShopCategory(IXivSheet sheet, IRelationalRow sourceRow) : base(sheet, sourceRow)
{
}
}
16 changes: 16 additions & 0 deletions SaintCoinach/Xiv/InclusionShopSeries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using SaintCoinach.Ex.Relational;

namespace SaintCoinach.Xiv;

public class InclusionShopSeries: XivSubRow
{
public SpecialShop SpecialShop => As<SpecialShop>();

public IEnumerable<Item> Items => SpecialShop.Items.SelectMany(i=> i.Rewards.Select(i=> i.Item));

public InclusionShopSeries(IXivSheet sheet, IRelationalRow sourceRow) : base(sheet, sourceRow)
{
}
}
26 changes: 20 additions & 6 deletions SaintCoinach/Xiv/SpecialShopListing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ public class SpecialShopListing : IShopListing {

private static Dictionary<int, int> _Currencies = new Dictionary<int, int>() {
{ 1, 28 },
{ 2, 25199 },
{ 4, 25200 },
{ 6, 33913 },
{ 7, 33914 }

// 6.0
/*
{ 2, 25199 }, // White Crafters Scrips
{ 4, 25200 }, // White Gatherers Scrips
{ 6, 33913 }, // Purple Crafters Scrips
{ 7, 33914 } // Purple Gatherers Scrips
*/

// 7.0
{ 2, 33913 }, // Purple Crafters Scrips
{ 4, 33914 }, // Purple Gatherers Scrips
{ 6, 41784 }, // Orange Crafters Scrips
{ 7, 41785 } // Orange Gatherers Scrips
};

private static Dictionary<int, int> _Tomestones;
Expand Down Expand Up @@ -93,6 +103,8 @@ public SpecialShopListing(SpecialShop shop, int index) {
_Rewards = rewards.ToArray();
Quest = shop.As<Quest>("Quest{Item}", index);

AchievementUnlock = shop.As<Achievement>("AchievementUnlock", index);

int UseCurrencyType = shop.As<byte>("UseCurrencyType");

const int CostCount = 3;
Expand Down Expand Up @@ -129,14 +141,16 @@ public SpecialShopListing(SpecialShop shop, int index) {
}
hq = false;
}

var collectabilityRating = shop.AsInt16("CollectabilityRating{Cost}", index, i);

costs.Add(new ShopListingItem(this, item, count, hq, collectabilityRating));
}
_Costs = costs.ToArray();
}

public Achievement AchievementUnlock { get; set; }

#endregion

/// <summary>
Expand All @@ -161,4 +175,4 @@ public SpecialShopListing(SpecialShop shop, int index) {

#endregion
}
}
}