From cbf041c88567964497a91a739586f857f4c0d6e8 Mon Sep 17 00:00:00 2001 From: Torwent Date: Sat, 21 Dec 2024 22:13:35 +0100 Subject: [PATCH] feat(house): finished the house teleports framework - also updated the example with more info and teleports usage example --- optional/handlers/house/house.simba | 96 +++++++++++++++++------- optional/handlers/house/houseutils.simba | 11 +++ templates/househandler_example.simba | 23 +++++- 3 files changed, 102 insertions(+), 28 deletions(-) diff --git a/optional/handlers/house/house.simba b/optional/handlers/house/house.simba index 7d205e73..579e9603 100644 --- a/optional/handlers/house/house.simba +++ b/optional/handlers/house/house.simba @@ -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; @@ -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 @@ -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(); diff --git a/optional/handlers/house/houseutils.simba b/optional/handlers/house/houseutils.simba index 58b87779..3a71c427 100644 --- a/optional/handlers/house/houseutils.simba +++ b/optional/handlers/house/houseutils.simba @@ -146,6 +146,7 @@ begin end; end; + function EHouseRoom.IsOutdoors(): Boolean; begin case Self of @@ -154,6 +155,7 @@ begin end; end; + function EHouseObject.GetSize(): Vector3; begin case Self of @@ -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 diff --git a/templates/househandler_example.simba b/templates/househandler_example.simba index 84f55a1d..37e3c876 100644 --- a/templates/househandler_example.simba +++ b/templates/househandler_example.simba @@ -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} @@ -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.