megamappingway/game-data-extractor/ServerInfo.cs

62 lines
2.4 KiB
C#

using System.Text;
using Lumina;
using Lumina.Excel.GeneratedSheets;
namespace GameDataExtractor;
internal class ServerInfo {
private GameData Data { get; }
internal ServerInfo(GameData data) {
this.Data = data;
}
internal string Extract() {
var sb = new StringBuilder();
var questSheet = this.Data.GetExcelSheet<Quest>()!;
var ttSheet = this.Data.GetExcelSheet<TerritoryType>()!;
var territories = ttSheet.OrderBy(tt => tt.RowId).ToList();
var max = territories.Select(tt => tt.RowId).Max();
sb.Append("#[derive(Clone, Copy)]\npub struct TerritoryInfo {\n pub parties_visible: bool,\n pub map_visible: bool,\n}\n\n");
sb.Append($"pub const TERRITORY_INFO: [TerritoryInfo; {max + 1}] = [\n TerritoryInfo {{ parties_visible: false, map_visible: false }}, // 0 - none\n");
var last = 0u;
foreach (var territory in ttSheet.OrderBy(tt => tt.RowId)) {
var diff = territory.RowId - last;
for (var i = 1; i < diff; i++) {
sb.Append($" TerritoryInfo {{ parties_visible: false, map_visible: false }}, // {last + i} - missing\n");
}
last = territory.RowId;
var name = territory.PlaceName.Value?.Name.RawString;
var (subtitle, category) = territory.GetSubtitleAndCategory(questSheet);
var comment = $"// {territory.RowId}";
if (!string.IsNullOrWhiteSpace(name)) {
comment += $" - {name}";
}
var hasSubtitle = !string.IsNullOrWhiteSpace(subtitle);
var hasCategory = !string.IsNullOrWhiteSpace(category);
if (hasSubtitle && hasCategory) {
comment += $" ({category}: {subtitle})";
} else if (hasSubtitle) {
comment += $" ({subtitle})";
} else if (hasCategory) {
comment += $" ({category})";
}
var pvp = territory.IsPvpZone && territory.RowId != 250;
var battle = territory.ContentFinderCondition.Row != 0 && !pvp;
var battleString = battle ? "true" : "false";
var allowedString = pvp ? "false" : "true";
sb.Append($" TerritoryInfo {{ parties_visible: {battleString}, map_visible: {allowedString} }}, {comment}\n");
}
// sb.Append(" };\n}\n");
sb.Append("];\n");
return sb.ToString();
}
}