Skip to content

Commit c5c8cb7

Browse files
committed
fix(antibanform): percentages are now more human friendly
1 parent d6b2c68 commit c5c8cb7

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

osrs/antiban/antibanform.simba

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ Do feel free to read the source code though if you so desire.
2929
PageControl: TLazPageControl;
3030

3131
TaskCombobox: TLazComboBox;
32-
TaskIntervalSpinner, TaskVariationSpinner: TLazFloatSpinEdit;
32+
TaskIntervalSpinner: TLazFloatSpinEdit;
33+
TaskVariationSpinner: TLazSpinEdit;
3334
TaskDelButton, TaskEditButton, TaskAddButton, TaskPresetButton: TLazButton;
3435

35-
BreakIntervalSpinner, BreakLengthSpinner, BreakVariationSpinner, BreakLogoutSpinner: TLazFloatSpinEdit;
36+
BreakIntervalSpinner, BreakLengthSpinner: TLazFloatSpinEdit;
37+
BreakVariationSpinner, BreakLogoutSpinner: TLazSpinEdit;
3638
BreakDelButton, BreakEditButton, BreakAddButton, BreakPresetButton: TLazButton;
3739

3840
SleepTimeEdit: TLazTimeEdit;
39-
SleepLengthSpinner, SleepVariationSpinner, SleepLogoutSpinner: TLazFloatSpinEdit;
41+
SleepLengthSpinner: TLazFloatSpinEdit;
42+
SleepVariationSpinner, SleepLogoutSpinner: TLazSpinEdit;
4043
SleepPresetButton: TLazButton;
4144

4245
Config: TConfigJSON;
@@ -246,8 +249,8 @@ begin
246249

247250
Self.SleepTimeEdit.Text := Antiban.Sleeps[0].Time;
248251
Self.SleepLengthSpinner.Value := len;
249-
Self.SleepVariationSpinner.Value := Antiban.Sleeps[0].StdVar;
250-
Self.SleepLogoutSpinner.Value := Antiban.Sleeps[0].LogoutChance;
252+
Self.SleepVariationSpinner.Value := Round(Antiban.Sleeps[0].StdVar * 100);
253+
Self.SleepLogoutSpinner.Value := Round(Antiban.Sleeps[0].LogoutChance * 100);
251254

252255
Self.SleepTimeEdit.OnChange := event;
253256
Self.SleepLengthSpinner.OnChange := event;
@@ -361,8 +364,8 @@ begin
361364
Self.SleepCheckbox.SetChecked(obj.Item['enabled'].AsBool);
362365
Self.SleepTimeEdit.Text := obj.Item['time'].AsString;
363366
Self.SleepLengthSpinner.Value := obj.Item['length'].AsFloat;
364-
Self.SleepVariationSpinner.Value := obj.Item['variation'].AsFloat;
365-
Self.SleepLogoutSpinner.Value := obj.Item['logout'].AsFloat;
367+
Self.SleepVariationSpinner.Value := Round(obj.Item['variation'].AsFloat * 100);
368+
Self.SleepLogoutSpinner.Value := Round(obj.Item['logout'].AsFloat * 100);
366369

367370
Self.SleepTimeEdit.OnChange := event;
368371
Self.SleepLengthSpinner.OnChange := event;
@@ -477,7 +480,7 @@ begin
477480

478481
Self.TaskCombobox.ItemIndex := Self.TaskCombobox.Items.IndexOf(strings[0].Trim());
479482
Self.TaskIntervalSpinner.Value := Antiban.Tasks[i].Interval / ONE_MINUTE;
480-
Self.TaskVariationSpinner.Value := Antiban.Tasks[i].StdVar;
483+
Self.TaskVariationSpinner.Value := Round(Antiban.Tasks[i].StdVar * 100);
481484
end;
482485

483486
procedure TAntibanFormHelper.OnTaskAdd(sender: TLazObject);
@@ -496,15 +499,16 @@ begin
496499
Self.TaskList.Items.Insert(
497500
idx,
498501
Self.GetTaskListString(
499-
Self.TaskCombobox.Text, ToStr(Self.TaskIntervalSpinner.Value) + ' mins',
500-
ToStr(Self.TaskVariationSpinner.Value * 100) + '%'
502+
Self.TaskCombobox.Text,
503+
ToStr(Self.TaskIntervalSpinner.Value) + ' mins',
504+
Self.TaskVariationSpinner.Text + '%'
501505
)
502506
);
503507

504508
Antiban.Tasks.Insert(Default(TAntibanTask), idx);
505509
Antiban._UpdateTask(
506510
idx, @ANTIBAN_TASKS[Self.TaskCombobox.ItemIndex].Method,
507-
interval, Self.TaskVariationSpinner.Value
511+
interval, Self.TaskVariationSpinner.Value / 100
508512
);
509513

510514
Self.TaskList.ItemIndex := idx;
@@ -517,7 +521,7 @@ begin
517521
taskObj := new TJSONObject();
518522
taskObj.AddString('task', Self.TaskCombobox.Text);
519523
taskObj.AddFloat('interval', Self.TaskIntervalSpinner.Value);
520-
taskObj.AddFloat('variation', Self.TaskVariationSpinner.Value);
524+
taskObj.AddFloat('variation', Round(Self.TaskVariationSpinner.Value/100, 3));
521525
newArray.Add('task', taskObj);
522526

523527
for i := idx+1 to oldArray.Count-1 do
@@ -584,8 +588,8 @@ begin
584588

585589
Self.BreakIntervalSpinner.Value := Antiban.Breaks[i].Interval / ONE_MINUTE;
586590
Self.BreakLengthSpinner.Value := Antiban.Breaks[i].Length / ONE_MINUTE;
587-
Self.BreakVariationSpinner.Value := Antiban.Breaks[i].StdVar;
588-
Self.BreakLogoutSpinner.Value := Antiban.Breaks[i].LogoutChance;
591+
Self.BreakVariationSpinner.Value := Round(Antiban.Breaks[i].StdVar * 100);
592+
Self.BreakLogoutSpinner.Value := Round(Antiban.Breaks[i].LogoutChance * 100);
589593
end;
590594

591595
procedure TAntibanFormHelper.OnBreakAdd(sender: TLazObject);
@@ -606,14 +610,16 @@ begin
606610
Self.GetBreakListString(
607611
ToStr(Self.BreakLengthSpinner.Value) + ' mins',
608612
ToStr(Self.BreakIntervalSpinner.Value) + ' mins',
609-
ToStr(Self.BreakVariationSpinner.Value * 100) + '%',
610-
ToStr(Self.BreakLogoutSpinner.Value * 100) + '%'
613+
Self.BreakVariationSpinner.Text + '%',
614+
Self.BreakLogoutSpinner.Text + '%'
611615
)
612616
);
613617

614618
Antiban.Breaks.Insert(Default(TBreakTask), idx);
615619
Antiban._UpdateBreak(
616-
idx, interval, Self.BreakLengthSpinner.Value * ONE_MINUTE, Self.BreakVariationSpinner.Value, Self.BreakLogoutSpinner.Value
620+
idx, interval, Self.BreakLengthSpinner.Value * ONE_MINUTE,
621+
Self.BreakVariationSpinner.Value / 100,
622+
Self.BreakLogoutSpinner.Value / 100
617623
);
618624

619625
Self.BreakList.ItemIndex := idx;
@@ -626,8 +632,8 @@ begin
626632
breakObj := new TJSONObject();
627633
breakObj.AddFloat('interval', Self.BreakIntervalSpinner.Value * ONE_MINUTE);
628634
breakObj.AddFloat('length', Self.BreakLengthSpinner.Value * ONE_MINUTE);
629-
breakObj.AddFloat('variation', Self.BreakVariationSpinner.Value);
630-
breakObj.AddFloat('logout', Self.BreakLogoutSpinner.Value);
635+
breakObj.AddFloat('variation', Self.BreakVariationSpinner.Value / 100);
636+
breakObj.AddFloat('logout', Self.BreakLogoutSpinner.Value / 100);
631637
newArray.Add('break', breakObj);
632638

633639
for i := idx+1 to oldArray.Count-1 do
@@ -681,13 +687,13 @@ procedure TAntibanFormHelper.OnSleepChange(sender: TLazObject);
681687
begin
682688
Antiban._UpdateSleep(
683689
0, Self.SleepTimeEdit.Text, Self.SleepLengthSpinner.Value * ONE_HOUR,
684-
Self.SleepVariationSpinner.Value, Self.SleepLogoutSpinner.Value
690+
Self.SleepVariationSpinner.Value/100, Self.SleepLogoutSpinner.Value/100
685691
);
686692

687693
Self.Config.Data.Item['sleep'].Item['time'].AsString := Self.SleepTimeEdit.Text;
688694
Self.Config.Data.Item['sleep'].Item['length'].AsFloat := Self.SleepLengthSpinner.Value;
689-
Self.Config.Data.Item['sleep'].Item['variation'].AsFloat := Self.SleepVariationSpinner.Value;
690-
Self.Config.Data.Item['sleep'].Item['logout'].AsFloat := Self.SleepLogoutSpinner.Value;
695+
Self.Config.Data.Item['sleep'].Item['variation'].AsFloat := Self.SleepVariationSpinner.Value/100;
696+
Self.Config.Data.Item['sleep'].Item['logout'].AsFloat := Self.SleepLogoutSpinner.Value/100;
691697
Self.Config.Save();
692698
end;
693699

@@ -786,11 +792,12 @@ begin
786792
Self.TaskPresetButton.BorderSpacing.Around := 10;
787793

788794

789-
Self.TaskVariationSpinner := TLazFloatSpinEdit.CreateEx(lPanel, '', 'Edit the currently selected task interval variation.');
790-
Self.TaskVariationSpinner.Value := 0.33;
795+
Self.TaskVariationSpinner := TLazSpinEdit.CreateEx(lPanel, '', 'Edit the currently selected task interval variation.');
796+
Self.TaskVariationSpinner.Value := 33;
791797
Self.TaskVariationSpinner.MinValue := 0;
792-
Self.TaskVariationSpinner.MaxValue := 1;
793-
Self.TaskVariationSpinner.Increment := 0.05;
798+
Self.TaskVariationSpinner.MaxValue := 100;
799+
Self.TaskVariationSpinner.Increment := 5;
800+
Self.TaskVariationSpinner.ValueEmpty := False;
794801
Self.TaskVariationSpinner.Align := ELazAlign.Top;
795802
Self.TaskVariationSpinner.BorderSpacing.Left := 10;
796803
Self.TaskVariationSpinner.BorderSpacing.Right := 10;
@@ -908,11 +915,12 @@ begin
908915
Self.BreakPresetButton.Align := ELazAlign.Bottom;
909916
Self.BreakPresetButton.BorderSpacing.Around := 10;
910917

911-
Self.BreakLogoutSpinner := TLazFloatSpinEdit.CreateEx(lPanel);
912-
Self.BreakLogoutSpinner.MinValue := 0.00;
913-
Self.BreakLogoutSpinner.MaxValue := 1.00;
914-
Self.BreakLogoutSpinner.Increment := 0.10;
915-
Self.BreakLogoutSpinner.Value := 0.05;
918+
Self.BreakLogoutSpinner := TLazSpinEdit.CreateEx(lPanel);
919+
Self.BreakLogoutSpinner.MinValue := 0;
920+
Self.BreakLogoutSpinner.MaxValue := 100;
921+
Self.BreakLogoutSpinner.Increment := 5;
922+
Self.BreakLogoutSpinner.Value := 5;
923+
Self.BreakLogoutSpinner.ValueEmpty := False;
916924
Self.BreakLogoutSpinner.Align := ELazAlign.Top;
917925
Self.BreakLogoutSpinner.BorderSpacing.Left := 10;
918926
Self.BreakLogoutSpinner.BorderSpacing.Right := 10;
@@ -924,11 +932,12 @@ begin
924932
lbl.BorderSpacing.Left := 10;
925933
lbl.BorderSpacing.Right := 10;
926934

927-
Self.BreakVariationSpinner := TLazFloatSpinEdit.CreateEx(lPanel);
928-
Self.BreakVariationSpinner.Value := 0.33;
935+
Self.BreakVariationSpinner := TLazSpinEdit.CreateEx(lPanel);
936+
Self.BreakVariationSpinner.Value := 33;
929937
Self.BreakVariationSpinner.MinValue := 0;
930-
Self.BreakVariationSpinner.MaxValue := 1;
931-
Self.BreakVariationSpinner.Increment := 0.05;
938+
Self.BreakVariationSpinner.MaxValue := 100;
939+
Self.BreakVariationSpinner.Increment := 5;
940+
Self.BreakVariationSpinner.ValueEmpty := False;
932941
Self.BreakVariationSpinner.Align := ELazAlign.Top;
933942
Self.BreakVariationSpinner.BorderSpacing.Left := 10;
934943
Self.BreakVariationSpinner.BorderSpacing.Right := 10;
@@ -991,17 +1000,21 @@ begin
9911000
Self.SleepLengthSpinner.OnChange := @Self.OnSleepChange;
9921001
Self.SleepLengthSpinner.AnchorHorizontally(Self.SleepTimeEdit, 60);
9931002

994-
Self.SleepVariationSpinner := TLazFloatSpinEdit.CreateEx(parent, 'Variation (%):', 'Edit the sleep variation.', 0, 0, 120);
995-
Self.SleepVariationSpinner.MinValue := 0.00;
996-
Self.SleepVariationSpinner.MaxValue := 0.30;
997-
Self.SleepVariationSpinner.Increment := 0.03;
1003+
Self.SleepVariationSpinner := TLazSpinEdit.CreateEx(parent, 'Variation (%):', 'Edit the sleep variation.', 0, 0, 120);
1004+
Self.SleepVariationSpinner.Value := 10;
1005+
Self.SleepVariationSpinner.MinValue := 0;
1006+
Self.SleepVariationSpinner.MaxValue := 30;
1007+
Self.SleepVariationSpinner.Increment := 3;
1008+
Self.SleepVariationSpinner.ValueEmpty := False;
9981009
Self.SleepVariationSpinner.OnChange := @Self.OnSleepChange;
9991010
Self.SleepVariationSpinner.AnchorHorizontally(Self.SleepLengthSpinner, 60);
10001011

1001-
Self.SleepLogoutSpinner := TLazFloatSpinEdit.CreateEx(parent, 'Logout chance (%):', 'Edit the sleep logout chance.', 0, 0, 120);
1002-
Self.SleepLogoutSpinner.MinValue := 0.00;
1003-
Self.SleepLogoutSpinner.MaxValue := 1.00;
1004-
Self.SleepLogoutSpinner.Increment := 0.10;
1012+
Self.SleepLogoutSpinner := TLazSpinEdit.CreateEx(parent, 'Logout chance (%):', 'Edit the sleep logout chance.', 0, 0, 120);
1013+
Self.SleepLogoutSpinner.Value := 65;
1014+
Self.SleepLogoutSpinner.MinValue := 0;
1015+
Self.SleepLogoutSpinner.MaxValue := 100;
1016+
Self.SleepLogoutSpinner.Increment := 5;
1017+
Self.SleepLogoutSpinner.ValueEmpty := False;
10051018
Self.SleepLogoutSpinner.OnChange := @Self.OnSleepChange;
10061019
Self.SleepLogoutSpinner.AnchorHorizontally(Self.SleepVariationSpinner, 60);
10071020

0 commit comments

Comments
 (0)