Advertisement
hugol

Untitled

Apr 11th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.62 KB | None | 0 0
  1. #include "cavebot.h"
  2.  
  3.  
  4.  
  5. cavebot::cavebot(QObject *parent) :
  6.     QThread(parent)
  7. {
  8.  
  9. }
  10.  
  11. void cavebot::run()
  12. {
  13.  
  14.     bool looting=false;
  15.     int lastx, lasty;
  16.     // szukanie labeli
  17.     label bufflabel;
  18.     std::vector <label> labels;
  19.     for (int i =0; i<WayPoint.size(); i++)
  20.         if (WayPoint[i].typ==3)
  21.         {
  22.             bufflabel.id=i;
  23.             bufflabel.text=WayPoint[i].textarg;
  24.             labels.push_back(bufflabel);
  25.         }
  26.  
  27.     // glowna petla
  28.  
  29.     wptid=0;
  30.     int timestuck=0;
  31.     int bpdest;
  32.     int currstyle=0;
  33.     while(wptid<WayPoint.size())
  34.     {
  35.  
  36.         // looting
  37.         if (tibia.IsAttacking())
  38.         {
  39.             monster target;
  40.             target = tibia.Creature(tibia.CreatureBtlPos(tibia.TargetId()));
  41.             if (target.hppc==0 && target.name!="Snake" && target.name!="Slime")
  42.             {
  43.  
  44.  
  45.                 //looting = true;
  46.                 int timer =0;
  47.                 while(tibia.IsAttacking() && timer < 200)
  48.                 {
  49.                     timer ++;
  50.                     Sleep(10);
  51.                     lastx=target.x;
  52.                     lasty=target.y;
  53.                 }
  54.                 std::vector <int> firstbp = tibia.OpenedBps();
  55.                 std::vector <int> secondbp = tibia.OpenedBps();
  56.                 timer=0;
  57.                 while(secondbp==firstbp && timer < 50)
  58.                 {
  59.                     tibia.OpenGroundItem(lastx,lasty);
  60.                     int timer2=0;
  61.                     while(secondbp==firstbp && timer2 < 5)
  62.                     {
  63.                         timer2++;
  64.                         Sleep(50);
  65.                         secondbp = tibia.OpenedBps();
  66.                     }
  67.                     timer ++;
  68.                     Sleep(50);
  69.                     secondbp = tibia.OpenedBps();
  70.                 }
  71.                 if (timer==50)
  72.                     continue;
  73.  
  74.                 int deadbpid = tibia.BpDifference(firstbp, secondbp);
  75.                 if (deadbpid<0 || deadbpid>=15)
  76.                     continue;
  77.                 // jezeli cos pojdzie nie tak
  78.  
  79.                 if (tibia.WindowEatFood(deadbpid))
  80.                 {
  81.                     Sleep(300);
  82.                     if (!(tibia.GetWhiteText()=="You are full.") && tibia.WindowEatFood(deadbpid))
  83.                         Sleep(300);
  84.                 }
  85.                 for (int i =0; i<Looting.size(); i++)
  86.                 {
  87.                     if ((Looting[i].dest==-1 || tibia.WindowIsOpen(Looting[i].dest)) && Looting[i].dest!=deadbpid)
  88.                     {
  89.                         if (Looting[i].dest==-1)
  90.                         {
  91.                             bpdest= tibia.WindowFirstFreeSlot(deadbpid);
  92.                             if (bpdest==-1)
  93.                                 continue;
  94.                         }
  95.                         else
  96.                             bpdest=Looting[i].dest;
  97.  
  98.                         tibia.MoveItems(Looting[i].id,deadbpid,bpdest);
  99.                         Sleep(200);
  100.                     }
  101.                 }
  102.  
  103.                 // bag opener
  104.                 if(tibia.OpenBag(deadbpid))
  105.                 {
  106.                     while(tibia.OpenBag(deadbpid)) // wait for bag
  107.                         Sleep(200);
  108.  
  109.                     if (tibia.WindowEatFood(deadbpid))
  110.                     {
  111.                         Sleep(300);
  112.                         if (!(tibia.GetWhiteText()=="You are full.") && tibia.WindowEatFood(deadbpid))
  113.                             Sleep(300);
  114.                     }
  115.                     // loot bag
  116.                     for (int i =0; i<Looting.size(); i++)
  117.                     {
  118.                         if (( Looting[i].dest==-1 || tibia.WindowIsOpen(Looting[i].dest)) && Looting[i].dest!=deadbpid)
  119.                         {
  120.                             if (Looting[i].dest==-1)
  121.                             {
  122.                                 bpdest= tibia.WindowFirstFreeSlot(deadbpid);
  123.                                 if (bpdest==-1)
  124.                                     continue;
  125.                             }
  126.  
  127.                             else
  128.                                 bpdest=Looting[i].dest;
  129.  
  130.                             tibia.MoveItems(Looting[i].id,deadbpid,bpdest);
  131.                             Sleep(200);
  132.                         }
  133.                     }
  134.                 }
  135.                 tibia.CloseBp(deadbpid);
  136.                 Sleep(200);
  137.  
  138.             }
  139.         }
  140.  
  141.         // stop attack unreachable monster
  142.         if (tibia.IsAttacking())
  143.  
  144.         {
  145.             monster target = tibia.Creature(tibia.CreatureBtlPos(tibia.TargetId()));
  146.             if (!tibia.IsReachable(target.offx,target.offy,-1))
  147.                 tibia.StopAttack();
  148.         }
  149.  
  150.         // skip wpt if unreachable
  151.         std::string whitetext =tibia.GetWhiteText();
  152.         if (WayPoint[wptid].typ==1 &&
  153.            (whitetext == "There is no way." || whitetext == "Sorry, not possible." || whitetext == "Destination is out of range." ))
  154.             timestuck++;
  155.         else
  156.             timestuck=0;
  157.  
  158.         if (timestuck>100)
  159.         {
  160.             wptid++;
  161.             timestuck=0;
  162.         }
  163.  
  164.  
  165.         // accept wpt if stands on it
  166.         if (tibia.IsAttacking() && WayPoint[wptid].typ==1 &&
  167.                 WayPoint[wptid].arg1==tibia.SelfPosX() && WayPoint[wptid].arg2==tibia.SelfPosY() && WayPoint[wptid].arg3==tibia.SelfPosZ())
  168.             wptid++;
  169.  
  170.  
  171.          // targeting------------------
  172.  
  173.         if (!tibia.IsAttacking() && !looting)
  174.         {
  175.             int stance;
  176.             int id= tibia.BestTarget(Monsters, &stance);
  177.             if (id!=-1)
  178.             {
  179.                 tibia.AttackBtlPos(id);
  180.             }
  181.         }
  182.  
  183.         // beta rune shoter
  184.  
  185.         if (tibia.IsAttacking())
  186.         {
  187.             tibia.UseOnCreature(2311,tibia.CreatureBtlPos(tibia.TargetId())); // hmm
  188.             Sleep(100);
  189.         }
  190.  
  191.         // walker-----------------------------
  192.         if (!tibia.IsAttacking() && !looting)
  193.             switch(WayPoint[wptid].typ)
  194.             {
  195.             case (1):
  196.                 {
  197.                     if (!tibia.IsWalking() && (tibia.SelfPosZ()==WayPoint[wptid].arg3))
  198.                     tibia.Goto(WayPoint[wptid].arg1,WayPoint[wptid].arg2);
  199.  
  200.                     if ((tibia.SelfPosZ()!=WayPoint[wptid].arg3) || //jezeli nie to pietro
  201.                        ((WayPoint[wptid].arg1==tibia.SelfPosX()) && (WayPoint[wptid].arg2==tibia.SelfPosY())))
  202.                     {
  203.                         Sleep(50);
  204.                         wptid++;
  205.                     }
  206.  
  207.                     break;
  208.                 }
  209.             case (2):
  210.                 {
  211.                     wptid=WayPoint[wptid].arg1;
  212.                     break;
  213.                 }
  214.             case(3):
  215.                 {
  216.                     wptid++;
  217.                     break;
  218.                 }
  219.             case(4):
  220.                 {
  221.                     int nextid = cavebot::GetLabel(WayPoint[wptid].textarg,labels);
  222.                     if (nextid==-1)
  223.                         wptid++;
  224.                     else
  225.                         wptid=nextid;
  226.                     break;
  227.                 }
  228.             case(5):
  229.                 {
  230.                     if (tibia.SelfCap()<WayPoint[wptid].arg1)
  231.                         wptid++;
  232.                     else
  233.                         wptid+=2;
  234.                     break;
  235.                 }
  236.             case(6):
  237.                 {
  238.  
  239.                     if (tibia.SelfCap()>WayPoint[wptid].arg1)
  240.                         wptid++;
  241.                     else
  242.                         wptid+=2;
  243.                     break;
  244.                 }
  245.             case(7):
  246.                 {
  247.                     int stackpos;
  248.                     item itembuff = tibia.MapTopItemStruct(WayPoint[wptid].arg1-tibia.SelfPosX(),WayPoint[wptid].arg2-tibia.SelfPosY(),&stackpos);
  249.                     if (itembuff.id==WayPoint[wptid].arg3)
  250.                     {
  251.                         tibia.UseGroundItem(WayPoint[wptid].arg1,WayPoint[wptid].arg2);
  252.                         Sleep(800);
  253.                     }
  254.                     wptid++;
  255.                     break;
  256.                 }
  257.             case(8):
  258.                 {
  259.                     int stackpos;
  260.                     item itembuff = tibia.MapTopItemStruct(WayPoint[wptid].arg1-tibia.SelfPosX(),WayPoint[wptid].arg2-tibia.SelfPosY(),&stackpos);
  261.                     if (itembuff.id==WayPoint[wptid].arg3)
  262.                     {
  263.                         tibia.OpenGroundItem(WayPoint[wptid].arg1,WayPoint[wptid].arg2);
  264.                         Sleep(1000);
  265.                     }
  266.                     wptid++;
  267.                     break;
  268.                 }
  269.              case(9):
  270.                 {
  271.                     tibia.MoveItems(WayPoint[wptid].arg3,WayPoint[wptid].arg1,WayPoint[wptid].arg2);
  272.                     wptid++;
  273.                     Sleep(1000);
  274.                     break;
  275.                 }
  276.             case(10):
  277.                {
  278.                    Sleep(WayPoint[wptid].arg1);
  279.                    wptid++;
  280.                    break;
  281.                }
  282.             case(11):
  283.                {
  284.                    tibia.Say(WayPoint[wptid].textarg);
  285.                    Sleep(500);
  286.                    wptid++;
  287.                    break;
  288.                }
  289.             case(12):
  290.                {
  291.                    if (tibia.SelfPosZ()==WayPoint[wptid].arg3)
  292.                    {
  293.                         tibia.UseItemOnGround(2120,WayPoint[wptid].arg1,WayPoint[wptid].arg2);
  294.                         Sleep(500);
  295.                    }
  296.                    wptid++;
  297.                    break;
  298.                }
  299.             case(13):
  300.                {
  301.                    int igoldcount = tibia.WindowsItemCount(2148);
  302.                    if (igoldcount>=100)
  303.                    {
  304.                         std::ostringstream goldcount;
  305.                         goldcount << int(igoldcount/100);
  306.                         tibia.Say("hi");
  307.                         Sleep(1500);
  308.                         tibia.Say("change gold");
  309.                         Sleep(1500);
  310.                         tibia.Say(goldcount.str());
  311.                         Sleep(1500);
  312.                         tibia.Say("yes");
  313.                         Sleep(1000);
  314.                    }
  315.                    wptid++;
  316.                    break;
  317.                }
  318.  
  319.             }
  320.  
  321.         Sleep(100);
  322.     }
  323.     emit CaveBotOff();
  324. }
  325.  
  326. int cavebot::GetLabel(std::string text,std::vector <label> labels)
  327. {
  328.     for (int i=0; i<labels.size(); i++)
  329.         if (labels[i].text==text)
  330.             return labels[i].id;
  331.     else
  332.             return -1;
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement