SRL Archive - SRL Suggestions

GetXP Fix


legoace

2011-12-04 01:36:43

I've written a new GetXP function. I used both the current GetXP function and GetChooseOptions as my guides.

Why it should be committed: this one actually works!

function GetXPNew(Skill: Variant): Integer;
var
TPA1, TPA2: TPointArray;
ATPA, ATPAt: T2DPointArray;
P: TPoint;
B: TBox;
begin
Result := -1;
if (not TabExists(tab_Stats)) then exit;
GameTab(tab_Stats);
if (GetCurrentTab <> tab_Stats) then exit;
P := SkillToCoords(Skill);
if (P.x < 1) then exit;
MMouse(P.x, P.y + 5, 12, 4);
if (not WaitFindColors(TPA1, 4305653, MIX1, MIY1, MIX2, MIY2, 1, 4000)) then exit; // Orange text color of XP boxes
FindColorsTolerance(TPA2, 921102, MIX1, MIY1, MIX2, MIY2, 1); // black behind the orange text
//15133931 is another useful color: the white bound of the hover box
TPA1 := CombineTPA(TPA1, TPA2);
B := GetTPABounds(TPA1);

B := IntToBox(B.X1, B.Y1 + 17, B.X2, B.Y1 + 17 + 13); // get just the line that current xp is on
FindColorsTolerance(TPA1, 4305653, B.X1, B.Y1, B.X2, B.Y2, 2); // TPA of that line's text
ATPA := SplitTPAEx(TPA1, 15, 2);
SortATPAFromFirstPointY(ATPA, Point(B.X2-B.X1+2/2,0));

TPA1 := ATPA[0];
ATPAt := SplitTPAEx(TPA1, 1, 10); // Split one into characters
SortATPAFromFirstPointX(ATPAt, Point(0, 0));
Result := StrToIntDef(GetNumbers(GetTextATPA(ATPAt, 4, 'SmallChars')), -1);
end;

Wizzup?

2011-12-04 06:32:13

Looks sound to me. One thing: What if the length of ATPA is 0 - if you didn't find any colours?

legoace

2011-12-04 12:18:51

That should be covered by the default value in StrToIntDef correct? Also these colors are all static, this shouldn't ever be a problem.

I get your point though, I'm also going to expand it to be able to fetch values for the next level and the remaining xp to level so I'll add a failsafe I guess.

E:
Actually I've found a problem - GetTextATPA seems to quit if there's a lot of blank horizontal spacing?
In this image GetTextATPA returns the whole line with numbers for the 2nd and 3rd rows but not the 4th:
what I'm talking about

E2:
It was a stupid oversight on my part, I figured it out.
Here's what I propose should be committed:
{*******************************************************************************
function GetXP(Skill: Variant; Which: String): Integer;
By: Legoace
Credit to: Nielsie95 for the original
Description: Returns xp value for a skill depending on Which
Options for Which are ['current', 'next', 'remaining']
Returns -3 if super-fails
-2 if skill is mem and this is F2P account
-1 if text-reading sucked
*******************************************************************************}
function GetXPNew(Skill: Variant; Which: String): Integer;
var
TPA1, TPA2: TPointArray;
ATPA, ATPAt: T2DPointArray;
P: TPoint;
B: TBox;
YOffset, I: Integer;
S: String;
begin
Result := -3;

if(not(TabExists(tab_Stats)))then exit;
GameTab(tab_Stats);
if(GetCurrentTab <> tab_Stats)then exit;
P := SkillToCoords(Skill);
if(P.x < 1)then exit;
MMouse(P.x, P.y + 5, 12, 4);
Wait(100 + Random(50));

FindColorsTolerance(TPA2, 921102, MIX1, MIY1, MIX2, MIY2, 1); // black behind the orange text
FindColorsTolerance(TPA1, 4305653, MIX1, MIY1, MIX2, MIY2, 1); // Orange text color of XP boxes
//15133931 is another useful color: the white bound of the hover box
TPA1 := CombineTPA(TPA1, TPA2);
B := GetTPABounds(TPA1);

if((B.Y2 - B.Y1) > 20)then // F2P boxes for Mem skills won't be large enough
begin
case Which of
'current': YOffset := 17;
'next': YOffset := 31;
'remaining': YOffset := 45;
end;

B := IntToBox(B.X1, B.Y1 + YOffset, B.X2, B.Y1 + YOffset + 13); // get just the line that current xp is on
FindColorsTolerance(TPA1, 4305653, B.X1, B.Y1, B.X2, B.Y2, 2); // TPA of that line's text
ATPA := SplitTPAEx(TPA1, 15, 2);
SortATPAFromFirstPointY(ATPA, Point(B.X2-B.X1+2/2,0));

if(length(ATPA) > 0)then
begin
for I := 0 to High(ATPA) do
begin
TPA1 := ATPA[I];
ATPAt := SplitTPAEx(TPA1, 1, 10); // Split one into characters
SortATPAFromFirstPointX(ATPAt, Point(0, 0));
S := S + GetTextATPA(ATPAt, 4, 'SmallChars');
end;
Result := StrToIntDef(GetNumbers(S), -1);
end;
end else result := -2;
end;

Coh3n

2011-12-06 01:48:42

I'd split that function so scripts don't break because of the parameter addition. Change your function name to GetSpecificXP or something, then still use the GetXP(skill: variant) like what's in the include right now.

legoace

2011-12-06 09:52:11

How about this?

E: Added Nava's suggestions.


{*******************************************************************************
function GetXP(Skill: Variant): Integer;
By: Legoace
Credit to: Nielsie95 for the original
Description: Returns current xp value for a skill
*******************************************************************************}
function GetXP(Skill: Variant): Integer;
begin
result := GetXPEx(Skill, 'current', True);
end;

{*******************************************************************************
function GetXPEx(Skill: Variant; Which: String, MaintainTab: Boolean): Integer;
By: Legoace
Credit to: Nielsie95 for the original
Description: Returns xp value for a skill depending on Which.
Options for Which are ['current', 'next', 'remaining']
If MaintainTab is true, returns to current tab after execution.
Returns -3 if super-fails
-2 if skill is mem and this is F2P account
-1 if text-reading sucked
*******************************************************************************}
function GetXPNew(Skill: Variant; Which: String): Integer;
var
TPA1, TPA2: TPointArray;
ATPA, ATPAt: T2DPointArray;
P: TPoint;
B: TBox;
YOffset, I, T: Integer;
S: String;
begin
Result := -3;
T := GetCurrentTab;
if(not(GameTab(tab_Stats)))then exit;
P := SkillToCoords(Skill);
if(P.x < 1)then exit;
MMouse(P.x, P.y + 5, 12, 4);
Wait(100 + Random(50));

FindColorsTolerance(TPA2, 921102, MIX1, MIY1, MIX2, MIY2, 1); // black behind the orange text
FindColorsTolerance(TPA1, 4305653, MIX1, MIY1, MIX2, MIY2, 1); // Orange text color of XP boxes
//15133931 is another useful color: the white bound of the hover box
TPA1 := CombineTPA(TPA1, TPA2);
B := GetTPABounds(TPA1);

if((B.Y2 - B.Y1) > 20)then // F2P boxes for Mem skills won't be large enough
begin
case Which of
'current': YOffset := 17;
'next': YOffset := 31;
'remaining': YOffset := 45;
end;

B := IntToBox(B.X1, B.Y1 + YOffset, B.X2, B.Y1 + YOffset + 13); // get just the line that current xp is on
FindColorsTolerance(TPA1, 4305653, B.X1, B.Y1, B.X2, B.Y2, 2); // TPA of that line's text
ATPA := SplitTPAEx(TPA1, 15, 2);
SortATPAFromFirstPointY(ATPA, Point(B.X2-B.X1+2/2,0));

if(length(ATPA) > 0)then
begin
for I := 0 to High(ATPA) do
begin
TPA1 := ATPA[I];
ATPAt := SplitTPAEx(TPA1, 1, 10); // Split one into characters
SortATPAFromFirstPointX(ATPAt, Point(0, 0));
S := S + GetTextATPA(ATPAt, 4, 'SmallChars');
end;
Result := StrToIntDef(GetNumbers(S), -1);
end;
end else result := -2;
if(T)then GameTab(T);
end;

Nava2

2011-12-06 10:45:12

iirc, this:
if(not(TabExists(tab_Stats)))then exit;
GameTab(tab_Stats);
if(GetCurrentTab <> tab_Stats)then exit;

Can be replaced with:
if (not GameTab(tab_stats)) then exit;

Also, perhaps maintaining the old gametab isn't a bad idea?

legoace

2011-12-06 12:51:18

Thanks Nava, I'll condense those lines.

I'm not sure if the old tab should be stored and returned to. I guess the main point of me writing this was so I could quickly get the xp for my F2P accounts now that they are off the highscores.

I guess I'll add it as an option.