def check_pos(self): if self.old_pos is not None: if (self.position.x == self.old_pos.x) and (self.position.y == self.old_pos.y) and (self.position.z == self.old_pos.z): return True server = self.server cpres = self.scripts.call('on_pos_update').result if cpres is False: self.entity_data.x = self.old_pos.x self.entity_data.y = self.old_pos.y return True # check new coordinates and distances edist = get_distance_3d(self.old_pos.x, self.old_pos.y, self.old_pos.z, self.position.x, self.position.y, self.position.z) if edist > (reactor.seconds() * constants.MAX_MOVE_DISTANCE): self.entity_data.x = self.old_pos.x self.entity_data.y = self.old_pos.y self.entity_data.z = self.old_pos.z print 'Player %s moved to fast!' % self.name return False cxo = math.floor(self.old_pos.x / constants.CHUNK_SCALE) cyo = math.floor(self.old_pos.y / constants.CHUNK_SCALE) cxn = math.ceil(self.position.x / constants.CHUNK_SCALE) cyn = math.ceil(self.position.y / constants.CHUNK_SCALE) if (cxo != cxn) or (cyo != cyn): self.server.world.move_locatable(self.entity_id, self.position.x, self.position.y, self.position.z) print '%s entered chunk (%s,%s)' % (self.name, cxn, cyn) self.old_pos = self.position return True
def get_closest_locatable(locatable_iter, lx, ly, lz, max_distance=3): if not locatable_iter: return None max_distance = math.abs(max_distance) closest_dst = None closest_lct = None while True: try: ltv = next(locatable_iter) if not ltv: continue ltd = common.get_distance_3d(lx, ly, lz, ltv.x, ltv.y, ltv.z) if ( (not max_distance) or (ltd <= max_distance) ) and ( (not closest_dst) or (not closest_ent) or (ltd < closest_dst) ): closest_dst = ltd closest_lct = ltv except StopIteration: break except: continue return closest_lct
def on_hit_packet(self, packet): try: target = self.server.entities[packet.target_id] except KeyError: return if constants.MAX_DISTANCE > 0: edist = get_distance_3d(self.position.x, self.position.y, self.position.z, target.entity_data.pos.x, target.entity_data.pos.y, target.entity_data.pos.z) if edist > constants.MAX_DISTANCE: print '[ANTICHEAT BASE] Player %s tried to attack target that is %s away!' % (self.name, edist) self.kick('Range error') return if self.scripts.call('on_hit', target=target, packet=packet).result is False: return self.server.update_packet.player_hits.append(packet) if packet.damage <= 0: return if packet.damage > 1000: packet.damage = 1000 if target.hp > packet.damage: if self.scripts.call('on_damage', target=target, packet=packet).result is False: return target.hp -= packet.damage else: target.hp = 0 self.scripts.call('on_kill', target=target)
def get_locatables_in_range(locatable_iter, lx, ly, lz, max_distance=3): if not locatable_iter: return None max_distance = math.abs(max_distance) locatable_set = set() while True: try: ltv = next(locatable_iter) if not ltv: continue ltd = common.get_distance_3d(lx, ly, lz, ltv.x, ltv.y, ltv.z) if ( ltd <= max_distance ): locatable_set.add(ltv) except StopIteration: break except: continue return locatable_set