Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gtk.gdk
- import numpy
- import numpy as np
- import time
- import os
- import timeit
- from collections import Counter
- from math import sqrt
- global move
- move = 0
- os.sytem('xdotool search --name Tibia windowmove %@ 81 35')
- global wp
- wp = 0
- def pix(x, y):
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 440, 322)
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, ((264+x)-1), ((38+y)-1), 0, 0, 1, 1)
- returne = pb.pixel_array[0][0]
- returne = str(returne[0])+str(returne[1])+str(returne[2])
- return returne
- def rdRgb(a):
- a = a + 25
- a = a / 51
- a = a* 51
- return a
- def ss():
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 114, 200)
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, 106, 51, 0, 0, 114, 200)#+22
- #pb.saturate_and_pixelate(pb,1,True)
- a = numpy.array(pb.get_pixels_array())
- pb.save('ssDD2D.png','png')
- data = ''
- with open('black.txt',"w") as f:
- for x in range(0,20):
- data = data+"\n"
- for y in range(0,20):
- data = data+str(a[x][y])
- f.write(data)
- return a
- def playerHP():
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 95, 23)
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, 725, 313, 0, 0, 95, 23)
- a = numpy.array(pb.get_pixels_array())
- pb.save('ssDD2D.png','png')
- hpproc = 100
- hp = numpy.asarray(["".join(row) for row in a[7].astype(str)])
- for x in xrange(4,93):
- if hp[x] != '2197979':
- hpproc = (x + 3) * 95 /100
- break
- mpproc = 100
- mp = numpy.asarray(["".join(row) for row in a[20].astype(str)])
- for x in xrange(4,93):
- if mp[x] != '8380218':
- mpproc = (x + 3) * 95 /100
- break
- data=[]
- data.append(hpproc)
- data.append(mpproc)
- return data
- def ssCustom():
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 440, 322)#434
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, 261, 38, 0, 0, 440, 322)
- #pb.saturate_and_pixelate(pb,1,True)
- a = numpy.asarray(pb.get_pixels_array())
- #a = rdRgb(a)
- #pb.save('ss.png','png')
- return a
- def findCreatureSquare(mobxy):
- ddx = -7
- ddy = 5
- for y in range(1,13):
- for x in range(1,17):
- min_x = 262
- max_x = 262+(x*28)
- min_y = 39
- max_y = 39+(y*28)
- if mobxy[0] > min_x and mobxy[0] < max_x:
- if mobxy[1] > min_y and mobxy[1] < max_y:
- distX = x-8
- distY = y-6
- distdata=[distX,distY]
- return (distdata)
- print("ERRORRERERER")
- def lfCombatFrame():
- a = ssCustom().tolist()
- saveX = 0
- mobcount = 0
- MobData=[]
- #for y in range(0,322):
- for y,e in enumerate(a):
- s = 0
- #ex = numpy.asarray(["".join(row) for row in a[y].astype(str)],int).tolist()
- for x in range(0,440):
- #if ex[x] == 0:
- if a[y][x][0] == 0 and a[y][x][1] == 0 and a[y][x][1] == 0:
- if s == 0:
- skip = 0
- for xe in xrange(1,4):
- if (y+xe) == 322:
- skip = 1
- break
- y22 = y + xe
- if a[y22][x][0] != 0 or a[y22][x][1] != 0 or a[y22][x][2] != 0:
- skip = 1
- break
- if skip == 1:
- continue
- for xe in xrange(1,4):
- if (y+xe) == 322:
- skip = 1
- break
- y22 = y + xe
- x22 = x+26
- if x22 >= 440:
- skip = 1
- break
- if a[y22][x22][0] != 0 or a[y22][x22][1] != 0 or a[y22][x22][2] != 0:
- skip = 1
- break
- if skip == 1:
- continue
- saveX = x
- s = s +1
- if s == 27:
- mob = []
- colorframe = 0
- if y == 17:
- localx = x + 261 - 10
- localy = y + 38 - 3
- else:
- localx = x + 261 - 10
- localy = y + 38 +18
- colorframe = lfcolorFrame(a,x,y)
- mob.append(localx)
- mob.append(localy)
- mob.append(colorframe)
- if y != 17:
- mobmapdata = findCreatureSquare(mob)
- mob.append(mobmapdata)
- MobData.append(mob)
- mobcount = mobcount + 1
- else:
- if s > 0:
- s = 0
- x = saveX
- asd = 1
- return MobData
- def lfcolorFrame(buffer,hpx,hpy):
- startx = hpx - 26
- starty = hpy + 4
- counter = 0
- counter2 = 0
- lY = len(buffer)
- lX = len(buffer[0])
- #25500
- #255 0 0
- #255128128
- for times in range(0,2):
- starty = starty +(times*24)
- for y in range(0,2):
- for x in range(0,26):
- newy = starty + y
- newx = startx + x
- if newy >= lY or newx >= lX:
- continue
- if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 255 and buffer[newy][newx][2] == 255:
- counter = counter + 1
- if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 0 and buffer[newy][newx][2] == 0:
- counter2 = counter2 + 1
- if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 128 and buffer[newy][newx][2] == 128:
- counter2 = counter2 + 1
- startx = hpx - 26
- starty = hpy + 28
- for times in range(0,2):
- startx = startx+(times*25)
- for x in range(0,3):
- for y in range(0,26):
- newy = starty + y
- newx = startx + x
- if newy >= lY or newx >= lX:
- continue
- if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 255 and buffer[newy][newx][2] == 255:
- counter = counter + 1
- if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 0 and buffer[newy][newx][2] == 0:
- counter2 = counter2 + 1
- if buffer[newy][newx][0] == 255 and buffer[newy][newx][1] == 128 and buffer[newy][newx][2] == 128:
- counter2 = counter2 + 1
- frame = 0
- if counter > 15:
- frame = 1
- if counter2 > 15:
- frame = 2
- return frame
- def lfCombatFrame2():
- a = ssCustom()
- streak = 0
- prev = 0
- app = 0
- mobs = []
- 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])
- print('start')
- for x,ex in enumerate(a):
- ex = numpy.asarray(["".join(row) for row in ex.astype(str)],int)
- pos = search_sequence_numpy(ex,blackstripe)
- if len(pos) > 26:
- times = int(round(len(pos)/26))
- for x343 in range(0,times):
- off = 0
- s = 0
- for x22 in range(0,2):
- for x2 in range(0,4):
- x2 = x + x2
- if x22 == 0:
- pox = pos[0] + off
- else:
- pox = pos[0] + 26 + off
- if a[x2][pos[0]][0] == 0 and a[x2][pos[0]][1] == 0 and a[x2][pos[0]][2] == 0:
- s =s + 1
- else:
- s = 0
- break
- off = off + 27
- if s == 8:
- mx = pos[0] + 13
- my = x + 22
- cords = [mx,my]
- mobs.append(cords)
- print('stop')
- return mobs
- def map():
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 106, 109)
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, 714, 40, 0, 0, 106, 109)
- #pb.saturate_and_pixelate(pb,1,True)
- a = numpy.asarray(pb.get_pixels_array(),int)
- #a = rdRgb(a)
- #pb.save('map.png','png')
- return a
- def search_sequence_numpy(arr,seq):
- """ Find sequence in an array using NumPy only.
- Parameters
- ----------
- arr : input 1D array
- seq : input 1D array
- Output
- ------
- Output : 1D Array of indices in the input array that satisfy the
- matching of input sequence in the input array.
- In case of no match, an empty list is returned.
- """
- # Store sizes of input array and sequence
- Na, Nseq = arr.size, seq.size
- # Range of sequence
- r_seq = np.arange(Nseq)
- # Create a 2D array of sliding indices across the entire length of input array.
- # Match up with the input sequence & get the matching starting indices.
- M = (arr[np.arange(Na-Nseq+1)[:,None] + r_seq] == seq).all(1)
- # Get the range of those indices as final output
- if M.any() >0:
- return np.where(np.convolve(M,np.ones((Nseq),dtype=int))>0)[0]
- else:
- return [] # No match found
- #38/175
- def getMapPoint2(b,m):
- runs = 0
- map = numpy.asarray([''.join(row) for row in m[0].astype(str)],int).tolist()
- saveX = 0
- hs = 0
- for iY, eY in enumerate(b):
- eY = numpy.asarray(["".join(row) for row in eY.astype(str)],int).tolist()
- s = 0
- l = len(eY)
- hs = 0
- for x in xrange(0,l):
- if eY[x] == map[0]:
- l2 = len(map)
- if (x+l2) < l:
- for xmap in range(0,l2):
- xx22 = x + xmap
- if eY[xx22] == map[xmap]:
- if xmap == 105:
- px = x+53
- py = iY+54
- playerPos=[px,py]
- playerSquare = []
- sqx = px - 1
- sqy = py - 1
- for y in range(0,3):
- line = []
- for x in range(0,3):
- l_sqx = sqx + x
- l_sqy = sqy + y
- line.append(b[l_sqy][l_sqx])
- playerSquare.append(line)
- playerSquare = numpy.asarray(playerSquare)
- PS = []
- for i, e in enumerate(playerSquare):
- playerSquare = ["".join(row) for row in e.astype(str)]
- PS.append(playerSquare)
- returne= []
- returne.append(playerPos)
- returne.append(PS)
- return(returne)
- else:
- break
- return 0
- def isWall(str):
- wall = [255510,153510]
- intwall = int(str)
- for x in range(0,len(wall)):
- if intwall == wall[x]:
- return 1
- return 0
- def calcReachableSquare(globalMap,xy):
- 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]]
- AccessibleSquare[5][5] = 1338
- for multipl in range(0,4):
- x1 = xy[0]-1 -multipl
- y1 = xy[1]-1 -multipl
- base_x3 = 4 -multipl
- base_y3 =4 -multipl
- maxY = 3 + (2*multipl)
- maxX = 3 + (2*multipl)
- for y in range(0,maxY):
- y1 = xy[1]-1 -multipl + y
- if y1 == 256:
- break
- map = numpy.asarray([''.join(row) for row in globalMap[y1].astype(str)],int).tolist()
- x1 = xy[0]-1 -multipl
- y3 = base_y3 + y
- for x in range(0,maxX):
- x3 = base_x3+x
- if AccessibleSquare[y3][x3] == 2:
- x1 = x1 + 1
- continue
- if isWall(map[x1]) == 1 and AccessibleSquare[y3][x3] != -1:
- AccessibleSquare[y3][x3] = -1
- x1 = x1 + 1
- continue
- if AccessibleSquare[y3][x3] == -1:
- x1 = x1 + 1
- continue
- AccessibleSquare[y3][x3] = 1
- nx3 = x3 -1
- ny3 = y3 - 1
- skip = 0
- for y2 in range(1,4):
- nx3 = x3 -1
- for x2 in range(1,4):
- if AccessibleSquare[ny3][nx3] == 2 or AccessibleSquare[ny3][nx3] == 1338:
- AccessibleSquare[y3][x3] = 2
- #print(y3)
- #print(x3)
- #print('GITARA')
- skip = 1
- break
- nx3 = nx3 + 1
- if skip == 1:
- break
- ny3 = ny3 + 1
- x3 = x3 + 1
- x1 = x1 + 1
- AccessibleSquare[5][5] = 3
- return AccessibleSquare
- def getMapPoint(b,m):
- runs = 0
- map = numpy.asarray([''.join(row) for row in m[0].astype(str)],int)
- for iY, eY in enumerate(b):
- eY = numpy.asarray(["".join(row) for row in eY.astype(str)],int)
- pos = search_sequence_numpy(eY,map)
- if len(pos) == 106:
- px = pos[0]+53
- py = iY+54
- playerPos=[px,py]
- AccessibleSquare = calcReachableSquare(b,playerPos)
- playerSquare = []
- sqx = px - 1
- sqy = py - 1
- for y in range(0,3):
- line = []
- for x in range(0,3):
- l_sqx = sqx + x
- l_sqy = sqy + y
- line.append(b[l_sqy][l_sqx])
- playerSquare.append(line)
- playerSquare = numpy.asarray(playerSquare)
- PS = []
- for i, e in enumerate(playerSquare):
- playerSquare = ["".join(row) for row in e.astype(str)]
- PS.append(playerSquare)
- returne= []
- returne.append(playerPos)
- returne.append(PS)
- returne.append(AccessibleSquare)
- return(returne)
- return 0
- def isWalkable(side,sq,wall,wrldside):
- wpAround=[]
- if side == 'Left':
- if str(sq[1][0]) in wall:
- if str(sq[0][0]) not in wall:
- wpAround.append("KP_Home")
- return wpAround
- if str(sq[2][0]) not in wall:
- wpAround.append("KP_End")
- return wpAround
- if wrldside == "Up":
- if str(sq[0][1]) not in wall:
- wpAround.append("Up")
- return wpAround
- else:
- if str(sq[2][1]) not in wall:
- wpAround.append("Down")
- return wpAround
- if str(sq[0][2]) not in wall:
- wpAround.append("KP_Page_Up")
- return wpAround
- if str(sq[2][2]) not in wall:
- wpAround.append("KP_PageDown")
- return wpAround
- if str(sq[1][2]) not in wall:
- wpAround.append("Right")
- return wpAround
- if side == 'Right':
- if str(sq[1][2]) in wall:
- if str(sq[0][2]) not in wall:
- wpAround.append("KP_Page_Up")
- return wpAround
- if str(sq[2][2]) not in wall:
- wpAround.append("KP_Page_Down")
- return wpAround
- if wrldside == 'Up':
- if str(sq[0][1]) not in wall:
- wpAround.append("Up")
- return wpAround
- else:
- if str(sq[2][1]) not in wall:
- wpAround.append("Down")
- return wpAround
- if str(sq[0][0]) not in wall:
- wpAround.append("KP_Home")
- return wpAround
- if str(sq[2][0]) not in wall:
- wpAround.append("KP_End")
- return wpAround
- if str(sq[1][0]) not in wall:
- wpAround.append("Left")
- return wpAround
- if side == 'Up':
- if str(sq[0][1]) in wall:
- if str(sq[0][0]) not in wall:
- wpAround.append("KP_Home")
- return wpAround
- if str(sq[0][2]) not in wall:
- wpAround.append("KP_Page_Up")
- return wpAround
- if wrldside == 'Left':
- if str(sq[1][0]) not in wall:
- wpAround.append("Left")
- return wpAround
- else:
- if str(sq[1][2]) not in wall:
- wpAround.append("Right")
- return wpAround
- if str(sq[2][0]) not in wall:
- wpAround.append("KP_End")
- return wpAround
- if str(sq[2][2]) not in wall:
- wpAround.append("KP_Page_Down")
- return wpAround
- if str(sq[2][1]) not in wall:
- wpAround.append("Down")
- return wpAround
- if side == 'Down':
- if str(sq[2][1]) in wall:
- if str(sq[2][0]) not in wall:
- wpAround.append("KP_End")
- return wpAround
- if str(sq[2][2]) not in wall:
- wpAround.append("KP_Page_Down")
- return wpAround
- if wrldside == 'Left':
- if str(sq[1][0]) not in wall:
- wpAround.append("Left")
- return wpAround
- else:
- if str(sq[1][2]) not in wall:
- wpAround.append("Right")
- return wpAround
- if str(sq[0][0]) not in wall:
- wpAround.append("KP_Home")
- return wpAround
- if str(sq[0][2]) not in wall:
- wpAround.append("KP_Page_Up")
- return wpAround
- if str(sq[0][1]) not in wall:
- wpAround.append("Up")
- return wpAround
- def battlelistCheck(tryanother):
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 135, 200)
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, 85, 51, 0, 0, 135, 200)#+22
- #pb.saturate_and_pixelate(pb,1,True)
- a = numpy.array(pb.get_pixels_array())
- pb.save('battle.png','png')
- BattleMobs=[['caverat',176],['rat',82],['spider',140],['bat',84]]
- #LIST COLOR FRAMES&NAMES
- #CHECK FOR COMBAT
- fighting = 0
- for slots in range(0,10):
- ycalc0 = 4+(slots*22)
- ycalc1 = 13+(slots*22)
- if ycalc1 > 200:
- break
- newSlot = numpy.asarray(["".join(row) for row in a[ycalc0].astype(str)],int).tolist()
- if newSlot[0] == 25500 or newSlot[0] == 255128128:
- fighting = 1
- if tryanother == 1:
- xclick = 95+(slots*22)
- yclick = 61+(slots*22)
- os.system('xdotool mousemove '+str(xclick)+" "+str(yclick))
- os.system('xdotool click 1')
- return 0
- return 1
- if fighting == 0:
- for slots in range(0,10):
- counter = 0
- ycalc0 = 4+(slots*22)
- ycalc1 = 13+(slots*22)
- if ycalc1 > 200:
- break
- for y in range(ycalc0,ycalc1):
- newSlot = numpy.asarray(["".join(row) for row in a[y].astype(str)],int).tolist()
- for x in range(21,106):
- if newSlot[x] == 192192192 or newSlot[x] == 247247247:
- counter = counter + 1
- for ie,xe in enumerate(BattleMobs):
- #if counter == xe[1]:
- if counter == xe[1]:
- xclick = 95+(slots*22)
- yclick = 61+(slots*22)
- os.system('xdotool mousemove '+str(xclick)+" "+str(yclick))
- os.system('xdotool click 1')
- return 3
- if counter == 0:
- break
- #print(counter)
- #exit()
- return 0
- def checkIfMobIsAccessible(sq_acces,mobmapdata):
- l = len(mobmapdata)
- l2 = len(sq_acces)
- l2_min = (l2 - 1) / 2
- for x in range(0,l):
- p0 = [l2_min,l2_min]
- if mobmapdata[x][2] == 2 and len(mobmapdata[x]) > 3:
- checkX = p0[0] + mobmapdata[x][3][0]
- checkY = p0[1] + mobmapdata[x][3][1]
- #print(str(p0[0])+"+"+str(mobmapdata[x][3][0])+"="+str(checkX))
- #print(str(p0[1])+"+"+str(mobmapdata[x][3][1])+"="+str(checkY))
- if checkX < 0 or checkX >= l2:
- return 0
- if checkY < 0 or checkY >= l2:
- return 0
- if sq_acces[checkY][checkX] == 2:
- return 1
- else:
- return 0
- return 0
- def getXYaroundSQ(xy):
- playerx=480
- playery=200
- sqsize = 29
- if xy[0] == -1:
- playerx = playerx-sqsize
- if xy[0] == 1:
- playerx = playerx+sqsize
- if xy[1] == -1:
- playery = playery-sqsize
- if xy[1] == 1:
- playery = playery+sqsize
- data=[playerx,playery]
- return data
- def loot(listXY,playerxy):
- l = len(listXY)-1
- for x in range(l,-1,-1):
- mathX = int(str(listXY[x][0]))-int(str(playerxy[0]))
- mathY = int(str(listXY[x][1]))-int(str(playerxy[1]))
- xy=[mathX,mathY]
- if mathX < 2 and mathX > -2:
- if mathY < 2 and mathY > -2:
- clickpos = getXYaroundSQ(xy)
- print("LOOTING")
- print(str(mathX)+"/"+str(mathY))
- print(playerxy)
- print(clickpos)
- os.system('xdotool keydown SHIFT')
- os.system('xdotool mousemove '+str(clickpos[0])+" "+str(clickpos[1]))
- time.sleep(0.2)
- os.system('xdotool click 3')
- os.system('xdotool keyup SHIFT')
- del listXY[x]
- def walk(wps):
- global move
- global wp
- #grey/green0
- walkColors=['153153153','02040']
- #yellow
- dropcolor = ['2552550']
- #red
- wall = ['255510','1337','153510']
- l_wps = len(wps)
- fightingXY = []
- while True:
- battle = battlelistCheck(0)
- m = map()
- pos = getMapPoint(b,m)
- mobmapdata = lfCombatFrame()
- #print(pos[0])
- #exit()
- if pos == 0:
- print('%pos not found')
- else:
- if battle == 1 or battle == 3:
- accessible = checkIfMobIsAccessible(pos[2],mobmapdata)
- if accessible == 0:
- battle = battlelistCheck(1)
- loot(fightingXY,pos[0])
- waitTillDeath = 0
- l_lootlist = len(fightingXY)
- if battle == 1 or battle == 3:
- newWayPointx = 0
- newWayPointy = 0
- for xmobs in range(0,len(mobmapdata)):
- if mobmapdata[xmobs][2] == 2:
- newWayPointx = pos[0][0] + int(mobmapdata[xmobs][3][0])
- newWayPointy = pos[0][1] + int(mobmapdata[xmobs][3][1])
- if battle == 3:
- mightDropPos=[newWayPointx,newWayPointy]
- fightingXY.append(mightDropPos)
- l_lootlist = l_lootlist + 1
- if battle == 1:
- if l_lootlist > 0:
- newl_lootlist = l_lootlist - 1
- fightingXY[newl_lootlist][0] = newWayPointx
- fightingXY[newl_lootlist][1] = newWayPointy
- if abs(int(mobmapdata[xmobs][3][0])) <= 1 and abs(int(mobmapdata[xmobs][3][1])) <=1:
- waitTillDeath = 1
- break
- break
- print("gotoMob:"+str(newWayPointx)+"/"+str(newWayPointy))
- print(fightingXY)
- hp = playerHP()
- #near = getNearest(mobmapdata)
- #os.system('xdotool keydown SHIFT')
- #os.system('xdotool mousemove '+str(near[0])+" "+str(near[1]))
- #os.system('xdotool click 3')
- #os.system('xdotool keyup SHIFT')
- if waitTillDeath == 1:
- continue
- urpos = pos[0]
- SQ = pos[1]
- for x in range(0,len(mobmapdata)):
- if len(mobmapdata[x]) > 3:
- if mobmapdata[x][3][0] > -2 and mobmapdata[x][3][0] < 2 and mobmapdata[x][3][1] > -2 and mobmapdata[x][3][1] < 2:
- xmob = int(mobmapdata[x][3][0])
- ymob = int(mobmapdata[x][3][1])
- xmob = 1 + xmob
- ymob = 1 + ymob
- SQ[ymob][xmob] = '1337'
- if battle == 1 or battle == 3:
- dest = [newWayPointx,newWayPointy]
- else:
- if battle == 0 and l_lootlist > 0:
- newl_lootlist = l_lootlist - 1
- dest = fightingXY[newl_lootlist]
- else:
- dest = wps[wp]
- print(dest)
- try0 = 0
- wrldside = 0
- mathX = abs(int(str(dest[0]))-int(str(urpos[0])))
- mathY = abs(int(str(dest[1]))-int(str(urpos[1])))
- rawMath = []
- rawMath.append((int(str(dest[0]))-int(str(urpos[0]))))
- rawMath.append((int(str(dest[1]))-int(str(urpos[1]))))
- if mathX > mathY:
- if urpos[0] < dest[0]:
- try0='Right'
- if urpos[0] > dest[0]:
- try0='Left'
- if urpos[1] < dest[1]:
- wrldside='Down'
- if urpos[1] > dest[1]:
- wrldside='Up'
- else:
- if urpos[1] < dest[1]:
- try0='Down'
- if urpos[1] > dest[1]:
- try0='Up'
- if urpos[0] < dest[0]:
- wrldside='Right'
- if urpos[0] > dest[0]:
- wrldside='Left'
- if mathX <= 1 and mathY <= 1 and battle == 0:
- wp = wp + 1
- if wp == l_wps:
- wp = 0
- print("current waypoit;"+str(wp))
- print(wps[wp])
- continue
- walkk = isWalkable(try0,SQ,wall,wrldside)
- key = try0
- if walkk != None:
- key = walkk[0]
- os.system('xdotool key '+key)
- #time.sleep(0.30)
- #os.system('xdotool keyup '+key)
- print(key)
- def getNearest(mobdata):
- playerpos=[477,193]
- neardist = 0
- nearpoint = 0
- if len(mobdata) > 0:
- for x in xrange(0,len(mobdata)):
- xcalc = abs(int(str(mobdata[x][0])) - int(str(playerpos[0])))
- ycalc = abs(int(str(mobdata[x][1])) - int(str(playerpos[1])))
- dist = sqrt(xcalc**2+ycalc**2)
- if neardist == 0:
- neardist = dist
- nearpoint = x
- else:
- if dist < neardist:
- neardist = dist
- nearpoint = x
- return mobdata[nearpoint]
- return 0
- pb = gtk.gdk.pixbuf_new_from_file("maps/thais02.png")
- b = numpy.asarray(pb.get_pixels_array(),int)
- #walkPoints=[[89,222],[88,215],[77,216]]
- 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]]
- while True:
- walk(walkPoints)
- exit()
- def ssTile(x,y):
- Xx = x * 30
- Yy = y * 30
- w = gtk.gdk.get_default_root_window()
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 30, 30)
- cm = w.get_colormap()
- pb = pb.get_from_drawable(w, cm, (262+Xx), (41+Yy), 0, 0, 30, 30)
- pb.saturate_and_pixelate(pb,1,True)
- a = numpy.array(pb.get_pixels_array())
- a = rdRgb(a)
- pb.save('tile.jpeg','jpeg')
- data = ''
- with open('drff.txt',"w") as f:
- for x in range(0,30):
- data = data+"\n"
- for y in range(0,30):
- data = data+str(a[x][y])
- f.write(data)
- return a
- exit()
- with open("px.txt") as file:
- data = file.read()
- @@@
- #include <gtk/gtk.h>
- extern "C"
- {
- static int MobPosX[50];
- static int MobPosY[50];
- static int playerpos[2];
- static int playerSquare[3][3];
- int combine(int a, int b) {
- if (b == 0){
- return a * 10;
- }
- int times = 1;
- while (times <= b)
- times *= 10;
- return a*times + b;
- }
- int readPX(unsigned char *buffer, int rowstride, int n_channels,int x, int y)
- {
- int p1, p2, p3;
- unsigned char *p;
- p = buffer + y * rowstride + x * n_channels;
- p1 = int((unsigned char)(p[0]));
- p2 = int((unsigned char)(p[1]));
- p3 = int((unsigned char)(p[2]));
- int p4 = combine(p1, p2);
- p4 = combine(p4, p3);
- return p4;
- }
- int getMobPos(){
- int clientX = 261;
- int clientY = 48;
- int rowstride, n_channels;
- unsigned char *p;
- GdkPixbuf *pxbuf;
- GdkWindow *wind = gdk_get_default_root_window();
- pxbuf = gdk_pixbuf_get_from_window(wind, clientX, 48, 440, 322);
- //gdk_pixbuf_save(pxbuf, "ss.png", "png", NULL, NULL);
- //GdkPixbuf *pxbuf2 = gdk_pixbuf_new_from_file("123.png",NULL);
- unsigned char *px = gdk_pixbuf_get_pixels(pxbuf);
- //int *array2 = reinterpret_cast<int*>(px);
- rowstride = gdk_pixbuf_get_rowstride(pxbuf);
- n_channels = gdk_pixbuf_get_n_channels(pxbuf);
- int p1, p2, p3;
- int mobcount;
- int mobx, moby;
- int s, saveX;
- saveX = 0;
- mobcount = 0;
- for (int y = 0; y < 322; ++y) {
- s = 0;
- mobx = 0;
- moby = 0;
- for (int x = 0; x < 440; ++x) {
- p = px + y * rowstride + x * n_channels;
- p1 = int((unsigned char)(p[0]));
- p2 = int((unsigned char)(p[1]));
- p3 = int((unsigned char)(p[2]));
- int p4 = combine(p1, p2);
- p4 = combine(p4, p3);
- //ps2 << p1 << p2 << p3;
- //string str = ps2.str();
- //ps = to_string(p1) + to_string(p2) + to_string(p3);
- //string p11 = to_string(p1);
- //reinterpret_cast<int*>(Xline)[0] = p4;
- //Xline2[x] = int(p4);
- //char* end = Xline2 + sizeof(Xline2) / sizeof(Xline2[0]);
- //char ser = int(p4)+5;
- //char* position = std::find(Xline2, end, ser);
- //Xline[x] = p4;
- if (p4 == 0){
- if (s == 0){
- int skip = 0;
- for (int xe = 1; xe < 4; ++xe) {
- if ((y + xe) > 320){
- skip = 1;
- continue;
- }
- //std::cout << (clientX + x) << " " << (clientY+y) << std::endl;
- int pixel = readPX(px, rowstride, n_channels, x, (y + xe));
- if (pixel != 0){
- skip = 1;
- }
- }
- for (int xe = 1; xe < 26; ++xe) {
- if ((x + xe) > 437){
- skip = 1;
- continue;
- }
- int pixel = readPX(px, rowstride, n_channels, (x + xe), y);
- if (pixel != 0){
- skip = 1;
- continue;
- }
- }
- for (int xe = 1; xe < 4; ++xe) {
- if ((y + xe) > 320){
- skip = 1;
- continue;
- }
- //std::cout << (clientX + x) << " " << (clientY+y) << std::endl;
- int pixel = readPX(px, rowstride, n_channels, (x + 26), (y + xe));
- if (pixel != 0){
- skip = 1;
- continue;
- }
- }
- if (skip == 1)
- {
- continue;
- }
- saveX = x;
- }
- s = s + 1;
- if (s == 27){
- if (y == 14)//First square line in game
- {
- mobx = x + clientX - 10;
- moby = y + clientY - 3;
- }
- else
- {
- mobx = x + clientX - 9;
- moby = y + clientY + 21;
- }
- MobPosX[mobcount] = mobx;
- MobPosY[mobcount] = moby;
- //std::cout << MobPosX[mobcount] << " " << MobPosY[mobcount] << std::endl;
- //std::cout << mobcount << std::endl;
- mobcount++;
- }
- }
- else{
- if (s > 0){
- x = saveX;
- s = 0;
- }
- }
- //std::cout << p4 << "/ /" << p1 << "." << p2 << "." << " " << std::endl;
- //cin.get();
- }
- //std::cout << Xline << "/ /" << p1 << "." << p2 << "." << " " << std::endl;
- }
- return mobcount;
- }
- int getPlayerPos()
- {
- int rowstride, n_channels, rowstride2, n_channels2;
- GdkPixbuf *pxbuf;
- GdkWindow *wind = gdk_get_default_root_window();
- pxbuf = gdk_pixbuf_get_from_window(wind, 714, 40, 106, 109);
- //gdk_pixbuf_save(pxbuf, "ss.png", "png", NULL, NULL);
- GdkPixbuf *pxbuf2 = gdk_pixbuf_new_from_file("thais01.png",NULL);
- unsigned char *px = gdk_pixbuf_get_pixels(pxbuf);
- unsigned char *px2 = gdk_pixbuf_get_pixels(pxbuf2);
- rowstride = gdk_pixbuf_get_rowstride(pxbuf);
- n_channels = gdk_pixbuf_get_n_channels(pxbuf);
- rowstride2 = gdk_pixbuf_get_rowstride(pxbuf2);
- n_channels2 = gdk_pixbuf_get_n_channels(pxbuf2);
- int s, saveX;
- saveX = 0;
- int SSmapPattern[105];
- for (int x = 0; x < 105; ++x) {
- int pixel = readPX(px, rowstride, n_channels, x, 0);
- SSmapPattern[x] = pixel;
- }
- for (int y = 0; y <= 256; ++y) {
- s = 0;
- for (int x = 0; x <= 256; ++x) {
- int pixel = readPX(px2, rowstride2, n_channels2, x, y);
- if (pixel == SSmapPattern[s])
- {
- if (s == 0){
- saveX = x;
- }
- s++;
- if (s == 105){
- playerpos[0] = saveX+52;
- playerpos[1] = y+53;
- int sqx = playerpos[0] - 1;
- int sqy = playerpos[1] - 1;
- int l_sqx, l_sqy;
- for (int y02 = 0; y02 < 3; ++y02) {
- for (int x02 = 0; x02 < 3; ++x02) {
- l_sqx = sqx + x02;
- l_sqy = sqy + y02;
- playerSquare[y02][x02] = readPX(px2, rowstride2, n_channels2, l_sqx, l_sqy);
- }
- }
- return 1;
- //playerSqure
- }
- }
- else{
- if (s > 0){
- x = saveX;
- s = 0;
- }
- }
- }
- }
- return 0;
- }
- void initialize()
- {
- gtk_init(NULL,NULL);
- }
- int makeSS ()
- {
- int asd;
- asd = getPlayerPos();
- asd = getMobPos();
- return "asd";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement