示例#1
0
文件: WOW.py 项目: ngrogolev/WOW-Bot
 def stopmoving(self):
     self.z = gridmap.getheight(self.curmap, self.x, self.y, self.z)
     self.moving = None
     self.usedpoints = []
     self.sendpacket(
         MSG_MOVE_STOP,
         self.createmovementpackage(self.moving, self.x, self.y, self.z,
                                    self.o))
示例#2
0
文件: WOW.py 项目: hwwh1999/WOW-Bot
 def gotodest(self,x,y):
   debug("Go to %f %f"%(x,y))
   self.destx = x
   self.desty = y
   x1 = (x-self.x)
   y1 = (y-self.y)
   #self.setfacing(2.35619448975+get_angle_between_in_radians(1.0,1.0,self.destx,self.desty))
   #print "Angle : %f" % (self.o/(3.141592653*2.0)*360.0)
   self.z = gridmap.getheight(self.curmap,self.x,self.y,self.z)
   self.moving = MOVEMENTFLAG_FORWARD
   self.sendpacket(MSG_MOVE_START_FORWARD,self.createmovementpackage(MOVEMENTFLAG_FORWARD,self.x,self.y,self.z,self.o))
   debug("Go to %f %f - Running"%(x,y))
示例#3
0
文件: WOW.py 项目: ngrogolev/WOW-Bot
 def gotodest(self, x, y):
     debug("Go to %f %f" % (x, y))
     self.destx = x
     self.desty = y
     x1 = (x - self.x)
     y1 = (y - self.y)
     #self.setfacing(2.35619448975+get_angle_between_in_radians(1.0,1.0,self.destx,self.desty))
     #print "Angle : %f" % (self.o/(3.141592653*2.0)*360.0)
     self.z = gridmap.getheight(self.curmap, self.x, self.y, self.z)
     self.moving = MOVEMENTFLAG_FORWARD
     self.sendpacket(
         MSG_MOVE_START_FORWARD,
         self.createmovementpackage(MOVEMENTFLAG_FORWARD, self.x, self.y,
                                    self.z, self.o))
     debug("Go to %f %f - Running" % (x, y))
示例#4
0
文件: WOW.py 项目: hwwh1999/WOW-Bot
  def onpacket(self,opcode,data):
    #print "Ricevuto:",opcoded[opcode]#,list(data)
    try:
      if opcode == SMSG_AUTH_CHALLENGE:
        self.loggedin = True
      if opcode == SMSG_ATTACKSTART:
	self.combat = True
	debug("Entering combat!")
      if opcode == SMSG_ATTACKSTOP:
	self.combat = False
	debug("Leaving combat!")
	self.attack = 0
      if opcode == SMSG_AUTH_RESPONSE:
        if ord(data[0]) == 0x0c:
          good("Login effettuato")
          good("Ricezione della lista dei pg...")
          self.sendpacket(CMSG_CHAR_ENUM,"")
          self.sendpacket(CMSG_REALM_SPLIT,"\xff\xff\xff\xff")
        else:
            error("Authentication failed")
      if opcode == SMSG_CHAR_CREATE:
        status = ord(data[0])
        if status == 0x2F:
          good("PG Creato, Login...")
          self.sendpacket(CMSG_CHAR_ENUM,"")
        else:
          error("%x : Impossibile creare il pg")
          raise SystemExit(1)
      if opcode == SMSG_ATTACKERSTATEUPDATE:
	hitinfo = unpack("I",data[:4])
	data = data[4:]
	attackerguid,data = unpackguid(data)
	victimguid,data = unpackguid(data)
	totaldamage = unpack("I",data[:4])
	data = data[4:]
	subdamagecount = ord(data[0])
	data = data[1:]
	for x in range(0,subdamagecount):
	  school,damage1,damage2,absorb,resist = unpack("IfIII",data[:20])
	  data = data[20:]
	  debug("%s attack hits %s for %d damage: %d absorbed, %d resisted"%(str(attackerguid),str(victimguid),damage2,absorb,resist))
	if attackerguid == self.attack:
	  self.doattackswing(self.attack)
      if opcode == SMSG_CHAR_ENUM:
        if len(data) < 8:
          newpkdata = ""
          error("Non ci sono pg")
          notice("Creazione di uno nuovo")
          if not self.cname:
            name = raw_input("Inserisci il nome:")
            race = int(raw_input("Inserisci il codice della razza:"))
            _class = int(raw_input("Inserisci il codice della classe:"))
          else:
            name = self.cname
            race = self.crace
            _class = self.cclass
          gender = 0
          skin = 3
          face = 3
          hairStyle = 3
          hairColor = 3
          facialHair = 3
          outfitid = 0
          newpkdata += name +"\x00"
          newpkdata += chr(race)
          newpkdata += chr(_class)
          newpkdata += chr(gender)
          newpkdata += chr(skin)
          newpkdata += chr(face)
          newpkdata += chr(hairStyle)
          newpkdata += chr(hairColor)
          newpkdata += chr(facialHair)
          newpkdata += chr(outfitid)
          self.sendpacket(CMSG_CHAR_CREATE,newpkdata)
        else:
          d2 = data
          while len(d2) > 0:
            debug("Pg numero %i"% ord(d2[0]))
            guid = unpack("Q",d2[1:9])[0]
            d2 = d2[9:]
            
            debug("Guid: "+str(guid))
            name = d2[:d2.find("\x00")]
            d2 = d2[d2.find("\x00")+1:]
            
            race = ord(d2[0])
            _class = ord(d2[1])
            gender = ord(d2[2]) # 0 : Male , 1 : Female , >1 : Trans 
            debug("Nome: "+name+" Razza,classe,sesso: %i %i %i"%(race,_class,gender))
            d2 = d2[8:]#Salta l'estetica del pg
            level = ord(d2[0])
            d2 = d2[1:]
            debug("Livello: "+str(level))
            zone,mapp,self.x,self.y,self.z,guildid = unpack("IIfffI",d2[:24])
            self.curmap = mapp
            self.z = gridmap.getheight(self.curmap,self.x,self.y,self.z)
            good("%s: Entering world"%name)
            self.guid = guid
            self.sendpacket(CMSG_OPT_OUT_OF_LOOT,"\x00\x00\x00\x00")
            self.sendpacket(CMSG_SET_ACTIVE_VOICE_CHANNEL,"\x04\x00\x00\x00\x00")
            self.sendpacket(CMSG_PLAYER_LOGIN,pack("Q",guid))
            break
      if opcode == SMSG_SET_PROFICIENCY:
        self.proficiencies[ord(data[0])]=unpack("I",data[1:5])[0]
        print self.proficiencies
      if opcode == SMSG_NEW_WORLD:
        if len(data) != 20:
          error("Pacchetto SMSG_NEW_WORLD Non valido, dimensione errata")
        mapid,x,y,z,o = unpack("Iffff",data)
        notice("Far Teleport to map %d"%mapid)
        self.curmap = mapid
        notice("We got teleported to a new location")
        self.x = x
        self.y = y
        self.z = gridmap.getheight(self.curmap,x,y,z-3.0)
        self.sendpacket(MSG_MOVE_WORLDPORT_ACK,"")
        self.stopmoving()
        good("Teleport done: %f %f %f" %(self.x,self.y,self.z))
      if opcode == SMSG_MONSTER_MOVE:
	guid,data = unpackguid(data)
	monster = self.world.getobject(guid)
	if not monster:
	  debug("L'npc con la guid %s non esiste nel world"%str(guid))
	  return
	x,y,z = unpack("fff",data[:12])
	monster.x = x
	monster.y = y
	monster.z = z
	debug("NPC %s : Nuova posizione: %f %f %f"%(str(guid),x,y,z))
	self.updatetarget()
      if opcode == SMSG_GROUP_INVITE:
        pname = data[:data.find("\x00")]
        notice("Invitato in gruppo da %s"%pname)
        self.sendpacket(CMSG_GROUP_ACCEPT,"")
      if opcode == MSG_MOVE_TELEPORT_ACK:
        guid,data = unpackguid(data)
        unk1,data = (unpack("I",data[:4])[0],data[4:])
        movflags,data = (unpack("I",data[:4])[0],data[4:])
        unk1,data = (ord(data[0]),data[1:])
        time,data = (unpack("I",data[:4])[0],data[4:])
        x,data = (unpack("f",data[:4])[0],data[4:])
        y,data = (unpack("f",data[:4])[0],data[4:])
        z,data = (unpack("f",data[:4])[0],data[4:])
        notice("Received teleport ack of guid %u to %f %f %f"%(guid,x,y,z)) 
        if guid == self.guid:
          notice("We got teleported to a new location")
          
          self.x = x
          self.y = y
          self.z = gridmap.getheight(self.curmap,x,y,z-3.0)
          self.sendpacket(MSG_MOVE_TELEPORT_ACK,pack("Q",guid)+pack("I",0)+pack("I",time))
          self.stopmoving()
          good("Teleport done: %f %f %f" %(self.x,self.y,self.z))
      if opcode == SMSG_COMPRESSED_UPDATE_OBJECT:
        self.world.handlecompressedupdateobject(data)
      if opcode == SMSG_UPDATE_OBJECT:
        self.world.handleplainupdateobject(data)
      if opcode == SMSG_MESSAGECHAT:
        typ,data = (ord(data[0]),data[1:])
        language,data = (unpack("I",data[:4])[0],data[4:])
        guid,data =(unpack("Q",data[:8])[0],data[8:])
        unk1,data = (unpack("I",data[:4])[0],data[4:])
        targetguid,data = (unpack("Q",data[:8])[0],data[8:])
        msglen,data = (unpack("I",data[:4])[0],data[4:])
        message = data
        if 'chatcb' in dir(self) and guid != self.guid:
          self.chatcb(typ,guid,message)
      if opcode == MSG_MOVE_STOP or opcode == MSG_MOVE_HEARTBEAT or opcode == MSG_MOVE_START_FORWARD:
        guid,data =unpackguid(data)
        #if not guid in self.guidnames:
        #  self.sendpacket(CMSG_NAME_QUERY,pack("Q",guid))
        flags = unpack("I",data[:4])[0]
        
        data = data[4:]
        unk1 = ord(data[0])
        data = data[1:]
        time = unpack("I",data[:4])[0]
        data = data[4:]
        print len(data[:16])
        x,y,z,o = unpack("ffff",data[:16])
        
        #print "Move opcode:",guid,x,y,z,(float(time)/1000.0)
	player = self.world.getobject(guid)
	player.x = x
	player.y = y
	player.z = z
        if guid == self.following:
          self.destx = x
          self.desty = y
      if opcode == SMSG_NAME_QUERY_RESPONSE:
        guid = unpack("Q",data[:8])[0]
        data = data[8:]
        name = data[:data.find("\x00")]
        #print "%i is %s" % (guid,name)
        self.guidnames[guid] = name
      
    except:
      print traceback.format_exc()
示例#5
0
文件: WOW.py 项目: hwwh1999/WOW-Bot
 def stopmoving(self):
   self.z = gridmap.getheight(self.curmap,self.x,self.y,self.z)
   self.moving = None
   self.usedpoints = []
   self.sendpacket(MSG_MOVE_STOP,self.createmovementpackage(self.moving,self.x,self.y,self.z,self.o))
示例#6
0
文件: WOW.py 项目: hwwh1999/WOW-Bot
  def moveheartbeatthread(self):
    speed = self.speed
    sleept = 0.5
    time.sleep(sleept)
    print speed,sleept
    while 1:
      if self.loggedin:
        if self.moving != None:
          dists = dict()
          dists2 = dict()
          
          for i in range(0,360/4):
            xf =  cos((float(i*360/4)/360.0)*(3.141592653*2.0))
            yf = sin((float(i*360/4)/360.0)*(3.141592653*2.0))
            xx = self.x + xf*speed*sleept
            yy = self.y + yf*speed*sleept
            los = gridmap.los(self.curmap,self.x,self.y,self.z+1.0,xx*1.1,yy*1.1,self.z+1.0)
            #print los
            #debug("LOS: %d (%f,%f,%f) -> (%f,%f,%f) = %s" % (self.curmap,self.x,self.y,self.z+1.0,xx*1.1,yy*1.1,self.z+1.0,str(bool(los))))
	    loa = []
	    for i2 in range(0,5):
	      loa.append(gridmap.getheight(self.curmap,self.x + xf*speed*sleept*i2,self.y + yf*speed*sleept*i2,self.z+0.4)-self.z)
	    media = sum(loa)/float(len(loa))
	    quadrati = []
	    for v in loa:
	      quadrati.append(v*v)
	    mediaquadrati = sum(quadrati)/float(len(quadrati))
	    print mediaquadrati - media,i
	    XI = int(xx*1000.0)
	    YI = int(yy*1000.0)
            if mediaquadrati - media < 2.0 and (XI,YI) not in self.usedpoints: #and bool(los):
	      dists2[i] = (XI,YI)
	      dists[i] = sqrt((self.destx-xx)*(self.destx-xx)+(self.desty-yy)*(self.desty-yy))+(mediaquadrati - media)*1.0
                #print abs(gridmap.getheight(xx,yy,self.z)- self.z)
          lowest = -1
          l = 4000000.0
          for x in dists:
            if dists[x] < l:
              l = dists[x]
              lowest = x
	  print dists
          if lowest != -1:
            self.usedpoints.append(dists2[lowest])
            #print self.usedpoints
            if len(self.usedpoints) >5:
              self.usedpoints.remove(self.usedpoints[0])
	  self.setfacing((float(lowest*360/4)/360.0)*(3.141592653*2.0))
          self.x += cos(self.o)*speed*sleept
          self.y += sin(self.o)*speed*sleept
          
          try:
            self.z = gridmap.getheight(self.curmap,self.x,self.y,self.z-4.0)
            self.sendpacket(MSG_MOVE_HEARTBEAT,self.createmovementpackage(self.moving,self.x,self.y,self.z,self.o))
          except:
            pass
          if sqrt((self.x-self.destx)*(self.x-self.destx)+(self.y-self.desty)*(self.y-self.desty)) < speed*sleept:
            pdata = ""
            pdata += pack("I",1)
            pdata += pack("I",1)
            pdata += "Arrivato ( sto a %f dalla destinazione ) " % sqrt((self.x-self.destx)*(self.x-self.destx)+(self.y-self.desty)*(self.y-self.desty))
            self.sendpacket(CMSG_MESSAGECHAT,pdata)
            print "Arrivato ( sto a %f dalla destinazione ) " % sqrt((self.x-self.destx)*(self.x-self.destx)+(self.y-self.desty)*(self.y-self.desty))
            self.x = self.destx
	    self.y = self.desty
	    self.stopmoving()
	    if self.arrivedcb:
	      self.arrivedcb()
          if lowest == -1:
            pdata = ""
            pdata += pack("I",1)
            pdata += pack("I",1)
            pdata += "Cazzo mi sono incastrato"
            print "Cazzo mi sono incastrato"
            self.sendpacket(CMSG_MESSAGECHAT,pdata)
            self.stopmoving()
      time.sleep(sleept)
示例#7
0
文件: WOW.py 项目: ngrogolev/WOW-Bot
    def onpacket(self, opcode, data):
        #print "Ricevuto:",opcoded[opcode]#,list(data)
        try:
            if opcode == SMSG_AUTH_CHALLENGE:
                self.loggedin = True
            if opcode == SMSG_ATTACKSTART:
                self.combat = True
                debug("Entering combat!")
            if opcode == SMSG_ATTACKSTOP:
                self.combat = False
                debug("Leaving combat!")
                self.attack = 0
            if opcode == SMSG_AUTH_RESPONSE:
                if ord(data[0]) == 0x0c:
                    good("Login effettuato")
                    good("Ricezione della lista dei pg...")
                    self.sendpacket(CMSG_CHAR_ENUM, "")
                    self.sendpacket(CMSG_REALM_SPLIT, "\xff\xff\xff\xff")
                else:
                    error("Authentication failed")
            if opcode == SMSG_CHAR_CREATE:
                status = ord(data[0])
                if status == 0x2F:
                    good("PG Creato, Login...")
                    self.sendpacket(CMSG_CHAR_ENUM, "")
                else:
                    error("%x : Impossibile creare il pg")
                    raise SystemExit(1)
            if opcode == SMSG_ATTACKERSTATEUPDATE:
                hitinfo = unpack("I", data[:4])
                data = data[4:]
                attackerguid, data = unpackguid(data)
                victimguid, data = unpackguid(data)
                totaldamage = unpack("I", data[:4])
                data = data[4:]
                subdamagecount = ord(data[0])
                data = data[1:]
                for x in range(0, subdamagecount):
                    school, damage1, damage2, absorb, resist = unpack(
                        "IfIII", data[:20])
                    data = data[20:]
                    debug(
                        "%s attack hits %s for %d damage: %d absorbed, %d resisted"
                        % (str(attackerguid), str(victimguid), damage2, absorb,
                           resist))
                if attackerguid == self.attack:
                    self.doattackswing(self.attack)
            if opcode == SMSG_CHAR_ENUM:
                if len(data) < 8:
                    newpkdata = ""
                    error("Non ci sono pg")
                    notice("Creazione di uno nuovo")
                    if not self.cname:
                        name = raw_input("Inserisci il nome:")
                        race = int(
                            raw_input("Inserisci il codice della razza:"))
                        _class = int(
                            raw_input("Inserisci il codice della classe:"))
                    else:
                        name = self.cname
                        race = self.crace
                        _class = self.cclass
                    gender = 0
                    skin = 3
                    face = 3
                    hairStyle = 3
                    hairColor = 3
                    facialHair = 3
                    outfitid = 0
                    newpkdata += name + "\x00"
                    newpkdata += chr(race)
                    newpkdata += chr(_class)
                    newpkdata += chr(gender)
                    newpkdata += chr(skin)
                    newpkdata += chr(face)
                    newpkdata += chr(hairStyle)
                    newpkdata += chr(hairColor)
                    newpkdata += chr(facialHair)
                    newpkdata += chr(outfitid)
                    self.sendpacket(CMSG_CHAR_CREATE, newpkdata)
                else:
                    d2 = data
                    while len(d2) > 0:
                        debug("Pg numero %i" % ord(d2[0]))
                        guid = unpack("Q", d2[1:9])[0]
                        d2 = d2[9:]

                        debug("Guid: " + str(guid))
                        name = d2[:d2.find("\x00")]
                        d2 = d2[d2.find("\x00") + 1:]

                        race = ord(d2[0])
                        _class = ord(d2[1])
                        gender = ord(
                            d2[2])  # 0 : Male , 1 : Female , >1 : Trans
                        debug("Nome: " + name +
                              " Razza,classe,sesso: %i %i %i" %
                              (race, _class, gender))
                        d2 = d2[8:]  #Salta l'estetica del pg
                        level = ord(d2[0])
                        d2 = d2[1:]
                        debug("Livello: " + str(level))
                        zone, mapp, self.x, self.y, self.z, guildid = unpack(
                            "IIfffI", d2[:24])
                        self.curmap = mapp
                        self.z = gridmap.getheight(self.curmap, self.x, self.y,
                                                   self.z)
                        good("%s: Entering world" % name)
                        self.guid = guid
                        self.sendpacket(CMSG_OPT_OUT_OF_LOOT,
                                        "\x00\x00\x00\x00")
                        self.sendpacket(CMSG_SET_ACTIVE_VOICE_CHANNEL,
                                        "\x04\x00\x00\x00\x00")
                        self.sendpacket(CMSG_PLAYER_LOGIN, pack("Q", guid))
                        break
            if opcode == SMSG_SET_PROFICIENCY:
                self.proficiencies[ord(data[0])] = unpack("I", data[1:5])[0]
                print self.proficiencies
            if opcode == SMSG_NEW_WORLD:
                if len(data) != 20:
                    error(
                        "Pacchetto SMSG_NEW_WORLD Non valido, dimensione errata"
                    )
                mapid, x, y, z, o = unpack("Iffff", data)
                notice("Far Teleport to map %d" % mapid)
                self.curmap = mapid
                notice("We got teleported to a new location")
                self.x = x
                self.y = y
                self.z = gridmap.getheight(self.curmap, x, y, z - 3.0)
                self.sendpacket(MSG_MOVE_WORLDPORT_ACK, "")
                self.stopmoving()
                good("Teleport done: %f %f %f" % (self.x, self.y, self.z))
            if opcode == SMSG_MONSTER_MOVE:
                guid, data = unpackguid(data)
                monster = self.world.getobject(guid)
                if not monster:
                    debug("L'npc con la guid %s non esiste nel world" %
                          str(guid))
                    return
                x, y, z = unpack("fff", data[:12])
                monster.x = x
                monster.y = y
                monster.z = z
                debug("NPC %s : Nuova posizione: %f %f %f" %
                      (str(guid), x, y, z))
                self.updatetarget()
            if opcode == SMSG_GROUP_INVITE:
                pname = data[:data.find("\x00")]
                notice("Invitato in gruppo da %s" % pname)
                self.sendpacket(CMSG_GROUP_ACCEPT, "")
            if opcode == MSG_MOVE_TELEPORT_ACK:
                guid, data = unpackguid(data)
                unk1, data = (unpack("I", data[:4])[0], data[4:])
                movflags, data = (unpack("I", data[:4])[0], data[4:])
                unk1, data = (ord(data[0]), data[1:])
                time, data = (unpack("I", data[:4])[0], data[4:])
                x, data = (unpack("f", data[:4])[0], data[4:])
                y, data = (unpack("f", data[:4])[0], data[4:])
                z, data = (unpack("f", data[:4])[0], data[4:])
                notice("Received teleport ack of guid %u to %f %f %f" %
                       (guid, x, y, z))
                if guid == self.guid:
                    notice("We got teleported to a new location")

                    self.x = x
                    self.y = y
                    self.z = gridmap.getheight(self.curmap, x, y, z - 3.0)
                    self.sendpacket(
                        MSG_MOVE_TELEPORT_ACK,
                        pack("Q", guid) + pack("I", 0) + pack("I", time))
                    self.stopmoving()
                    good("Teleport done: %f %f %f" % (self.x, self.y, self.z))
            if opcode == SMSG_COMPRESSED_UPDATE_OBJECT:
                self.world.handlecompressedupdateobject(data)
            if opcode == SMSG_UPDATE_OBJECT:
                self.world.handleplainupdateobject(data)
            if opcode == SMSG_MESSAGECHAT:
                typ, data = (ord(data[0]), data[1:])
                language, data = (unpack("I", data[:4])[0], data[4:])
                guid, data = (unpack("Q", data[:8])[0], data[8:])
                unk1, data = (unpack("I", data[:4])[0], data[4:])
                targetguid, data = (unpack("Q", data[:8])[0], data[8:])
                msglen, data = (unpack("I", data[:4])[0], data[4:])
                message = data
                if 'chatcb' in dir(self) and guid != self.guid:
                    self.chatcb(typ, guid, message)
            if opcode == MSG_MOVE_STOP or opcode == MSG_MOVE_HEARTBEAT or opcode == MSG_MOVE_START_FORWARD:
                guid, data = unpackguid(data)
                #if not guid in self.guidnames:
                #  self.sendpacket(CMSG_NAME_QUERY,pack("Q",guid))
                flags = unpack("I", data[:4])[0]

                data = data[4:]
                unk1 = ord(data[0])
                data = data[1:]
                time = unpack("I", data[:4])[0]
                data = data[4:]
                print len(data[:16])
                x, y, z, o = unpack("ffff", data[:16])

                #print "Move opcode:",guid,x,y,z,(float(time)/1000.0)
                player = self.world.getobject(guid)
                player.x = x
                player.y = y
                player.z = z
                if guid == self.following:
                    self.destx = x
                    self.desty = y
            if opcode == SMSG_NAME_QUERY_RESPONSE:
                guid = unpack("Q", data[:8])[0]
                data = data[8:]
                name = data[:data.find("\x00")]
                #print "%i is %s" % (guid,name)
                self.guidnames[guid] = name

        except:
            print traceback.format_exc()
示例#8
0
文件: WOW.py 项目: ngrogolev/WOW-Bot
    def moveheartbeatthread(self):
        speed = self.speed
        sleept = 0.5
        time.sleep(sleept)
        print speed, sleept
        while 1:
            if self.loggedin:
                if self.moving != None:
                    dists = dict()
                    dists2 = dict()

                    for i in range(0, 360 / 4):
                        xf = cos(
                            (float(i * 360 / 4) / 360.0) * (3.141592653 * 2.0))
                        yf = sin(
                            (float(i * 360 / 4) / 360.0) * (3.141592653 * 2.0))
                        xx = self.x + xf * speed * sleept
                        yy = self.y + yf * speed * sleept
                        los = gridmap.los(self.curmap, self.x, self.y,
                                          self.z + 1.0, xx * 1.1, yy * 1.1,
                                          self.z + 1.0)
                        #print los
                        #debug("LOS: %d (%f,%f,%f) -> (%f,%f,%f) = %s" % (self.curmap,self.x,self.y,self.z+1.0,xx*1.1,yy*1.1,self.z+1.0,str(bool(los))))
                        loa = []
                        for i2 in range(0, 5):
                            loa.append(
                                gridmap.getheight(
                                    self.curmap, self.x +
                                    xf * speed * sleept * i2, self.y +
                                    yf * speed * sleept * i2, self.z + 0.4) -
                                self.z)
                        media = sum(loa) / float(len(loa))
                        quadrati = []
                        for v in loa:
                            quadrati.append(v * v)
                        mediaquadrati = sum(quadrati) / float(len(quadrati))
                        print mediaquadrati - media, i
                        XI = int(xx * 1000.0)
                        YI = int(yy * 1000.0)
                        if mediaquadrati - media < 2.0 and (
                                XI,
                                YI) not in self.usedpoints:  #and bool(los):
                            dists2[i] = (XI, YI)
                            dists[i] = sqrt((self.destx - xx) *
                                            (self.destx - xx) +
                                            (self.desty - yy) *
                                            (self.desty - yy)) + (
                                                mediaquadrati - media) * 1.0
                        #print abs(gridmap.getheight(xx,yy,self.z)- self.z)
                    lowest = -1
                    l = 4000000.0
                    for x in dists:
                        if dists[x] < l:
                            l = dists[x]
                            lowest = x
                    print dists
                    if lowest != -1:
                        self.usedpoints.append(dists2[lowest])
                        #print self.usedpoints
                        if len(self.usedpoints) > 5:
                            self.usedpoints.remove(self.usedpoints[0])
                    self.setfacing((float(lowest * 360 / 4) / 360.0) *
                                   (3.141592653 * 2.0))
                    self.x += cos(self.o) * speed * sleept
                    self.y += sin(self.o) * speed * sleept

                    try:
                        self.z = gridmap.getheight(self.curmap, self.x, self.y,
                                                   self.z - 4.0)
                        self.sendpacket(
                            MSG_MOVE_HEARTBEAT,
                            self.createmovementpackage(self.moving, self.x,
                                                       self.y, self.z, self.o))
                    except:
                        pass
                    if sqrt((self.x - self.destx) * (self.x - self.destx) +
                            (self.y - self.desty) *
                            (self.y - self.desty)) < speed * sleept:
                        pdata = ""
                        pdata += pack("I", 1)
                        pdata += pack("I", 1)
                        pdata += "Arrivato ( sto a %f dalla destinazione ) " % sqrt(
                            (self.x - self.destx) * (self.x - self.destx) +
                            (self.y - self.desty) * (self.y - self.desty))
                        self.sendpacket(CMSG_MESSAGECHAT, pdata)
                        print "Arrivato ( sto a %f dalla destinazione ) " % sqrt(
                            (self.x - self.destx) * (self.x - self.destx) +
                            (self.y - self.desty) * (self.y - self.desty))
                        self.x = self.destx
                        self.y = self.desty
                        self.stopmoving()
                        if self.arrivedcb:
                            self.arrivedcb()
                    if lowest == -1:
                        pdata = ""
                        pdata += pack("I", 1)
                        pdata += pack("I", 1)
                        pdata += "Cazzo mi sono incastrato"
                        print "Cazzo mi sono incastrato"
                        self.sendpacket(CMSG_MESSAGECHAT, pdata)
                        self.stopmoving()
            time.sleep(sleept)