unit SURecallMiner interface uses PUSuperScript Generics Collections T

  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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
unit SURecallMiner;
interface
uses PUSuperScript, Generics.Collections;
Type
PMiningSpot = class
private
m_Mode : Integer;
m_Tile : Word;
m_X : Integer;
m_Y : Integer;
m_Z : Integer;
public
property Mode : Integer read m_Mode write m_Mode;
property Tile : Word read m_Tile write m_Tile;
property X : Integer read m_X write m_X;
property Y : Integer read m_Y write m_Y;
property Z : Integer read m_Z write m_Z;
end;
PRecallMiner = class(PScript)
private
m_Mountain_Tiles : TList<Word>;
m_Sand_Tiles : TList<Word>;
m_Cave_Tiles : TList<Word>;
m_ToolTypes : TList<Word>;
m_Range : Integer;
m_MessageSuccess : String;
m_MessageFail : String;
m_Message_Full : String;
m_Message_Unable : String;
procedure Init();
public
procedure ScriptMain; override;
function Mine(X,Y:Cardinal):Integer;
end;
implementation
uses
SysUtils, BasicTypedefs, ScriptTypes;
{ PRecallMiner }
procedure PRecallMiner.ScriptMain;
var
Status : Integer;
x1,x2,x3 : Integer;
y1,y2,y3 : Integer;
begin
inherited;
Init();
x1 := Character.XLoc - m_Range;
x2 := x1 + (2*m_Range);
y1 := Character.YLoc - m_Range;
y2 := y1 + (2*m_Range);
for x3 := x1 to x2 do
begin
for y3 := y1 to y2 do
begin
Status := Mine(Character.XLoc,Character.YLoc);
Script_AddToSystemJournal(IntToStr(Status));
end;
end;
end;
procedure PRecallMiner.Init();
var
i : Word;
c : Cardinal;
ca : TArray<Cardinal>;
s : String;
begin
{$Region 'Init Mountain Tiles'}
m_Mountain_Tiles := TList<Word>.Create;
for i := 220 to 231 do begin m_Mountain_Tiles.Add(i); end;
for i := 236 to 247 do begin m_Mountain_Tiles.Add(i); end;
for i := 252 to 263 do begin m_Mountain_Tiles.Add(i); end;
for i := 268 to 279 do begin m_Mountain_Tiles.Add(i); end;
for i := 286 to 297 do begin m_Mountain_Tiles.Add(i); end;
for i := 321 to 324 do begin m_Mountain_Tiles.Add(i); end;
for i := 467 to 474 do begin m_Mountain_Tiles.Add(i); end;
for i := 476 to 487 do begin m_Mountain_Tiles.Add(i); end;
for i := 492 to 495 do begin m_Mountain_Tiles.Add(i); end;
for i := 543 to 579 do begin m_Mountain_Tiles.Add(i); end;
for i := 581 to 613 do begin m_Mountain_Tiles.Add(i); end;
m_Mountain_Tiles.Add(1010);
for i := 1741 to 1757 do begin m_Mountain_Tiles.Add(i); end;
for i := 1771 to 1790 do begin m_Mountain_Tiles.Add(i); end;
for i := 1801 to 1809 do begin m_Mountain_Tiles.Add(i); end;
for i := 1811 to 1824 do begin m_Mountain_Tiles.Add(i); end;
for i := 1831 to 1854 do begin m_Mountain_Tiles.Add(i); end;
for i := 1861 to 1884 do begin m_Mountain_Tiles.Add(i); end;
for i := 1981 to 2004 do begin m_Mountain_Tiles.Add(i); end;
for i := 2028 to 2033 do begin m_Mountain_Tiles.Add(i); end;
for i := 2100 to 2105 do begin m_Mountain_Tiles.Add(i); end;
for i := 17723 to 17743 do begin m_Mountain_Tiles.Add(i); end;
{$Endregion}
{$Region 'Init Sand Tiles'}
m_Sand_Tiles := TList<Word>.Create;
for i := 22 to 75 do begin m_Sand_Tiles.Add(i); end;
for i := 286 to 301 do begin m_Sand_Tiles.Add(i); end;
m_Sand_Tiles.Add(402);
for i := 424 to 427 do begin m_Sand_Tiles.Add(i); end;
for i := 441 to 465 do begin m_Sand_Tiles.Add(i); end;
for i := 642 to 645 do begin m_Sand_Tiles.Add(i); end;
for i := 650 to 657 do begin m_Sand_Tiles.Add(i); end;
for i := 821 to 828 do begin m_Sand_Tiles.Add(i); end;
for i := 833 to 836 do begin m_Sand_Tiles.Add(i); end;
for i := 845 to 852 do begin m_Sand_Tiles.Add(i); end;
for i := 857 to 860 do begin m_Sand_Tiles.Add(i); end;
for i := 951 to 958 do begin m_Sand_Tiles.Add(i); end;
for i := 967 to 970 do begin m_Sand_Tiles.Add(i); end;
for i := 1447 to 1458 do begin m_Sand_Tiles.Add(i); end;
for i := 1611 to 1618 do begin m_Sand_Tiles.Add(i); end;
for i := 1623 to 1626 do begin m_Sand_Tiles.Add(i); end;
for i := 1635 to 1642 do begin m_Sand_Tiles.Add(i); end;
for i := 1647 to 1650 do begin m_Sand_Tiles.Add(i); end;
{$Endregion}
{$Region 'Init Cave Tiles'}
m_Cave_Tiles := TList<Word>.Create;
for i := 1339 to 1359 do begin m_Cave_Tiles.Add(i); end;
{$Endregion}
{$Region 'Init ToolTypes'}
m_ToolTypes := TList<Word>.Create;
m_ToolTypes.Add($0F39); //Shovel
m_ToolTypes.Add($0E86); //Pickaxe
{$Endregion}
{$Region 'Success Messages'}
ca := [1112233,1007072,1007073,1007074,1007075,1007076,1007077,1007078,1007079,1007080,503044,501869,1044606,503042,501868,1044630,1044631];
for c in ca do
begin
s := '';
while(s = '')do s := Script_GetClilocByID(c);
m_MessageSuccess := m_MessageSuccess + s + '|$' + IntToHex(c,8) + '|';
end;
{$Endregion}
{$Region 'Fail Messages'}
ca := [501866,503040,1044629];
for c in ca do
begin
s := '';
while(s = '')do s := Script_GetClilocByID(c);
m_MessageFail := m_MessageFail + s + '|$' + IntToHex(c,8) + '|';
end;
{$Endregion}
{$Region 'Full Messages'}
ca := [1010481,1044632];
for c in ca do
begin
s := '';
while(s = '')do s := Script_GetClilocByID(c);
m_Message_Full := m_Message_Full + s + '|$' + IntToHex(c,8) + '|';
end;
{$Endregion}
{$Region 'Unable Messages'}
ca := [503038,501864,503039];
for c in ca do
begin
s := '';
while(s = '')do s := Script_GetClilocByID(c);
m_Message_Unable := m_Message_Unable + s + '|$' + IntToHex(c,8) + '|';
end;
{$Endregion}
{$Region 'Ranges'}
m_Range := 2;
{$Endregion}
end;
function PRecallMiner.Mine(X, Y: Cardinal): Integer;
var
CX : Integer;
CY : Integer;
DX : Integer;
DY : Integer;
M : TMapCell;
S : TStaticCellRealXY;
i : Integer;
Spot : PMiningSpot;
ii : Byte;
CurTool : Cardinal;
DigStatus : Integer;
ST : TDateTime;
begin
CX := Character.XLoc;
CY := Character.YLoc;
DX := CX - X;
DY := CY - Y;
{$Region 'Distance Check'}
if(DX > 0) and (DX > m_Range)then exit(-1);
if(DX < 0) and (DX < (m_Range * -1))then exit(-1);
if(DY > 0) and (DY > m_Range)then exit(-1);
if(DY < 0) and (DY < (m_Range * -1))then exit(-1);
{$Endregion}
Spot := PMiningSpot.Create;
Spot.Mode := -1;
{$Region 'Init Mountain Tiles'}
M := Script_GetCell(X,Y,Character.WorldNum);
for i in m_Mountain_Tiles do
begin
if(Spot.Mode = -1)then
begin
if(M.Tile = i)then
begin
if(abs(Character.ZLoc - M.Z)<15)then
begin
Spot.Mode := 1;
Spot.Tile := i;
Spot.X := X;
Spot.Y := Y;
Spot.Z := Character.ZLoc;
end;
end;
end;
end;
{$Endregion}
{$Region 'Init Sand Tiles'}
if(Spot.Mode = -1)then
begin
for i in m_Sand_Tiles do
begin
if(Spot.Mode = -1)then
begin
if(M.Tile = i) and(abs(Character.ZLoc - M.Z)<15)then
begin
Spot.Mode := 2;
Spot.Tile := i;
Spot.X := X;
Spot.Y := Y;
Spot.Z := M.Z;
end;
end;
end;
end;
{$Endregion}
{$Region 'Init Cave Tiles'}
if(Spot.Mode = -1)then
begin
S := Script_ReadStaticsXY(X, Y, Character.WorldNum);
if(S.StaticCount > 0)then
begin
for ii := 0 to S.StaticCount - 1 do
begin
for i in m_Cave_Tiles do
begin
if(Spot.Mode = -1)then
begin
if(S.Statics[ii].Tile = i)then
begin
Spot.Mode := 3;
Spot.Tile := i;
Spot.X := X;
Spot.Y := Y;
Spot.Z := S.Statics[ii].Z;
end;
end;
end;
end;
end;
end;
{$Endregion}
{$Region 'Initiate the Mining Process'}
while(True)do
begin
CurTool := Script_FindTypesArrayEx(m_ToolTypes.ToArray(),[$0],[Character.BackPackID],True);
if(CurTool = 0)then exit(-2);
if(Spot.Mode = -1)then exit(-3);
ST := Now;
Script_UseObject(CurTool);
if(Script_WaitForTarget(1000))then
begin
if(Spot.Mode in [1,2])then
begin
Script_WaitTargetXYZ(Spot.X,Spot.Y,Spot.Z);
end else if Spot.Mode = 3 then
begin
Script_WaitTargetTile(Spot.Tile, Spot.X, Spot.Y, Spot.Z); //Шахта.
end else begin
exit(0); //Unknown Error
end;
end else begin
exit(-1); //ISSUE??
end;
DigStatus := 0;
while(DigStatus = 0)do
begin
if(DigStatus = 0)and(Script_InJournalBetweenTimes(m_MessageSuccess,ST,Now)>-1)then DigStatus := 1;
if(DigStatus = 0)and(Script_InJournalBetweenTimes(m_MessageFail,ST,Now)>-1)then DigStatus := 2;
if(DigStatus = 0)and(Script_InJournalBetweenTimes(m_Message_Full,ST,Now)>-1)then DigStatus := 3;
if(DigStatus = 0)and(Script_InJournalBetweenTimes(m_Message_Unable,ST,Now)>-1)then DigStatus := 4;
end;
if(DigStatus = 2)then exit(1);
if(DigStatus = 3)then exit(2);
if(DigStatus = 4)then exit(3);
Script_Wait(100);
end;
{$Endregion}
end;
end.