Simba Code:
program GateDoorHandler
{$DEFINE SMART}
{$i Aerolib/Aerolib.simba}
{$i Reflection/Reflection.simba}
{
Gate and Door Handler
Author: Dissimulo (https://villavu.com/forum/member.php?u=160877)
Last Update: 21/05/2016
Version: 2.0
Category: Utility
Description: Finds the Gate or Door, then uses the objects orientation to
determine the color search area, then clicks on the object
Includes: Reflection
Features:
- Reflection (https://villavu.com/forum/showthread.php?t=111662)
- Aerolib (https://villavu.com/forum/showthread.php?t=108953)
- Simple SMART paint
Versions:
- 2.0 (21/05/2016)
Changed search area, and added clicking
- 1.0 (20/05/2016)
Cleaned up for the public
Credits:
- Kyle (Lape Reflection)
- Flight (Aerolib)
- Cynic (ACA Remake)
}
var MyGuy: TReflectLocalPlayer;
function SRLGaussRand(mean, dev:Extended): Extended;
var
len: Double;
function __random(): Double;
begin
Result := MaxE(Random(),1.0e-14);
end;
begin
len := dev * Sqrt(-2 * Ln(__random()));
Result := mean + len * Cos(2 * PI * __random());
end;
function GateDoorHandler(GDTile: TTile; Color, Tolerence: Integer; Hue, Sat: Extended; GDUptext: String; DrawBounds: Boolean): Boolean;
var
i, j, k, Orientation, tmpCTS, arL: integer;
PointUL, PointBR, tmpTPoint: TPoint;
tmpTBox: TBox;
TileArray: Array[0..3] of Array [0..3] of TPoint;
PointTileArray: Array[0..1] of Array [0..1] of TPoint;
GDObject: TReflectObject;
arC: TIntegerArray;
tmpTPA, tmpTPAx, tmpTPAy, arP: TPointArray;
tmpATPA, tmpATPAcolor: Array of TPointArray;
begin
tmpCTS := GetToleranceSpeed();
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(Hue, Sat);
GDObject.GetAt(objBoundary, GDTile);
if GDObject.Reference = 0 then
begin
Result := False;
Exit;
end;
case GDObject.GetOrientation of
1: begin //West
for j := 0 to 3 do
begin
for k := 0 to 2 do
begin
TileArray[j][k] := Point((GDObject.GetTile.X + 1 - j), (GDObject.GetTile.Y + 1 - k));
end;
end;
for j := 0 to 1 do
begin
for k := 0 to 1 do
begin
PointTileArray[j][k] := MiddleTPA([TReflectionTiles.TileToMS(TileArray[j][k]), TReflectionTiles.TileToMS(TileArray[j+2][k+1]),
TReflectionTiles.TileToMS(TileArray[j+2][k]), TReflectionTiles.TileToMS(TileArray[j][k+1])]);
end;
end;
end;
2: begin //North
for j := 0 to 2 do
begin
for k := 0 to 3 do
begin
TileArray[j][k] := Point((GDObject.GetTile.X - 1 + j), (GDObject.GetTile.Y - 1 + k));
end;
end;
for j := 0 to 1 do
begin
for k := 0 to 1 do
begin
PointTileArray[j][k] := MiddleTPA([TReflectionTiles.TileToMS(TileArray[j][k]), TReflectionTiles.TileToMS(TileArray[j+1][k+2]),
TReflectionTiles.TileToMS(TileArray[j+1][k]), TReflectionTiles.TileToMS(TileArray[j][k+2])]);
end;
end;
end;
4: begin //East
for j := 0 to 3 do
begin
for k := 0 to 2 do
begin
TileArray[j][k] := Point((GDObject.GetTile.X - 1 + j), (GDObject.GetTile.Y + 1 - k));
end;
end;
for j := 0 to 1 do
begin
for k := 0 to 1 do
begin
PointTileArray[j][k] := MiddleTPA([TReflectionTiles.TileToMS(TileArray[j][k]), TReflectionTiles.TileToMS(TileArray[j+2][k+1]),
TReflectionTiles.TileToMS(TileArray[j+2][k]), TReflectionTiles.TileToMS(TileArray[j][k+1])]);
end;
end;
end;
8: begin //South
for j := 0 to 2 do
begin
for k := 0 to 3 do
begin
TileArray[j][k] := Point((GDObject.GetTile.X - 1 + j), (GDObject.GetTile.Y + 1 - k));
end;
end;
for j := 0 to 1 do
begin
for k := 0 to 1 do
begin
PointTileArray[j][k] := MiddleTPA([TReflectionTiles.TileToMS(TileArray[j][k]), TReflectionTiles.TileToMS(TileArray[j+1][k+2]),
TReflectionTiles.TileToMS(TileArray[j+1][k]), TReflectionTiles.TileToMS(TileArray[j][k+2])]);
end;
end;
end;
end;
tmpTPA := [PointTileArray[0][0], PointTileArray[0][1], PointTileArray[1][1], PointTileArray[1][0]];
tmpTPAx := CopyTPA(tmpTPA);
SortTPAByX(tmpTPAx, True);
tmpTPAy := CopyTPA(tmpTPA);
SortTPAByY(tmpTPAy, True);
PointUL := Point(Round((tmpTPAx[0].X + tmpTPAx[1].X) / 2), Round((tmpTPAy[0].Y + tmpTPAy[1].Y) / 2));
PointBR := Point(Round((tmpTPAx[2].X + tmpTPAx[3].X) / 2), Round((tmpTPAy[2].Y + tmpTPAy[3].Y) / 2));
tmpTBox := PointToBox(PointUL, PointBR);
if (PointInBox(PointUL, intToBox(MSX1, MSY1, MSX2, MSY2)) and PointInBox(PointBR, intToBox(MSX1, MSY1, MSX2, MSY2)) and DrawBounds) then
begin
Reflect.Smart.Graphics.DrawBox(PointUL.X, PointUL.Y, PointBR.X, PointBR.Y, False, clYellow);
end;
if GDObject.IsOnMS then
begin
if not (FindColorsTolerance(arP, Color, PointUL.X, PointUL.Y, PointBR.X, PointBR.Y, Tolerence)) then
begin
Writeln('Failed to find the color, no result.');
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.2, 0.2);
Result := False;
Exit;
end else
begin
tmpTPoint := MiddleTPA(arP);
tmpTPoint := Point((tmpTPoint.X + Round(SRLGaussRand(0, 2))), (tmpTPoint.Y + Round(SRLGaussRand(0, 2))));
if not PointInTPA(tmpTPoint, arP) then
begin
SortTPAFrom(arP, tmpTPoint);
tmpTPoint := arP[0];
end;
if DrawBounds then
begin
Reflect.Smart.Graphics.DrawTPA(arP);
Reflect.Smart.Graphics.DrawCircle(tmpTPoint, 1, clBlue, True);
end;
end;
humanMMouse(tmpTPoint, 0, 0);
Wait(100 + Round(SRLGaussRand(0, 6)));
if TReflectionText.IsUpText(GDUptext) then
fastClick(1);
if waitFunc(@didRedClick, 100 + Round(SRLGaussRand(0, 6)), 2000) then
begin
Reflect.Smart.Graphics.Clear;
repeat
wait(100 + Round(SRLGaussRand(0, 6)));
GDObject.GetAt(objBoundary, GDTile);
until(GDObject.Reference = 0);
if not (GDObject.Reference = 0) then
begin
Result := False;
Exit;
end;
end;
end;
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.2, 0.2);
Result := True;
end;
procedure OnExit; //release DTMs, BMPs and other stuff on script closure
begin
Writeln('Ending Disimulo''s GateDoorHandler');
Reflect.Smart.Graphics.Clear;
end;
begin
initAL();
Reflect.Setup;
AddOnTerminate('OnExit');
Reflect.Smart.Graphics.Clear;
MyGuy.Username := 'USERNAME';
MyGuy.Password := 'PASSWORD';
MyGuy.Active := True;
MyGuy.Login;
repeat
wait(400);
Reflect.Smart.Graphics.Clear;
GateDoorHandler(Point(3236, 3296), 344160, 9, 0.05, 1.26, 'Open', True);
GateDoorHandler(Point(3241, 3301), 344160, 9, 0.05, 1.26, 'Open', True);
GateDoorHandler(Point(3261, 3321), 344160, 9, 0.05, 1.26, 'Open', True);
GateDoorHandler(Point(3198, 3282), 344160, 9, 0.05, 1.26, 'Open', True);
//Writeln(MyGuy.GetTile);
until(False);
end.