-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDcContent.cs
275 lines (234 loc) · 5.8 KB
/
DcContent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace DutyContent
{
public class DcContent
{
// roulette
public class Roulette
{
public string Name { get; set; }
public static explicit operator Roulette(string name)
{
return new Roulette { Name = name };
}
}
// instance
public class Instance
{
public string Name { get; set; }
public static explicit operator Instance(string name)
{
return new Instance { Name = name };
}
}
// area
public class Area
{
public string Name { get; set; }
public IReadOnlyDictionary<int, Fate> Fates { get; set; }
}
// fate
public class Fate
{
public Area Area { get; set; }
public string Name { get; set; }
public static explicit operator Fate(string name)
{
return new Fate { Name = name };
}
}
// group
public class Group
{
public decimal Version { get; set; }
public string Language { get; set; }
public string DisplayLanguage { get; set; }
public Dictionary<int, Roulette> Roulettes { get; set; }
public Dictionary<int, Instance> Instances { get; set; }
public Dictionary<int, Area> Areas { get; set; }
}
//
public static decimal Version { get; private set; } = 0;
public static string Language { get; private set; }
public static string DisplayLanguage { get; private set; }
public static IReadOnlyDictionary<int, Roulette> Roulettes { get; private set; } = new Dictionary<int, Roulette>();
public static IReadOnlyDictionary<int, Instance> Instances { get; private set; } = new Dictionary<int, Instance>();
public static IReadOnlyDictionary<int, Area> Areas { get; private set; } = new Dictionary<int, Area>();
public static IReadOnlyDictionary<int, Fate> Fates { get; private set; } = new Dictionary<int, Fate>();
public static Dictionary<int, int> Missions { get; private set; } = new Dictionary<int, int>();
//
public static string GetInformation()
{
return Locale.Text(20,
Language,
Version,
Areas.Count,
Roulettes.Count,
Instances.Count,
Fates.Count);
}
//
public static bool Initialize(string json)
{
if (string.IsNullOrWhiteSpace(json))
return false;
bool ret;
try
{
ret = Fill(json);
}
catch
{
ret = false;
}
return ret;
}
// parse json
public static bool Fill(string json)
{
Group data = JsonConvert.DeserializeObject<Group>(json);
Dictionary<int, Fate> fates = new Dictionary<int, Fate>();
var version = data.Version;
var language = data.Language;
if (version > Version || language != Language)
{
foreach (var area in data.Areas)
{
foreach (var fate in area.Value.Fates)
{
try
{
fate.Value.Area = area.Value;
fates.Add(fate.Key, fate.Value);
}
catch (NullReferenceException /*nex*/)
{
Logger.E(7, fate.Key);
return false;
}
catch (Exception ex)
{
Logger.Ex(ex, 8);
return false;
}
}
}
Version = data.Version;
Language = data.Language;
DisplayLanguage = data.DisplayLanguage;
Roulettes = data.Roulettes;
Instances = data.Instances;
Areas = data.Areas;
Fates = fates;
}
return true;
}
//
public static Roulette TryRoulette(int code)
{
return Roulettes.TryGetValue(code, out Roulette roulette) ? roulette : null;
}
//
public static Instance TryInstance(int code)
{
return Instances.TryGetValue(code, out Instance instance) ? instance : null;
}
//
public static Area TryArea(int code)
{
return Areas.TryGetValue(code, out Area area) ? area : null;
}
//
public static Fate TryFate(int code)
{
return Fates.ContainsKey(code) ? Fates[code] : null;
}
//
public static Roulette GetRoulette(int code)
{
return Roulettes.TryGetValue(code, out Roulette roulette) ? roulette :
new Roulette { Name = Locale.Text(9, code) };
}
//
public static Instance GetInstance(int code)
{
return Instances.TryGetValue(code, out Instance instance) ? instance :
new Instance { Name = Locale.Text(10, code) };
}
//
public static Area GetArea(int code)
{
return Areas.TryGetValue(code, out Area area) ? area :
new Area { Name = Locale.Text(11, code) };
}
//
public static Fate GetFate(int code)
{
return Fates.ContainsKey(code) ? Fates[code] :
new Fate { Name = Locale.Text(12, code) };
}
//
public static bool ReadContent(string language = null)
{
if (language == null)
language = DcConfig.Duty.Language;
else if (!DcConfig.Duty.Language.Equals(language))
DcConfig.Duty.Language = language;
string filename = DcConfig.BuildDutyFileName(language);
if (!File.Exists(filename))
{
filename = DcConfig.BuildDutyFileName(language = "English");
if (!File.Exists(filename))
{
Logger.E(14, filename);
return false;
}
if (!DcConfig.Duty.Language.Equals(language))
DcConfig.Duty.Language = language;
}
string json = File.ReadAllText(filename, Encoding.UTF8);
if (Initialize(json))
{
Logger.Write(GetInformation());
return true;
}
else
{
Logger.E(13);
return false;
}
}
public static string CeStatusToString(int s)
{
// 10[1] status 0=end, 1=wait, 2=??, 3=progress
switch (s)
{
case 0: return Locale.Text(10017);
case 1: return Locale.Text(10018);
case 2: return Locale.Text(10019);
case 3: return Locale.Text(10020);
default: return Locale.Text(10021);
}
}
// save the queen type
public enum SaveTheQueenType
{
No,
Bozja,
Delubrum,
Zadnor,
}
//
public static int SaveTheQueenTypeToCeBase(SaveTheQueenType stq)
{
return
stq == SaveTheQueenType.Bozja ? 30000 :
stq == SaveTheQueenType.Zadnor ? 30100 :
30100; // fail safe
}
}
}