-
Notifications
You must be signed in to change notification settings - Fork 0
/
PokeMMOCycle.cs
219 lines (199 loc) · 10.2 KB
/
PokeMMOCycle.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace PokeMMOCycleGUI
{
class PokeMMOCycle
{
public int Cycle
{
get
{
DateTime now = DateTime.Now.ToUniversalTime();
TimeSpan difference = now.Subtract(cycle1_Offset);
long currentCycle = difference.Ticks / cycleLength.Ticks % nbCycle;
return (int) currentCycle + 1;
}
}
public TimeSpan TimeLeft
{
get
{
DateTime now = DateTime.Now.ToUniversalTime();
TimeSpan difference = now.Subtract(cycle1_Offset);
long pastCycles = difference.Ticks / cycleLength.Ticks;
DateTime CycleEnd = cycle1_Offset.AddTicks((pastCycles+1) * cycleLength.Ticks);
return CycleEnd.Subtract(now);
}
}
public int nbCycle = 7;
public DateTime cycle1_Offset = new DateTime(2023, 2, 23, 6, 00, 00); // Cycle 1 starting time mesure (UTC)
public TimeSpan cycleLength = new TimeSpan(6,0,0); // one cycle is 6 hours
private String[][,] cyclesTab;
public static readonly string xmlPath = "./Resources/Cycles.xml";
public XmlDocument _doc;
public PokeMMOCycle()
{
init();
}
public String[,] PokemonListCurrentCycle
{
get
{
return cyclesTab[0];
}
}
// load the XML and initiate the array CycleTab
public void init()
{
OpenXML();
XmlNodeList cycles = _doc.SelectNodes("//Cycle");
cyclesTab = new String[cycles.Count][,];
foreach (XmlNode xCycle in cycles)
{
int id;
if (int.TryParse(xCycle.Attributes["id"].Value, out id))
{
id--;
XmlNodeList pokemons = xCycle.SelectNodes("Pokemon");
cyclesTab[id] = new String[pokemons.Count,3];
for(int i = 0; i < pokemons.Count; i++)
{
cyclesTab[id][i, 0] = pokemons[i]["Name"].InnerText;
cyclesTab[id][i, 1] = pokemons[i]["EncounterRate"].InnerText;
cyclesTab[id][i, 2] = pokemons[i]["Level"].InnerText;
}
}
}
}
private void OpenXML()
{
//("loading data");
_doc = new XmlDocument();
Boolean done;
int nbTry = 0; // after 3 tries, we stop trying
do
{
try
{
_doc.Load(xmlPath);
done = true;
}
catch (Exception e)
{
if (e is System.IO.FileNotFoundException) // the file doesn't exist, let's create it with the last data available (05 july 2013) Removed Shuckle.
{
done = false;
XmlElement cycles = _doc.CreateElement("Cycles");
String[][,] cyclesTab = new String[][,]
{
new String[,]{ // cycle 1
{"Houndour", "9", "18-28"},
{"Aipom", "10", "12-20"},
{"Pineco", "10", "5-16"},
{"Mareep", "10", "18-28"},
{"Smeargle", "1", "19-29"},
{"Stantler", "5", "18-28"},
{"Teddiursa", "10", "5-16"},
{"Zubat", "35", "5-16"},
},
new String[,]{ // cycle 2
{"Bagon", "0,5", "18-25"},
{"Stantler", "6,5", "12-20"},
{"Snubbull", "8", "18-28"},
{"Poochyena", "8", "5-16"},
{"Teddiursa", "8", "5-16"},
{"Smeargle", "8", "19-29"},
{"Zubat", "53", "10-20"},
},
new String[,]{ // cycle 3
{"Mawile", "1", "18-25"},
{"Poochyena", "9", "12-20"},
{"Snubbull", "10", "18-28"},
{"Slakoth", "10", "12-16"},
{"Spinda", "10", "19-29"},
{"Mareep", "10", "18-26"},
{"Sableye", "15", "12-28"},
{"Zubat", "35", "18-25"},
},
new String[,]{ // cycle 4
{"Zubat", "100", "18-25"},
},
new String[,]{ // cycle 5
{"Unown", "1", "18-25"},
{"Mawile", "5", "12-20"},
{"Poochyena", "9", "12-16"},
{"Mareep", "10", "18-28"},
{"Teddiursa", "10", "12-20"},
{"Spinda", "10", "19-29"},
{"Zubat", "45", "5-16"}
},
new String[,]{ // cycle 6
{"Absol", "0,5", "18-25"},
{"Duskull", "6,5", "12-20"},
{"Shuppet", "8", "18-28"},
{"Pineco", "8", "19-29"},
{"Houndour", "8", "5-16"},
{"Zigzagoon", "8", "5-16"},
{"Aipom", "8", "18-28"},
{"Snubbull", "8", "18-26"},
{"Zubat", "45", "5-16"}
},
new String[,]{ // cycle 7
{"Aron", "0,5", "18-28"},
{"Stantler", "6,5", "12-20"},
{"Shuppet", "8", "18-28"},
{"Pineco", "8", "19-29"},
{"Poochyena", "8", "5-16"},
{"Zigzagoon", "8", "5-16"},
{"Aipom", "8", "18-28"},
{"Snubbull", "8", "18-26"},
{"Zubat", "45", "5-16"}
}
};
for (int i = 0; i < cyclesTab.Length; i++)
{ // going through the cycles
XmlElement cycle = _doc.CreateElement("Cycle");
XmlAttribute idCycle = _doc.CreateAttribute("id");
idCycle.Value = (i+1).ToString();
cycle.Attributes.Append(idCycle);
for (int j = 0; j < cyclesTab[i].GetLength(0); j++)
{ // going through the pokemons
XmlElement pokemon = _doc.CreateElement("Pokemon");
XmlElement Name = _doc.CreateElement("Name");
Name.InnerText = cyclesTab[i][j, 0];
XmlElement EncouterLevel = _doc.CreateElement("EncounterRate");
EncouterLevel.InnerText = cyclesTab[i][j, 1];
XmlElement Level = _doc.CreateElement("Level");
Level.InnerText = cyclesTab[i][j, 2];
pokemon.AppendChild(Name);
pokemon.AppendChild(EncouterLevel);
pokemon.AppendChild(Level);
cycle.AppendChild(pokemon);
}
cycles.AppendChild(cycle);
}
_doc.AppendChild(cycles);
_doc.Save(xmlPath);
}
else
{
done = false;
}
}
nbTry++;
} while (!done && nbTry < 3);
if (!done)
{
// the file hasn't been loaded.
}
else
{
//the file has been loaded
}
}
}
}