Elin Decompiled Documentation EA 23.187 Stable
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 public int skin;
18 }
19
20 public static Dictionary<string, Dictionary<string, Item>> dict;
21
22 public static void Init()
23 {
24 dict = new Dictionary<string, Dictionary<string, Item>>();
25 AddDir("Book", CorePath.CorePackage.Book);
26 AddDir("Scroll", CorePath.CorePackage.Scroll);
27 static void AddDir(string id, string path)
28 {
29 DirectoryInfo directoryInfo = new DirectoryInfo(path);
30 Dictionary<string, Item> dictionary = new Dictionary<string, Item>();
31 dict.Add(id, dictionary);
32 FileInfo[] files = directoryInfo.GetFiles();
33 foreach (FileInfo fileInfo in files)
34 {
35 if (!(fileInfo.Extension != ".txt"))
36 {
37 StreamReader streamReader = new StreamReader(fileInfo.FullName);
38 string[] array = streamReader.ReadLine().Split(',');
39 Item item = new Item
40 {
41 title = array[0],
42 author = ((array.Length >= 2 && !array[1].IsEmpty()) ? "nameAuthor".lang(array[1]) : "unknownAuthor".lang()),
43 chance = ((array.Length >= 3) ? array[2].ToInt() : 100),
44 skin = ((array.Length >= 4) ? array[3].ToInt() : 0),
45 id = fileInfo.Name.Replace(fileInfo.Extension, "")
46 };
47 dictionary.Add(item.id, item);
48 streamReader.Close();
49 }
50 }
51 }
52 }
53
54 public static Item GetRandomItem(string idCat = "Book")
55 {
56 return dict[idCat].Where((KeyValuePair<string, Item> p) => p.Value.chance != 0).ToList().RandomItem()
57 .Value;
58 }
59
60 public static Item GetItem(string id, string idCat = "Book")
61 {
62 return dict[idCat].TryGetValue(id) ?? dict["Book"]["_default"];
63 }
64}
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:22
static Item GetRandomItem(string idCat="Book")
Definition: BookList.cs:54
static Item GetItem(string id, string idCat="Book")
Definition: BookList.cs:60
static Dictionary< string, Dictionary< string, Item > > dict
Definition: BookList.cs:20
static string Scroll
Definition: CorePath.cs:73
static string Book
Definition: CorePath.cs:71