-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAlSmelter.simba
457 lines (387 loc) · 12.2 KB
/
AlSmelter.simba
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
program AlSmelter_V002;
{$I SRL/OSR.simba}
{$I SRL/utils/rsclient.simba}
{$I SRL/utils/rsclient_overrides.simba}
{$I SRL/utils/itemfinder.simba}
{$I RSWalker/Walker.simba}
{$H-}{$X+}
{==============================================================================]
| AlKharid Smelter ™
|
| Steps to use:
| 1. For longer runs you need to declare login details bellow
| 2. Start the script wherever
[==============================================================================}
type
TRSBar = (BronzeBar, IronBar, SilverBar, SteelBar, GoldBar, MithrilBar, AdamantBar, RuneBar);
var
LOGIN_NAME = '';
LOGIN_PASS = '';
RS_WORLD = -1; // preferred world, -1 = random world
IS_MEMBER = FALSE; // TRUE or FALSE
BAR_TYPE = IronBar; //
type
TStatistics = record
Count: Int32;
StartInfo: TSkillInfo;
PrcToNextLvl, Rem, CurrLvl, CurrXP, Gains, XPPerBar: Double;
DismissedRandoms: Int32;
end;
TSmelter = record
StartTime: Int64;
BotStats: TStatistics;
StatsDebugTick: Int64;
OreNames: array [0..1] of String;
OreRatio: array [0..1] of Int8;
BarName: String;
MakeID: Int8;
FurnaceSpot: TPoint;
FurnaceColors: array of TCTS2Color;
BankSpots: TPointArray;
BankColors: array of TCTS2Color;
BankPath: TPointArray;
Antiban: TAntiban;
__RndCalls: Int32;
end;
var
Bot: TSmelter;
RSW: TRSWalker;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// UTILITY FUNCTIONS
function GetTimeRunning(): UInt32; override;
begin
if Bot.StartTime = 0 then Exit(0);
Result := GetTickCount() - Bot.StartTime;
end;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// METHODS FOR FATIGUE
procedure WaitFatigue(t: Double; Exp: Double=0.2);
begin
System.Wait(Trunc(2*t * (1-Power(System.Max(0.0001, Bot.Antiban.EnergyLevel()/100),Exp))));
end;
procedure Wait(min, max:Double; weight:EWaitDir=wdMean); override;
var t:Double;
begin
t := PerformanceTimer();
inherited(min, max, weight);
WaitFatigue(PerformanceTimer()-t,0.2);
end;
procedure WaitEx(mean, dev:Double); override;
var t:Double;
begin
t := PerformanceTimer();
inherited(mean, dev);
WaitFatigue(PerformanceTimer()-t, 0.2);
end;
// -----------------------------------------------------------------------------
// Break handling & antiban
procedure TSmelter.DoAntiban();
begin
srl.DismissRandom();
if Self.Antiban.DoAntiban() then
Players.GetCurrent()^.Login();
end;
procedure TSmelter.PostAction(CheckAntiban: Boolean = True);
begin
WaitEx(500,70);
if CheckAntiban then Self.DoAntiban;
end;
// -----------------------------------------------------------------------------
// SMITHER
procedure TSmelter.DeclarePlayers();
begin
with Players.New()^ do
begin
LoginName := LOGIN_NAME;
Password := LOGIN_PASS;
IsActive := True;
IsMember := IS_MEMBER;
World := RS_WORLD;
end;
Players.SetCurrent(0);
end;
function TSmelter.UseTwoOres(): Boolean;
begin
Result := Self.OreRatio[1] <> 0;
end;
procedure TSmelter.ProcessWhileWaiting();
var
n,atNextLvl,atCurrLvl:Int32;
begin
BotStats.Gains := BotStats.Count * BotStats.XPPerBar;
BotStats.CurrXP := BotStats.StartInfo.XP + BotStats.Gains;
BotStats.CurrLvl := srl.GetLevelAtXP(Ceil(BotStats.CurrXP));
atNextLvl := srl.GetXPAtLevel(Trunc(BotStats.CurrLvl)+1);
atCurrLvl := srl.GetXPAtLevel(Trunc(BotStats.CurrLvl));
BotStats.Rem := atNextLvl - BotStats.CurrXP;
BotStats.PrcToNextLvl := 100 - Round((BotStats.Rem / (atNextLvl - atCurrLvl)) * 100);
if GetTickCount() - StatsDebugTick > 6000 then
begin
ClearDebug();
WriteLn('+---| STATS |----------------------------------------');
WriteLn('|- Bars Made : ', BotStats.Count);
WriteLn('|- Experience Gained : ', Round(BotStats.Gains,2));
WriteLn('|- Experience Per Hour : ', Round(BotStats.Gains / (GetTimeRunning()/1000/60/60)) );
WriteLn('|- Smithing Level : ', Round(BotStats.CurrLvl,2));
WriteLn('|- Dismissed Randoms : ', BotStats.DismissedRandoms);
WriteLn('|- Time Since Break : ', SRL.MsToTime(Antiban.TimeSinceBreak, Time_Short));
WriteLn('|- Energy Level : ', Round(Antiban.EnergyLevel,2));
WriteLn('|- Script Runtime : ', SRL.MsToTime(GetTimeRunning, Time_Short));
WriteLn('+----------------------------------------------------');
StatsDebugTick := GetTickCount();
end;
Self.DoAntiban;
end;
function TSmelter.FindObject(Locations: TPointArray; Colors: array of TCTS2Color; MinCount:Int32=100): TRectArray;
var
i,j,count: Int32;
me: TPoint;
rect: TRectangle;
TPA: TPointArray;
begin
me := RSW.GetMyPos();
for i:=0 to High(Locations) do
begin
rect := RSW.GetTileMSEx(me, Locations[i]).Expand(-2);
if MainScreen.GetBounds.Contains(rect.Bounds) then
begin
count := 0;
for j:=0 to High(Colors) do
begin
count += srl.FindColors(TPA, Colors[j], rect.Bounds);
if count > MinCount then //XXXXXXXXXXXX
begin
Result += rect;
Break;
end;
end;
end;
end;
if Length(Result) = 0 then
TerminateScript('Not close enough to objects: ('+ ToStr(me.x) +','+ToStr(me.y)+') -> '+ ToStr(locations));
end;
function TSmelter.DoWork(): Boolean;
var
i,next: Int32;
T: TCountDown;
Furnace: array of TRectangle;
function ClickFurnace(rect: TRectangle): Boolean;
begin
mouse.Move(rect, Random(10) = 0);
WaitEx(65,10);
if not Mainscreen.IsUpText(['Smelt', 'Furnace']) then
Exit();
if (not ((Random()*100 <= 5) and ChooseOption.Select('Smelt Furnace'))) and
(not Mouse.Click(ctRed)) then
begin
Wait(300,6000,wdLeft);
Self.DoAntiban;
WaitFatigue(Random(1000,4500), 0.6);
Exit();
end;
WaitFatigue(Random(700,1200), 0.1);
Minimap.WaitPlayerMoving(False,,200);
if Chatbox.ClickButtonId('What would you', Self.MakeID, Self.BarName, 3000) then
Result := True;
end;
begin
Furnace := Self.FindObject([self.FurnaceSpot], self.FurnaceColors);
if Length(Furnace) = 0 then
Exit(False);
WaitFatigue(Random(700,1200), 0.1);
if not ClickFurnace(Furnace[0]) then
Exit;
T.Init(srl.NormalRange(ONE_MINUTE*4, ONE_MINUTE*4+ONE_MINUTE));
while (not T.IsFinished) do
begin
if (Inventory.Count(Self.OreNames[0]) < Self.OreRatio[0]) or
(Self.UseTwoOres() and (Inventory.Count(Self.OreNames[1]) < Self.OreRatio[1])) then
Break;
if(Chatbox.GotLevelUp()) then
begin
if(Random(9) = 0) then
Chatbox.HandleLevelUp();
Break;
end;
Self.ProcessWhileWaiting();
WaitEx(30,5);
end;
Result := True;
end;
procedure TSmelter.DoBanking();
function OpenBank(): Boolean;
var
rect: TRectangle;
me: TPoint;
begin
for 0 to 4 do
begin
me := RSW.GetMyPos();
self.BankSpots.Sort(me);
for rect in Self.FindObject(self.BankSpots, self.BankColors) do
if BankScreen.OpenAt(srl.RandomPoint(rect.Expand(-6))) then
Exit(True);
Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
Wait(800,1300);
end;
end;
var
WithdrawCount0, WithdrawCount1: Int32;
begin
if(not RSW.WebWalk([4885, 3776])) then
TerminateScript('Failed to walk to bank');
Self.DoAntiban;
if(not OpenBank()) then
TerminateScript('Failed to open bank');
WaitEx(450,70);
if(not BankScreen.DepositAll) then
TerminateScript('Failed to deposit items');
WaitEx(450,70);
repeat
WithdrawCount0 += Self.OreRatio[0];
WithdrawCount1 += Self.OreRatio[1];
until WithdrawCount0 + WithdrawCount1 + Self.OreRatio[0] + Self.OreRatio[1] > 28;
if(not BankScreen.Withdraw(Self.OreNames[0], WithdrawCount0, [Self.OreNames[0]])) then
TerminateScript('Failed to withdraw items');
WaitEx(450,70);
if Self.UseTwoOres() then
if(not BankScreen.Withdraw(Self.OreNames[1], WithdrawCount1, [Self.OreNames[1]])) then
TerminateScript('Failed to withdraw items');
WaitEx(450,70);
if Random() <= 0.25 then
begin
BankScreen.Close();
Self.DoAntiban;
end;
if (Inventory.Count(Self.OreNames[0]) < Self.OreRatio[0]) or
(Self.UseTwoOres() and (Inventory.Count(Self.OreNames[1]) < Self.OreRatio[1])) then
TerminateScript('Out of ores');
if(not RSW.WebWalk([4913, 3709])) then
TerminateScript('Failed to walk to furnace');
Self.DoAntiban;
end;
procedure TSmelter.Run();
var
tick: UInt64;
begin
Self.StartTime := GetTickCount();
Self.BotStats.StartInfo := Stats.GetSkillInfo(SKILL_SMITHING);
Mainscreen.SetAngle(True);
repeat
if (Inventory.Count(Self.OreNames[0]) < Self.OreRatio[0]) or
(Self.UseTwoOres() and (Inventory.Count(Self.OreNames[1]) < Self.OreRatio[1])) then
begin
Self.BotStats.Count += Length(Inventory.GetUsedSlots);
Self.DoBanking();
end;
if Self.DoWork() then
Self.DoAntiban;
Wait(1);
until False;
end;
procedure TSmelter.SetupAntiban();
begin
Antiban.Init(SKILL_SMITHING);
Antiban.AddTask([@Antiban.LoseFocus, ONE_MINUTE*6]);
Antiban.AddTask([@Antiban.HoverPlayers, ONE_MINUTE*8]);
Antiban.AddTask([@Antiban.CheckSkill, ONE_MINUTE*11]);
Antiban.AddTask([@Antiban.CheckStats, ONE_MINUTE*13]);
Antiban.AddTask([@Antiban.OpenRandomTab, ONE_MINUTE*16]);
Antiban.AddTask([@Antiban.VeryShortBreak, ONE_MINUTE*35]);
Antiban.AddTask([@Antiban.RandomCompass, ONE_MINUTE*35]);
Antiban.AddTask([@Antiban.DoMiscStuff, ONE_MINUTE*45]);
Antiban.AddBreak([65 * ONE_MINUTE, 05 * ONE_MINUTE, 0.15]);
Antiban.AddBreak([02 * ONE_HOUR, 10 * ONE_MINUTE, 0.75]);
Antiban.AddBreak([04 * ONE_HOUR, 45 * ONE_MINUTE, 0.85]);
Antiban.AddBreak([17 * ONE_HOUR, 07 * ONE_HOUR, 0.99]);
end;
procedure TSmelter.Init();
begin
self.DeclarePlayers();
Players.GetCurrent()^.Login();
Self.FurnaceSpot := [4902,3703];
Self.FurnaceColors := [CTS2(2500136, 15), CTS2(3026482, 15)];
Self.BankSpots := [[4882,3776],[4882,3772],[4882,3780],[4882,3784]];
Self.BankColors := [CTS2(608352,15),CTS2(605521,15),CTS2(5462367,15),CTS2(3158069,15),CTS2(4870227,15)];
Self.SetupAntiban();
case BAR_TYPE of
BronzeBar:
begin
Self.BotStats.XPPerBar := 12.5;
Self.MakeID := 1;
Self.OreNames := ['Iron ore',''];
Self.OreRatio := [1,0];
Self.BarName := 'Iron bar';
end;
IronBar:
begin
Self.BotStats.XPPerBar := 12.5;
Self.MakeID := 2;
Self.OreNames := ['Iron ore',''];
Self.OreRatio := [1,0];
Self.BarName := 'Iron bar';
end;
SilverBar:
begin
Self.BotStats.XPPerBar := 13.7;
Self.MakeID := 3;
Self.OreNames := ['Silver ore',''];
Self.OreRatio := [1,0];
Self.BarName := 'Silver bar';
end;
SteelBar:
begin
Self.BotStats.XPPerBar := 17.5;
Self.MakeID := 4;
Self.OreNames := ['Iron ore','Coal'];
Self.OreRatio := [1,2];
Self.BarName := 'Steel bar';
end;
GoldBar:
begin
Self.BotStats.XPPerBar := 22.5;
Self.MakeID := 5;
Self.OreNames := ['Gold ore',''];
Self.OreRatio := [1,0];
Self.BarName := 'Gold bar';
end;
MithrilBar:
begin
Self.BotStats.XPPerBar := 30.0;
Self.MakeID := 6;
Self.OreNames := ['Mithril ore','Coal'];
Self.OreRatio := [1,4];
Self.BarName := 'Mithril bar';
end;
AdamantBar:
begin
Self.BotStats.XPPerBar := 37.5;
Self.MakeID := 7;
Self.OreNames := ['Adamantite ore','Coal'];
Self.OreRatio := [1,6];
Self.BarName := 'Adamantite bar';
end;
RuneBar:
begin
Self.BotStats.XPPerBar := 75.0;
Self.MakeID := 8;
Self.OreNames := ['Runite ore','Coal'];
Self.OreRatio := [1,8];
Self.BarName := 'Runite bar';
end;
else
TerminateScript('Invalid bar name');
end;
end;
begin
srl.SetupForClient('',[]);
srl.Options := [soDebugAntiban];
RSClient.SetFocus();
Bot.Init();
RSW.Init('world.png');
RSW.skipClose := 30;
AddOnTerminate(@RSW.Free);
Bot.Run();
end.