Skip to content

Commit

Permalink
feat(TRSFairyRing): now wields dramen/lunar staff if present
Browse files Browse the repository at this point in the history
Features:
- Will now use some magic to wield dramen/lunar staff for fairy rings with the amount of tab openings. This is thanks to the `PRSInterface` added in SRL and I'm considering adding framework for equipment with this trick because it's really cool and the `TRSCombatHandler` would probably make good use of this too.
- FairyRing RSObject was removed and moved into `TRSObjects`.
Fixes and Refactors:
- Compatibility fixes with latest SRL-T. Removed ChooseOptions.HasOption() that were moved there.
- TRSDropDown were heavily based on TRSChooseOption, some of the tweaks I did to it on SRL were applied here.
- FairyRings had a couple of bugs, they should all be fixed and this should be completely working
  • Loading branch information
Torwent committed Jan 25, 2024
1 parent a5fd264 commit 61f4d9d
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 117 deletions.
146 changes: 124 additions & 22 deletions optional/interfaces/mainscreen/fairyring.simba
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ type
TRSFairyRing = record (TRSInterface)
Dials: array [ERSFairyRingDial] of String;
TravelLog: TRSInterface;
RSObject: TRSObject;
Item: TRSItem;
end;



function TRSFairyRing.ScrollAreaFunction(): TBox;
begin
Result := Self.TravelLog.Bounds();
Expand Down Expand Up @@ -52,13 +50,6 @@ begin
Self.TravelLog.Setup();
Self.TravelLog.Name := 'FairyRingTravelLog';
Self.TravelLog.GetScrollAreaFunction := @Self.ScrollAreaFunction;
Self.RSObject.Setup(1, 0, [[7378, 3992], [6194, 3460], [3360, 698], [6514, 1996], [6502, 5130], [8530, 5622], [4670, 1972], [5678, 4624], [5406, 1902], [9782, 2468], [10228, 4660], [5970, 2468], [9034, 3152], [8398, 4068], [5932, 3384], [4816, 4536], [7764, 2650], [3994, 4166], [4934, 4308], [4120, 214], [9268, 2724], [10150, 4090], [4654, 632], [6354, 3044], [6554, 5178], [5506, 3940], [1950, 986], [602, 1412], [6214, 2144], [9802, 400], [6598, 4436], [9182, 2568], [7722, 3624], [6096, 5210], [6120, 4124], [10142, 5106], [3320, 3916], [7824, 3852], [6026, 3528], [1214, 1828], [6994, 4004], [7910, 2464], [6370, 1572], [9086, 4384], [4246, 4052], [1424, 5140]]);
Self.RSObject.SetupUpText(['y ring']);
Self.RSObject.Finder.Colors := [
CTS2(4089424, 10, 0.14, 0.19),
CTS2(4807548, 17, 0.07, 0.21),
CTS2(14476264, 4, 0.36, 0.64)
];
end;

procedure TRSFairyRing.SetupAlignment(mode: ERSClientMode); override;
Expand Down Expand Up @@ -138,6 +129,109 @@ begin
Result := MainScreen.CloseInterface(chance);
end;


(*
FairyRing.HandleItem
~~~~~~~~~~~~~~~~~~~~
.. pascal:: function TRSFairyRing.HandleItem(): Boolean;

Magically finds, caches for next usages and equips dramen or lunar staff with the minimum tab opening possible.
If no item is found, we will assume the user has the elite lumbridge and draynor diary complete for next uses.

Example
-------

if FairyRing.HandleItem() then
WriteLn FairyRing.Item;
*)
function TRSFairyRing.HandleItem(): Boolean;
const
ITEMS: TRSItemArray = ['Dramen staff', 'Lunar staff'];
var
slot, i: Int32;
currentTab: PRSInterface;
begin
if Self.Item = 'null' then
Exit(True);

case GameTabs.GetCurrentTab() of
ERSGameTab.INVENTORY: currentTab := PRSInterface(@Inventory);
ERSGameTab.EQUIPMENT: currentTab := PRSInterface(@Equipment);
ERSGameTab.COMBAT: currentTab := PRSInterface(@Combat);
else if Inventory.Open() then Exit(Self.HandleItem()) else Exit;
end;

if not Self.Item.IsNull() then
begin
for i := 0 to 1 do
case currentTab^.Name of
'Inventory':
begin
if Inventory.FindItem(Self.Item, slot) then
begin
if Inventory.ClickSlot(slot) then
Inventory.WaitItemFade(slot);
Wait(100);
Exit(WaitUntil(not Inventory.ContainsItem(Self.Item), 300, 3000));
end;

currentTab := PRSInterface(@Equipment);
if not Equipment.Open() then
Exit;
end;
'Equipment':
begin
if Equipment.ContainsItem(Self.Item) then
Exit(True);

currentTab := PRSInterface(@Inventory);
if not Inventory.Open() then
Exit;
end;
'Combat':
begin
if LowerCase(Combat.GetWeapon()) = LowerCase(Self.Item) then
Exit(True);

currentTab := PRSInterface(@Inventory);
if not Inventory.Open() then
Exit;
end;
end;
end;

for Self.Item in ITEMS do
case currentTab^.Name of
'Combat': if LowerCase(Combat.GetWeapon()) = LowerCase(Self.Item) then
Exit(Self.HandleItem());
else if currentTab^.ItemInterface.Contains(Self.Item) then
Exit(Self.HandleItem());
end;

case currentTab^.Name of
'Inventory':
begin
currentTab := PRSInterface(@Equipment);
if not Equipment.Open() then
Exit;
end;
'Equipment', 'Combat':
begin
currentTab := PRSInterface(@Inventory);
if not Inventory.Open() then
Exit;
end;
end;

for Self.Item in ITEMS do
if currentTab^.ItemInterface.Contains(Self.Item) then
Exit(Self.HandleItem());

Self.Item := 'null';
Result := True;
end;


(*
FairyRing.Open
~~~~~~~~~~~~~~
Expand All @@ -158,7 +252,10 @@ begin
if Self.IsOpen() then
Exit(True);

Result := Self.RSObject.SelectOption(['onfigure']);
if not Self.HandleItem() then
Exit;

Result := RSObjects.FairyRing.SelectOption(['onfigure']);
if not Result then
Exit;

Expand Down Expand Up @@ -186,7 +283,10 @@ begin
if Self.IsOpen() then
Exit(True);

Result := Self.RSObject.WalkSelectOption(['onfigure']);
if not Self.HandleItem() then
Exit;

Result := RSObjects.FairyRing.WalkSelectOption(['onfigure']);
if not Result then
Exit;

Expand Down Expand Up @@ -591,7 +691,7 @@ begin
for i := 0 to High(boxes) do
begin
str := OCR.Recognize(boxes[i], TOCRColorFilter.Create(COLORS), RS_FONT_PLAIN_12);
Result += str.Replace(' ', '').Upper();
Result += str.Replace(' ', '');

boxes[i].X2 := Self.TravelLog.X2() - 22;
if i = High(boxes) then
Expand Down Expand Up @@ -621,7 +721,7 @@ begin
for i := 0 to High(boxes) do
begin
str := OCR.Recognize(boxes[i], TOCRColorFilter.Create(COLORS), RS_FONT_PLAIN_12);
Result += str.Replace(' ', '').Upper();
Result += str.Replace(' ', '');
end;
end;

Expand Down Expand Up @@ -780,7 +880,10 @@ begin
if Self.IsOpen() then
Exit(Self.HandleInterface(code));

if not Self.RSObject.SelectOption([code.Upper(), 'onfigure']) then
if not Self.HandleItem() then
Exit;

if not RSObjects.FairyRing.SelectOption([code.Upper(), 'onfigure']) then
Exit;

Minimap.WaitMoving();
Expand Down Expand Up @@ -813,7 +916,10 @@ begin
if Self.IsOpen() then
Exit(Self.HandleInterface(code));

if not Self.RSObject.WalkSelectOption([code.Upper(), 'onfigure']) then
if not Self.HandleItem() then
Exit;

if not RSObjects.FairyRing.WalkSelectOption([code.Upper(), 'onfigure']) then
Exit;

Minimap.WaitMoving();
Expand Down Expand Up @@ -877,17 +983,13 @@ end;
function TRSMainScreen.IsVisible(p: TPoint): Boolean; override;
begin
Result := inherited;

if not Result or (RSClient.Mode = ERSClientMode.FIXED) then
Exit;

if FairyRing.Bounds().Expand(5).Contains(p) and FairyRing.IsOpen() then
if Result and FairyRing.IsOpen() then
Exit(False);
end;

function TRSMainScreen.IsVisible(tpa: TPointArray; useCenter: Boolean = True): Boolean; override;
begin
Result := inherited;
if FairyRing.IsOpen() then
if Result and FairyRing.IsOpen() then
Exit(False);
end;
24 changes: 17 additions & 7 deletions osr/antiban/antibanextra.simba
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ begin
Result := Self.ClickContinue(useKeyboard);
end;

function TRSChooseOption.Select(text: TStringArray; mouseAction: Int32 = MOUSE_LEFT; caseSensitive: Boolean = True; closeIfNotFound: Boolean = True): Boolean; override;
function TRSChooseOption.HasOption(text: TStringArray; out option: TRSChooseOption_Option; caseSensitive: Boolean = True; closeIfNotFound: Boolean = True): Boolean; override;
var
choices: TRSChooseOption_OptionArray;
i, j, maxTime: Int32;
Expand All @@ -96,19 +96,29 @@ begin

choices := Self.GetOptions();

for i := 0 to High(choices) do
for j := 0 to High(text) do
if (caseSensitive and (text[j] in choices[i].Text)) or ((not caseSensitive) and (Lowercase(text[j]) in Lowercase(Choices[i].Text))) then
WriteLn choices;
WriteLn text;

for i := 0 to High(text) do
for j := 0 to High(choices) do
begin
if not caseSensitive then
begin
Self.Select(choices[i], mouseAction);
text[i] := Lowercase(text[i]);
choices[j].Text := Lowercase(choices[j].Text);
end;

if text[i] in choices[j].Text then
begin
option := choices[j];
option.StringIndex := i;
Exit(True);
end;
end;

if CloseIfNotFound then
if closeIfNotFound then
begin
WaitEx(500, 250);

Self.Close();
end;
end;
51 changes: 1 addition & 50 deletions osr/chooseoption.simba
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,4 @@
{$I WaspLib/osr.simba}
{$ENDIF}

function TRSChooseOption.HasOption(Text: TStringArray; CaseSensitive: Boolean = True; CloseIfNotFound: Boolean = True): Boolean;
var
Choices: TRSChooseOption_OptionArray;
I, J: Int32;
begin
if not Self.IsOpen() then
Exit;

Choices := Self.GetOptions();

for I := 0 to High(Choices) do
for J := 0 to High(Text) do
if (CaseSensitive and (Text[J] in Choices[I].Text)) or ((not CaseSensitive) and (Lowercase(Text[J]) in Lowercase(Choices[I].Text))) then
Exit(True);

if CloseIfNotFound then
begin
WaitEx(500, 250);

Self.Close();
end;
end;

function TRSChooseOption.HasOption(Text: TStringArray; out Index: Int32; CaseSensitive: Boolean = True; CloseIfNotFound: Boolean = True): Boolean; overload;
var
Choices: TRSChooseOption_OptionArray;
I: Int32;
begin
if not Self.IsOpen then
Exit;

Choices := GetOptions;

for I := 0 to High(Choices) do
for Index := 0 to High(Text) do
if (CaseSensitive and (Text[Index] in Choices[I].Text)) or ((not CaseSensitive) and (Lowercase(Text[Index]) in Lowercase(Choices[I].Text))) then
Exit(True);

if CloseIfNotFound then
begin
WaitEx(500, 250);

Self.Close;
end;
end;

function TRSChooseOption.HasOption(Text: String; CaseSensitive: Boolean = True; CloseIfNotFound: Boolean = True): Boolean; overload;
begin
Result := Self.HasOption([Text], CaseSensitive, CloseIfNotFound);
end;
//placeholder
Loading

0 comments on commit 61f4d9d

Please sign in to comment.