-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffectAuto.cs
289 lines (268 loc) · 7.15 KB
/
EffectAuto.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using System.Collections;
public class EffectAuto : Effect2
{
private short id;
private MyImage img;
private int x;
private int y;
private int f;
private int dir;
private sbyte loopCount;
private long endTime;
public static EffAtutoTemp[] arrEffAtutoTemplate = new EffAtutoTemp[20];
public static mHashtable imgEffAuto = new mHashtable();
public static mHashtable dataEffAuto = new mHashtable();
private bool isInfinite_loop;
public static void addEffectAuto(short id, int x, int y, sbyte loopCount, short time, int dir)
{
EffectAuto effectAuto = new EffectAuto();
effectAuto.id = id;
effectAuto.x = x;
effectAuto.y = y;
effectAuto.loopCount = loopCount;
if (effectAuto.loopCount < 0)
{
effectAuto.isInfinite_loop = true;
}
else
{
effectAuto.isInfinite_loop = false;
}
if (time > 0)
{
effectAuto.endTime = mSystem.currentTimeMillis() + time * 1000;
}
else
{
effectAuto.endTime = -1L;
}
effectAuto.dir = dir;
Effect2.vEffect2.addElement(effectAuto);
}
public EffAtutoTemp getTemplate()
{
return arrEffAtutoTemplate[id];
}
public override void paint(mGraphics g)
{
if (img == null || img.img == null || getTemplate().frameRunning == null)
{
return;
}
Frame frame = getTemplate().frameEffAuto[getTemplate().frameRunning[f]];
for (int i = 0; i < frame.dx.Length; i++)
{
ImageInfo imgInfo = getTemplate().getImgInfo(frame.idImg[i]);
if (dir > 0)
{
g.drawRegion(img.img, imgInfo.x0, imgInfo.y0, imgInfo.w, imgInfo.h, 0, x + frame.dx[i], y + frame.dy[i] - 1, mGraphics.TOP | mGraphics.LEFT);
}
else
{
g.drawRegion(img.img, imgInfo.x0, imgInfo.y0, imgInfo.w, imgInfo.h, 2, x - frame.dx[i], y + frame.dy[i] - 1, mGraphics.TOP | mGraphics.RIGHT);
}
}
}
public override void update()
{
try
{
arrEffAtutoTemplate[id] = (EffAtutoTemp)dataEffAuto.get(id + string.Empty);
if (arrEffAtutoTemplate[id] == null)
{
arrEffAtutoTemplate[id] = new EffAtutoTemp();
getTemplate().idEffAuto = id;
dataEffAuto.put(id + string.Empty, arrEffAtutoTemplate[id]);
getTemplate().timerequest = mSystem.currentTimeMillis();
Service.gI().request_imgEffAuto(1, id);
}
else if (getTemplate().frameRunning == null && mSystem.currentTimeMillis() - getTemplate().timerequest > 3000)
{
getTemplate().timerequest = mSystem.currentTimeMillis();
Service.gI().request_imgEffAuto(1, id);
}
if (getTemplate().frameRunning != null)
{
img = (MyImage)imgEffAuto.get(id + string.Empty);
if (img == null)
{
img = new MyImage();
img.idImage = id;
imgEffAuto.put(id + string.Empty, img);
img.img = Controller.createImage(RMS.loadRMS("effauto " + id));
if (img.img == null)
{
img.timerequest = mSystem.currentTimeMillis();
Service.gI().request_imgEffAuto(0, id);
}
}
else if (img.img == null && mSystem.currentTimeMillis() - img.timerequest > 6000)
{
img.timerequest = mSystem.currentTimeMillis();
Service.gI().request_imgEffAuto(0, id);
}
}
if (img == null || img.img == null || getTemplate().frameRunning == null)
{
return;
}
f++;
if (f >= getTemplate().frameRunning.Length)
{
if (endTime != -1)
{
if (endTime - mSystem.currentTimeMillis() <= 0)
{
Effect2.vEffect2.removeElement(this);
}
else
{
f = 0;
}
}
else if (isInfinite_loop)
{
f = 0;
}
else
{
loopCount--;
if (loopCount <= 0)
{
Effect2.vEffect2.removeElement(this);
}
else
{
f = 0;
}
}
}
img.timeUse = mSystem.currentTimeMillis();
}
catch (Exception)
{
mSystem.println("Err update effauto:");
}
}
public static void reciveData(short id, sbyte[] data)
{
EffAtutoTemp effAtutoTemp = (EffAtutoTemp)dataEffAuto.get(id + string.Empty);
if (effAtutoTemp.frameRunning == null)
{
effAtutoTemp = new EffAtutoTemp();
effAtutoTemp = creatDataEffauto(id, data);
dataEffAuto.put(id + string.Empty, effAtutoTemp);
}
}
public static EffAtutoTemp creatDataEffauto(short idEff, sbyte[] data)
{
try
{
EffAtutoTemp effAtutoTemp = new EffAtutoTemp();
DataInputStream dataInputStream = new DataInputStream(data);
effAtutoTemp.idEffAuto = idEff;
effAtutoTemp.imginfo = new ImageInfo[dataInputStream.readByte()];
for (int i = 0; i < effAtutoTemp.imginfo.Length; i++)
{
effAtutoTemp.imginfo[i] = new ImageInfo();
effAtutoTemp.imginfo[i].ID = dataInputStream.readByte();
effAtutoTemp.imginfo[i].x0 = dataInputStream.readUnsignedByte();
effAtutoTemp.imginfo[i].y0 = dataInputStream.readUnsignedByte();
effAtutoTemp.imginfo[i].w = dataInputStream.readUnsignedByte();
effAtutoTemp.imginfo[i].h = dataInputStream.readUnsignedByte();
}
effAtutoTemp.frameEffAuto = new Frame[dataInputStream.readShort()];
for (int j = 0; j < effAtutoTemp.frameEffAuto.Length; j++)
{
effAtutoTemp.frameEffAuto[j] = new Frame();
sbyte b = dataInputStream.readByte();
effAtutoTemp.frameEffAuto[j].dx = new short[b];
effAtutoTemp.frameEffAuto[j].dy = new short[b];
effAtutoTemp.frameEffAuto[j].idImg = new sbyte[b];
for (int k = 0; k < b; k++)
{
effAtutoTemp.frameEffAuto[j].dx[k] = dataInputStream.readShort();
effAtutoTemp.frameEffAuto[j].dy[k] = dataInputStream.readShort();
effAtutoTemp.frameEffAuto[j].idImg[k] = dataInputStream.readByte();
}
}
short num = dataInputStream.readShort();
effAtutoTemp.frameRunning = new short[num];
for (int l = 0; l < num; l++)
{
effAtutoTemp.frameRunning[l] = dataInputStream.readShort();
}
return effAtutoTemp;
}
catch (Exception)
{
return null;
}
}
public static void reciveImage(short id, sbyte[] data)
{
MyImage myImage = (MyImage)imgEffAuto.get(id + string.Empty);
if (myImage == null)
{
myImage = new MyImage();
imgEffAuto.put(id + string.Empty, myImage);
}
myImage.idImage = id;
myImage.img = Controller.createImage(data);
if (GameMidlet.CLIENT_TYPE != 1)
{
RMS.saveRMSImage("effauto " + id, data);
}
}
public static void checkTimeUseImg()
{
try
{
IDictionaryEnumerator enumerator = imgEffAuto.GetEnumerator();
MyVector myVector = new MyVector();
while (enumerator.MoveNext())
{
string text = enumerator.Key.ToString();
MyImage myImage = (MyImage)imgEffAuto.get(text);
if (mSystem.currentTimeMillis() - myImage.timeUse > 60000)
{
myVector.addElement(text);
}
}
for (int i = 0; i < myVector.size(); i++)
{
string k = (string)myVector.elementAt(i);
imgEffAuto.remove(k);
}
}
catch (Exception)
{
}
}
public static void checkTimeUseData()
{
try
{
IDictionaryEnumerator enumerator = dataEffAuto.GetEnumerator();
MyVector myVector = new MyVector();
while (enumerator.MoveNext())
{
string text = enumerator.Key.ToString();
EffAtutoTemp effAtutoTemp = (EffAtutoTemp)dataEffAuto.get(text);
if (mSystem.currentTimeMillis() - effAtutoTemp.timeUse > 600000)
{
myVector.addElement(text);
}
}
for (int i = 0; i < myVector.size(); i++)
{
string k = (string)myVector.elementAt(i);
dataEffAuto.remove(k);
}
}
catch (Exception)
{
}
}
}