/// <summary> /// Gets a list of items from the requested list of item name strings. /// </summary> /// <remarks> /// If a item name parse fails or the item ID does not exist as a known item, exceptions will be thrown. /// </remarks> /// <param name="split">List of item names</param> /// <param name="config">Item packaging options</param> /// <param name="type">Destination where the item will end up at</param> /// <param name="lang">Language code to parse with. If the first entry in <see cref="split"/> is a language code, it will be used instead of <see cref="lang"/>.</param> public static IReadOnlyCollection <Item> GetItemsLanguage(IReadOnlyList <string> split, IConfigItem config, ItemDestination type = ItemDestination.PlayerDropped, string lang = GameLanguage.DefaultLanguage) { if (split.Count > 1 && split[0].Length < 3) { var langIndex = GameLanguage.GetLanguageIndex(split[0]); lang = GameLanguage.Language2Char(langIndex); split = split.Skip(1).ToArray(); } var strings = GameInfo.Strings.itemlistdisplay; var result = new Item[split.Count]; for (int i = 0; i < result.Length; i++) { var text = split[i].Trim(); var item = CreateItem(text, i, config, type, lang); if (item.ItemId >= strings.Length) { throw new Exception($"Item requested is out of expected range ({item.ItemId:X4} > {strings.Length:X4})."); } if (string.IsNullOrWhiteSpace(strings[item.ItemId])) { throw new Exception($"Item requested does not have a valid name ({item.ItemId:X4})."); } result[i] = item; } return(result); }
/// <summary> /// Gets a list of DIY item cards from the requested list of item name strings. /// </summary> /// <remarks> /// If a item name parse fails or a recipe ID does not exist, exceptions will be thrown. /// </remarks> /// <param name="split">List of item names</param> /// <param name="lang">Language code to parse with. If the first entry in <see cref="split"/> is a language code, it will be used instead of <see cref="lang"/>.</param> public static IReadOnlyCollection <Item> GetDIYItemsLanguage(IReadOnlyList <string> split, string lang = GameLanguage.DefaultLanguage) { if (split.Count > 1 && split[0].Length < 3) { var langIndex = GameLanguage.GetLanguageIndex(split[0]); lang = GameLanguage.Language2Char(langIndex); split = split.Skip(1).ToArray(); } var result = new Item[split.Count]; for (int i = 0; i < result.Length; i++) { var text = split[i].Trim(); var item = GetItem(text, lang); if (!InvertedRecipeDictionary.TryGetValue(item.ItemId, out var diy)) { throw new Exception($"DIY recipe appears to be invalid ({text})."); } result[i] = new Item(Item.DIYRecipe) { Count = diy }; } return(result); }
public static GameStrings GetStrings(int index) { return(Languages[index] ??= new GameStrings(GameLanguage.Language2Char(index))); }