/// <summary> /// Get the pets entries list, optionally with a substring filter. /// </summary> /// <param name="substring"></param> /// <returns></returns> public async Task <List <XivPet> > GetCachedPetList(string substring = null) { var where = new WhereClause(); var petClause = new WhereClause(); petClause.Column = "category"; petClause.Value = XivStrings.Pets; petClause.Join = WhereClause.JoinType.And; petClause.Comparer = WhereClause.ComparisonType.Equal; where.Inner.Add(petClause); if (substring != null) { var w = new WhereClause(); w.Comparer = WhereClause.ComparisonType.Like; w.Join = WhereClause.JoinType.And; w.Column = "name"; w.Value = "%" + substring + "%"; where.Inner.Add(w); } try { return(await BuildListFromTable("monsters", where, async (reader) => { var item = new XivPet { PrimaryCategory = XivStrings.Companions, SecondaryCategory = reader.GetString("category"), Name = reader.GetString("name"), ModelInfo = new XivMonsterModelInfo { ModelType = (XivItemType)Enum.Parse(typeof(XivItemType), reader.GetString("model_type")), PrimaryID = reader.GetInt32("primary_id"), SecondaryID = reader.GetInt32("secondary_id"), ImcSubsetID = reader.GetInt32("imc_variant"), } }; return item; })); } catch (Exception ex) { throw ex; } }
/// <summary> /// Gets the list to be displayed in the Pets category /// </summary> /// <remarks> /// The pet_0 exd does not contain the model ID or a reference to a modelchara, it contains names and other data /// Because of this, the Pet data is hardcoded until a better way of obtaining it is found. /// </remarks> /// <returns>A list containing XivMount data</returns> public async Task <List <XivPet> > GetPetList() { var petLock = new object(); var petList = new List <XivPet>(); // A list of indices in modelchara that contain Pet model data var petModelIndexList = new List <int>() { 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 537, 618, 1027, 1028, 1430, 1930, 2023 }; // A dictionary consisting of <model ID, Pet Name> // All pet IDs are in the 7000 range // This list does not contain Pets that are separate but share the same ID (Fairy, Turrets) var petModelDictionary = new Dictionary <int, string>() { { 7002, XivStrings.Carbuncle }, { 7003, XivStrings.Ifrit_Egi }, { 7004, XivStrings.Titan_Egi }, { 7005, XivStrings.Garuda_Egi }, { 7006, XivStrings.Ramuh_Egi }, { 7007, XivStrings.Sephirot_Egi }, { 7102, XivStrings.Bahamut_Egi }, { 7103, XivStrings.Placeholder_Egi }, }; var modelCharaEx = await XivModelChara.GetModelCharaData(_gameDirectory); // Loops through the list of indices containing Pet model data await Task.Run(() => Parallel.ForEach(petModelIndexList, (petIndex) => { var xivPet = new XivPet { Category = XivStrings.Companions, ItemCategory = XivStrings.Pets, }; // Gets the model info from modelchara for the given index var modelInfo = XivModelChara.GetModelInfo(modelCharaEx, petIndex); // Finds the name of the pet using the model ID and the above dictionary if (petModelDictionary.ContainsKey(modelInfo.ModelID)) { var petName = petModelDictionary[modelInfo.ModelID]; if (modelInfo.Variant > 1) { petName += $" {modelInfo.Variant - 1}"; } xivPet.Name = petName; } // For cases where there are separate pets under the same model ID with different body IDs else { switch (modelInfo.ModelID) { case 7001: xivPet.Name = modelInfo.Body == 1 ? XivStrings.Eos : XivStrings.Selene; break; case 7101: xivPet.Name = modelInfo.Body == 1 ? XivStrings.Rook_Autoturret : XivStrings.Bishop_Autoturret; break; default: xivPet.Name = "Unknown"; break; } } xivPet.ModelInfo = modelInfo; lock (petLock) { petList.Add(xivPet); } })); petList.Sort(); return(petList); }