Пример #1
0
    def change_movement(self, location, position, t):
        """
        give a request to the bot to move somewhere or position itself
        return a generator that will return packets so that the movement
        is smooth.  the packets will be written to the wire at regular
        intervals.  
        NOTE: wouldn't it be real nice if we implimented position as a vector?
        Would look a lot better if plugging in some real math.  splines, anyone?
        """

        this_loc = Location()

        this_loc.x = self.location.x
        this_loc.z = self.location.z

        steps = float(t) / float(self.conn.bot_tick_interval)
   
        x_origin = self.location.x
        x_offset = 0
        x_dist = location.x - self.location.x
        x_step = x_dist / steps
        
        z_origin = self.location.z
        z_offset = 0
        z_dist = location.z - self.location.z
        z_step = z_dist / steps

        arrived = False

        while arrived == False:
            if abs(x_offset) < abs(x_dist):
                x_offset += x_step
                this_loc.x = x_origin + x_offset
            else:
                arrived = True
            
            if abs(z_offset) < abs(z_dist):
                z_offset += z_step
                this_loc.z = z_origin + z_offset
                arrived = False

            self.location.x = this_loc.x
            self.location.z = this_loc.z
            
            p, l, f = self.location.build_containers()

            yield make_packet("position", position=p, flying=f)
Пример #2
0
    def move_to(self, x, z):
        """
        Move to the place.  Don't do pathfinding.

        """

        l = Location()
        l.x = x
        l.z = z

        g = self.change_movement(l, None, 3)
        self.cmd_queue.append(g)
Пример #3
0
    def move_random(self):
        """
        Just move the bot around...

        There are no tests about the world geometry, etc
        """

        l = Location()
        
        l.x = self.location.x + 2 - random.random() * 4
        l.z = self.location.z + 2 - random.random() * 4
        
        g = self.change_movement(l, None, 5)

        self.cmd_queue.append(g)
Пример #4
0
    def _load_entity_from_tag(self, tag):
        location = Location()

        position = tag["Pos"].tags
        rotation = tag["Rotation"].tags
        location.x = position[0].value
        location.y = position[1].value
        location.z = position[2].value
        location.yaw = rotation[0].value
        location.pitch = rotation[1].value
        location.grounded = bool(tag["OnGround"])

        entity = entities[tag["id"].value](location=location)

        self._entity_loaders[entity.name](entity, tag)

        return entity
Пример #5
0
    def _load_entity_from_tag(self, tag):
        location = Location()

        position = tag["Pos"].tags
        rotation = tag["Rotation"].tags
        location.x = position[0].value
        location.y = position[1].value
        location.z = position[2].value
        location.yaw = rotation[0].value
        location.pitch = rotation[1].value
        location.grounded = bool(tag["OnGround"])

        entity = entities[tag["id"].value](location=location)

        self._entity_loaders[entity.name](entity, tag)

        return entity
Пример #6
0
    def create_entity(self, x, y, z, name, **kwargs):
        """
        Spawn an entirely new entity.

        Handles entity registration as well as instantiation.
        """

        location = Location()
        location.x = x
        location.y = y
        location.z = z
        entity = entities[name](eid=0, location=location, **kwargs)

        self.register_entity(entity)

        bigx = entity.location.x // 16
        bigz = entity.location.z // 16

        d = self.world.request_chunk(bigx, bigz)
        d.addCallback(lambda chunk: chunk.entities.add(entity))
        d.addCallback(lambda none: log.msg("Created entity %s" % entity))

        return entity
Пример #7
0
    def create_entity(self, x, y, z, name, **kwargs):
        """
        Spawn an entirely new entity.

        Handles entity registration as well as instantiation.
        """

        location = Location()
        location.x = x
        location.y = y
        location.z = z
        entity = entities[name](eid=0, location=location, **kwargs)

        self.register_entity(entity)

        bigx = entity.location.x // 16
        bigz = entity.location.z // 16

        d = self.world.request_chunk(bigx, bigz)
        d.addCallback(lambda chunk: chunk.entities.add(entity))
        d.addCallback(lambda none: log.msg("Created entity %s" % entity))

        return entity
Пример #8
0
    def create_entity(self, x, y, z, name, **kwargs):
        """
        Spawn an entirely new entity.

        Handles entity registration as well as instantiation.
        """

        location = Location()
        location.x = x
        location.y = y
        location.z = z
        entity = entities[name](eid=0, location=location, **kwargs)

        self.register_entity(entity)

        bigx = entity.location.x // 16
        bigz = entity.location.z // 16

        d = self.world.request_chunk(bigx, bigz)
        d.addCallback(lambda chunk: chunk.entities.add(entity))
        d.addCallback(lambda none: log.msg("Created entity %s" % entity))
        if hasattr(entity,'loop'): # XXX Maybe just send the entity object to the manager?
            self.world.mob_manager.start_mob(entity)
        return entity
Пример #9
0
 def test_distance(self):
     other = Location()
     other.x = 2
     other.y = 3
     other.z = 6
     self.assertEqual(self.l.distance(other), 7)