Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
SpawnList.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3
4public class SpawnList : EClass
5{
6 public static Dictionary<string, SpawnList> allList = new Dictionary<string, SpawnList>();
7
8 public static SpawnList tempList = new SpawnList();
9
10 public string id;
11
12 public List<CardRow> rows = new List<CardRow>();
13
15
16 public int totalChance;
17
18 public static SpawnList Get(string id, string parent = null, CardFilter filter = null)
19 {
20 SpawnList spawnList = allList.TryGetValue(id);
21 if (spawnList != null)
22 {
23 if (spawnList.filter != filter && filter != null)
24 {
25 spawnList.CreateMaster(filter, parent);
26 }
27 return spawnList;
28 }
29 spawnList = new SpawnList(id);
30 if (filter != null)
31 {
32 spawnList.CreateMaster(filter, parent);
33 }
34 allList.Add(id, spawnList);
35 return spawnList;
36 }
37
38 public SpawnList(string id = null)
39 {
40 if (!id.IsEmpty())
41 {
42 SourceSpawnList.Row row = EClass.sources.spawnLists.map.TryGetValue(id);
43 if (row != null)
44 {
45 bool flag = row.type == "chara";
46 CardFilter cardFilter = (flag ? ((CardFilter)new CharaFilter()) : ((CardFilter)new ThingFilter()));
47 cardFilter.isChara = flag;
48 cardFilter.strTag = row.tag;
49 cardFilter.strFilter = row.filter;
50 cardFilter.filterCategory = row.category;
51 cardFilter.idCard = row.idCard;
52 CreateMaster(cardFilter, row.parent);
53 }
54 this.id = id;
55 }
56 }
57
58 public void Add(CardRow row)
59 {
60 rows.Add(row);
61 totalChance += row.chance;
62 }
63
64 public void CreateMaster(CardFilter _filter, string parent = null)
65 {
66 rows.Clear();
67 totalChance = 0;
68 filter = _filter;
69 List<CardRow> list = (parent.IsEmpty() ? EClass.sources.cards.rows : Get(parent).rows);
70 for (int i = 0; i < list.Count; i++)
71 {
72 CardRow cardRow = list[i];
73 if (cardRow.chance > 0 && filter.Pass(cardRow))
74 {
75 Add(cardRow);
76 }
77 }
78 if (!filter.idCard.IsEmpty())
79 {
80 string[] idCard = filter.idCard;
81 foreach (string key in idCard)
82 {
83 CardRow row = EClass.sources.cards.map[key];
84 Add(row);
85 }
86 }
87 }
88
89 public SpawnList Filter(int lv, int levelRange = -1)
90 {
91 tempList.rows.Clear();
92 tempList.totalChance = 0;
93 tempList.filter = filter;
94 for (int i = 0; i < rows.Count; i++)
95 {
96 CardRow cardRow = rows[i];
97 if (levelRange != -1)
98 {
99 if (cardRow.isChara && (cardRow as SourceChara.Row).mainElement.Length >= 2)
100 {
101 SourceChara.Row obj = cardRow as SourceChara.Row;
102 bool flag = false;
103 string[] mainElement = obj.mainElement;
104 for (int j = 0; j < mainElement.Length; j++)
105 {
106 string[] array = mainElement[j].Split('/');
107 SourceElement.Row row = EClass.sources.elements.alias["ele" + array[0]];
108 if (Mathf.Abs(cardRow.LV * row.eleP / 100 - lv) < levelRange)
109 {
110 flag = true;
111 break;
112 }
113 }
114 if (!flag)
115 {
116 continue;
117 }
118 }
119 else if (Mathf.Abs(cardRow.LV - lv) >= levelRange)
120 {
121 continue;
122 }
123 }
124 else if (cardRow.LV > lv)
125 {
126 continue;
127 }
128 tempList.rows.Add(cardRow);
129 tempList.totalChance += cardRow.chance;
130 }
131 if (tempList.rows.Count == 0)
132 {
133 Debug.Log("list contains no item: " + id + "/" + lv);
134 return this;
135 }
136 return tempList;
137 }
138
139 public CardRow Select(int lv = -1, int levelRange = -1)
140 {
141 if (lv != -1)
142 {
143 if (levelRange != -1)
144 {
145 for (int i = 0; i < 50; i++)
146 {
147 SpawnList spawnList = Filter(lv + i - i * i, levelRange + i * i);
148 if (spawnList.rows.Count > 5)
149 {
150 return spawnList.Select();
151 }
152 }
153 }
154 lv = lv + 2 + EClass.rnd(EClass.rnd(EClass.rnd(EClass.rnd(Mathf.Min(lv * 2, 20)) + 1) + 1) + 1);
155 return Filter(lv).Select();
156 }
157 if (filter != null && filter.categoriesInclude.Count > 0)
158 {
160 for (int j = 0; j < 100; j++)
161 {
162 CardRow cardRow = _Select();
163 if (cardRow != null && cardRow.Category.IsChildOf(r))
164 {
165 return cardRow;
166 }
167 }
168 }
169 return _Select();
170 CardRow _Select()
171 {
172 int num = EClass.rnd(totalChance);
173 int num2 = 0;
174 foreach (CardRow row in rows)
175 {
176 num2 += row.chance;
177 if (num < num2)
178 {
179 return row;
180 }
181 }
182 if (rows.Count == 0)
183 {
184 Debug.Log("no item:" + id);
185 foreach (CardFilter.FilterItem tag in filter.tags)
186 {
187 Debug.Log(tag.name + "/" + tag.exclude);
188 }
189 return null;
190 }
191 return rows[EClass.rnd(rows.Count)];
192 }
193 }
194
196 {
197 return rows[EClass.rnd(rows.Count)];
198 }
199
201 {
202 return rows[0];
203 }
204}
string[] idCard
Definition: CardFilter.cs:37
List< FilterItem > tags
Definition: CardFilter.cs:39
List< SourceCategory.Row > categoriesInclude
Definition: CardFilter.cs:45
bool Pass(CardRow source)
Definition: CardFilter.cs:91
bool isChara
Definition: CardRow.cs:55
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static SourceManager sources
Definition: EClass.cs:42
SourceCategory.Row Category
Definition: RenderRow.cs:119
int chance
Definition: RenderRow.cs:24
int LV
Definition: RenderRow.cs:22
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
string[] mainElement
Definition: SourceChara.cs:33
SourceCard cards
SourceSpawnList spawnLists
SourceElement elements
SpawnList Filter(int lv, int levelRange=-1)
Definition: SpawnList.cs:89
static SpawnList Get(string id, string parent=null, CardFilter filter=null)
Definition: SpawnList.cs:18
void Add(CardRow row)
Definition: SpawnList.cs:58
CardRow Select(int lv=-1, int levelRange=-1)
Definition: SpawnList.cs:139
void CreateMaster(CardFilter _filter, string parent=null)
Definition: SpawnList.cs:64
CardRow GetRandom()
Definition: SpawnList.cs:195
string id
Definition: SpawnList.cs:10
CardRow GetFirst()
Definition: SpawnList.cs:200
CardFilter filter
Definition: SpawnList.cs:14
static SpawnList tempList
Definition: SpawnList.cs:8
int totalChance
Definition: SpawnList.cs:16
static Dictionary< string, SpawnList > allList
Definition: SpawnList.cs:6
List< CardRow > rows
Definition: SpawnList.cs:12
SpawnList(string id=null)
Definition: SpawnList.cs:38