Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 12.86 KB | None | 0 0
  1. program ApeAtollCourse;
  2. {$DEFINE SMART}
  3. {$i SRL/SRL.scar}
  4. {$i SRL/SRL/misc/stats.simba}
  5. {$i Reflection/Reflection.simba}
  6.  
  7. {==============================================================================]
  8.  
  9.                               ADVANCED GNOME AGILITY
  10.                                      by enoyhs
  11.                                   24th April 2011
  12.  
  13. {==============================================================================}
  14.  
  15. {==============================================================================]
  16.   x Set up lines from 20 to 27.
  17. {==============================================================================}
  18.  
  19. const
  20.   USERNAME        = '';
  21.   PASSWORD        = '';
  22.  
  23.   SRLStats_Username = '';
  24.   SRLStats_Password = '';
  25.  
  26.   MINUTES_TO_RUN  = 24 * 60;
  27.   BREAK_EVERY     = 45; // Break every x +/- Random(10) for ~5mins
  28.  
  29. const
  30.   VERSION         = '0.4';
  31.  
  32.   OBSTACLE_COUNT  = 7;
  33.   LOG_BALANCE     = 0;
  34.   OBSTACLE_NET    = 1;
  35.   TREE_BRANCH     = 2;
  36.   TREE            = 3;
  37.   SIGNPOST        = 4;
  38.   POLE            = 5;
  39.   BARRIER         = 6;
  40.  
  41.   OBSTACLE_TIMEOUT = 15;
  42.  
  43. type
  44.   TObstacle = record
  45.     Name: string;
  46.     ClickTile: TTile;
  47.     Plane: Integer;
  48.     Colors: TIntegerArray;
  49.     CompassDir: Double;
  50.     UpText: TStringArray;
  51.   end;
  52.  
  53. var
  54.   Obstacles: Array [0..OBSTACLE_COUNT] of TObstacle;
  55.   StartTile: TTile;
  56.   StartXP, LastXP: Integer;
  57.   FailTimer, NextBreak: Integer;
  58.   FailCounter, CurrentObstacle: Integer;
  59.   DTM: Integer;
  60.   TotalBreaks: Integer;
  61.  
  62. procedure InitScript;
  63. begin
  64.   LampSkill := 'agility';
  65.  
  66.   with Obstacles[LOG_BALANCE] do
  67.   begin
  68.     Name        := 'Log balance';
  69.     ClickTile   := Tile(2474, 3435);
  70.     Plane       := 0;
  71.     Colors      := [932711, 532794];
  72.     CompassDir  := 230;
  73.     UpText      := ['k-a'];
  74.   end;
  75.  
  76.   with Obstacles[OBSTACLE_NET] do
  77.   begin
  78.     Name        := 'Obstacle net';
  79.     ClickTile   := Tile(2472, 3423);
  80.     Plane       := 0;
  81.     Colors      := [465969, 400175, 2570310, 790806];
  82.     CompassDir  := 230;
  83.     UpText      := ['b-o'];
  84.   end;
  85.  
  86.   with Obstacles[TREE_BRANCH] do
  87.   begin
  88.     Name        := 'Tree branch';
  89.     ClickTile   := Tile(2473, 3422);
  90.     Plane       := 1;
  91.     Colors      := [1052945, 1654868, 2051687];
  92.     CompassDir  := 90;
  93.     UpText      := ['mb T', 'e b'];
  94.   end;
  95.  
  96.   with Obstacles[TREE] do
  97.   begin
  98.     Name        := 'Tree';
  99.     ClickTile   := Tile(2473, 3419);
  100.     Plane       := 2;
  101.     Colors      := [2184045, 1059383];
  102.     CompassDir  := 90;
  103.     UpText      := ['b-u'];
  104.   end;
  105.  
  106.   with Obstacles[SIGNPOST] do
  107.   begin
  108.     Name        := 'Signpost';
  109.     ClickTile   := Tile(2478, 3418);
  110.     Plane       := 3;
  111.     Colors      := [4290710, 4554655, 6137807];
  112.     CompassDir  := 90;
  113.     UpText      := ['n-a'];
  114.   end;
  115.  
  116.   with Obstacles[POLE] do
  117.   begin
  118.     Name        := 'Pole';
  119.     ClickTile   := Tile(2485, 3427);
  120.     Plane       := 3;
  121.     Colors      := [4475727, 4344141, 1052945];
  122.     CompassDir  := 0;
  123.     UpText      := ['g-t'];
  124.   end;
  125.  
  126.   with Obstacles[BARRIER] do
  127.   begin
  128.     Name        := 'Barrier';
  129.     ClickTile   := Tile(2486, 3434);
  130.     Plane       := 3;
  131.     Colors      := [11066877, 1521230];
  132.     CompassDir  := 0;
  133.     UpText      := ['p-o'];
  134.   end;
  135. end;
  136.  
  137. procedure AntiBan;
  138. begin
  139.   case random(10000) of
  140.       0..5: HoverSkill('agility',false);
  141.       6..8: RandomRClick;
  142.      9..10: PickupMouse;
  143.     11..30: RandomMovement;
  144.   end;
  145. end;
  146.  
  147. procedure CheckRandoms;
  148. begin
  149.   R_FindRandoms;
  150.   FindNormalRandoms;
  151. end;
  152.  
  153. function WaitToComplete(Obstacle: TObstacle): boolean;
  154. var
  155.   MyPos: TTile;
  156. begin
  157.   Result := False;
  158.   FailTimer := GetSystemTime;
  159.   Wait(RandomRange(1000, 1500));
  160.   if (IsIdle) or ((GetMyPos = StartTile) and (not FlagPresent)) then
  161.   begin
  162.     if not (((CurrentObstacle = TREE_BRANCH) or (CurrentObstacle = TREE)) and (not IsIdle))  then
  163.     begin
  164.       WriteLn('Did not even try to do anything for a second.. Maybe just failed, or just a lag..');
  165.       Exit;
  166.     end;
  167.   end;
  168.   if (CurrentObstacle = LOG_BALANCE) and (not WaitToMove(RandomRange(500, 800))) then
  169.   begin
  170.     WriteLn('Did not even try to do anything for a second.. Maybe just failed, or just a lag..');
  171.     Exit;
  172.   end;
  173.  
  174.   MakeCompass(Obstacles[(CurrentObstacle + 1) mod OBSTACLE_COUNT].CompassDir + Random(100) * 0.1);
  175.   repeat
  176.     wait(RandomRange(50, 100));
  177.     AntiBan;
  178.     if (ClickToContinue) then
  179.     begin
  180.       Writeln('Oops! Clicked on NPC!');
  181.       Exit;
  182.     end;
  183.     MyPos := GetMyPos;
  184.     case Obstacle.Name of
  185.       'Log balance':  Result := (MyPos = Tile(2474, 3429)) and (GetPlaneIndex = 0);
  186.       'Obstacle net': Result := (GetPlaneIndex = 1);
  187.       'Tree branch':  Result := (GetPlaneIndex = 2);
  188.       'Tree':         Result := (MeInBox(IntToBox(2472, 3420, 2477, 3418))) and (GetPlaneIndex = 3);
  189.       'Signpost':     Result := (MyPos = Tile(2484, 3418)) and (GetPlaneIndex = 3) and (not CharacterAnimating);
  190.       'Pole':         Result := (MeInBox(IntToBox(2482, 3435, 2488, 3432))) and (GetPlaneIndex = 3);
  191.       'Barrier':      Result := (MyPos = Tile(2485, 3436)) and (GetPlaneIndex = 0) and (not CharacterAnimating);
  192.       else            Exit;
  193.     end;
  194.   until (Result) or (GetSystemTime > FailTimer + OBSTACLE_TIMEOUT * 1000);
  195.  
  196.   if ((GetSystemTime > FailTimer + OBSTACLE_TIMEOUT * 1000)) then
  197.     writeln('Could not finish obstacle in ' + IntToStr(OBSTACLE_TIMEOUT) + ' seconds:' + Obstacle.Name);
  198. end;
  199.  
  200. function FindNextObstacle: Integer;
  201. var MyPos: TTile;
  202. begin
  203.   MyPos := GetMyPos;
  204.   Result := LOG_BALANCE;
  205.   if (MeInBox(IntToBox(2470, 3429, 2477, 3426))) and (GetPlaneIndex = 0) then
  206.     Result := OBSTACLE_NET
  207.   else if (MeInBox(IntToBox(2471, 3424, 2476, 3422))) and (GetPlaneIndex = 1) then
  208.     Result := TREE_BRANCH
  209.   else if (MeInBox(IntToBox(2472, 3421, 2477, 3418))) and (GetPlaneIndex = 2) then
  210.     Result := TREE
  211.   else if (MeInBox(IntToBox(2472, 3420, 2477, 3418))) and (GetPlaneIndex = 3) then
  212.     Result := SIGNPOST
  213.   else if (MeInBox(IntToBox(2484, 3421, 2487, 3418))) and (GetPlaneIndex = 3) then
  214.     Result := POLE
  215.   else if (MeInBox(IntToBox(2482, 3435, 2488, 3432))) and (GetPlaneIndex = 3) then
  216.     Result := BARRIER
  217. end;
  218.  
  219. function ClickObstacle(Obstacle: TObstacle): boolean;
  220. var
  221.   MS: TPoint;
  222.   TPA, tTPA: TPointArray;
  223.   ATPA: T2DPointArray;
  224.   ObstacleClicked, ColorFound: Boolean;
  225.   i, j, adj, n: Integer;
  226. begin
  227.   Result := False;
  228.   if not LoggedIn then
  229.   begin
  230.     WriteLn('Not logged in!');
  231.     Exit;
  232.   end;
  233.   ObstacleClicked := False;
  234.   ColorFound := False;
  235.  
  236.   CheckRandoms;
  237.  
  238.   MakeCompass(Obstacle.CompassDir + Random(100) * 0.1);
  239.  
  240.   if (Obstacle.Name = 'Pole') and (GetMyPos <> Tile(2486, 3418)) then
  241.   begin
  242.     MS := TileToMS(Tile(2486, 3418), 0);
  243.     Mouse(MS.X - 2, MS.Y - 2, 2, 2, True);
  244.   end;
  245.  
  246.   if (not TileOnMS(Obstacle.ClickTile, 0)) then
  247.   begin
  248.     WalkToTile(Obstacle.ClickTile, 1, 1);
  249.  
  250.     WaitToMove(300 + Random(50));
  251.     while CharacterMoving do
  252.       Wait(100);
  253.   end;
  254.  
  255.   StartTile := GetMyPos;
  256.   adj := 75;
  257.  
  258.   MS := TileToMS(Obstacle.ClickTile, 0);
  259.   MMouse(MS.X, MS.Y, 0, 0);
  260.   if TileOnMS(Obstacle.ClickTile, 0) then
  261.   begin
  262.     for i := 0 to High(Obstacle.Colors) do
  263.     begin
  264.       FindColorsSpiralTolerance(MS.X, MS.Y, tTPA, Obstacle.Colors[i],
  265.                               Max(0, MS.X - adj), Max(0, MS.Y - adj), Min(MS.X + adj, MSX2), Min(MS.Y + adj, MSY2), 2);
  266.       TPA := CombineTPA(TPA, tTPA);
  267.     end;
  268.     ATPA := SplitTPA(TPA, Max(5 - (FailCounter div 3), 0));
  269.     if (Length(ATPA) > 0) then
  270.     begin
  271.       SortATPAFrom(ATPA, Point(MS.X, MS.Y));
  272.       n := High(ATPA);
  273.       for j := 0 to n do begin
  274.         if (CurrentObstacle <> FindNextObstacle) then
  275.         begin
  276.           WriteLn('Already finished: ' + Obstacle.Name);
  277.           Exit;
  278.         end;
  279.         MS := MiddleTPA(ATPA[j]);
  280.         MMouse(MS.X, MS.Y, Random(3), Random(3));
  281.         if r_WaitUpTextMulti(Obstacle.UpText, 100 + random(50)) then
  282.         begin
  283.           GetMousePos(MS.X, MS.Y);
  284.           Mouse(MS.X, MS.Y, 0, 0, True);
  285.           ObstacleClicked := DidRedClick;
  286.           Break;
  287.         end;
  288.       end;
  289.     end else
  290.     begin
  291.       Writeln('Color not found: ' + Obstacle.Name);
  292.       Exit;
  293.     end;
  294.   end else
  295.   begin
  296.     WriteLn('Not visible: ' + Obstacle.Name);
  297.     Exit;
  298.   end;
  299.  
  300.   if not ObstacleClicked then
  301.   begin
  302.     Writeln('Uptext not found: ' + Obstacle.Name);
  303.     Exit;
  304.   end;
  305.  
  306.   Result := WaitToComplete(Obstacle);
  307. end;
  308.  
  309. function SolveObstacle: boolean;
  310. begin
  311.   Result := False;
  312.   if not LoggedIn then
  313.   begin
  314.     WriteLn('Not logged in!');
  315.     Exit;
  316.   end;
  317.  
  318.   CheckRandoms;
  319.  
  320.   WriteLn('Next obstacle: ' + Obstacles[CurrentObstacle].Name);
  321.  
  322.   Result := ClickObstacle(Obstacles[CurrentObstacle]);
  323.  
  324.   if Result = True then
  325.   begin
  326.     FailCounter := 0;
  327.     CurrentObstacle := (CurrentObstacle + 1) mod OBSTACLE_COUNT;
  328.   end else
  329.   begin
  330.     FailCounter := FailCounter + 1;
  331.     CurrentObstacle := FindNextObstacle;
  332.   end;
  333.  
  334. end;
  335.  
  336. procedure ProgressReport;
  337. var
  338.   Me: TMe;
  339. begin
  340.   ClearDebug;
  341.   Me := GetMe;
  342.   WriteLn('=== ADVANCED GNOME AGILITY COURSE ' + VERSION + ' ~ By enoyhs =======');
  343.   WriteLn(' Experience gained: ' + GroupDigits(Me.Experience[SKILL_AGILITY] - StartXP, ','));
  344.   WriteLn(' XP/H             : ' + GroupDigits(
  345.                                   Round((Me.Experience[SKILL_AGILITY] - StartXP) / (GetTimeRunning/3600000.0)), ',') );
  346.   WriteLn(' Time running     : ' + TimeRunning);
  347.   WriteLn('====================================');
  348.   WriteLn('');
  349.  
  350.   stats_Commit;
  351. end;
  352.  
  353. // Credits to HobboBobbo for this procedure, thanks!
  354. procedure PrintOnSmart(TP: TStringArray; Placement: TPoint; Colour, Shadow: integer);
  355. var
  356.   mx, my, Pic, I, B, H, TPH, Numb: Integer;
  357.   TTP: TPointArray;
  358.   Canvas: TCanvas;
  359. begin
  360.   SmartSetDebug(True);
  361.   GetClientDimensions(mx,my);
  362.   Pic := BitmapFromString(mx,my,'');
  363.   TPH := High(TP);
  364.   for I := 0 to TPH do
  365.   begin
  366.     TTP := LoadTextTPA(TP[i], UpChars, H);
  367.     for B := 0 to High(TTP) do
  368.     begin
  369.       try
  370.         Numb := ((I + 1) * 13);
  371.         FastSetPixel(Pic, TTP[b].x + 1, TTP[b].y + Numb + 1, Shadow);
  372.         FastSetPixel(Pic, TTP[b].x, TTP[b].y + Numb, Colour);
  373.       except
  374.       end;
  375.     end;
  376.   end;
  377.   Canvas := TCANVAS.Create;
  378.   Canvas.Handle := SmartGetDebugDC;
  379.   DrawBitmap(Pic, Canvas, Placement.x, Placement.y);
  380.   FreeBitmap(Pic);
  381. end;
  382.  
  383. procedure PaintReport;
  384. var Exp: integer;
  385.     Me: TMe;
  386. begin
  387.   Me := GetMe;
  388.   Exp := Me.Experience[SKILL_AGILITY] - StartXP;
  389.  
  390.   PrintOnSmart(['Advanced Gnomes ' + VERSION + ' ~ By enoyhs'],Point(20, 25), 16777215, 8388736);
  391.   PrintOnSmart(['Running for: ' + TimeRunning,
  392.                 'Next break in: ' + MsToTime(NextBreak - GetTimeRunning, Time_Formal),
  393.                 'Experience: ' + GroupDigits(Exp, ','),
  394.                 'Exp/hour: ' + GroupDigits(Round(Exp / (GetTimeRunning / 3600000.0)), ',')
  395.                 ], Point(20,55), 16777215, 8388736);
  396.  
  397. end;
  398.  
  399. procedure DoBreak;
  400. var Timer: Integer;
  401. begin
  402.   Logout;
  403.   Timer := GetSystemTime + 6000 + Random(4 * 60 * 1000);
  404.   while (GetSystemTime < Timer) do
  405.   begin
  406.     writeln('Time left till we continue: ' + MsToTime(Timer - GetSystemTime, Time_Short));
  407.     Wait(10000);
  408.     if (LoggedIn) then
  409.       Break;
  410.   end;
  411.   LogInPlayer;
  412.   R_FindRandoms;
  413.   Wait(RandomRange(3000,4000));  //Give time to load before continuing script
  414.   Inc(TotalBreaks);
  415. end;
  416.  
  417. procedure EndScript;
  418. begin
  419.   stats_SetVariable('Agility EXP (Gained)', R_GetSkillExperience(SKILL_AGILITY) - StartXP);
  420.   ProgressReport;
  421.   LogOut;
  422. end;
  423.  
  424. begin
  425.   AddOnTerminate('EndScript');
  426.   Smart_Signed := true;
  427.   Smart_Members := true;
  428.   Smart_Server := 96;
  429.   SetupSRL;
  430.   NumberOfPlayers(1);
  431.   CurrentPlayer := 0;
  432.   Players[0].Name := USERNAME;
  433.   Players[0].Pass := PASSWORD;
  434.   Players[0].Active:= True;
  435.  
  436.   if (SRLStats_Username = '') and (SRLStats_Password = '') then
  437.     SetupSRLStats(45, 'enoyhsDefault', 'enoyhs')
  438.   else
  439.     SetupSRLStats(45, SRLStats_Username, SRLStats_Password);
  440.   LogInPlayer;
  441.  
  442.   ClearDebug;
  443.  
  444.   InitScript;
  445.  
  446.   SetAngle(False);
  447.   StartXP := R_GetSkillExperience(SKILL_AGILITY);
  448.   LastXP := StartXP;
  449.   CurrentObstacle := FindNextObstacle;
  450.  
  451.   NextBreak := GetTimeRunning + (BREAK_EVERY * 60 * 1000) + (Random(10) * 60 * 1000) + Random(60 * 1000);
  452.  
  453.   while GetTimeRunning < MINUTES_TO_RUN * 60 * 1000 do begin
  454.     if (CurrentObstacle = LOG_BALANCE) then PaintReport;
  455.     CheckRandoms;
  456.     if (GetTimeRunning > NextBreak) or (not LoggedIn) or (LobbyScreen) then
  457.     begin
  458.       DoBreak;
  459.       Wait(1000);
  460.       NextBreak := GetTimeRunning + (BREAK_EVERY * 60 * 1000) + (Random(10) * 60 * 1000) + Random(60 * 1000);
  461.     end;
  462.     if (FailCounter > 20) then
  463.       TerminateScript;
  464.     if (FailCounter > 0) and (FailCounter mod 5 = 0) then
  465.     begin
  466.       WalkToTile(GetMyPos, 3, 0);
  467.       SetAngle(False);
  468.     end;
  469.     if (SolveObstacle) then
  470.       ProgressReport;
  471.     Wait(100 + Random(100));
  472.   end;
  473. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement