Simba Code:
program Fletch;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/Reflection/Reflection.simba}
{$i SRL-OSR\SRL\misc\findxp.simba}
{$I SRL-OSR\SRL\misc\SmartGraphics.simba}
const
OUTLINE_LOGS = 85;
OUTLINE_KNIFE = 60;
OUTLINE_LONGBOW = 68;
type
TProgress = record
Start, Current: Integer;
Name: String;
end;
TProgressArray = record
TProg: array of TProgress;
VariablesSet: boolean;
end;
var
PlayerProgress: Array of TProgressArray;
procedure SetupTProgress;
var
I: Integer;
begin
SetLength(PlayerProgress, HowManyPlayers);
For I:=0 to High(PlayerProgress)do
SetLength(PlayerProgress[I].TProg, 3);
end;
var
DoBreak: boolean;
SleepAfter, MinorBreak: Integer;
SleepTimer, BreakTimer: Integer;
procedure SetMinorBreak;
begin
MarkTime(BreakTimer);
MinorBreak := 1000*60*RandomRange(1, 130);
end;
Procedure SetSleepAfter;
begin
MarkTime(SleepTimer);
SleepAfter := 1000*60*60*RandomRange(7, 10);
end;
procedure DeclarePlayer;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
SetupTProgress;
DoBreak := True;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Active := True;
Players[0].Member := True;
Players[0].Strings[0] := 'e';
Players[0].Pin := '';
end;
var
GLOBAL_HOVERBANK: Boolean;
GLOBAL_DONE, GLOBAL_LVLS: Integer;
function BankTile: TPoint;
var
M: TPoint;
begin
M := R_GetTileGlobal;
Case Players[CurrentPlayer].Strings[0] of
'n': Result := Point(M.X, M.Y+1);
's': Result := Point(M.X, M.Y-1);
'w': Result := Point(M.X-1, M.Y);
'e': Result := Point(M.X+1, M.Y);
end;
end;
Procedure DB(S: String);
begin
Writeln('[SCRIPT] ' + S + ' [TimeStamp]: ' + timeRunning);
end;
function TillLevel(CurrentXP: Integer): Integer;
begin
Result := ConvertLvlToXP(ConvertXpToLvl(CurrentXP))-CurrentXP;
end;
Procedure handle_PendingPin;
begin
If InRange(CountColor(255, 42, 61, 454, 84), 700, 800) then
begin
DB('Pending pin -> click yes');
MouseBox(118, 137, 381, 154, mouse_Left);
WaitFunc(@BankScreen, 500+Random(200), 3000);
end;
end;
Procedure DrawBox(B: TBox);
begin
If (B.X1-20 < 1)or(B.Y1-20 < 1)then
Exit;
SMART_DrawBox(B);
end;
Procedure CleanBox(B: TBox);
begin
If (B.X1-20 < 1)or(B.Y1-20 < 1)then
Exit;
SMART_ClearCanvasArea(B);
end;
Procedure DrawPoint(P: TPoint; Dist: Integer);
begin
If (P.X-20 < 1)or(P.Y-20 < 1)then
Exit;
SMART_DrawBox(IntToBox(P.X-20, P.Y-20, P.X+20, P.Y+20));
end;
Procedure CleanPoint(P: TPoint; Dist: Integer);
begin
If (P.X-20 < 1)or(P.Y-20 < 1)then
Exit;
SMART_ClearCanvasArea(IntToBox(P.X-20, P.Y-20, P.X+20, P.Y+20));
end;
Procedure CMHere(left: Boolean);
var
x, y: Integer;
begin
GetMousePos(x, y);
DrawPoint(Point(X, Y), 5);
Mouse(x, y, 0, 0, left);
CleanPoint(Point(X, Y), 5);
end;
function hover_ChooseOption(Option: String): Boolean;
var
Index, MenuX, MenuY, MenuWidth, XOff, YOff: Integer;
Options: TStringArray;
Left: Boolean;
begin
Options := R_GetMenuOptions;
if (not R_IsMenuOpen) then
Exit;
Index := R_GetMenuIndex(Option, Options);
MenuX := SmartGetFieldInt(SmartCurrentTarget, 0, client_menuX) * client_menuX_Multiplier + 4;
MenuY := SmartGetFieldInt(SmartCurrentTarget, 0, client_menuY) * client_menuY_Multiplier + 4;
MenuWidth := SmartGetFieldInt(SmartCurrentTarget, 0, client_menuWidth) * client_menuWidth_Multiplier;
XOff := RandomRange(4, MenuWidth - 4);
YOff := RandomRange(20, 25) + (Index * 15);
if (MenuX + (MenuWidth div 2) > 765) then
begin
Left := True;
end;
if (MenuX - (MenuWidth div 2) < 0) then
begin
Left := False;
end;
if (Index = -1) then
begin
GetMousePos(MenuX, MenuY);
if (Left) then
MMouse(MenuX - 30 - MenuWidth + Random(10), MenuY + RandomRange(-2, 2), 2, 2)
else
MMouse(MenuX + 30 + MenuWidth + Random(10), MenuY + RandomRange(-2, 2), 2, 2);
Exit;
end;
MMouse(MenuX + XOff, MenuY + YOff, 2, 2);
Result := True;
end;
function hover_WaitChooseOption(Option: String; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (R_IsMenuOpen) then
begin
Hover_ChooseOption(Option);
Result := True;
Exit;
end;
Wait(20 + Random(20));
end;
end;
function didLevel: boolean;
begin
Result := CountColor(0, 181, 405, 366, 424) = 368;
end;
function interface_Fletch: boolean;
begin
Result := CountColor(128, 151, 361, 364, 382) = 408;
end;
function interface_EnterAmount: boolean;
begin
Result := (CountColor(0, 209, 391, 308, 409) = 277);
end;
function MouseOnScreen: boolean;
var
x, y: integer;
begin
GetMousePos(x, y);
Result := PointInBox(Point(x, y), IntToBox(0, 0, 760, 500));
end;
procedure Handle_MouseOffScreen;
begin
If MouseOnScreen then
MMouseOffClient('rand');
end;
procedure Handle_MightOffScreen;
begin
If Random(5) = 0 then
Handle_MouseOffScreen;
end;
procedure RandomizeActions;
begin
If Not LoggedIn then
Exit;
Case Random(1000)of
0: GameTab(TAB_INV);
1: GameTab(TAB_STATS);
3..100: Handle_MouseOffScreen;
101..106: compassMovement(0, 360, False);
end;
end;
procedure Handle_AfterClick;
begin
Case Random(8) of
0,1,2,3: SleepAndMoveMouse(200+Random(2000));
4: MakeCompass(Random(361));
5..7: Wait(100+Random(200));
end;
end;
function r_TileOnMS(tile: TPoint): Boolean;
begin
Result := (PointInBox(r_TileToMS(tile), IntToBox(MSX1, MSY1, MSX2, MSY2)));
end;
procedure Fail(FailedAT: String);
begin
Writeln('A function failed: ' + FailedAT);
LogOut;
end;
Procedure handle_Run;
begin
If R_GetRunEnergy > RandomRange(10, 30) then
If not R_IsRunOn then
begin
DB('Run -> On');
DrawBox(IntToBox(571, 127, 589, 148));
MouseBox(571, 127, 589, 148, Mouse_left);
CleanBox(IntToBox(571, 127, 589, 148));
end;
end;
function countInvSpot_Outline(inv: integer): integer;
var
CurBox: TBox;
begin
GameTab(TAB_INV);
CurBox := invBox(inv);
Result := (CountColor(65536, CurBox.X1, CurBox.Y1, CurBox.X2, CurBox.Y2));
end;
function countInv_Index(count_Outline: Integer): integer;
var
I: Integer;
begin
If Not LoggedIn then
Exit;
For I:=1 to 28 do
If countInvSpot_Outline(I) = count_Outline then
Inc(Result);
end;
function find_KnifeSpot: Integer;
var
I: Integer;
begin
gameTab(TAB_INV);
For I:=1 to 28 do
If countInvSpot_Outline(I) = OUTLINE_KNIFE then
Break;
If I = 29 then
Result := -1
else
Result := I;
DB('Found knife spot ' + ToStr(I));
end;
function Handle_PairItems: boolean;
var
Timer: Integer;
begin
If Not LoggedIn then
Exit;
If interface_Fletch then
begin
Result := True;
Exit;
end;
If Not InvMouse(find_KnifeSpot, MOUSE_LEFT)then
begin
Fail('Handle_Fletch - KnifeSpot');
Exit;
end;
Wait(20+Random(300));
Case CountInv_Index(OUTLINE_LOGS) of
1..26:
InvMouse(28, mouse_left);
27:
Case Random(10)of
0..5: InvMouse(2, MOUSE_LEFT);
6..8: InvMouse(5, MOUSE_LEFT);
9: InvMouse(6, MOUSE_LEFT);
end;
end;
DB('Found items, waiting for interface');
MarkTime(Timer);
While (TimeFromMark(Timer) < 2000)and(interface_Fletch = False) do
Wait(50+Random(200));
DB('Out of interface loop');
Result := interface_Fletch;
DB('Interface fletch > ' + ToStr(Result));
end;
function handle_FletchInterface: boolean;
begin
If Not interface_Fletch then
Exit;
Wait(150+Random(200));
MouseBox(209, 383, 299, 441, mouse_Right);
Result := r_waitChooseOption('Make X', 500+Random(400));
If Not Result then
DB('Make X? FletchInterface')
else
begin
Handle_MightOffScreen;
If Not WaitFunc(@interface_EnterAmount, 100, 1500)then
begin
fail('no Enter Amount?');
Result := False;
Exit;
end;
Handle_MightOffScreen;
typeSend(ToStr(RandomRange(27, 100)));
Handle_MightOffScreen;
end;
end;
function hover_Bank: boolean;
var
P: TPoint;
begin
If Not LoggedIn then
Exit;
Result := (r_IsUpText('Bank Bank Booth')or(R_IsMenuOpen));
If Result then
Exit;
P := r_TileToMS(BankTile);
MMouse(P.X, P.Y, 15, 15);
If r_waitUptext('Bank Bank booth', 100+Random(200))then
begin
DB('hover found');
Case Random(5) of
1..4:
begin
CMHere(False);
Hover_waitChooseOption('Bank Bank booth', 300+Random(500));
end;
end;
Result := True;
Exit;
end;
end;
Procedure UpdateTProgress;
begin
If Not LoggedIn then
Exit;
If Not PlayerProgress[CurrentPlayer].VariablesSet then
begin
PlayerProgress[CurrentPlayer].TProg[0].Name := 'XP Gained';
PlayerProgress[CurrentPlayer].TProg[0].Start := R_GetSkillExp(SKILL_FLETCHING);
PlayerProgress[CurrentPlayer].TProg[1].Name := 'Level Gained';
PlayerProgress[CurrentPlayer].TProg[1].Start := R_GetSkillLevel(SKILL_FLETCHING);
PlayerProgress[CurrentPlayer].TProg[2].Name := 'XP till level';
PlayerProgress[CurrentPlayer].TProg[2].Start := 0;
PlayerProgress[CurrentPlayer].VariablesSet := True;
end else
begin
PlayerProgress[CurrentPlayer].TProg[0].Current := R_GetSkillExp(SKILL_FLETCHING);
PlayerProgress[CurrentPlayer].TProg[1].Current := R_GetSkillLevel(SKILL_FLETCHING);
PlayerProgress[CurrentPlayer].TProg[2].Current := TillLevel(PlayerProgress[CurrentPlayer].TProg[0].Current);
PlayerProgress[CurrentPlayer].VariablesSet := True;
end;
end;
Procedure Print_Progress;
var
I, Ind: Integer;
S: TStringArray;
begin
UpdateTProgress;
SetLength(S, 1000);
S[0] := 'Sleep in: ' + MSToTime(SleepAfter-TimeFromMark(SleepTimer), Time_Short);
S[1] := 'Break in: ' + MSToTIme(MinorBreak-TimeFromMark(BreakTimer), Time_Short);
S[2] := '';
Ind := 3;
For I:=0 to High(PlayerProgress[CurrentPlayer].TProg)do
begin
S[Ind] := PlayerProgress[CurrentPlayer].TProg[I].Name + ': ' + ToStr(PlayerProgress[CurrentPlayer].TProg[I].Current - PlayerProgress[CurrentPlayer].TProg[I].Start);
Inc(Ind);
end;
SetLength(S, Ind);
SMART_ClearCanvasArea(IntToBox(0, 0, 207, 180));
For I:=0 to High(S)do
SMART_DrawText(10, 30+(I*13), 'upchars07', S[I], clYellow);
end;
Procedure wait_Fletching;
var
at_Logs: Integer;
Hover: Boolean;
begin
If Not LoggedIn then
Exit;
Handle_MightOffScreen;
If GLOBAL_HOVERBANK then
begin
at_Logs := RandomRange(1, 15);
DB('Will hover bank at ' + ToStr(at_Logs));
end;
repeat
Wait(150+Random(200));
Print_Progress;
If not Hover then
Handle_MouseOffScreen;
If ((GLOBAL_HOVERBANK) and (CountInv_Index(OUTLINE_LOGS) = at_Logs) and (Hover = False)) then
begin
DB('Time to hover bank..');
Hover := True;
If Not hover_Bank then
begin
DB('Failed to hover bank');
GLOBAL_HOVERBANK := False;
end;
end;
until(Not LoggedIn)or(CountInv_Index(OUTLINE_LOGS) = 0)or(didLevel);
If didLevel then
begin
DB('Lvl''d');
Inc(GLOBAL_LVLS);
If Random(5) = 0 then
begin
ClickToContinue;
ClickToContinue;
end;
GLOBAL_HOVERBANK := False;
Exit;
end;
If GLOBAL_HOVERBANK then
begin
DB('Done fletching, already hovering');
If (R_IsMenuOpen) then
begin
CMHere(True);
DB('Waiting for bank..');
waitFunc(@BankScreen, 100+Random(100), RandomRange(2000, 3000));
end else
DB('Hovering failed..');
end;
GLOBAL_HOVERBANK := False;
end;
function find_Bank: boolean;
var
P: TPoint;
begin
If Not LoggedIn then
Exit;
Result := (bankScreen);
If Result then
Exit;
P := r_TileToMS(BankTile);
MMouse(P.X, P.Y, 15, 15);
If r_waitUptext('Bank Bank booth', 100+Random(200))then
begin
DB('Bank found');
Case Random(5) of
0: CMHere(True);
1..4:
begin
CMHere(False);
r_waitChooseOption('Bank Bank booth', 300+Random(500));
end;
end;
Result := waitFunc(@BankScreen, 100+Random(100), 3000);
Exit;
end;
end;
function myWithdraw: boolean;
var
B: TBox;
S: String;
begin
B := BankIndexToMSBox(BankPointToBankIndex(Point(7, 0)));
case Random(10)of
0:
begin
Result := Withdraw(7, 0, 27+Random(100));
Exit;
end;
1..4: S := 'All Maple';
4..9: S := 'one Maple';
end;
MouseBox(B.X1, B.Y1, B.X2, B.Y2, MOUSE_RIGHT);
Result := R_WaitChooseOption(S, 500+Random(300));
end;
Procedure Handle_Bank;
var
C: Integer;
begin
repeat
Inc(C);
handle_PendingPin;
If PinScreen then
InPin(Players[CurrentPlayer].Pin);
until(C > 4)or(find_Bank);
If C > 4 then
begin
Fail('Failed opening bank');
Exit;
end else
DB('Opened bank in ' + ToStr(C) + ' try(ies)');
DB('Depositing items..');
IncEx(GLOBAL_DONE, countInv_Index(OUTLINE_LONGBOW));
Deposit(2, 28, True);
DB('Withdrawing items..');
if not myWithdraw then
begin
fail('withdrawpointEx');
Exit;
end;
DB('Closing interface..');
CloseBank;
Wait(250+Random(500));
end;
Procedure SetupPlayer;
begin
If R_GetCameraZ > -1250 then
begin
DB('Camera -> High');
SetAngle(SRL_ANGLE_HIGH);
end;
handle_Run;
end;
procedure handle_Break;
var
SleepFor, Timer: Integer;
begin
If Not DoBreak then
Exit;
If TimeFromMark(SleepTimer) > SleepAfter then
SleepFor := RandomRange(1000*60*60*6, 1000*60*60*9);
If TimeFroMMark(BreakTimer) > MinorBreak then
SleepFor := RandomRange(1000*60*1, 1000*60*90);
If SleepFor > 0 then
begin
DB('handle_Break -> Break');
LogOut;
If SleepFor > 1000*60*90 then
SetSleepAfter
else
SetMinorBreak;
MarkTime(Timer);
repeat
ClearDebug;
If SleepFor > 1000*60*90 then
DB('Sleeping for another ' + MSToTime(SleepFor-TimeFromMark(Timer), Time_Short))
else
DB('Breaking for another ' + MSToTime(SleepFor-TimeFromMark(Timer), Time_Short));
Sleep(1000);
SleepFor := SleepFor - 1000;
until(TimeFromMark(Timer) > SleepFor)or(IsFKeyDown(2));
LoginPlayer;
SetupPlayer;
end;
end;
begin
setupSRL();
SetupReflection;
DeclarePlayer;
Wait(1000*60*60*6);
If Not LoggedIn then
begin
DB('Not LoggedIn -> LoginPlayer');
LoginPlayer;
end;
SetupPlayer;
SetSleepAfter;
SetMinorBreak;
repeat
handle_Break;
handle_Run;
Print_Progress;
If Random(12) = 0 then
GLOBAL_HOVERBANK := True;
If CountInv_Index(OUTLINE_LOGS) > 0 then
begin
DB('Logs > 0');
Handle_PairItems;
If Handle_FletchInterface then
wait_Fletching;
end;
handle_Break;
If (CountInv_Index(OUTLINE_LOGS) = 0)and(LoggedIn) then
begin
DB('Logs = 0');
Handle_Bank;
end;
until(AllPlayersInactive);
end.