forked from aly/qstbak
qstcompanion v1.0.1
This commit is contained in:
parent
3e10cbbbf2
commit
44c67ab71b
79 changed files with 21148 additions and 0 deletions
|
|
@ -0,0 +1,206 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Lumina.Excel;
|
||||
using Lumina.Excel.Sheets;
|
||||
|
||||
namespace QuestionableCompanion.Services;
|
||||
|
||||
public class DataCenterService
|
||||
{
|
||||
private readonly IDataManager dataManager;
|
||||
|
||||
private readonly IPluginLog log;
|
||||
|
||||
private readonly Dictionary<string, string> worldToDCCache = new Dictionary<string, string>();
|
||||
|
||||
private readonly Dictionary<string, string> dataCenterToRegion = new Dictionary<string, string>
|
||||
{
|
||||
{ "Chaos", "EU" },
|
||||
{ "Light", "EU" },
|
||||
{ "Shadow", "EU" },
|
||||
{ "Aether", "NA" },
|
||||
{ "Primal", "NA" },
|
||||
{ "Crystal", "NA" },
|
||||
{ "Dynamis", "NA" },
|
||||
{ "Elemental", "JP" },
|
||||
{ "Gaia", "JP" },
|
||||
{ "Mana", "JP" },
|
||||
{ "Meteor", "JP" },
|
||||
{ "Materia", "OCE" },
|
||||
{ "陆行鸟", "Others" },
|
||||
{ "莫古力", "Others" },
|
||||
{ "猫小胖", "Others" },
|
||||
{ "豆豆柴", "Others" }
|
||||
};
|
||||
|
||||
public DataCenterService(IDataManager dataManager, IPluginLog log)
|
||||
{
|
||||
this.dataManager = dataManager;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public void InitializeWorldMapping()
|
||||
{
|
||||
try
|
||||
{
|
||||
ExcelSheet<World> worldSheet = dataManager.GetExcelSheet<World>();
|
||||
if (worldSheet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int worldCount = 0;
|
||||
int skippedCount = 0;
|
||||
foreach (World world in worldSheet)
|
||||
{
|
||||
if (world.RowId == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string worldName = world.Name.ExtractText();
|
||||
if (string.IsNullOrEmpty(worldName))
|
||||
{
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
WorldDCGroupType? dataCenterGroup = world.DataCenter.ValueNullable;
|
||||
if (!dataCenterGroup.HasValue)
|
||||
{
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
string dataCenterName = dataCenterGroup.Value.Name.ExtractText();
|
||||
if (string.IsNullOrEmpty(dataCenterName))
|
||||
{
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
if (!world.IsPublic)
|
||||
{
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
string region = GetRegionForDataCenter(dataCenterName);
|
||||
worldToDCCache[worldName.ToLower()] = region;
|
||||
worldCount++;
|
||||
if (worldCount > 10)
|
||||
{
|
||||
_ = region != "Others";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRegionForDataCenter(string dataCenterName)
|
||||
{
|
||||
if (dataCenterToRegion.TryGetValue(dataCenterName, out string region))
|
||||
{
|
||||
return region;
|
||||
}
|
||||
return "Others";
|
||||
}
|
||||
|
||||
public string GetDataCenterForWorld(string worldName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(worldName))
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
string key = worldName.ToLower();
|
||||
if (worldToDCCache.TryGetValue(key, out string dataCenter))
|
||||
{
|
||||
return dataCenter;
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
public Dictionary<string, List<string>> GroupCharactersByDataCenter(List<string> characters)
|
||||
{
|
||||
Dictionary<string, List<string>> grouped = new Dictionary<string, List<string>>
|
||||
{
|
||||
{
|
||||
"EU",
|
||||
new List<string>()
|
||||
},
|
||||
{
|
||||
"NA",
|
||||
new List<string>()
|
||||
},
|
||||
{
|
||||
"JP",
|
||||
new List<string>()
|
||||
},
|
||||
{
|
||||
"OCE",
|
||||
new List<string>()
|
||||
},
|
||||
{
|
||||
"Others",
|
||||
new List<string>()
|
||||
},
|
||||
{
|
||||
"Unknown",
|
||||
new List<string>()
|
||||
}
|
||||
};
|
||||
foreach (string character in characters)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] parts = character.Split('@');
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
grouped["Unknown"].Add(character);
|
||||
continue;
|
||||
}
|
||||
string worldName = parts[1];
|
||||
string dataCenter = GetDataCenterForWorld(worldName);
|
||||
if (!grouped.ContainsKey(dataCenter))
|
||||
{
|
||||
grouped[dataCenter] = new List<string>();
|
||||
}
|
||||
grouped[dataCenter].Add(character);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
grouped["Unknown"].Add(character);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> item in grouped.Where((KeyValuePair<string, List<string>> g) => g.Value.Count > 0))
|
||||
{
|
||||
_ = item;
|
||||
}
|
||||
return grouped;
|
||||
}
|
||||
|
||||
public List<string> GetAvailableDataCenters(Dictionary<string, List<string>> charactersByDataCenter)
|
||||
{
|
||||
List<string> dataCenters = new List<string> { "All" };
|
||||
string[] array = new string[6] { "EU", "NA", "JP", "OCE", "Others", "Unknown" };
|
||||
foreach (string dc in array)
|
||||
{
|
||||
if (charactersByDataCenter.TryGetValue(dc, out List<string> chars) && chars.Count > 0)
|
||||
{
|
||||
dataCenters.Add(dc);
|
||||
}
|
||||
}
|
||||
return dataCenters;
|
||||
}
|
||||
|
||||
public List<string> GetCharactersForDataCenter(List<string> allCharacters, string dataCenterName, Dictionary<string, List<string>> charactersByDataCenter)
|
||||
{
|
||||
if (dataCenterName == "All")
|
||||
{
|
||||
return allCharacters;
|
||||
}
|
||||
if (charactersByDataCenter.TryGetValue(dataCenterName, out List<string> characters))
|
||||
{
|
||||
return characters;
|
||||
}
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue