2using System.Collections.Generic;
30 public static Dictionary<string, Dictionary<string, Item>>
dict;
38 dict =
new Dictionary<string, Dictionary<string, Item>>();
39 List<string> list =
new List<string>();
45 list.AddRange(booklistLoader());
49 Debug.LogWarning(
$"#book external booklist loader failed\n{arg}");
52 foreach (
string item in list)
54 DirectoryInfo directoryInfo =
new DirectoryInfo(
item);
55 if (!directoryInfo.Exists)
57 Debug.LogWarning(
"#book invalid booklist path/" +
item);
60 string name = directoryInfo.Name;
61 dict.TryAdd(name,
new Dictionary<string, Item>());
62 FileInfo[] files = directoryInfo.GetFiles(
"*.txt", SearchOption.TopDirectoryOnly);
63 foreach (FileInfo fileInfo
in files)
65 using StreamReader streamReader =
new StreamReader(fileInfo.FullName);
66 string text = Path.ChangeExtension(fileInfo.Name,
null);
67 string text2 = streamReader.ReadLine();
68 int? num = text2?.Length;
69 if (!num.HasValue || num.GetValueOrDefault() <= 0)
71 Debug.LogWarning(
"#book invalid first line/" +
item);
74 string[] array = text2.Split(
',');
79 author = ((array.Length > 1) ?
"nameAuthor".lang(array[1]) :
"unknownAuthor".lang()),
80 chance = ((array.Length > 2) ? array[2].ToInt() : 100),
81 skin = ((array.Length > 3) ? array[3].ToInt() : 0),
83 path = fileInfo.FullName
92 return dict[idCat].Where((KeyValuePair<string, Item> p) => p.Value.chance != 0).ToList().RandomItemWeighted((KeyValuePair<string, Item> p) => p.Value.chance)
99 return dict[idCat].TryGetValue(
id) ??
dict[
"Book"][
"_default"];
107 CorePath.CorePackage.Scroll
static Item GetRandomItem(string idCat="Book")
static Item GetItem(string id, string idCat="Book")
static string[] LoadDefaultBookList()
static Dictionary< string, Dictionary< string, Item > > dict
static List< Func< string[]> > booklistLoaders