chaosbot/ChaosBot/Services/LodestoneManager.cs

116 lines
6.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using ChaosBot.Lodestone;
namespace ChaosBot.Services
{
public static class LodestoneManager
{
private static readonly Dictionary<Endpoints, string> EndpointPaths = new Dictionary<Endpoints, string>
{
{Endpoints.CHARACTER_SEARCH_BY_ID, "character/{0}"},
{Endpoints.CHARACTER_SEARCH, "character/search"},
{Endpoints.FREECOMPANY_SEARCH_BY_ID, "freecompany/{0}"},
{Endpoints.FREECOMPANY_SEARCH, "freecompany/search"},
};
public static readonly Dictionary<string, Tuple<string, ClassType>> Classes = new Dictionary<string, Tuple<string, ClassType>>
{
{ "Marauder", new Tuple<string, ClassType>("MRD", ClassType.Tank) },
{ "Warrior", new Tuple<string, ClassType>("WAR", ClassType.Tank) },
{ "Gladiator", new Tuple<string, ClassType>("GLA", ClassType.Tank) },
{ "Paladin", new Tuple<string, ClassType>("PLD", ClassType.Tank) },
{ "Lancer", new Tuple<string, ClassType>("LNC", ClassType.Dps) },
{ "Dragoon", new Tuple<string, ClassType>("DRG", ClassType.Dps) },
{ "Pugilist", new Tuple<string, ClassType>("PGL", ClassType.Dps) },
{ "Monk", new Tuple<string, ClassType>("MNK", ClassType.Dps) },
{ "Rogue", new Tuple<string, ClassType>("ROG", ClassType.Dps) },
{ "Ninja", new Tuple<string, ClassType>("NIN", ClassType.Dps) },
{ "Archer", new Tuple<string, ClassType>("ARC", ClassType.Dps) },
{ "Bard", new Tuple<string, ClassType>("BRD", ClassType.Dps) },
{ "Thaumaturge", new Tuple<string, ClassType>("THM", ClassType.Dps) },
{ "Black Mage", new Tuple<string, ClassType>("BLM", ClassType.Dps) },
{ "Arcanist", new Tuple<string, ClassType>("ACN", ClassType.Dps) },
{ "Summoner", new Tuple<string, ClassType>("SMN", ClassType.Dps) },
{ "Scholar", new Tuple<string, ClassType>("SCH", ClassType.Healer) },
{ "Conjurer", new Tuple<string, ClassType>("CNJ", ClassType.Healer) },
{ "White Mage", new Tuple<string, ClassType>("WHM", ClassType.Healer) },
{ "Blue Mage (Limited Job)", new Tuple<string, ClassType>("BLU", ClassType.Dps) },
{ "Dark Knight", new Tuple<string, ClassType>("DRK", ClassType.Tank) },
{ "Astrologian", new Tuple<string, ClassType>("AST", ClassType.Healer) },
{ "Machinist", new Tuple<string, ClassType>("MCH", ClassType.Dps) },
{ "Samurai", new Tuple<string, ClassType>("SAM", ClassType.Dps) },
{ "Red Mage", new Tuple<string, ClassType>("RDM", ClassType.Dps) },
{ "Gunbreaker", new Tuple<string, ClassType>("GNB", ClassType.Tank) },
{ "Dancer", new Tuple<string, ClassType>("DNC", ClassType.Dps) },
{ "Miner", new Tuple<string, ClassType>("MIN", ClassType.Gathering) },
{ "Botanist", new Tuple<string, ClassType>("BTN", ClassType.Gathering) },
{ "Fisher", new Tuple<string, ClassType>("FSH", ClassType.Gathering) },
{ "Alchemist", new Tuple<string, ClassType>("ALC", ClassType.Crafting) },
{ "Armorer", new Tuple<string, ClassType>("ARM", ClassType.Crafting) },
{ "Blacksmith", new Tuple<string, ClassType>("BSM", ClassType.Crafting) },
{ "Carpenter", new Tuple<string, ClassType>("CRP", ClassType.Crafting) },
{ "Culinarian", new Tuple<string, ClassType>("CUL", ClassType.Crafting) },
{ "Goldsmith", new Tuple<string, ClassType>("GSM", ClassType.Crafting) },
{ "Leatherworker", new Tuple<string, ClassType>("LTW", ClassType.Crafting) },
{ "Weaver", new Tuple<string, ClassType>("WVR", ClassType.Crafting) }
};
public static string GetEndpointPaths(Endpoints endpoint, params object[] parameters)
{
return string.Format(EndpointPaths.GetValueOrDefault(endpoint, string.Empty)!, parameters);
}
public static CharacterDetailed
GetCharacter(string server, string name)
{
Dictionary<string,string> parameters = new Dictionary<string, string>
{{"name", name}, {"server", server}};
PaginationWrapper<Character> characterWrapper = LodestoneHttpProxy.Fetch<PaginationWrapper<Character>>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH), parameters);
return GetCharacter(characterWrapper.Results.First().ID);
}
public static CharacterDetailed GetCharacter(long id)
{
Dictionary<string, string> parameters = new Dictionary<string, string>
{{"data", "CJ"}};
CharacterDetailed character = LodestoneHttpProxy.Fetch<CharacterDetailed>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH_BY_ID, id.ToString()), parameters);
return character;
}
public static FreeCompanyDetailed GetFreeCompany(string server, string name)
{
Dictionary<string,string> parameters = new Dictionary<string, string>
{{"name", name}, {"server", server}};
PaginationWrapper<FreeCompany> freeCompanyWrapper = LodestoneHttpProxy.Fetch<PaginationWrapper<FreeCompany>>(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH), parameters);
return GetFreeCompanyById(freeCompanyWrapper.Results.First().ID);
}
public static FreeCompanyDetailed GetFreeCompanyById(string id) {
Dictionary<string, string> parameters = new Dictionary<string, string>
{{"data", "FCM"}};
FreeCompanyDetailed freeCompany = LodestoneHttpProxy.Fetch<FreeCompanyDetailed>(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH_BY_ID, id), parameters);
return freeCompany;
}
}
public enum Endpoints
{
CHARACTER_SEARCH_BY_ID,
CHARACTER_SEARCH,
FREECOMPANY_SEARCH_BY_ID,
FREECOMPANY_SEARCH
}
public enum ClassType
{
Tank,
Dps,
Healer,
Gathering,
Crafting
}
}