Code: Select all
Program AnimalTaming;
const
debug = true;
testmode = False;
mov = True;
skup = 0.21; // max skill up on 1 animal
FindDistanceMob=50; // distance for mob search.
ijl = 'You fail to tame the creature|It seems to accept you as master|You do not have a clear path|That is too far away';
// in Jelom with Cow, lama and bull.
// coords 1.1 = x 1168 y 3600 & 1.2 x 1198 y 3622 | 2.1 x 1176 y 3592 & 2.2 x 1198 y 3599
x11 = 1168;
y11 = 3600;
x12 = 1198;
y12 = 3622;
//
x21 = 1176;
y21 = 3592;
x22 = 1198;
y22 = 3599;
swait = 100; // small wait pause
lwait = 500; // wait betwean looting items
lagwait = 1000; // wait for chacklag function
//inzone(ax,ay,bx,by: integer; obj: Cardinal)
var
i,j : integer;
inz,itp,ntk,tr,ntr : Boolean;
ttls : String;
// mob : Cardinal;
cskill : Double;
TempTypeList,TempTypeListK : array of Word;
MobTypeList : array of Word;
MobTypeSkillList : array of Double;
Procedure AllMobTypeList;
Begin
MobTypeList:= [$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000,$0000, $0000, $0000, $0000, $0000];
if debug then AddToSystemJournal('Length MobTypeList: '+IntToStr(Length(MobTypeList)));
MobTypeSkillList:=[200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9,200.9, 200.9, 200.9, 200.9, 200.9];
if debug then AddToSystemJournal('Length MobTypeSkillList: '+IntToStr(Length(MobTypeSkillList)));
MobTypeList[0]:=$00CF; //Sheep
MobTypeSkillList[0]:=11.1;
if debug then AddToSystemJournal(IntToHex(MobTypeList[0],4)+' '+FloatToStr(MobTypeSkillList[0]));
MobTypeList[1]:=$00D8; //Cow $00D8
MobTypeSkillList[1]:=11.1;
if debug then AddToSystemJournal(IntToHex(MobTypeList[1],4)+' '+FloatToStr(MobTypeSkillList[1]));
MobTypeList[2]:=$00E7; //Cow $00E7
MobTypeSkillList[2]:=11.1;
if debug then AddToSystemJournal(IntToHex(MobTypeList[2],4)+' '+FloatToStr(MobTypeSkillList[2]));
MobTypeList[3]:=$00DC; //RLama
MobTypeSkillList[3]:=29.1;
if debug then AddToSystemJournal(IntToHex(MobTypeList[3],4)+' '+FloatToStr(MobTypeSkillList[3]));
MobTypeList[4]:=$00E8; //Bull
MobTypeSkillList[4]:=71.1;
if debug then AddToSystemJournal(IntToHex(MobTypeList[4],4)+' '+FloatToStr(MobTypeSkillList[4]));
MobTypeList[5]:=$00E9; //Bull 2
MobTypeSkillList[5]:=71.1;
if debug then AddToSystemJournal(IntToHex(MobTypeList[5],4)+' '+FloatToStr(MobTypeSkillList[5]));
end;
Function IsTaming(a: Integer): Boolean;
begin
if ( (GetSkillCurrentValue('Animal Taming')-MobTypeSkillList[a]-0.2)*2<100 ) and (GetSkillCurrentValue('Animal Taming')>=MobTypeSkillList[a]) then begin Result:=True; end else Result:=False;
end;
Function TypeFTaming : array of Word;
var
TypeForTaming : array of Word;
a : Integer;
begin
SetLength(TypeForTaming,0)
for a:=0 to Length(MobTypeList)-1 do
begin
if IsTaming(a) then
begin
SetLength(TypeForTaming,Length(TypeForTaming)+1);
TypeForTaming[Length(TypeForTaming)-1]:=MobTypeList[a];
end;
end;
Result:= TypeForTaming;
end;
Function TypeFKill : array of Word;
var
TypeForKill : array of Word;
a : Integer;
begin
SetLength(TypeForKill,0)
for a:=0 to Length(MobTypeList)-1 do
begin
if not IsTaming(a) and (MobTypeSkillList[a]<200) then
begin
SetLength(TypeForKill,Length(TypeForKill)+1);
TypeForKill[Length(TypeForKill)-1]:=MobTypeList[a];
end;
end;
Result:= TypeForKill;
end;
Function BoolToStr(Value: Boolean): String;
begin
if Value then
Result := 'Yes'
else
Result := 'No';
end;
Function inzone(ax,ay,bx,by: integer; obj: Cardinal): Boolean;
var
cx,cy,dx,dy : integer;
begin
if (ax<=bx) then
begin
cx:=ax;
dx:=bx;
end else
begin
cx:=bx;
dx:=ax;
end;
if (ay<=by) then
begin
cy:=ay;
dy:=by;
end else
begin
cy:=by;
dy:=ay;
end;
// 1173 3592
//coords 1.1 = x 1168 y 3600 & 1.2 x 1198 y 3622
//coords2 2.1 x 1176 y 3592 & 2.2 x 1198 y 3599
if ((cx<=GetX(obj)) and (dx>=GetX(obj)) and (cy<=GetY(obj)) and (dy>=GetY(obj))) then
begin
Result:=true;
end else Result:=False;
end;
procedure mymovexy(x,y,cl:integer);
begin
ClearBadLocationList;
ClearBadObjectList;
while ((ABS(x-getx(self))>cl) or (ABS(y-gety(self))>cl)) and ((x<>0) and (y<>0)) do
begin
// break;
NewMoveXY(x,y,false,cl,true);
wait(100);
ClearBadLocationList;
ClearBadObjectList;
end;
end;
procedure HitWithMA(mob:Cardinal);
begin
CastToObject('Magic Arrow',mob);
wait(500);
end;
Function tame(mobt:Cardinal): Boolean;
var
res,wft : Boolean;
cp : Byte;
ta : TDateTime;
begin
SetContextMenuHook(0,0);
if debug then AddToSystemJournal('tame = 1 x= '+inttostr(GetX(mobt))+' y= '+inttostr(GetY(mobt)));
ta:=Now;
cp:= PetsCurrent;
wft:=True;
mymovexy(getx(mobt),gety(mobt),0);
if TargetPresent then CancelTarget;
if debug then AddToSystemJournal('GetHP = '+inttostr(GetHP(mobt)));
UseSkill('Animal Taming');
WaitTargetObject(mobt);
wait(lwait);
checklag(lagwait);
if debug then AddToSystemJournal('tame = 2');
while wft do
Begin
wait(swait);
mymovexy(getx(mobt),gety(mobt),0);
if (cp<PetsCurrent) or (InJournalBetweenTimes(ijl,ta,Now)<>-1) or (GetHP(mobt)=0) then
begin
if (cp<PetsCurrent) then
begin
Result := True;
if debug then AddToSystemJournal('Result = '+BoolToStr(Result));
break;
end else
begin
Result := False;
if debug then AddToSystemJournal('Result = '+BoolToStr(Result));
break;
end;
end
end;
end;
begin
MoveThroughNPC := 0;
FindDistance:=FindDistanceMob;
AllMobTypeList;
While GetSkillValue('Animal Taming')<GetSkillCap('Animal Taming') do
begin
//IgnoreReset;
TempTypeList := TypeFTaming;
if debug then AddToSystemJournal('TempTypeList Length = '+IntToStr(Length(TempTypeList)));
cskill := GetSkillCurrentValue('Animal Taming');
for i:=0 to Length(TempTypeList)-1 do
begin
if debug then AddToSystemJournal('TempTypeList['+inttostr(i)+'] '+IntToHex(TempTypeList[i],4));
FindType(TempTypeList[i],Ground);
if (findcount>0) and (inzone(x11,y11,x12,y12,FindItem) or inzone(x21,y21,x22,y22,FindItem)) then break;
end;
if debug and (findcount>0) then AddToSystemJournal('FindItem '+IntToHex(FindItem,8));
if (FindCount>0) then
begin
if inzone(x11,y11,x12,y12,FindItem) or inzone(x21,y21,x22,y22,FindItem) then Begin inz:= True; end else inz:= False;
if debug then AddToSystemJournal(Format('IsInZone = %d', [inz])+' '+BoolToStr(inz));
if inz then begin
itp := True;
While itp do
begin
if GetHP(FindItem)>0 then
begin
tr := tame(FindItem);
if debug then AddToSystemJournal('tame end = '+BoolToStr(tr));
if (tr = True) then
Begin
if debug then AddToSystemJournal('tr 1 = '+BoolToStr(tr));
ntr:=True; //Need to release
ntk:=True; //need to kill
itp := False; // for While is end
ignore(FindItem);
end else
Begin
if debug then AddToSystemJournal('tr 2 = '+BoolToStr(tr));
if (cskill+skup<GetSkillValue('Animal Taming')) then
begin
if debug then AddToSystemJournal('cskill = '+BoolToStr(tr));
ntk:=True; //need to kill
itp := False; // for While is end.
ignore(FindItem);
end;
if (GetHP(FindItem)=0) then ignore(FindItem);
end;
if ntr then
Begin
WaitGump('2');
SetContextMenuHook(FindItem,8);
RequestContextMenu(FindItem);
wait(lwait);
checklag(lagwait);
SetContextMenuHook(0,0);
ignore(FindItem);
ntr:=false;
end;
if ntk then
begin
while ntk and (GetHP(FindItem)>0) do
begin
attack(FindItem);
if TargetPresent then CancelTarget;
CastToObject('Magic Arrow',FindItem);
wait(1000);
mymovexy(getx(FindItem),gety(FindItem),0);
end;
ntk:=false;
end;
end else
begin
itp := False; // for While is end.
ignore(FindItem);
end;
end;
end else ignore(FindItem);
end;
if debug then AddToSystemJournal(' to check for taming ');
for i:=0 to Length(TempTypeList)-1 do
begin
inz:= False;
FindType(TempTypeList[i],Ground);
if findcount>0 then
begin
if inzone(x11,y11,x12,y12,FindItem) or inzone(x21,y21,x22,y22,FindItem) then
Begin
inz:= True;
Break;
end else ignore(FindItem);
end;
end;
if debug then AddToSystemJournal(' end check for taming '+BoolToStr(inz));
While not inz do
Begin
if debug then AddToSystemJournal(' inz false lets kill some ');
TempTypeListK:=TypeFKill;
if debug then AddToSystemJournal('TempTypeListK Length = '+IntToStr(Length(TempTypeListK)));
for i:=0 to Length(TempTypeListK)-1 do
begin
if debug then AddToSystemJournal('TempTypeListK['+inttostr(i)+'] '+IntToHex(TempTypeListK[i],4));
FindType(TempTypeListK[i],Ground);
if findcount>0 then
Begin
if inzone(x11,y11,x12,y12,FindItem) or inzone(x21,y21,x22,y22,FindItem) then
Begin
if debug then AddToSystemJournal('inzone 1 '+BoolToStr(inz));
while (GetHP(FindItem)>0) do
begin
attack(FindItem);
if TargetPresent then CancelTarget;
CastToObject('Magic Arrow',FindItem);
wait(1000);
mymovexy(getx(FindItem),gety(FindItem),0);
end;
end else ignore(FindItem);
end;
if debug then AddToSystemJournal('try to search for tame ');
for j:=0 to Length(TempTypeList)-1 do
begin
inz:= False;
FindType(TempTypeList[j],Ground);
if findcount>0 then
begin
if inzone(x11,y11,x12,y12,FindItem) or inzone(x21,y21,x22,y22,FindItem) then
Begin
if debug then AddToSystemJournal(' found inzone '+BoolToStr(inz));
inz:= True;
Break;
end else ignore(FindItem);
end;
end;
wait(500);
end;
end;
end;
end.