Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.99 KB | None | 0 0
  1. import gtk.gdk
  2. import numpy
  3. import numpy as np
  4. import time
  5. import os
  6. import timeit
  7. from collections import Counter
  8. from math import sqrt
  9.  
  10. global move
  11. move = 0
  12.  
  13. os.sytem('xdotool search --name Tibia windowmove %@ 81 35')
  14.  
  15. global wp
  16. wp = 0
  17.  
  18. def pix(x, y):
  19. w = gtk.gdk.get_default_root_window()
  20. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 440, 322)
  21. cm = w.get_colormap()
  22. pb = pb.get_from_drawable(w, cm, ((264+x)-1), ((38+y)-1), 0, 0, 1, 1)
  23. returne = pb.pixel_array[0][0]
  24. returne = str(returne[0])+str(returne[1])+str(returne[2])
  25. return returne
  26.  
  27. def rdRgb(a):
  28. a = a + 25
  29. a = a / 51
  30. a = a* 51
  31. return a
  32.  
  33.  
  34. def ss():
  35. w = gtk.gdk.get_default_root_window()
  36. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 114, 200)
  37. cm = w.get_colormap()
  38. pb = pb.get_from_drawable(w, cm, 106, 51, 0, 0, 114, 200)#+22
  39. #pb.saturate_and_pixelate(pb,1,True)
  40. a = numpy.array(pb.get_pixels_array())
  41. pb.save('ssDD2D.png','png')
  42. data = ''
  43. with open('black.txt',"w") as f:
  44. for x in range(0,20):
  45. data = data+"\n"
  46. for y in range(0,20):
  47. data = data+str(a[x][y])
  48. f.write(data)
  49. return a
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. def playerHP():
  57. w = gtk.gdk.get_default_root_window()
  58. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 95, 23)
  59. cm = w.get_colormap()
  60. pb = pb.get_from_drawable(w, cm, 725, 313, 0, 0, 95, 23)
  61. a = numpy.array(pb.get_pixels_array())
  62. pb.save('ssDD2D.png','png')
  63.  
  64. hpproc = 100
  65. hp = numpy.asarray(["".join(row) for row in a[7].astype(str)])
  66. for x in xrange(4,93):
  67. if hp[x] != '2197979':
  68. hpproc = (x + 3) * 95 /100
  69. break
  70.  
  71. mpproc = 100
  72. mp = numpy.asarray(["".join(row) for row in a[20].astype(str)])
  73. for x in xrange(4,93):
  74. if mp[x] != '8380218':
  75. mpproc = (x + 3) * 95 /100
  76. break
  77.  
  78. data=[]
  79. data.append(hpproc)
  80. data.append(mpproc)
  81. return data
  82.  
  83.  
  84.  
  85. def ssCustom():
  86. w = gtk.gdk.get_default_root_window()
  87. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 440, 322)#434
  88. cm = w.get_colormap()
  89. pb = pb.get_from_drawable(w, cm, 261, 38, 0, 0, 440, 322)
  90. #pb.saturate_and_pixelate(pb,1,True)
  91. a = numpy.asarray(pb.get_pixels_array())
  92. #a = rdRgb(a)
  93. #pb.save('ss.png','png')
  94. return a
  95.  
  96.  
  97. def findCreatureSquare(mobxy):
  98. ddx = -7
  99. ddy = 5
  100. for y in range(1,13):
  101. for x in range(1,17):
  102. min_x = 262
  103. max_x = 262+(x*28)
  104. min_y = 39
  105. max_y = 39+(y*28)
  106. if mobxy[0] > min_x and mobxy[0] < max_x:
  107. if mobxy[1] > min_y and mobxy[1] < max_y:
  108. distX = x-8
  109. distY = y-6
  110. distdata=[distX,distY]
  111. return (distdata)
  112. print("ERRORRERERER")
  113.  
  114.  
  115. def lfCombatFrame():
  116. a = ssCustom().tolist()
  117. saveX = 0
  118. mobcount = 0
  119.  
  120. MobData=[]
  121.  
  122.  
  123. #for y in range(0,322):
  124. for y,e in enumerate(a):
  125. s = 0
  126. #ex = numpy.asarray(["".join(row) for row in a[y].astype(str)],int).tolist()
  127. for x in range(0,440):
  128. #if ex[x] == 0:
  129. if a[y][x][0] == 0 and a[y][x][1] == 0 and a[y][x][1] == 0:
  130. if s == 0:
  131. skip = 0
  132. for xe in xrange(1,4):
  133. if (y+xe) == 322:
  134. skip = 1
  135. break
  136. y22 = y + xe
  137. if a[y22][x][0] != 0 or a[y22][x][1] != 0 or a[y22][x][2] != 0:
  138. skip = 1
  139. break
  140. if skip == 1:
  141. continue
  142.  
  143. for xe in xrange(1,4):
  144. if (y+xe) == 322:
  145. skip = 1
  146. break
  147. y22 = y + xe
  148. x22 = x+26
  149. if x22 >= 440:
  150. skip = 1
  151. break
  152. if a[y22][x22][0] != 0 or a[y22][x22][1] != 0 or a[y22][x22][2] != 0:
  153. skip = 1
  154. break
  155. if skip == 1:
  156. continue
  157.  
  158. saveX = x
  159. s = s +1
  160. if s == 27:
  161. mob = []
  162. colorframe = 0
  163. if y == 17:
  164. localx = x + 261 - 10
  165. localy = y + 38 - 3
  166. else:
  167. localx = x + 261 - 10
  168. localy = y + 38 +18
  169. colorframe = lfcolorFrame(a,x,y)
  170.  
  171.  
  172. mob.append(localx)
  173. mob.append(localy)
  174. mob.append(colorframe)
  175. if y != 17:
  176. mobmapdata = findCreatureSquare(mob)
  177. mob.append(mobmapdata)
  178.  
  179. MobData.append(mob)
  180. mobcount = mobcount + 1
  181. else:
  182. if s > 0:
  183. s = 0
  184. x = saveX
  185.  
  186. asd = 1
  187. return MobData
  188.  
  189. def lfcolorFrame(buffer,hpx,hpy):
  190. startx = hpx - 26
  191. starty = hpy + 4
  192. counter = 0
  193. counter2 = 0
  194. lY = len(buffer)
  195. lX = len(buffer[0])
  196. #25500
  197. #255 0 0
  198. #255128128
  199. for times in range(0,2):
  200. starty = starty +(times*24)
  201. for y in range(0,2):
  202. for x in range(0,26):
  203. newy = starty + y
  204. newx = startx + x
  205. if newy >= lY or newx >= lX:
  206. continue
  207. if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 255 and buffer[newy][newx][2] == 255:
  208. counter = counter + 1
  209. if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 0 and buffer[newy][newx][2] == 0:
  210. counter2 = counter2 + 1
  211. if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 128 and buffer[newy][newx][2] == 128:
  212. counter2 = counter2 + 1
  213.  
  214. startx = hpx - 26
  215. starty = hpy + 28
  216. for times in range(0,2):
  217. startx = startx+(times*25)
  218. for x in range(0,3):
  219. for y in range(0,26):
  220. newy = starty + y
  221. newx = startx + x
  222. if newy >= lY or newx >= lX:
  223. continue
  224. if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 255 and buffer[newy][newx][2] == 255:
  225. counter = counter + 1
  226. if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 0 and buffer[newy][newx][2] == 0:
  227. counter2 = counter2 + 1
  228. if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 128 and buffer[newy][newx][2] == 128:
  229. counter2 = counter2 + 1
  230. frame = 0
  231. if counter > 15:
  232. frame = 1
  233. if counter2 > 15:
  234. frame = 2
  235. return frame
  236.  
  237.  
  238.  
  239.  
  240. def lfCombatFrame2():
  241. a = ssCustom()
  242. streak = 0
  243. prev = 0
  244. app = 0
  245. mobs = []
  246. blackstripe = numpy.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
  247. print('start')
  248. for x,ex in enumerate(a):
  249. ex = numpy.asarray(["".join(row) for row in ex.astype(str)],int)
  250.  
  251. pos = search_sequence_numpy(ex,blackstripe)
  252. if len(pos) > 26:
  253. times = int(round(len(pos)/26))
  254. for x343 in range(0,times):
  255. off = 0
  256. s = 0
  257. for x22 in range(0,2):
  258. for x2 in range(0,4):
  259. x2 = x + x2
  260. if x22 == 0:
  261. pox = pos[0] + off
  262. else:
  263. pox = pos[0] + 26 + off
  264. if a[x2][pos[0]][0] == 0 and a[x2][pos[0]][1] == 0 and a[x2][pos[0]][2] == 0:
  265. s =s + 1
  266. else:
  267. s = 0
  268. break
  269. off = off + 27
  270. if s == 8:
  271. mx = pos[0] + 13
  272. my = x + 22
  273. cords = [mx,my]
  274. mobs.append(cords)
  275. print('stop')
  276. return mobs
  277.  
  278.  
  279.  
  280. def map():
  281. w = gtk.gdk.get_default_root_window()
  282. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 106, 109)
  283. cm = w.get_colormap()
  284. pb = pb.get_from_drawable(w, cm, 714, 40, 0, 0, 106, 109)
  285. #pb.saturate_and_pixelate(pb,1,True)
  286. a = numpy.asarray(pb.get_pixels_array(),int)
  287. #a = rdRgb(a)
  288. #pb.save('map.png','png')
  289. return a
  290.  
  291. def search_sequence_numpy(arr,seq):
  292. """ Find sequence in an array using NumPy only.
  293.  
  294. Parameters
  295. ----------
  296. arr : input 1D array
  297. seq : input 1D array
  298.  
  299. Output
  300. ------
  301. Output : 1D Array of indices in the input array that satisfy the
  302. matching of input sequence in the input array.
  303. In case of no match, an empty list is returned.
  304. """
  305.  
  306. # Store sizes of input array and sequence
  307. Na, Nseq = arr.size, seq.size
  308.  
  309. # Range of sequence
  310. r_seq = np.arange(Nseq)
  311.  
  312. # Create a 2D array of sliding indices across the entire length of input array.
  313. # Match up with the input sequence & get the matching starting indices.
  314. M = (arr[np.arange(Na-Nseq+1)[:,None] + r_seq] == seq).all(1)
  315.  
  316. # Get the range of those indices as final output
  317. if M.any() >0:
  318. return np.where(np.convolve(M,np.ones((Nseq),dtype=int))>0)[0]
  319. else:
  320. return [] # No match found
  321.  
  322.  
  323.  
  324. #38/175
  325. def getMapPoint2(b,m):
  326. runs = 0
  327. map = numpy.asarray([''.join(row) for row in m[0].astype(str)],int).tolist()
  328. saveX = 0
  329. hs = 0
  330.  
  331. for iY, eY in enumerate(b):
  332. eY = numpy.asarray(["".join(row) for row in eY.astype(str)],int).tolist()
  333. s = 0
  334. l = len(eY)
  335. hs = 0
  336. for x in xrange(0,l):
  337. if eY[x] == map[0]:
  338. l2 = len(map)
  339. if (x+l2) < l:
  340. for xmap in range(0,l2):
  341. xx22 = x + xmap
  342. if eY[xx22] == map[xmap]:
  343. if xmap == 105:
  344. px = x+53
  345. py = iY+54
  346. playerPos=[px,py]
  347.  
  348. playerSquare = []
  349. sqx = px - 1
  350. sqy = py - 1
  351. for y in range(0,3):
  352. line = []
  353. for x in range(0,3):
  354. l_sqx = sqx + x
  355. l_sqy = sqy + y
  356. line.append(b[l_sqy][l_sqx])
  357. playerSquare.append(line)
  358.  
  359. playerSquare = numpy.asarray(playerSquare)
  360. PS = []
  361. for i, e in enumerate(playerSquare):
  362. playerSquare = ["".join(row) for row in e.astype(str)]
  363. PS.append(playerSquare)
  364.  
  365. returne= []
  366. returne.append(playerPos)
  367. returne.append(PS)
  368. return(returne)
  369. else:
  370. break
  371. return 0
  372.  
  373. def isWall(str):
  374. wall = [255510,153510]
  375. intwall = int(str)
  376. for x in range(0,len(wall)):
  377. if intwall == wall[x]:
  378. return 1
  379. return 0
  380.  
  381.  
  382.  
  383.  
  384. def calcReachableSquare(globalMap,xy):
  385. AccessibleSquare=[[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0]]
  386. AccessibleSquare[5][5] = 1338
  387.  
  388. for multipl in range(0,4):
  389. x1 = xy[0]-1 -multipl
  390. y1 = xy[1]-1 -multipl
  391. base_x3 = 4 -multipl
  392. base_y3 =4 -multipl
  393.  
  394. maxY = 3 + (2*multipl)
  395. maxX = 3 + (2*multipl)
  396.  
  397. for y in range(0,maxY):
  398. y1 = xy[1]-1 -multipl + y
  399. if y1 == 256:
  400. break
  401. map = numpy.asarray([''.join(row) for row in globalMap[y1].astype(str)],int).tolist()
  402. x1 = xy[0]-1 -multipl
  403. y3 = base_y3 + y
  404. for x in range(0,maxX):
  405. x3 = base_x3+x
  406. if AccessibleSquare[y3][x3] == 2:
  407. x1 = x1 + 1
  408. continue
  409. if isWall(map[x1]) == 1 and AccessibleSquare[y3][x3] != -1:
  410. AccessibleSquare[y3][x3] = -1
  411. x1 = x1 + 1
  412. continue
  413. if AccessibleSquare[y3][x3] == -1:
  414. x1 = x1 + 1
  415. continue
  416. AccessibleSquare[y3][x3] = 1
  417. nx3 = x3 -1
  418. ny3 = y3 - 1
  419. skip = 0
  420. for y2 in range(1,4):
  421. nx3 = x3 -1
  422. for x2 in range(1,4):
  423. if AccessibleSquare[ny3][nx3] == 2 or AccessibleSquare[ny3][nx3] == 1338:
  424. AccessibleSquare[y3][x3] = 2
  425. #print(y3)
  426. #print(x3)
  427. #print('GITARA')
  428. skip = 1
  429. break
  430. nx3 = nx3 + 1
  431. if skip == 1:
  432. break
  433. ny3 = ny3 + 1
  434.  
  435. x3 = x3 + 1
  436. x1 = x1 + 1
  437.  
  438. AccessibleSquare[5][5] = 3
  439. return AccessibleSquare
  440.  
  441.  
  442.  
  443. def getMapPoint(b,m):
  444. runs = 0
  445. map = numpy.asarray([''.join(row) for row in m[0].astype(str)],int)
  446. for iY, eY in enumerate(b):
  447. eY = numpy.asarray(["".join(row) for row in eY.astype(str)],int)
  448.  
  449. pos = search_sequence_numpy(eY,map)
  450. if len(pos) == 106:
  451. px = pos[0]+53
  452. py = iY+54
  453. playerPos=[px,py]
  454.  
  455.  
  456.  
  457. AccessibleSquare = calcReachableSquare(b,playerPos)
  458. playerSquare = []
  459. sqx = px - 1
  460. sqy = py - 1
  461. for y in range(0,3):
  462. line = []
  463. for x in range(0,3):
  464. l_sqx = sqx + x
  465. l_sqy = sqy + y
  466. line.append(b[l_sqy][l_sqx])
  467. playerSquare.append(line)
  468.  
  469. playerSquare = numpy.asarray(playerSquare)
  470. PS = []
  471. for i, e in enumerate(playerSquare):
  472. playerSquare = ["".join(row) for row in e.astype(str)]
  473. PS.append(playerSquare)
  474.  
  475. returne= []
  476. returne.append(playerPos)
  477. returne.append(PS)
  478. returne.append(AccessibleSquare)
  479. return(returne)
  480. return 0
  481.  
  482. def isWalkable(side,sq,wall,wrldside):
  483. wpAround=[]
  484. if side == 'Left':
  485. if str(sq[1][0]) in wall:
  486. if str(sq[0][0]) not in wall:
  487. wpAround.append("KP_Home")
  488. return wpAround
  489. if str(sq[2][0]) not in wall:
  490. wpAround.append("KP_End")
  491. return wpAround
  492.  
  493. if wrldside == "Up":
  494. if str(sq[0][1]) not in wall:
  495. wpAround.append("Up")
  496. return wpAround
  497. else:
  498. if str(sq[2][1]) not in wall:
  499. wpAround.append("Down")
  500. return wpAround
  501.  
  502.  
  503.  
  504. if str(sq[0][2]) not in wall:
  505. wpAround.append("KP_Page_Up")
  506. return wpAround
  507. if str(sq[2][2]) not in wall:
  508. wpAround.append("KP_PageDown")
  509. return wpAround
  510. if str(sq[1][2]) not in wall:
  511. wpAround.append("Right")
  512. return wpAround
  513.  
  514. if side == 'Right':
  515. if str(sq[1][2]) in wall:
  516. if str(sq[0][2]) not in wall:
  517. wpAround.append("KP_Page_Up")
  518. return wpAround
  519. if str(sq[2][2]) not in wall:
  520. wpAround.append("KP_Page_Down")
  521. return wpAround
  522.  
  523. if wrldside == 'Up':
  524. if str(sq[0][1]) not in wall:
  525. wpAround.append("Up")
  526. return wpAround
  527. else:
  528. if str(sq[2][1]) not in wall:
  529. wpAround.append("Down")
  530. return wpAround
  531.  
  532.  
  533. if str(sq[0][0]) not in wall:
  534. wpAround.append("KP_Home")
  535. return wpAround
  536. if str(sq[2][0]) not in wall:
  537. wpAround.append("KP_End")
  538. return wpAround
  539. if str(sq[1][0]) not in wall:
  540. wpAround.append("Left")
  541. return wpAround
  542.  
  543. if side == 'Up':
  544. if str(sq[0][1]) in wall:
  545. if str(sq[0][0]) not in wall:
  546. wpAround.append("KP_Home")
  547. return wpAround
  548. if str(sq[0][2]) not in wall:
  549. wpAround.append("KP_Page_Up")
  550. return wpAround
  551.  
  552. if wrldside == 'Left':
  553. if str(sq[1][0]) not in wall:
  554. wpAround.append("Left")
  555. return wpAround
  556. else:
  557. if str(sq[1][2]) not in wall:
  558. wpAround.append("Right")
  559. return wpAround
  560.  
  561.  
  562. if str(sq[2][0]) not in wall:
  563. wpAround.append("KP_End")
  564. return wpAround
  565. if str(sq[2][2]) not in wall:
  566. wpAround.append("KP_Page_Down")
  567. return wpAround
  568. if str(sq[2][1]) not in wall:
  569. wpAround.append("Down")
  570. return wpAround
  571.  
  572. if side == 'Down':
  573. if str(sq[2][1]) in wall:
  574. if str(sq[2][0]) not in wall:
  575. wpAround.append("KP_End")
  576. return wpAround
  577. if str(sq[2][2]) not in wall:
  578. wpAround.append("KP_Page_Down")
  579. return wpAround
  580.  
  581. if wrldside == 'Left':
  582. if str(sq[1][0]) not in wall:
  583. wpAround.append("Left")
  584. return wpAround
  585. else:
  586. if str(sq[1][2]) not in wall:
  587. wpAround.append("Right")
  588. return wpAround
  589.  
  590.  
  591. if str(sq[0][0]) not in wall:
  592. wpAround.append("KP_Home")
  593. return wpAround
  594. if str(sq[0][2]) not in wall:
  595. wpAround.append("KP_Page_Up")
  596. return wpAround
  597. if str(sq[0][1]) not in wall:
  598. wpAround.append("Up")
  599. return wpAround
  600.  
  601. def battlelistCheck(tryanother):
  602. w = gtk.gdk.get_default_root_window()
  603. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 135, 200)
  604. cm = w.get_colormap()
  605. pb = pb.get_from_drawable(w, cm, 85, 51, 0, 0, 135, 200)#+22
  606. #pb.saturate_and_pixelate(pb,1,True)
  607. a = numpy.array(pb.get_pixels_array())
  608. pb.save('battle.png','png')
  609.  
  610. BattleMobs=[['caverat',176],['rat',82],['spider',140],['bat',84]]
  611.  
  612.  
  613. #LIST COLOR FRAMES&NAMES
  614. #CHECK FOR COMBAT
  615. fighting = 0
  616. for slots in range(0,10):
  617. ycalc0 = 4+(slots*22)
  618. ycalc1 = 13+(slots*22)
  619. if ycalc1 > 200:
  620. break
  621. newSlot = numpy.asarray(["".join(row) for row in a[ycalc0].astype(str)],int).tolist()
  622. if newSlot[0] == 25500 or newSlot[0] == 255128128:
  623. fighting = 1
  624. if tryanother == 1:
  625. xclick = 95+(slots*22)
  626. yclick = 61+(slots*22)
  627. os.system('xdotool mousemove '+str(xclick)+" "+str(yclick))
  628. os.system('xdotool click 1')
  629. return 0
  630. return 1
  631.  
  632. if fighting == 0:
  633. for slots in range(0,10):
  634. counter = 0
  635. ycalc0 = 4+(slots*22)
  636. ycalc1 = 13+(slots*22)
  637. if ycalc1 > 200:
  638. break
  639. for y in range(ycalc0,ycalc1):
  640. newSlot = numpy.asarray(["".join(row) for row in a[y].astype(str)],int).tolist()
  641. for x in range(21,106):
  642. if newSlot[x] == 192192192 or newSlot[x] == 247247247:
  643. counter = counter + 1
  644. for ie,xe in enumerate(BattleMobs):
  645. #if counter == xe[1]:
  646. if counter == xe[1]:
  647. xclick = 95+(slots*22)
  648. yclick = 61+(slots*22)
  649. os.system('xdotool mousemove '+str(xclick)+" "+str(yclick))
  650. os.system('xdotool click 1')
  651. return 3
  652.  
  653. if counter == 0:
  654. break
  655. #print(counter)
  656. #exit()
  657. return 0
  658.  
  659.  
  660. def checkIfMobIsAccessible(sq_acces,mobmapdata):
  661. l = len(mobmapdata)
  662.  
  663. l2 = len(sq_acces)
  664. l2_min = (l2 - 1) / 2
  665. for x in range(0,l):
  666. p0 = [l2_min,l2_min]
  667. if mobmapdata[x][2] == 2 and len(mobmapdata[x]) > 3:
  668. checkX = p0[0] + mobmapdata[x][3][0]
  669. checkY = p0[1] + mobmapdata[x][3][1]
  670. #print(str(p0[0])+"+"+str(mobmapdata[x][3][0])+"="+str(checkX))
  671. #print(str(p0[1])+"+"+str(mobmapdata[x][3][1])+"="+str(checkY))
  672. if checkX < 0 or checkX >= l2:
  673. return 0
  674. if checkY < 0 or checkY >= l2:
  675. return 0
  676. if sq_acces[checkY][checkX] == 2:
  677. return 1
  678. else:
  679. return 0
  680. return 0
  681.  
  682.  
  683. def getXYaroundSQ(xy):
  684. playerx=480
  685. playery=200
  686. sqsize = 29
  687. if xy[0] == -1:
  688. playerx = playerx-sqsize
  689. if xy[0] == 1:
  690. playerx = playerx+sqsize
  691.  
  692. if xy[1] == -1:
  693. playery = playery-sqsize
  694. if xy[1] == 1:
  695. playery = playery+sqsize
  696.  
  697. data=[playerx,playery]
  698. return data
  699.  
  700.  
  701.  
  702.  
  703. def loot(listXY,playerxy):
  704. l = len(listXY)-1
  705. for x in range(l,-1,-1):
  706. mathX = int(str(listXY[x][0]))-int(str(playerxy[0]))
  707. mathY = int(str(listXY[x][1]))-int(str(playerxy[1]))
  708. xy=[mathX,mathY]
  709. if mathX < 2 and mathX > -2:
  710. if mathY < 2 and mathY > -2:
  711. clickpos = getXYaroundSQ(xy)
  712. print("LOOTING")
  713. print(str(mathX)+"/"+str(mathY))
  714. print(playerxy)
  715. print(clickpos)
  716.  
  717. os.system('xdotool keydown SHIFT')
  718. os.system('xdotool mousemove '+str(clickpos[0])+" "+str(clickpos[1]))
  719. time.sleep(0.2)
  720. os.system('xdotool click 3')
  721. os.system('xdotool keyup SHIFT')
  722. del listXY[x]
  723.  
  724.  
  725.  
  726.  
  727.  
  728. def walk(wps):
  729. global move
  730. global wp
  731. #grey/green0
  732. walkColors=['153153153','02040']
  733. #yellow
  734. dropcolor = ['2552550']
  735. #red
  736. wall = ['255510','1337','153510']
  737.  
  738. l_wps = len(wps)
  739.  
  740.  
  741.  
  742. fightingXY = []
  743. while True:
  744.  
  745. battle = battlelistCheck(0)
  746. m = map()
  747. pos = getMapPoint(b,m)
  748. mobmapdata = lfCombatFrame()
  749. #print(pos[0])
  750. #exit()
  751. if pos == 0:
  752. print('%pos not found')
  753. else:
  754. if battle == 1 or battle == 3:
  755. accessible = checkIfMobIsAccessible(pos[2],mobmapdata)
  756. if accessible == 0:
  757. battle = battlelistCheck(1)
  758.  
  759.  
  760. loot(fightingXY,pos[0])
  761. waitTillDeath = 0
  762. l_lootlist = len(fightingXY)
  763.  
  764.  
  765. if battle == 1 or battle == 3:
  766. newWayPointx = 0
  767. newWayPointy = 0
  768. for xmobs in range(0,len(mobmapdata)):
  769. if mobmapdata[xmobs][2] == 2:
  770. newWayPointx = pos[0][0] + int(mobmapdata[xmobs][3][0])
  771. newWayPointy = pos[0][1] + int(mobmapdata[xmobs][3][1])
  772. if battle == 3:
  773. mightDropPos=[newWayPointx,newWayPointy]
  774. fightingXY.append(mightDropPos)
  775. l_lootlist = l_lootlist + 1
  776. if battle == 1:
  777. if l_lootlist > 0:
  778. newl_lootlist = l_lootlist - 1
  779. fightingXY[newl_lootlist][0] = newWayPointx
  780. fightingXY[newl_lootlist][1] = newWayPointy
  781.  
  782.  
  783. if abs(int(mobmapdata[xmobs][3][0])) <= 1 and abs(int(mobmapdata[xmobs][3][1])) <=1:
  784. waitTillDeath = 1
  785. break
  786. break
  787. print("gotoMob:"+str(newWayPointx)+"/"+str(newWayPointy))
  788.  
  789. print(fightingXY)
  790. hp = playerHP()
  791. #near = getNearest(mobmapdata)
  792. #os.system('xdotool keydown SHIFT')
  793. #os.system('xdotool mousemove '+str(near[0])+" "+str(near[1]))
  794. #os.system('xdotool click 3')
  795. #os.system('xdotool keyup SHIFT')
  796.  
  797. if waitTillDeath == 1:
  798. continue
  799.  
  800. urpos = pos[0]
  801. SQ = pos[1]
  802.  
  803. for x in range(0,len(mobmapdata)):
  804. if len(mobmapdata[x]) > 3:
  805. if mobmapdata[x][3][0] > -2 and mobmapdata[x][3][0] < 2 and mobmapdata[x][3][1] > -2 and mobmapdata[x][3][1] < 2:
  806. xmob = int(mobmapdata[x][3][0])
  807. ymob = int(mobmapdata[x][3][1])
  808. xmob = 1 + xmob
  809. ymob = 1 + ymob
  810. SQ[ymob][xmob] = '1337'
  811.  
  812. if battle == 1 or battle == 3:
  813. dest = [newWayPointx,newWayPointy]
  814. else:
  815. if battle == 0 and l_lootlist > 0:
  816. newl_lootlist = l_lootlist - 1
  817. dest = fightingXY[newl_lootlist]
  818. else:
  819. dest = wps[wp]
  820.  
  821. print(dest)
  822. try0 = 0
  823. wrldside = 0
  824. mathX = abs(int(str(dest[0]))-int(str(urpos[0])))
  825. mathY = abs(int(str(dest[1]))-int(str(urpos[1])))
  826. rawMath = []
  827. rawMath.append((int(str(dest[0]))-int(str(urpos[0]))))
  828. rawMath.append((int(str(dest[1]))-int(str(urpos[1]))))
  829.  
  830. if mathX > mathY:
  831. if urpos[0] < dest[0]:
  832. try0='Right'
  833. if urpos[0] > dest[0]:
  834. try0='Left'
  835.  
  836. if urpos[1] < dest[1]:
  837. wrldside='Down'
  838. if urpos[1] > dest[1]:
  839. wrldside='Up'
  840. else:
  841. if urpos[1] < dest[1]:
  842. try0='Down'
  843. if urpos[1] > dest[1]:
  844. try0='Up'
  845.  
  846. if urpos[0] < dest[0]:
  847. wrldside='Right'
  848. if urpos[0] > dest[0]:
  849. wrldside='Left'
  850.  
  851.  
  852. if mathX <= 1 and mathY <= 1 and battle == 0:
  853. wp = wp + 1
  854. if wp == l_wps:
  855. wp = 0
  856. print("current waypoit;"+str(wp))
  857. print(wps[wp])
  858. continue
  859.  
  860.  
  861. walkk = isWalkable(try0,SQ,wall,wrldside)
  862. key = try0
  863. if walkk != None:
  864. key = walkk[0]
  865.  
  866. os.system('xdotool key '+key)
  867. #time.sleep(0.30)
  868. #os.system('xdotool keyup '+key)
  869. print(key)
  870.  
  871.  
  872. def getNearest(mobdata):
  873. playerpos=[477,193]
  874. neardist = 0
  875. nearpoint = 0
  876. if len(mobdata) > 0:
  877. for x in xrange(0,len(mobdata)):
  878. xcalc = abs(int(str(mobdata[x][0])) - int(str(playerpos[0])))
  879. ycalc = abs(int(str(mobdata[x][1])) - int(str(playerpos[1])))
  880. dist = sqrt(xcalc**2+ycalc**2)
  881.  
  882. if neardist == 0:
  883. neardist = dist
  884. nearpoint = x
  885. else:
  886. if dist < neardist:
  887. neardist = dist
  888. nearpoint = x
  889. return mobdata[nearpoint]
  890. return 0
  891.  
  892.  
  893.  
  894. pb = gtk.gdk.pixbuf_new_from_file("maps/thais02.png")
  895. b = numpy.asarray(pb.get_pixels_array(),int)
  896. #walkPoints=[[89,222],[88,215],[77,216]]
  897. walkPoints=[[109,214],[97,214],[87,215],[79,214],[73,215],[73,222],[74,227],[80,227],[83,232],[83,238],[82,244],[82,250],[88,251],[95,251],[103,252],[109,251],[111,248],[111,242],[112,237],[112,230],[112,224],[112,217]]
  898.  
  899.  
  900.  
  901. while True:
  902. walk(walkPoints)
  903.  
  904. exit()
  905.  
  906.  
  907.  
  908.  
  909.  
  910. def ssTile(x,y):
  911. Xx = x * 30
  912. Yy = y * 30
  913. w = gtk.gdk.get_default_root_window()
  914. pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 30, 30)
  915. cm = w.get_colormap()
  916. pb = pb.get_from_drawable(w, cm, (262+Xx), (41+Yy), 0, 0, 30, 30)
  917. pb.saturate_and_pixelate(pb,1,True)
  918. a = numpy.array(pb.get_pixels_array())
  919. a = rdRgb(a)
  920. pb.save('tile.jpeg','jpeg')
  921. data = ''
  922. with open('drff.txt',"w") as f:
  923. for x in range(0,30):
  924. data = data+"\n"
  925. for y in range(0,30):
  926. data = data+str(a[x][y])
  927. f.write(data)
  928. return a
  929.  
  930.  
  931. exit()
  932.  
  933.  
  934. with open("px.txt") as file:
  935. data = file.read()
  936.  
  937. @@@
  938. #include <gtk/gtk.h>
  939. extern "C"
  940. {
  941. static int MobPosX[50];
  942. static int MobPosY[50];
  943. static int playerpos[2];
  944. static int playerSquare[3][3];
  945. int combine(int a, int b) {
  946. if (b == 0){
  947. return a * 10;
  948. }
  949. int times = 1;
  950. while (times <= b)
  951. times *= 10;
  952. return a*times + b;
  953. }
  954.  
  955. int readPX(unsigned char *buffer, int rowstride, int n_channels,int x, int y)
  956. {
  957. int p1, p2, p3;
  958. unsigned char *p;
  959. p = buffer + y * rowstride + x * n_channels;
  960. p1 = int((unsigned char)(p[0]));
  961. p2 = int((unsigned char)(p[1]));
  962. p3 = int((unsigned char)(p[2]));
  963. int p4 = combine(p1, p2);
  964. p4 = combine(p4, p3);
  965. return p4;
  966. }
  967. int getMobPos(){
  968. int clientX = 261;
  969. int clientY = 48;
  970. int rowstride, n_channels;
  971. unsigned char *p;
  972. GdkPixbuf *pxbuf;
  973. GdkWindow *wind = gdk_get_default_root_window();
  974. pxbuf = gdk_pixbuf_get_from_window(wind, clientX, 48, 440, 322);
  975. //gdk_pixbuf_save(pxbuf, "ss.png", "png", NULL, NULL);
  976. //GdkPixbuf *pxbuf2 = gdk_pixbuf_new_from_file("123.png",NULL);
  977. unsigned char *px = gdk_pixbuf_get_pixels(pxbuf);
  978. //int *array2 = reinterpret_cast<int*>(px);
  979. rowstride = gdk_pixbuf_get_rowstride(pxbuf);
  980. n_channels = gdk_pixbuf_get_n_channels(pxbuf);
  981.  
  982. int p1, p2, p3;
  983. int mobcount;
  984. int mobx, moby;
  985.  
  986.  
  987. int s, saveX;
  988. saveX = 0;
  989. mobcount = 0;
  990. for (int y = 0; y < 322; ++y) {
  991. s = 0;
  992. mobx = 0;
  993. moby = 0;
  994. for (int x = 0; x < 440; ++x) {
  995.  
  996. p = px + y * rowstride + x * n_channels;
  997. p1 = int((unsigned char)(p[0]));
  998. p2 = int((unsigned char)(p[1]));
  999. p3 = int((unsigned char)(p[2]));
  1000. int p4 = combine(p1, p2);
  1001. p4 = combine(p4, p3);
  1002. //ps2 << p1 << p2 << p3;
  1003. //string str = ps2.str();
  1004. //ps = to_string(p1) + to_string(p2) + to_string(p3);
  1005. //string p11 = to_string(p1);
  1006. //reinterpret_cast<int*>(Xline)[0] = p4;
  1007. //Xline2[x] = int(p4);
  1008. //char* end = Xline2 + sizeof(Xline2) / sizeof(Xline2[0]);
  1009. //char ser = int(p4)+5;
  1010. //char* position = std::find(Xline2, end, ser);
  1011. //Xline[x] = p4;
  1012. if (p4 == 0){
  1013.  
  1014. if (s == 0){
  1015. int skip = 0;
  1016. for (int xe = 1; xe < 4; ++xe) {
  1017. if ((y + xe) > 320){
  1018. skip = 1;
  1019. continue;
  1020. }
  1021. //std::cout << (clientX + x) << " " << (clientY+y) << std::endl;
  1022. int pixel = readPX(px, rowstride, n_channels, x, (y + xe));
  1023. if (pixel != 0){
  1024. skip = 1;
  1025. }
  1026. }
  1027. for (int xe = 1; xe < 26; ++xe) {
  1028. if ((x + xe) > 437){
  1029. skip = 1;
  1030. continue;
  1031. }
  1032. int pixel = readPX(px, rowstride, n_channels, (x + xe), y);
  1033. if (pixel != 0){
  1034. skip = 1;
  1035. continue;
  1036. }
  1037. }
  1038. for (int xe = 1; xe < 4; ++xe) {
  1039. if ((y + xe) > 320){
  1040. skip = 1;
  1041. continue;
  1042. }
  1043. //std::cout << (clientX + x) << " " << (clientY+y) << std::endl;
  1044. int pixel = readPX(px, rowstride, n_channels, (x + 26), (y + xe));
  1045. if (pixel != 0){
  1046. skip = 1;
  1047. continue;
  1048. }
  1049. }
  1050.  
  1051.  
  1052. if (skip == 1)
  1053. {
  1054. continue;
  1055. }
  1056. saveX = x;
  1057. }
  1058. s = s + 1;
  1059. if (s == 27){
  1060. if (y == 14)//First square line in game
  1061. {
  1062. mobx = x + clientX - 10;
  1063. moby = y + clientY - 3;
  1064. }
  1065. else
  1066. {
  1067. mobx = x + clientX - 9;
  1068. moby = y + clientY + 21;
  1069. }
  1070. MobPosX[mobcount] = mobx;
  1071. MobPosY[mobcount] = moby;
  1072.  
  1073.  
  1074. //std::cout << MobPosX[mobcount] << " " << MobPosY[mobcount] << std::endl;
  1075. //std::cout << mobcount << std::endl;
  1076. mobcount++;
  1077. }
  1078.  
  1079. }
  1080. else{
  1081. if (s > 0){
  1082. x = saveX;
  1083. s = 0;
  1084. }
  1085. }
  1086.  
  1087.  
  1088.  
  1089. //std::cout << p4 << "/ /" << p1 << "." << p2 << "." << " " << std::endl;
  1090. //cin.get();
  1091. }
  1092. //std::cout << Xline << "/ /" << p1 << "." << p2 << "." << " " << std::endl;
  1093. }
  1094.  
  1095. return mobcount;
  1096.  
  1097. }
  1098. int getPlayerPos()
  1099. {
  1100. int rowstride, n_channels, rowstride2, n_channels2;
  1101. GdkPixbuf *pxbuf;
  1102. GdkWindow *wind = gdk_get_default_root_window();
  1103. pxbuf = gdk_pixbuf_get_from_window(wind, 714, 40, 106, 109);
  1104. //gdk_pixbuf_save(pxbuf, "ss.png", "png", NULL, NULL);
  1105. GdkPixbuf *pxbuf2 = gdk_pixbuf_new_from_file("thais01.png",NULL);
  1106.  
  1107.  
  1108. unsigned char *px = gdk_pixbuf_get_pixels(pxbuf);
  1109. unsigned char *px2 = gdk_pixbuf_get_pixels(pxbuf2);
  1110.  
  1111. rowstride = gdk_pixbuf_get_rowstride(pxbuf);
  1112. n_channels = gdk_pixbuf_get_n_channels(pxbuf);
  1113.  
  1114. rowstride2 = gdk_pixbuf_get_rowstride(pxbuf2);
  1115. n_channels2 = gdk_pixbuf_get_n_channels(pxbuf2);
  1116.  
  1117. int s, saveX;
  1118. saveX = 0;
  1119.  
  1120. int SSmapPattern[105];
  1121. for (int x = 0; x < 105; ++x) {
  1122. int pixel = readPX(px, rowstride, n_channels, x, 0);
  1123. SSmapPattern[x] = pixel;
  1124.  
  1125. }
  1126.  
  1127.  
  1128. for (int y = 0; y <= 256; ++y) {
  1129. s = 0;
  1130. for (int x = 0; x <= 256; ++x) {
  1131. int pixel = readPX(px2, rowstride2, n_channels2, x, y);
  1132. if (pixel == SSmapPattern[s])
  1133. {
  1134. if (s == 0){
  1135. saveX = x;
  1136. }
  1137. s++;
  1138. if (s == 105){
  1139. playerpos[0] = saveX+52;
  1140. playerpos[1] = y+53;
  1141.  
  1142.  
  1143. int sqx = playerpos[0] - 1;
  1144. int sqy = playerpos[1] - 1;
  1145.  
  1146. int l_sqx, l_sqy;
  1147. for (int y02 = 0; y02 < 3; ++y02) {
  1148. for (int x02 = 0; x02 < 3; ++x02) {
  1149. l_sqx = sqx + x02;
  1150. l_sqy = sqy + y02;
  1151. playerSquare[y02][x02] = readPX(px2, rowstride2, n_channels2, l_sqx, l_sqy);
  1152.  
  1153. }
  1154. }
  1155. return 1;
  1156.  
  1157. //playerSqure
  1158. }
  1159.  
  1160. }
  1161. else{
  1162. if (s > 0){
  1163. x = saveX;
  1164. s = 0;
  1165. }
  1166.  
  1167. }
  1168.  
  1169. }
  1170.  
  1171. }
  1172.  
  1173. return 0;
  1174.  
  1175. }
  1176. void initialize()
  1177. {
  1178. gtk_init(NULL,NULL);
  1179. }
  1180. int makeSS ()
  1181. {
  1182. int asd;
  1183. asd = getPlayerPos();
  1184. asd = getMobPos();
  1185. return "asd";
  1186. }
  1187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement