klizmabeqa1992 Posted March 6, 2010 Posted March 6, 2010 Предлагаю на суд общественности вот такой вот небольшой крафтер-бот. Спорить не буду, скрипт сыроват, кое-где может и остался мусор, хотя, старался убрать всё лишнее. Возможности: крафт и продажа сосок всех видов в автоматическом режиме, закупка соул/спирит оре. Надо только закидывать кристаллы. Думаю, в будущем научу его делать себе Д, Ц и Б кристаллы. Только не судите слишком строго. С паскалем я практически впервые общаюсь - первый раз был в школе лет этак 10 назад. Потому, есть один огромный вопрос к знатокам: а есть ли возможность в этом самом FastScript'е запускать альтернативные потоки, которые имели бы доступ к данным основного потока? Если да, это ОЧЕНЬ сильно упростило бы дело написания ботов. Просьба ко всем, кто будет пользоваться этим скриптом: переправьте в массиве pathX, pathY и pathZ последнюю точку пути. Или сам массив измените, чтоб бегал по другому маршруту. Иначе, все боты будут сидеть в одном месте. kod: const crafterName = 'crafterBot'; shopMessage = 'Ваша реклама'; minMP = 200; maxMPtoCraft = 500; shopResetupTime = 200; minSoulOre = 500; minSpiritOre = 500; maxSoulOre = 7000; maxSpiritOre = 7000; SSDprice = 30; //цены на соски. чего не понятного? SSCprice = 60; SSBprice = 120; SSAprice = 240; SSSprice = 1500; BSSDprice = 125; BSSCprice = 250; BSSBprice = 300; BSSAprice = 600; BSSSprice = 3000; maxSSD = 20000; // максимальное число шотов для крафта на продажу, которое бот будет maxSSC = 20000; // стремиться поддерживать. Ноль означает не крафтить, но если в инвентаре уже есть maxSSB = 0; // соски, он будет пытаться их продать. maxSSA = 0; // Если установлено число больше 0, соответствующий рецепт должен быть изучен maxSSS = 0; maxBSSD = 20000; maxBSSC = 20000; maxBSSB = 0; maxBSSA = 0; maxBSSS = 0; SSDid = 1463; SSCid = 1464; SSBid = 1465; SSAid = 1466; SSSid = 1467; BSSDid = 3948; BSSCid = 3949; BSSBid = 3950; BSSAid = 3951; BSSSid = 3952; soulOreID = 1785; spiritOreID = 3031; pathWayPoints = 11; //число точек пути в массиве path buyPoint = 5; //точка пути, по достижению которой можно начинать закупку сырья var out:TForm; m:TMemo; infoUpdate, moveOn, mainLoop, crafting, shop, delayedProc, fixTrade :TTimer; act:integer; initMode, trading :boolean; pathX, pathY, pathZ :array[1..pathWayPoints] of integer; shopping :array[1..3] of String; posX, posY, posZ, currentWayPoint, targetWayPoint, lastRSM :integer; SSD, SSC, SSB, SSA, SSS, BSSD, BSSC, BSSB, BSSA, BSSS, soulOre, spiritOre :integer; SSDoid, SSCoid, SSBoid, SSAoid, SSSoid, BSSDoid, BSSCoid, BSSBoid, BSSAoid, BSSSoid :integer; MyID, MP, maxMP, traderId, buyListID, shopPhase, requestShopManage :integer; i, count, resetupTimer :integer; procedure OnTimer; begin m.Lines.Clear; m.Lines.Add('Current position: '+IntToStr(posX)+', '+IntToStr(posY)+', '+IntToStr(posZ)); m.Lines.Add('Target waypoint: #'+IntToStr(targetWayPoint)+' ('+IntToStr(pathX[targetWayPoint])+', '+IntToStr(pathY[targetWayPoint])+', '+IntToStr(pathZ[targetWayPoint])+')'); m.Lines.Add('Current waypoint: #'+IntToStr(currentWayPoint)); m.Lines.Add('MP: '+IntToStr(MP)+'/'+IntToStr(maxMP)); m.Lines.Add('SSD count:'+IntToStr(SSD)); m.Lines.Add('SSC count:'+IntToStr(SSC)); m.Lines.Add('SSB count:'+IntToStr(SSB)); m.Lines.Add('SSA count:'+IntToStr(SSA)); m.Lines.Add('SSS count:'+IntToStr(SSS)); m.Lines.Add('BSSD count:'+IntToStr(BSSD)); m.Lines.Add('BSSC count:'+IntToStr(BSSC)); m.Lines.Add('BSSB count:'+IntToStr(BSSB)); m.Lines.Add('BSSA count:'+IntToStr(BSSA)); m.Lines.Add('BSSS count:'+IntToStr(BSSS)); m.Lines.Add('SpiritOre count:'+IntToStr(spiritOre)); m.Lines.Add('SoulOre count:'+IntToStr(soulOre)); m.Lines.Add('Last shop request: '+IntToStr(lastRSM)); if trading then m.Lines.Add('Trading...') else m.Lines.Add('Trading stopped.'); if infoUpdate.enabled then m.Lines.Add('infoUpdate: enabled') else m.Lines.Add('infoUpdate: disabled'); if moveOn.enabled then m.Lines.Add('moveOn: enabled') else m.Lines.Add('moveOn: disabled'); if mainLoop.enabled then m.Lines.Add('mainLoop: enabled') else m.Lines.Add('mainLoop: disabled'); if crafting.enabled then m.Lines.Add('crafting: enabled') else m.Lines.Add('crafting: disabled'); if shop.enabled then m.Lines.Add('shop: enabled') else m.Lines.Add('shop: disabled'); end; procedure moveOnTimer; var dx, dy, dz, d :integer; begin dx:=posX-pathX[currentWayPoint]; dy:=posY-pathY[currentWayPoint]; dz:=posZ-pathZ[currentWayPoint]; d:=Round(sqrt(dx*dx+dy*dy)); if (d<40) and (sqrt(dz*dz)<500) then begin if (currentWayPoint=targetWayPoint) then moveOn.enabled:=false else begin currentWayPoint:=currentWayPoint+1; if (currentWayPoint>pathWayPoints) then currentWayPoint:=1; end; exit; end else begin buf:=''; WriteC(1); WriteD(pathX[currentWayPoint]); WriteD(pathY[currentWayPoint]); WriteD(pathZ[currentWayPoint]); WriteD(posX); WriteD(posY); WriteD(posZ); WriteD(1); SendToServerEx(crafterName); end; end; procedure StartTrade; begin mainLoop.enabled:=false; requestShopManage:=1; buf:=#$73; SendToServerEx(crafterName); fixTrade.enabled:=true; end; procedure StartTrade2; begin requestShopManage:=0; buf:=#$77; WriteS(shopMessage); SendToServerEx(crafterName); delay(100); buf:=#$74; WriteD(0); WriteD(0); count:=0; if (SSD>0) then begin inc(count); WriteD(SSDoid); WriteD(SSD); WriteD(SSDprice); end; if (SSC>0) then begin inc(count); WriteD(SSCoid); WriteD(SSC); WriteD(SSCprice); end; if (SSB>0) then begin inc(count); WriteD(SSBoid); WriteD(SSB); WriteD(SSBprice); end; if (SSA>0) then begin inc(count); WriteD(SSAoid); WriteD(SSA); WriteD(SSAprice); end; if (SSS>0) and (count<4) then begin inc(count); WriteD(SSSoid); WriteD(SSS); WriteD(SSSprice); end; if (BSSD>0) and (count<4) then begin inc(count); WriteD(BSSDoid); WriteD(BSSD); WriteD(BSSDprice); end; if (BSSC>0) and (count<4) then begin inc(count); WriteD(BSSCoid); WriteD(BSSC); WriteD(BSSCprice); end; if (BSSB>0) and (count<4) then begin inc(count); WriteD(BSSBoid); WriteD(BSSB); WriteD(BSSBprice); end; if (BSSA>0) and (count<4) then begin inc(count); WriteD(BSSAoid); WriteD(BSSA); WriteD(BSSAprice); end; if (BSSS>0) and (count<4) then begin inc(count); WriteD(BSSSoid); WriteD(BSSS); WriteD(BSSSprice); end; if (count=0) then exit; WriteD(count,6); SendToServerEx(crafterName); resetupTimer:=0; trading:=true; mainLoop.enabled:=true; delayedProc.enabled:=false; fixTrade.enabled:=false; end; procedure StopTrade; begin mainLoop.enabled:=false; buf:=HStr('1D 01 00 00 00'); SendToServerEx(crafterName); delay(200); requestShopManage:=2; buf:=#$73; SendToServerEx(crafterName); fixTrade.enabled:=true; end; procedure StopTrade2; begin requestShopManage:=0; buf:=#$76; SendToServerEx(crafterName); delay(100); trading:=false; mainLoop.enabled:=true; delayedProc.enabled:=false; fixTrade.enabled:=false; end; procedure mainLoopTick; var toCraft :boolean; begin if moveOn.enabled then exit; if (currentWayPoint=buyPoint) then begin mainLoop.enabled:=false; targetWayPoint:=pathWayPoints; shop.enabled:=true; exit; end; if(soulOre<minSoulOre) or (spiritOre<minSpiritOre) then begin if (SSD+SSC+SSB+SSA+SSS+BSSD+BSSC+BSSB+BSSA+BSSS=0) then begin buf:=HStr('1D 01 00 00 00'); SendToServerEx(crafterName); end else StopTrade; targetWayPoint:=buyPoint; moveOn.enabled:=true; exit; end; resetupTimer:=resetupTimer+10; toCraft:=false; if (SSD<maxSSD) then toCraft:=true; if (SSC<maxSSC) then toCraft:=true; if (SSB<maxSSB) then toCraft:=true; if (SSA<maxSSA) then toCraft:=true; if (SSS<maxSSS) then toCraft:=true; if (BSSD<maxBSSD) then toCraft:=true; if (BSSC<maxBSSC) then toCraft:=true; if (BSSB<maxBSSB) then toCraft:=true; if (BSSA<maxBSSA) then toCraft:=true; if (BSSS<maxBSSS) then toCraft:=true; if toCraft and (MP>maxMPtoCraft) and trading then begin mainLoop.enabled:=false; crafting.enabled:=true; exit; end; if (trading=false) then begin StartTrade; exit; end; if (resetupTimer<shopResetupTime) then exit; if (SSD+SSC+SSB+SSA+SSS+BSSD+BSSC+BSSB+BSSA+BSSS=0) then begin buf:=HStr('1D 01 00 00 00'); SendToServerEx(crafterName); exit; end; StopTrade; end; procedure craftingTick; var nocraft :boolean; begin nocraft:=true; if (SSD<maxSSD) then begin buf:=HStr('AF 14 00 00 00'); SendToServerEx(crafterName); delay(33); nocraft:=false; end; if (SSC<maxSSC) then begin buf:=HStr('AF 15 00 00 00'); SendToServerEx(crafterName); delay(33); nocraft:=false; end; if (SSB<maxSSB) then ; if (SSA<maxSSA) then ; if (SSS<maxSSS) then ; if (BSSD<maxBSSD) then begin buf:=HStr('AF 43 01 00 00'); SendToServerEx(crafterName); delay(33); nocraft:=false; end; if (BSSC<maxBSSC) then begin buf:=HStr('AF 44 01 00 00'); SendToServerEx(crafterName); delay(33); nocraft:=false; end; if (BSSB<maxBSSB) then ; if (BSSA<maxBSSA) then ; if (BSSS<maxBSSS) then ; if (MP<minMP) or nocraft then begin crafting.enabled:=false; mainLoop.enabled:=true; exit; end; end; procedure shoppingTick; begin if(shopPhase<4) then begin buf:=shopping[shopPhase]; SendToServerEx(crafterName); inc(shopPhase); exit; end; if(buyListID=0) then exit; shopPhase:=1; shop.enabled:=false; buf:=#$1F; WriteD(buyListID); WriteD(0); i:=0; if(soulOre<maxSoulOre) then begin WriteD(soulOreID); WriteD(maxSoulOre-soulOre); inc(i); end; if(spiritOre<maxSpiritOre) then begin WriteD(spiritOreID); WriteD(maxSpiritOre-spiritOre); inc(i); end; WriteD(i,6); SendToServerEx(crafterName); buyListID:=0; moveOn.enabled:=true; mainLoop.enabled:=true; end; procedure fixOnTimer; begin buf:=#$76; SendToServerEx(crafterName); delay(200); buf:=#$73; SendToServerEx(crafterName); end; procedure Init; //Вызывается при включении скрипта begin out := TForm.Create(nil); out.Caption := 'Status'; out.BorderStyle := bsSizeable; out.Position := poScreenCenter; out.Width:=400; out.Height:=600; m:=TMemo.Create(out); m.parent:=out; m.align:=alClient; m.ReadOnly:=true; m.ScrollBars:=ssBoth; out.Show; infoUpdate:=TTimer.Create(nil); infoUpdate.OnTimer:=@OnTimer; infoUpdate.interval:=1000; moveOn:=TTimer.Create(nil); moveOn.OnTimer:=@moveOnTimer; moveOn.interval:=1000; moveOn.enabled:=false; mainLoop:=TTimer.Create(nil); mainLoop.OnTimer:=@mainLoopTick; mainLoop.interval:=10000; mainLoop.enabled:=false; crafting:=TTimer.Create(nil); crafting.OnTimer:=@craftingTick; crafting.interval:=333; crafting.enabled:=false; shop:=TTimer.Create(nil); shop.OnTimer:=@shoppingTick; shop.interval:=500; shop.enabled:=false; delayedProc:=TTimer.Create(nil); delayedProc.OnTimer:=nil; delayedProc.interval:=333; delayedProc.enabled:=false; fixTrade:=TTimer.Create(nil); fixTrade.OnTimer:=@fixOnTimer; fixTrade.interval:=30000; fixTrade.enabled:=false; posX:=0; posY:=0; posZ:=0; SSD:=0; SSC:=0; SSB:=0; SSA:=0; SSS:=0; BSSD:=0; BSSC:=0; BSSB:=0; BSSA:=0; BSSS:=0; act:=0; MyID:=0; traderId:=0; shopPhase:=1; buyListID:=0; currentWayPoint:=pathWayPoints; targetWayPoint:=pathWayPoints; pathX[1]:= 80687; pathY[1]:= 148621; pathZ[1]:= -3490; pathX[2]:= 79833; pathY[2]:= 148476; pathZ[2]:= -3559; pathX[3]:= 79804; pathY[3]:= 148213; pathZ[3]:= -3559; pathX[4]:= 80247; pathY[4]:= 148172; pathZ[4]:= -3534; pathX[5]:= 80466; pathY[5]:= 147892; pathZ[5]:= -3533; pathX[6]:= 80185; pathY[6]:= 148185; pathZ[6]:= -3534; pathX[7]:= 79787; pathY[7]:= 148246; pathZ[7]:= -3559; pathX[8]:= 79867; pathY[8]:= 148584; pathZ[8]:= -3559; pathX[9]:= 80885; pathY[9]:= 148624; pathZ[9]:= -3495; pathX[10]:= 81749; pathY[10]:= 148292; pathZ[10]:= -3493; pathX[11]:= 0; pathY[11]:= 0; pathZ[11]:= -3493; shopping[3]:=HStr('21 6D 00 65 00 6E 00 75 00 5F 00 73 00 65 00 6C 00 65 00 63 00 74 00 3F 00 61 00 73 00 6B 00 3D 00 2D 00 31 00 26 00 72 00 65 00 70 00 6C 00 79 00 3D 00 30 00 00 00'); infoUpdate.enabled:=true; initMode:=true; trading:=false; buf:=#$0F; SendToServerEx(crafterName); {delay(100); buf:=HStr('A0 03 00 00 00'); SendToServerEx(crafterName);} end; procedure Free; //Вызывается при выключении скрипта begin mainLoop.Free; crafting.Free; infoUpdate.Free; moveOn.Free; m.Free; out.Free; fixTrade.Free; delayedProc.Free; shop.free; end; procedure OnConnect(WithClient: Boolean); //Вызывается при установке соединения begin end; procedure OnDisonnect(WithClient: Boolean); //Вызывается при потере соединения begin end; //основная часть скрипта //вызывается при приходе каждого пакета если скрипт включен begin if (ConnectName<>crafterName) then exit; case FromServer of true: begin //Обработка пакетов сервера if (pck[1]=#$04) then begin maxMP:=ReadD(84); MP:=ReadD(88); if initMode=false then exit; posX:=ReadD(2); posY:=ReadD(6); posZ:=ReadD(10); initMode:=false; MyID:=ReadD(18); moveOn.enabled:=true; mainLoop.enabled:=true; resetupTimer:=0; exit; end; if (pck[1]=#$1B) then //Загрузка инвентаря begin count:=ReadH(4); for i:=0 to count-1 do case ReadD(i*28+12) of SSDid: begin SSD:=ReadD(i*28+16); SSDoid:=ReadD(i*28+8); end; SSCid: begin SSC:=ReadD(i*28+16); SSCoid:=ReadD(i*28+8); end; SSBid: begin SSB:=ReadD(i*28+16); SSBoid:=ReadD(i*28+8); end; SSAid: begin SSA:=ReadD(i*28+16); SSAoid:=ReadD(i*28+8); end; SSSid: begin SSS:=ReadD(i*28+16); SSSoid:=ReadD(i*28+8); end; BSSDid: begin BSSD:=ReadD(i*28+16); BSSDoid:=ReadD(i*28+8); end; BSSCid: begin BSSC:=ReadD(i*28+16); BSSCoid:=ReadD(i*28+8); end; BSSBid: begin BSSB:=ReadD(i*28+16); BSSBoid:=ReadD(i*28+8); end; BSSAid: begin BSSA:=ReadD(i*28+16); BSSAoid:=ReadD(i*28+8); end; BSSSid: begin BSSS:=ReadD(i*28+16); BSSSoid:=ReadD(i*28+8); end; soulOreID: begin soulOre:=ReadD(i*28+16); end; spiritOreID: begin spiritOre:=ReadD(i*28+16); end; end; exit; end; if (pck[1]=#$27) then //Обновление инвентаря begin count:=ReadH(2); for i:=0 to count-1 do begin act:=ReadH(i*30+4); case ReadD(i*30+12) of SSDid: case act of 1: SSD:=SSD+ReadD(i*30+16); 2: SSD:=ReadD(i*30+16); 3: SSD:=SSD-ReadD(i*30+16); end; SSCid: case act of 1: SSC:=SSC+ReadD(i*30+16); 2: SSC:=ReadD(i*30+16); 3: SSC:=SSC-ReadD(i*30+16); end; SSBid: case act of 1: SSB:=SSB+ReadD(i*30+16); 2: SSB:=ReadD(i*30+16); 3: SSB:=SSB-ReadD(i*30+16); end; SSAid: case act of 1: SSA:=SSA+ReadD(i*30+16); 2: SSA:=ReadD(i*30+16); 3: SSA:=SSA-ReadD(i*30+16); end; SSSid: case act of 1: SSS:=SSS+ReadD(i*30+16); 2: SSS:=ReadD(i*30+16); 3: SSS:=SSS-ReadD(i*30+16); end; BSSDid: case act of 1: BSSD:=BSSD+ReadD(i*30+16); 2: BSSD:=ReadD(i*30+16); 3: BSSD:=BSSD-ReadD(i*30+16); end; BSSCid: case act of 1: BSSC:=BSSC+ReadD(i*30+16); 2: BSSC:=ReadD(i*30+16); 3: BSSC:=BSSC-ReadD(i*30+16); end; BSSBid: case act of 1: BSSB:=BSSB+ReadD(i*30+16); 2: BSSB:=ReadD(i*30+16); 3: BSSB:=BSSB-ReadD(i*30+16); end; BSSAid: case act of 1: BSSA:=BSSA+ReadD(i*30+16); 2: BSSA:=ReadD(i*30+16); 3: BSSA:=BSSA-ReadD(i*30+16); end; BSSSid: case act of 1: BSSS:=BSSS+ReadD(i*30+16); 2: BSSS:=ReadD(i*30+16); 3: BSSS:=BSSS-ReadD(i*30+16); end; soulOreID: case act of 1: soulOre:=soulOre+ReadD(i*30+16); 2: soulOre:=ReadD(i*30+16); 3: soulOre:=soulOre-ReadD(i*30+16); end; spiritOreID: case act of 1: spiritOre:=spiritOre+ReadD(i*30+16); 2: spiritOre:=ReadD(i*30+16); 3: spiritOre:=spiritOre-ReadD(i*30+16); end; end; end; exit; end; if (pck[1]=#$0E) and (ReadD(2)=MyID) then begin count:=ReadD(6); for i:=0 to (count-1) do case ReadD(10+i*8) of 11: MP:=ReadD(14+i*8); 12: maxMP:=ReadD(14+i*8); end; exit; end; if (pck[1]=#$9A) and (ReadD(2)=MyID) then begin count:=ReadD(14); for i:=0 to count-1 do case ReadD(i*30+26) of SSDid: SSDoid:=ReadD(i*30+22); SSCid: SSCoid:=ReadD(i*30+22); SSBid: SSBoid:=ReadD(i*30+22); SSAid: SSAoid:=ReadD(i*30+22); SSSid: SSSoid:=ReadD(i*30+22); BSSDid: BSSDoid:=ReadD(i*30+22); BSSCid: BSSCoid:=ReadD(i*30+22); BSSBid: BSSBoid:=ReadD(i*30+22); BSSAid: BSSAoid:=ReadD(i*30+22); BSSSid: BSSSoid:=ReadD(i*30+22); end; case requestShopManage of 0: exit; 1: delayedProc.OnTimer:=@StartTrade2; 2: delayedProc.OnTimer:=@StopTrade2; end; delayedProc.enabled:=true; exit; end; if (pck[1]=#$11) then buyListID:= ReadD(6); end; //end of case 'true' false: begin //Обработка пакетов клиента if (pck[1]=#$48) then begin posX:=ReadD(2); posY:=ReadD(6); posZ:=ReadD(10); exit; end; if (pck[1]=#$04) and (traderId=0) then begin traderId:=ReadD(2); buf:=#$04; WriteD(traderID); WriteD(posX); WriteD(posY); WriteD(posZ); WriteC(0); shopping[1]:=buf; shopping[2]:=buf; end; end; //end of case 'false' end; //end of case end. Quote
EdenEternal Posted July 18, 2010 Posted July 18, 2010 спасибо за это. очень полезная вещь. Вы грузин? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.