SRL Archive - Reflection Development

Frog Cave solver


Cstrike

2010-10-14 13:45:59

Here's another one.

The function at the top won't be needed if it's commited.

I ran this and it got me through the random, though I need to work on it more. I don't say commit it yet, but tell me if you find any flaws with it…etc

{*******************************************************************************
function GetNPCsNull: TNPCArray;
By: Drags111 [modded by Cstrike]
Description: Stores all the loaded NPCs into an array of TNPC including nulls;
*******************************************************************************}
function GetNPCsNull : array of TNPC;
var
i, c, NumNPCs, Index, TheNPC, TheNPCDef, TheBytes, TheNPCNode: integer;
begin
NumNPCs := SmartGetFieldInt(0,hook_static_NPCCount);
if (NumNPCs < 1) then Exit;
SetArrayLength(Result,NumNPCs);
for i := 0 to (NumNPCs-1) do
try
Index := SmartGetFieldArrayInt(0, hook_static_NPCIndexArray, i);
TheNPCNode := SmartGetFieldArrayObject(0, hook_static_NPCNodes, i);
TheNPC := SmartGetFieldObject(TheNPCNode, hook_npcnode_GetNPC);
TheNPCDef := SmartGetFieldObject(TheNPC, hook_npc_NPCDef);
TheBytes := SmartGetFieldObject(TheNPCDef, hook_npcdef_GetName);

//if (lowercase(trim(GetJavaString(TheBytes, 255))) = 'null') then continue; // Commented this line out
Result[c].Index := Index;
Result[c].ID := SmartGetFieldInt(TheNPCDef, hook_npcdef_GetID);
Result[c].Name := GetJavaString(TheBytes, 255);
Result[c].Actions := _GetNPCActionArray(TheNPCDef);
Result[c].Tile.X := (SmartGetFieldInt(0, hook_static_BaseX) + (SmartGetFieldInt(TheNPC, hook_animable_PixelX) / 512));
Result[c].Tile.Y := (SmartGetFieldInt(0, hook_static_BaseY) + (SmartGetFieldInt(TheNPC, hook_animable_PixelY) / 512));
Result[c].Pixel.X := SmartGetFieldInt(TheNPC, hook_animable_PixelX) mod 512;
Result[c].Pixel.Y := SmartGetFieldInt(TheNPC, hook_animable_PixelY) mod 512;
Result[c].Moving := (SmartGetFieldInt(TheNPC, hook_character_Motion)>0);
Result[c].Animation := SmartGetFieldInt(TheNPC, hook_character_Animation);
Result[c].Height := iabs(SmartGetFieldInt(TheNPC, hook_character_GetHeight));
Result[c].HPRatio := SmartGetFieldInt(TheNPC, hook_character_HPRatio) * 100 / $FF;
Result[c].Fighting := (SmartGetFieldInt(TheNPC, hook_character_LoopCycleStatus) >
SmartGetFieldInt(0, hook_static_LoopCycle));
Result[c].Orientation := Round(FixD(180 + (SmartGetFieldInt(TheNPC, hook_character_Orientation)* 45) / 2048));
Result[c].Level := SmartGetFieldInt(TheNPCDef, hook_npcdef_GetLevel);
Result[c].Interacting := SmartGetFieldInt(TheNPC, hook_character_GetInteracting);
Inc(c);

finally
SmartFreeObject(TheNPCNode);
SmartFreeObject(TheNPC);
SmartFreeObject(TheNPCDef);
SmartFreeObject(TheBytes);
end;
SetLength(Result, c);
end;

{*******************************************************************************
function R_InFrogCave: Boolean;
by: Cstrike
Description: Checks if in Frog Random.
*******************************************************************************}
function R_InFrogCave: Boolean;
begin
Result := ValidNPC('Frog herald');
end;

{*******************************************************************************
function R_FrogFindClickPrincess: Boolean;
by: Cstrike
Description: Finds princess and selects her
*******************************************************************************}
function R_FrogFindClickPrincess : Boolean;
var allFrogNPCs : TNPCArray;
i, j, height, timeCount, NPCTalkTimeCount : Integer;
TP : TPoint;
allDirections : TStringArray;
begin
result := false;
height := 0; // If height isn't working, change (works for me)
MarkTime (timeCount);
repeat
wait (200+random(200));
SetAngle (true);
allDirections := ['w','s','e','n'];
for i:=0 to high(allDirections) do
begin
MakeCompass (allDirections[i]);
allFrogNPCs := GetNPCsNull;
for j:=0 to high(allFrogNPCs) do
begin
if (allFrogNPCs[j].ID = 393) or (allFrogNPCs[j].Height = 278) then
begin
writeln ('Found princess! [Index #'+inttostr(j)+']');
if TileOnMS (allFrogNPCs[j].Tile, height) then
begin
writeln ('Found princess tile on mainscreen');
TP := TileToMS (allFrogNPCs[j].Tile, height);
Mouse (TP.x, TP.y, 1, 1, false);
Break;
end else writeln ('Did not find princess!');
end; // End finding ID 393 or height 278
end; // End checking entire NPC frog array
end; // Direction changing
wait (450+random(300));
if R_ChooseOption('Talk-to Frog') then
begin
writeln ('Now selecting talk to frog princess');
MarkTime (NPCTalkTimeCount);
repeat
wait (100+random(100));
if GetInterfaceText (243,3) = 'Frog Princess' then
begin
result := true;
writeln ('Interacting with princess frog');
Exit;
end;
until (TimeFromMark(NPCTalkTimeCount) > 6000)
writeln ('Did not end up interacting with frog princess!');
end else writeln ('No ChooseOption found, frog must have been moving, re-attempting....');
until (TimeFromMark(timeCount) > 40000)
writeln ('Had a problem with the frog random!');
end;

{*******************************************************************************
function R_FrogPrincessChat : Boolean;
by: Cstrike
Description: Continues chat with frog princess as to exit the random. Call this
procedure after you know you're interacting with the princess. Needs failsafe.
*******************************************************************************}
function R_FrogPrincessChat : Boolean;
var timeUntilExit, xpos, ypos : Integer;
begin
result := false;
MarkTime (timeUntilExit);
MMouse (287, 455, 50, 2);
GetMousePos (xpos, ypos);
repeat
if GetInterfaceText(243,7) = 'Click here to continue' then Mouse (xpos, ypos, 0, 0, true);
if ValidInterface(241) then Mouse (xpos, ypos, 0, 0, true);
if GetInterfaceText(65,6) = 'Click here to continue' then Mouse (xpos, ypos, 0, 0, true);
wait (1000+random(500));
until (TimeFromMark(timeUntilExit) > 15000) // It exits way too quickly for me to get an ID, I'll have to RSBot it next time, but returns true anyways :)
if (not ValidInterface(63)) and (not ValidInterface(241)) and (not ValidInterface(243)) then result := true; // No chats are up
end;

{*******************************************************************************
function R_SolveFrogCave : Boolean;
by: Cstrike
Description: Attempts to solve frog random, returns true if successful.
*******************************************************************************}
function R_SolveFrogCave : Boolean;
var TimedCount : Integer;
begin
if R_InFrogCave then
begin
result := false;
MarkTime (TimedCount);
repeat
if R_FrogFindClickPrincess then
begin
if R_FrogPrincessChat then
begin
result := true;
writeln ('Solved frog random');
Exit;
end;
end;
until (TimeFromMark(TimedCount) > 81000)
end else writeln ('It says we are not in the frog random!');
end;

This really needs to be tested more, it solved it once, which was my only test run :(

EDIT: I'll be updating it later with NextPlayer(false) in there in case it fails.