Skip to content

Commit

Permalink
feat(house): finished the house teleports framework
Browse files Browse the repository at this point in the history
- also updated the example with more info and teleports usage example
  • Loading branch information
Torwent committed Dec 21, 2024
1 parent 086bb45 commit cbf041c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 28 deletions.
96 changes: 69 additions & 27 deletions optional/handlers/house/house.simba
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The core record used to handle navigating a POH.
Walker: TRSWalkerV2;

Objects: array [EHouseObject] of TRSObjectV2;
Teleports: array [EHouseTeleport] of TRSObjectV2;

Downscale: Int32;
Similarity: Double;
Expand All @@ -79,25 +80,47 @@ The core record used to handle navigating a POH.

function THouseHandler.Position(): TPoint; forward;

(*
## POH.Setup()
```pascal
procedure THouseHandler.Setup();
```
Method you need to use at the start of your script after the user has already configured his house
with `TScriptForm.CreateHouseBuilder()`.
*)
procedure THouseHandler.Setup(downscale: Int32 = 8);

procedure THouseHandler._SetupTeleport(obj: EHouseObject; coordinate: TPoint; rotation: Int32; teleport: EHouseTeleport);
begin
if Self.Teleports[teleport].Coordinates <> [] then
begin
Self.Teleports[teleport].Coordinates += coordinate;
Self.Teleports[teleport].Rotations += rotation;
Exit;
end;

Self.Teleports[teleport].SetupCoordinates([coordinate]);
Self.Teleports[teleport].Size := obj.GetSize();
Self.Teleports[teleport].Rotations := [rotation];
Self.Teleports[teleport].SetupUpText(teleport.GetUpText());
Self.Teleports[teleport].Finder := teleport.GetFinder();
Self.Teleports[teleport].Walker := @Self.Walker;
end;

procedure THouseHandler._SetupObject(obj: EHouseObject; coordinate: TPoint; rotation: Int32);
begin
if Self.Objects[obj].Coordinates <> [] then
begin
Self.Objects[obj].Coordinates += coordinate;
Self.Objects[obj].Rotations += rotation;
Exit;
end;

Self.Objects[obj].SetupCoordinates([coordinate]);
Self.Objects[obj].Size := obj.GetSize();
Self.Objects[obj].Rotations := [rotation];
Self.Objects[obj].SetupUpText(obj.GetUpText());
Self.Objects[obj].Finder := obj.GetFinder();
Self.Objects[obj].Walker := @Self.Walker;
end;

procedure THouseHandler.SetupObjects();
var
minimapImage, minimapSample: TMufasaBitmap;
idx, coordinate: TPoint;
room: THouseRoom;
obj: EHouseObject;
begin
if Self.IsSetup then Exit;
if Self.Sample.Amount = 0 then Self.Sample.Amount := 2;
if Self.Sample.Radius = 0 then Self.Sample.Radius := 67;

for idx.Y := 0 to Self.Loader.AMOUNT-1 do
for idx.X := 0 to Self.Loader.AMOUNT-1 do
begin
Expand All @@ -108,23 +131,42 @@ begin
coordinate := obj.RotateOffset(Self.Loader.SIZE, room.Rotation);
coordinate += idx * Self.Loader.SIZE;

if Self.Objects[obj].Coordinates <> [] then
begin
Self.Objects[obj].Coordinates += coordinate;
Self.Objects[obj].Rotations += room.Rotation;
Continue;
case obj of
EHouseObject.LEFT_PORTAL, EHouseObject.LEFT_AMULET:
Self._SetupTeleport(obj, coordinate, room.Rotation,
Self.Loader.TeleportRooms[idx.Y,idx.X].Left);

EHouseObject.MIDDLE_PORTAL:
Self._SetupTeleport(obj, coordinate, room.Rotation,
Self.Loader.TeleportRooms[idx.Y,idx.X].Middle);

EHouseObject.RIGHT_PORTAL, EHouseObject.RIGHT_AMULET:
Self._SetupTeleport(obj, coordinate, room.Rotation,
Self.Loader.TeleportRooms[idx.Y,idx.X].Right);
end;

Self.Objects[obj].SetupCoordinates([coordinate]);
Self.Objects[obj].Size := obj.GetSize();
Self.Objects[obj].Rotations := [room.Rotation];
Self.Objects[obj].SetupUpText(obj.GetUpText());
Self.Objects[obj].Finder := obj.GetFinder();
Self.Objects[obj].Walker := @Self.Walker;
Self._SetupObject(obj, coordinate, room.Rotation);
end;

//TODO... do something about portals
end;
end;

(*
## POH.Setup()
```pascal
procedure THouseHandler.Setup();
```
Method you need to use at the start of your script after the user has already configured his house
with `TScriptForm.CreateHouseBuilder()`.
*)
procedure THouseHandler.Setup(downscale: Int32 = 8);
var
minimapImage, minimapSample: TMufasaBitmap;
begin
if Self.IsSetup then Exit;
if Self.Sample.Amount = 0 then Self.Sample.Amount := 2;
if Self.Sample.Radius = 0 then Self.Sample.Radius := 67;

Self.SetupObjects();

Self.Loader.Setup(downscale);
minimapImage := Minimap.GetCleanMinimap();
Expand Down
11 changes: 11 additions & 0 deletions optional/handlers/house/houseutils.simba
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ begin
end;
end;


function EHouseRoom.IsOutdoors(): Boolean;
begin
case Self of
Expand All @@ -154,6 +155,7 @@ begin
end;
end;


function EHouseObject.GetSize(): Vector3;
begin
case Self of
Expand Down Expand Up @@ -414,6 +416,15 @@ begin
end;
end;


function EHouseTeleport.GetUpText(): TStringArray;
begin
case Self of
EHouseTeleport.VARROCK: Result := ['Varrock'];
//TODO... same as `EHouseObject.GetUpText()` but for each portal uptext lol
end;
end;

function EHouseTeleport.GetFinder(): TRSObjectFinder;
begin
case Self of
Expand Down
23 changes: 22 additions & 1 deletion templates/househandler_example.simba
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{$DEFINE SRL_DISABLE_REMOTEINPUT}
(*
====================================================================================
A lot of things are missing colors, uptext and coordinates. feel free to contribute:
Simba/Includes/WaspLib/optional/handlers/house/houseutils.simba
there's some basic instructions on the file.
====================================================================================
*)

{.$DEFINE SRL_DISABLE_REMOTEINPUT}
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/osr.simba}
Expand Down Expand Up @@ -67,8 +75,21 @@ begin
MyScriptForm.Run();
{$ENDIF}

(*
====================================================================================
A lot of things are missing colors, uptext and coordinates. feel free to contribute:
Simba/Includes/WaspLib/optional/handlers/house/houseutils.simba
there's some basic instructions on the file.
====================================================================================
*)

//Do stuff with your house:
House.Objects[EHouseObject.ORNATE_POOL].WalkClick();
House.Objects[EHouseObject.NEXUS].WalkClick();
Debug(House.Objects[EHouseObject.SPIRITUAL_FAIRY_TREE]);

//Using teleports that can be in multiple positions (portals and nexus amulets)
House.Teleports[EHouseTeleport.BARROWS].WalkClick();
House.Teleports[EHouseTeleport.GRAND_EXCHANGE].WalkClick();
Debug(House.Teleports[EHouseTeleport.WATERBIRTH_ISLAND]);
end.

0 comments on commit cbf041c

Please sign in to comment.