public static Dictionary <ushort, SimpleVillager> GetCaravanBindingSource() { var waDatabase = VillagerInfo.GetVillagerDatabase(SaveType.WelcomeAmiibo); if (waDatabase == null) { return(null); } foreach (var v in WaSpecialVillagers) { var specialVillager = new SimpleVillager { VillagerId = v.Key, Name = v.Value }; waDatabase.Add(v.Key, specialVillager); } return(waDatabase); }
public static Dictionary <ushort, SimpleVillager> GetVillagerDatabase(SaveType saveType, string language = "en") { var database = new Dictionary <ushort, SimpleVillager>(); StreamReader contents; var databaseFilename = "{0}_Villagers_" + language + ".txt"; switch (saveType) { case SaveType.DoubutsuNoMori: case SaveType.DongwuSenlin: databaseFilename = string.Format(databaseFilename, "DnM"); break; case SaveType.DoubutsuNoMoriPlus: case SaveType.AnimalCrossing: databaseFilename = string.Format(databaseFilename, "AC"); break; case SaveType.DoubutsuNoMoriEPlus: case SaveType.AnimalForestEPlus: databaseFilename = string.Format(databaseFilename, "DBNM_e_Plus"); break; case SaveType.WildWorld: databaseFilename = string.Format(databaseFilename, "WW"); break; case SaveType.NewLeaf: databaseFilename = string.Format(databaseFilename, "NL"); break; case SaveType.WelcomeAmiibo: databaseFilename = string.Format(databaseFilename, "WA"); break; case SaveType.Unknown: break; case SaveType.CityFolk: break; default: throw new ArgumentOutOfRangeException(nameof(saveType), saveType, null); } databaseFilename = Path.Combine(PathUtility.GetResourcesDirectory(), databaseFilename); try { contents = File.OpenText(databaseFilename); } catch (Exception e) { DebugUtility.DebugManagerInstance.WriteLine( $"An error occured opening villager database file:\n\"{databaseFilename}\"\nError Info:\n{e.Message}", DebugLevel.Error); return(null); } string line; switch (saveType) { case SaveType.NewLeaf: case SaveType.WelcomeAmiibo: while ((line = contents.ReadLine()) != null) { if (!line.Contains("0x")) { continue; } var entry = new SimpleVillager(); var id = Regex.Match(line, @"ID = 0x....,").Value.Substring(7, 4); entry.VillagerId = ushort.Parse(id, NumberStyles.AllowHexSpecifier); var nameStr = Regex.Match(line, @"Name = .+").Value.Substring(7); entry.Name = nameStr.Substring(0, nameStr.IndexOf(',')); var personality = Regex.Match(line, @"Personality = .").Value; entry.Personality = byte.Parse(personality.Substring(personality.Length - 1, 1)); database.Add(entry.VillagerId, entry); } break; case SaveType.WildWorld: while ((line = contents.ReadLine()) != null) { if (!line.Contains("0x")) { continue; } var entry = new SimpleVillager { VillagerId = ushort.Parse(line.Substring(2, 2), NumberStyles.AllowHexSpecifier), Name = line.Substring(6) }; database.Add(entry.VillagerId, entry); } break; case SaveType.DoubutsuNoMori: case SaveType.AnimalCrossing: case SaveType.DoubutsuNoMoriPlus: case SaveType.DoubutsuNoMoriEPlus: case SaveType.AnimalForestEPlus: case SaveType.DongwuSenlin: while ((line = contents.ReadLine()) != null) { if (!line.Contains("0x")) { continue; } var entry = new SimpleVillager { VillagerId = ushort.Parse(line.Substring(2, 4), NumberStyles.AllowHexSpecifier), Name = line.Substring(8) }; database.Add(entry.VillagerId, entry); } break; case SaveType.Unknown: break; case SaveType.CityFolk: break; default: throw new ArgumentOutOfRangeException(nameof(saveType), saveType, null); } contents.Close(); contents.Dispose(); return(database); }