@@ -59,6 +59,7 @@ Main record to handle the built-in WaspLib antiban.
5959 Tasks: array of TAntibanTask;
6060 Breaks: array of TBreakTask;
6161 Sleeps: array of TSleepTask;
62+ WalkTasks: array of TAntibanTask;
6263
6364 OnStartTask, OnFinishTask: procedure(task: PAntibanTask) of object;
6465 OnStartBreak, OnFinishBreak: procedure(task: PBreakTask) of object;
@@ -93,14 +94,37 @@ begin
9394 Result += @Self.Tasks[i];
9495end;
9596
97+ function TAntiban.GetActiveWalkTasks(): PAntibanTaskArray;
98+ var
99+ i: Integer;
100+ begin
101+ for i := 0 to High(Self.WalkTasks) do
102+ if not Self.WalkTasks[i].Countdown.IsPaused then
103+ Result += @Self.WalkTasks[i];
104+ end;
105+
106+ function TAntiban.GetInactiveWalkTasks(): PAntibanTaskArray;
107+ var
108+ i: Integer;
109+ begin
110+ for i := 0 to High(Self.WalkTasks) do
111+ if Self.WalkTasks[i].Countdown.IsPaused then
112+ Result += @Self.WalkTasks[i];
113+ end;
114+
96115
97116
98117procedure TAntiban._UpdateTask(idx: Integer; method: TAntibanMethod; interval, randomness: Double);
99118begin
100119 Self.Tasks[idx].Interval := interval;
101120 Self.Tasks[idx].Method := @method;
102121 Self.Tasks[idx].StdVar := randomness;
103- Self.Tasks[idx].Countdown.Start(Random(Trunc(Abs(GaussRand(Self.Tasks[idx].Interval, Self.Tasks[idx].Interval * Self.Tasks[idx].StdVar)))));
122+ Self.Tasks[idx].Countdown.Start(
123+ Random(Trunc(Abs(GaussRand(
124+ Self.Tasks[idx].Interval,
125+ Self.Tasks[idx].Interval * Self.Tasks[idx].StdVar
126+ ))))
127+ );
104128end;
105129
106130procedure TAntiban._UpdateBreak(idx: Integer; interval, length, randomness, logoutChance: Double);
@@ -109,7 +133,11 @@ begin
109133 Self.Breaks[idx].Length := length;
110134 Self.Breaks[idx].StdVar := randomness;
111135 Self.Breaks[idx].LogoutChance := logoutChance;
112- Self.Breaks[idx].Next := GetTimeRunning() + Abs(GaussRand(Self.Breaks[idx].Interval, Self.Breaks[idx].Interval * Self.Breaks[idx].StdVar));
136+ Self.Breaks[idx].Next := GetTimeRunning() +
137+ Abs(GaussRand(
138+ Self.Breaks[idx].Interval,
139+ Self.Breaks[idx].Interval * Self.Breaks[idx].StdVar
140+ ));
113141end;
114142
115143procedure TAntiban._UpdateSleep(idx: Integer; time: String; length, randomness, logoutChance: Double);
@@ -121,6 +149,19 @@ begin
121149 Self.Sleeps[idx].Next := Self.TimeRunningAtClock(time, randomness);
122150end;
123151
152+ procedure TAntiban._UpdateWalkTask(idx: Integer; method: TAntibanMethod; interval, randomness: Double);
153+ begin
154+ Self.WalkTasks[idx].Interval := interval;
155+ Self.WalkTasks[idx].Method := @method;
156+ Self.WalkTasks[idx].StdVar := randomness;
157+ Self.WalkTasks[idx].Countdown.Start(
158+ Random(Trunc(Abs(GaussRand(
159+ Self.WalkTasks[idx].Interval,
160+ Self.WalkTasks[idx].Interval * Self.WalkTasks[idx].StdVar
161+ ))))
162+ );
163+ end;
164+
124165
125166(*
126167## Antiban.AddTask
@@ -131,7 +172,8 @@ Schedule a antiban task.
131172An antiban task can be any procedure but they should be short actions that won't
132173break your main script.
133174
134- `method` is a pointer to the task you want to perform. WaspLib includes a couple of them but you may make your own if you want.
175+ `method` is a pointer to the task you want to perform. WaspLib includes a couple
176+ of them but you may make your own if you want.
135177
136178`interval` is the aproximate interval of time that has to pass for the antiban
137179task to occur and it will be repeated everytime that the interval has passed
@@ -146,25 +188,27 @@ Antiban.AddTask(@Antiban.HoverSkills, 15 * ONE_MINUTE); //Every 15 minutes the s
146188*)
147189procedure TAntiban.AddTask(method: TAntibanMethod; interval: Double; randomness: Double = 0.2);
148190var
149- len : Integer;
191+ idx : Integer;
150192begin
151- len := Length(Self.Tasks);
152- SetLength(Self.Tasks, len +1);
153- Self._UpdateTask(len , @method, interval, randomness);
193+ idx := Length(Self.Tasks);
194+ SetLength(Self.Tasks, idx +1);
195+ Self._UpdateTask(idx , @method, interval, randomness);
154196end;
155197
156198(*
157199## Antiban.AddBreak
158200```pascal
159201procedure TAntiban.AddBreak(interval, length: Double; randomness: Double = 0.2; logoutChance: Double = 0.33);
160202```
161- Schedule a break. Breaks can be of short or medium length and should be shorter than any sleep breaks.
203+ Schedule a break. Breaks can be of short or medium length and should be shorter
204+ than any sleep breaks.
162205
163206`interval` is the aproximate interval of time that has to pass for the break to
164207occur and it will be repeated everytime that interval passes and the antiban is
165208checked either with {ref}`Antiban.DoBreak` or {ref}`Antiban.DoAntiban`.
166209
167- `length`, `randomness` and `logoutChance` are the same as {ref}`Antiban.AddSleep`.
210+ `length`, `randomness` and `logoutChance` are the same as
211+ {ref}`Antiban.AddSleep`.
168212
169213This break will only occur when {ref}`Antiban.DoAntiban` is called.
170214
@@ -175,11 +219,11 @@ Antiban.AddBreak(30 * ONE_MINUTE, 5 * ONE_MINUTE); //Every 30 minutes the script
175219*)
176220procedure TAntiban.AddBreak(interval, length: Double; randomness: Double = 0.2; logoutChance: Double = 0.33);
177221var
178- len : Integer;
222+ idx : Integer;
179223begin
180- len := System.Length(Self.Breaks);
181- SetLength(Self.Breaks, len +1);
182- Self._UpdateBreak(len , interval, length, randomness, logoutChance);
224+ idx := System.Length(Self.Breaks);
225+ SetLength(Self.Breaks, idx +1);
226+ Self._UpdateBreak(idx , interval, length, randomness, logoutChance);
183227end;
184228
185229(*
@@ -203,7 +247,8 @@ In other words, you will never sleep before `time`.
203247`logoutChance` is the probability of logging out for the sleep break or to
204248simply afk and logout from inactivity.
205249
206- This sleep break will only occur when {ref}`Antiban.DoAntiban` is called and our sleep break is due.
250+ This sleep break will only occur when {ref}`Antiban.DoAntiban` is called and our
251+ sleep break is due.
207252
208253Example:
209254```pascal
@@ -212,11 +257,43 @@ Antiban.AddSleep('01:30:45', 8 * ONE_HOUR, 0.1, 0.8); //At 01:30:45 on our compu
212257*)
213258procedure TAntiban.AddSleep(time: String; length: Double; randomness: Double = 0.1; logoutChance: Double = 0.5);
214259var
215- len : Integer;
260+ idx : Integer;
216261begin
217- len := System.Length(Self.Sleeps);
218- SetLength(Self.Sleeps, len+1);
219- Self._UpdateSleep(len, time, length, randomness, logoutChance);
262+ idx := System.Length(Self.Sleeps);
263+ SetLength(Self.Sleeps, idx+1);
264+ Self._UpdateSleep(idx, time, length, randomness, logoutChance);
265+ end;
266+
267+ (*
268+ ## Antiban.AddWalkTask
269+ ```pascal
270+ procedure TAntiban.AddWalkTask(method: TAntibanMethod; interval: Double; randomness: Double = 0.2);
271+ ```
272+ Schedule a walking antiban task.
273+ An antiban task can be any procedure but they should be short actions that won't
274+ break your main script.
275+
276+ `method` is a pointer to the task you want to perform.
277+ WaspLib includes a couple of them but you may make your own if you want.
278+
279+ `interval` is the aproximate interval of time that has to pass for the antiban
280+ task to occur and it will be repeated everytime that the interval has passed
281+ and the antiban is checked with {ref}`Antiban.DoAntiban`.
282+
283+ This task will only occur when **TAntiban.DoAntiban** is called.
284+
285+ Example:
286+ ```pascal
287+ Antiban.AddWalkTask(@Antiban.HoverSkills, 15 * ONE_MINUTE); //Every 15 minutes the script will run Antiban.HoverSkills().
288+ ```
289+ *)
290+ procedure TAntiban.AddWalkTask(method: TAntibanMethod; interval: Double; randomness: Double = 0.2);
291+ var
292+ idx: Integer;
293+ begin
294+ idx := Length(Self.WalkTasks);
295+ SetLength(Self.WalkTasks, idx+1);
296+ Self._UpdateWalkTask(idx, @method, interval, randomness);
220297end;
221298
222299
@@ -416,7 +493,7 @@ function TAntiban.DoTask(): Boolean;
416493```
417494Checks for scheduled antiban tasks, if any is due it will do it.
418495
419- You should only call this when taking doing an antiban task won't break your script.
496+ You should only call this when doing an antiban task won't break your script.
420497
421498Returns true if a task was performed.
422499
@@ -427,36 +504,40 @@ Antiban.DoTask();
427504*)
428505function TAntiban.DoTask(): Boolean;
429506var
430- i: Int32 ;
507+ i: Integer ;
431508 task: PAntibanTask;
432- activeTasks : PAntibanTaskArray;
509+ active : PAntibanTaskArray;
433510begin
434- activeTasks := Self.GetActiveTasks();
435- for i := 0 to High(activeTasks ) do
436- activeTasks [i]^.Countdown.Pause();
511+ active := Self.GetActiveTasks();
512+ for i := 0 to High(active ) do
513+ active [i]^.Countdown.Pause();
437514
438- for i := 0 to High(activeTasks ) do
515+ for i := 0 to High(active ) do
439516 begin
440- task := activeTasks [i];
517+ task := active [i];
441518
442- if task^.Countdown.Remaining = 0 then
443- begin
444- if (@Self.OnStartTask <> nil) then
445- Self.OnStartTask(Task);
519+ if task^.Countdown.Remaining <> 0 then
520+ Continue;
446521
447- task^.Method();
448- task^.Countdown.Start(Trunc(Abs(GaussRand(task^.Interval, task^.Interval * task^.StdVar))));
449- task^.Countdown.Pause();
522+ if @Self.OnStartTask <> nil then
523+ Self.OnStartTask(Task);
450524
451- if (@Self.OnFinishTask <> nil) then
452- Self.OnFinishTask(Task);
525+ task^.Method();
526+ task^.Countdown.Start(
527+ Trunc(Abs(GaussRand(
528+ task^.Interval, task^.Interval * task^.StdVar
529+ )))
530+ );
531+ task^.Countdown.Pause();
453532
454- Result := True;
455- end;
533+ if @Self.OnFinishTask <> nil then
534+ Self.OnFinishTask(Task);
535+
536+ Result := True;
456537 end;
457538
458- for i := 0 to High(activeTasks ) do
459- activeTasks [i]^.Countdown.Resume();
539+ for i := 0 to High(active ) do
540+ active [i]^.Countdown.Resume();
460541end;
461542
462543(*
@@ -525,6 +606,61 @@ begin
525606 end;
526607end;
527608
609+ (*
610+ ## Antiban.DoWalkTask
611+ ```pascal
612+ function TAntiban.DoWalkTask(): Boolean;
613+ ```
614+ Checks for scheduled walking antiban tasks, if any is due it will do it.
615+
616+ You should only call this when walking and doing an antiban task won't break
617+ your script.
618+
619+ Returns true if a task was performed.
620+
621+ Example:
622+ ```pascal
623+ Antiban.DoWalkTask();
624+ ```
625+ *)
626+ function TAntiban.DoWalkTask(): Boolean;
627+ var
628+ i: Integer;
629+ task: PAntibanTask;
630+ active: PAntibanTaskArray;
631+ begin
632+ active := Self.GetActiveWalkTasks();
633+ for i := 0 to High(active) do
634+ active[i]^.Countdown.Pause();
635+
636+ for i := 0 to High(active) do
637+ begin
638+ task := active[i];
639+
640+ if task^.Countdown.Remaining <> 0 then
641+ Continue;
642+
643+ if @Self.OnStartTask <> nil then
644+ Self.OnStartTask(Task);
645+
646+ task^.Method();
647+ task^.Countdown.Start(
648+ Trunc(Abs(GaussRand(
649+ task^.Interval, task^.Interval * task^.StdVar
650+ )))
651+ );
652+ task^.Countdown.Pause();
653+
654+ if @Self.OnFinishTask <> nil then
655+ Self.OnFinishTask(Task);
656+
657+ Result := True;
658+ end;
659+
660+ for i := 0 to High(active) do
661+ active[i]^.Countdown.Resume();
662+ end;
663+
528664
529665(*
530666## Antiban.DoAntiban
@@ -576,6 +712,33 @@ begin
576712 Self.TimeRunning.Pause();
577713end;
578714
715+ (*
716+ ## Antiban.DoWalkingAntiban
717+ ```pascal
718+ function TAntiban.DoWalkingAntiban(): Boolean;
719+ ```
720+ This should be called in your script when walking and walking tasks won't break
721+ your script.
722+
723+ When this is called, the setup walking tasks will be checked, if enough time has
724+ passed to perform any of them, they will be performed, otherwise,
725+ nothing will happen.
726+ *)
727+ function TAntiban.DoWalkingAntiban(): Boolean;
728+ begin
729+ if Self.DoingAntiban then
730+ Exit;
731+
732+ Self.DoingAntiban := True;
733+ Self.TimeRunning.Resume();
734+
735+ if Self.DoWalkTask() then
736+ Result := True;
737+
738+ Self.DoingAntiban := False;
739+ Self.TimeRunning.Pause();
740+ end;
741+
579742
580743(*
581744## Antiban.TimeUntilBreak
@@ -650,12 +813,6 @@ begin
650813 WriteLn('Running for ', FormatMilliseconds(Round(active), TIME_FORMAL), ' per day, on average.');
651814end;
652815
653-
654- procedure TAntiban.WalkingTasks();
655- begin
656- //overriden later.
657- end;
658-
659816var
660817(*
661818## Antiban variable
0 commit comments