Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
BookList.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using System.Linq;
4
5public class BookList
6{
7 public class Item
8 {
9 public string title;
10
11 public string author;
12
13 public string id;
14
15 public int chance = 100;
16 }
17
18 public static Dictionary<string, Dictionary<string, Item>> dict;
19
20 public static void Init()
21 {
22 dict = new Dictionary<string, Dictionary<string, Item>>();
23 AddDir("Book", CorePath.CorePackage.Book);
24 AddDir("Scroll", CorePath.CorePackage.Scroll);
25 static void AddDir(string id, string path)
26 {
27 DirectoryInfo directoryInfo = new DirectoryInfo(path);
28 Dictionary<string, Item> dictionary = new Dictionary<string, Item>();
29 dict.Add(id, dictionary);
30 FileInfo[] files = directoryInfo.GetFiles();
31 foreach (FileInfo fileInfo in files)
32 {
33 if (!(fileInfo.Extension != ".txt"))
34 {
35 StreamReader streamReader = new StreamReader(fileInfo.FullName);
36 string[] array = streamReader.ReadLine().Split(',');
37 Item item = new Item
38 {
39 title = array[0],
40 author = ((array.Length >= 2 && !array[1].IsEmpty()) ? "nameAuthor".lang(array[1]) : "unknownAuthor".lang()),
41 chance = ((array.Length >= 3) ? array[2].ToInt() : 100),
42 id = fileInfo.Name.Replace(fileInfo.Extension, "")
43 };
44 dictionary.Add(item.id, item);
45 streamReader.Close();
46 }
47 }
48 }
49 }
50
51 public static Item GetRandomItem(string idCat = "Book")
52 {
53 return dict[idCat].Where((KeyValuePair<string, Item> p) => p.Value.chance != 0).ToList().RandomItem()
54 .Value;
55 }
56
57 public static Item GetItem(string id, string idCat = "Book")
58 {
59 return dict[idCat].TryGetValue(id) ?? dict["Book"]["_default"];
60 }
61}
item3. title
Definition: UIBook.cs:616
string author
Definition: BookList.cs:11
string id
Definition: BookList.cs:13
string title
Definition: BookList.cs:9
static void Init()
Definition: BookList.cs:20
static Item GetRandomItem(string idCat="Book")
Definition: BookList.cs:51
static Item GetItem(string id, string idCat="Book")
Definition: BookList.cs:57
static Dictionary< string, Dictionary< string, Item > > dict
Definition: BookList.cs:18
static string Scroll
Definition: CorePath.cs:73
static string Book
Definition: CorePath.cs:71