Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cavebot.h"
- cavebot::cavebot(QObject *parent) :
- QThread(parent)
- {
- }
- void cavebot::run()
- {
- bool looting=false;
- int lastx, lasty;
- // szukanie labeli
- label bufflabel;
- std::vector <label> labels;
- for (int i =0; i<WayPoint.size(); i++)
- if (WayPoint[i].typ==3)
- {
- bufflabel.id=i;
- bufflabel.text=WayPoint[i].textarg;
- labels.push_back(bufflabel);
- }
- // glowna petla
- wptid=0;
- int timestuck=0;
- int bpdest;
- int currstyle=0;
- while(wptid<WayPoint.size())
- {
- // looting
- if (tibia.IsAttacking())
- {
- monster target;
- target = tibia.Creature(tibia.CreatureBtlPos(tibia.TargetId()));
- if (target.hppc==0 && target.name!="Snake" && target.name!="Slime")
- {
- //looting = true;
- int timer =0;
- while(tibia.IsAttacking() && timer < 200)
- {
- timer ++;
- Sleep(10);
- lastx=target.x;
- lasty=target.y;
- }
- std::vector <int> firstbp = tibia.OpenedBps();
- std::vector <int> secondbp = tibia.OpenedBps();
- timer=0;
- while(secondbp==firstbp && timer < 50)
- {
- tibia.OpenGroundItem(lastx,lasty);
- int timer2=0;
- while(secondbp==firstbp && timer2 < 5)
- {
- timer2++;
- Sleep(50);
- secondbp = tibia.OpenedBps();
- }
- timer ++;
- Sleep(50);
- secondbp = tibia.OpenedBps();
- }
- if (timer==50)
- continue;
- int deadbpid = tibia.BpDifference(firstbp, secondbp);
- if (deadbpid<0 || deadbpid>=15)
- continue;
- // jezeli cos pojdzie nie tak
- if (tibia.WindowEatFood(deadbpid))
- {
- Sleep(300);
- if (!(tibia.GetWhiteText()=="You are full.") && tibia.WindowEatFood(deadbpid))
- Sleep(300);
- }
- for (int i =0; i<Looting.size(); i++)
- {
- if ((Looting[i].dest==-1 || tibia.WindowIsOpen(Looting[i].dest)) && Looting[i].dest!=deadbpid)
- {
- if (Looting[i].dest==-1)
- {
- bpdest= tibia.WindowFirstFreeSlot(deadbpid);
- if (bpdest==-1)
- continue;
- }
- else
- bpdest=Looting[i].dest;
- tibia.MoveItems(Looting[i].id,deadbpid,bpdest);
- Sleep(200);
- }
- }
- // bag opener
- if(tibia.OpenBag(deadbpid))
- {
- while(tibia.OpenBag(deadbpid)) // wait for bag
- Sleep(200);
- if (tibia.WindowEatFood(deadbpid))
- {
- Sleep(300);
- if (!(tibia.GetWhiteText()=="You are full.") && tibia.WindowEatFood(deadbpid))
- Sleep(300);
- }
- // loot bag
- for (int i =0; i<Looting.size(); i++)
- {
- if (( Looting[i].dest==-1 || tibia.WindowIsOpen(Looting[i].dest)) && Looting[i].dest!=deadbpid)
- {
- if (Looting[i].dest==-1)
- {
- bpdest= tibia.WindowFirstFreeSlot(deadbpid);
- if (bpdest==-1)
- continue;
- }
- else
- bpdest=Looting[i].dest;
- tibia.MoveItems(Looting[i].id,deadbpid,bpdest);
- Sleep(200);
- }
- }
- }
- tibia.CloseBp(deadbpid);
- Sleep(200);
- }
- }
- // stop attack unreachable monster
- if (tibia.IsAttacking())
- {
- monster target = tibia.Creature(tibia.CreatureBtlPos(tibia.TargetId()));
- if (!tibia.IsReachable(target.offx,target.offy,-1))
- tibia.StopAttack();
- }
- // skip wpt if unreachable
- std::string whitetext =tibia.GetWhiteText();
- if (WayPoint[wptid].typ==1 &&
- (whitetext == "There is no way." || whitetext == "Sorry, not possible." || whitetext == "Destination is out of range." ))
- timestuck++;
- else
- timestuck=0;
- if (timestuck>100)
- {
- wptid++;
- timestuck=0;
- }
- // accept wpt if stands on it
- if (tibia.IsAttacking() && WayPoint[wptid].typ==1 &&
- WayPoint[wptid].arg1==tibia.SelfPosX() && WayPoint[wptid].arg2==tibia.SelfPosY() && WayPoint[wptid].arg3==tibia.SelfPosZ())
- wptid++;
- // targeting------------------
- if (!tibia.IsAttacking() && !looting)
- {
- int stance;
- int id= tibia.BestTarget(Monsters, &stance);
- if (id!=-1)
- {
- tibia.AttackBtlPos(id);
- }
- }
- // beta rune shoter
- if (tibia.IsAttacking())
- {
- tibia.UseOnCreature(2311,tibia.CreatureBtlPos(tibia.TargetId())); // hmm
- Sleep(100);
- }
- // walker-----------------------------
- if (!tibia.IsAttacking() && !looting)
- switch(WayPoint[wptid].typ)
- {
- case (1):
- {
- if (!tibia.IsWalking() && (tibia.SelfPosZ()==WayPoint[wptid].arg3))
- tibia.Goto(WayPoint[wptid].arg1,WayPoint[wptid].arg2);
- if ((tibia.SelfPosZ()!=WayPoint[wptid].arg3) || //jezeli nie to pietro
- ((WayPoint[wptid].arg1==tibia.SelfPosX()) && (WayPoint[wptid].arg2==tibia.SelfPosY())))
- {
- Sleep(50);
- wptid++;
- }
- break;
- }
- case (2):
- {
- wptid=WayPoint[wptid].arg1;
- break;
- }
- case(3):
- {
- wptid++;
- break;
- }
- case(4):
- {
- int nextid = cavebot::GetLabel(WayPoint[wptid].textarg,labels);
- if (nextid==-1)
- wptid++;
- else
- wptid=nextid;
- break;
- }
- case(5):
- {
- if (tibia.SelfCap()<WayPoint[wptid].arg1)
- wptid++;
- else
- wptid+=2;
- break;
- }
- case(6):
- {
- if (tibia.SelfCap()>WayPoint[wptid].arg1)
- wptid++;
- else
- wptid+=2;
- break;
- }
- case(7):
- {
- int stackpos;
- item itembuff = tibia.MapTopItemStruct(WayPoint[wptid].arg1-tibia.SelfPosX(),WayPoint[wptid].arg2-tibia.SelfPosY(),&stackpos);
- if (itembuff.id==WayPoint[wptid].arg3)
- {
- tibia.UseGroundItem(WayPoint[wptid].arg1,WayPoint[wptid].arg2);
- Sleep(800);
- }
- wptid++;
- break;
- }
- case(8):
- {
- int stackpos;
- item itembuff = tibia.MapTopItemStruct(WayPoint[wptid].arg1-tibia.SelfPosX(),WayPoint[wptid].arg2-tibia.SelfPosY(),&stackpos);
- if (itembuff.id==WayPoint[wptid].arg3)
- {
- tibia.OpenGroundItem(WayPoint[wptid].arg1,WayPoint[wptid].arg2);
- Sleep(1000);
- }
- wptid++;
- break;
- }
- case(9):
- {
- tibia.MoveItems(WayPoint[wptid].arg3,WayPoint[wptid].arg1,WayPoint[wptid].arg2);
- wptid++;
- Sleep(1000);
- break;
- }
- case(10):
- {
- Sleep(WayPoint[wptid].arg1);
- wptid++;
- break;
- }
- case(11):
- {
- tibia.Say(WayPoint[wptid].textarg);
- Sleep(500);
- wptid++;
- break;
- }
- case(12):
- {
- if (tibia.SelfPosZ()==WayPoint[wptid].arg3)
- {
- tibia.UseItemOnGround(2120,WayPoint[wptid].arg1,WayPoint[wptid].arg2);
- Sleep(500);
- }
- wptid++;
- break;
- }
- case(13):
- {
- int igoldcount = tibia.WindowsItemCount(2148);
- if (igoldcount>=100)
- {
- std::ostringstream goldcount;
- goldcount << int(igoldcount/100);
- tibia.Say("hi");
- Sleep(1500);
- tibia.Say("change gold");
- Sleep(1500);
- tibia.Say(goldcount.str());
- Sleep(1500);
- tibia.Say("yes");
- Sleep(1000);
- }
- wptid++;
- break;
- }
- }
- Sleep(100);
- }
- emit CaveBotOff();
- }
- int cavebot::GetLabel(std::string text,std::vector <label> labels)
- {
- for (int i=0; i<labels.size(); i++)
- if (labels[i].text==text)
- return labels[i].id;
- else
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement