Exemplo n.º 1
0
    def handle_bot_transform_sync(
            self, bot_id, position,
            rotation, waypoint_position):
        if bot_id != -2:
            return message.BotTransformSyncRequestResponse()

        position = message.Vector3(**position)
        position.y = 0  # ???

        # use ammo
        if self.ammo_item:
            item_position = self.ammo_item.position
            item_position = message.Vector3(
                x=item_position.x, y=0, z=item_position.z)
            if v3_distance(item_position, position) < 1:
                print '[+] use_item'
                self.actor.max_ammo += 18
                dbutil.actor_update(self.connection.actordb, self.actor)
                _remote(self, 'use_item', item_type=self.ammo_item.item_type)
                self.ammo_item = None

        # TODO
        self.player.position = position
        self.player.rotation = rotation
        return message.BotTransformSyncRequestResponse()
Exemplo n.º 2
0
    def test_find_path(self):
        m = level1.TileMap()
        # path = m._find_path(message.Vector3(x=42, y=0, z=9),
        #                    message.Vector3(x=14, y=0, z=4),
        #                    smooth=True)
        # path = m._find_path(message.Vector3(x=42, y=0, z=9),
        #                    message.Vector3(x=22, y=0, z=26),
        #                    smooth=True)
        # path = m._find_path(message.Vector3(x=42, y=0, z=9),
        #                    message.Vector3(x=7.79, y=0, z=1.60),
        #                    smooth=True)
        # path = m._find_path(message.Vector3(x=37.54, y=0, z=7.49),
        #                    message.Vector3(x=7.79, y=0, z=1.60),
        #                    smooth=True)
        path = m._find_path(message.Vector3(x=19, y=0, z=8),
                            message.Vector3(x=34, y=0, z=16.4),
                            smooth=True)
        print path
        result = {}
        result['Waypoints'] = []
        for p in path:
            result['Waypoints'].append({'Index': p[0]})

        with open(r'..\Shooter\find_path_result', 'w') as f:
            import json
            json.dump(result, f)
Exemplo n.º 3
0
def v3_to_euler_y(v3):
    """v3_to_euler_y -> forward to euler angle (around y-axis)
    >>> v = message.Vector3(x=1, y=0, z=1)
    >>> int(v3_to_euler_y(v))
    45
    """
    v = message.Vector3(x=v3.x, y=0, z=v3.z)
    return v3_angle_cw(message.Vector3(x=0, y=0, z=1), v)
Exemplo n.º 4
0
    def test_see_through(self):
        print 'test_see_through'
        m = level1.TileMap()

        start = message.Vector3(x=42, y=0, z=9)
        end = message.Vector3(x=14, y=0, z=4)
        self.assertFalse(
            m.see_through(m.position_to_index(start),
                          m.position_to_index(end)))

        self.assertTrue(m.see_through((5, 16), (6, 17)))
        self.assertTrue(m.see_through((12, 36), (14, 34)))
        self.assertTrue(m.see_through((14, 34), (12, 36)))
        self.assertTrue(m.see_through((13, 33), (9, 40)))
Exemplo n.º 5
0
 def _spawn_bot(self, bot_type,
                x=0, y=0, z=0, rot_y=0):
     self.bot_count += 1
     _remote_callback(
         self, 'spawn_bot', bot_id=self.bot_id, bot_type=bot_type,
         position=message.Vector3(x=x, y=y, z=z), rotation=rot_y)
     self.bot_id += 1
Exemplo n.º 6
0
    def __init__(self, connection, level):
        print '[+] ShootGameLevel1'
        self.connection = connection

        self.actor = connection.actor
        self.sockutil = connection.sockutil
        self.client_sock = connection.client_sock
        self.level = level

        self.bots = []

        self.entered = False

        self.tile_map = TileMap()

        self.explose_target = Tower(
            0, 200, message.Vector3(x=34, y=0, z=16.4),
            self.on_tower_destroyed)
        self.explose_target.sockutil = self.sockutil
        self.explose_target.client_sock = self.client_sock
        self.explose_target.on_damage = self._on_tower_damage

        self.player = Player()

        self.kill_reporter = KillReporter()
        self.kill_reporter.sockutil = self.sockutil
        self.kill_reporter.client_sock = self.client_sock

        # TODO
        self.sockutil.register_handler(
            'level0_bot_killed', self.handle_level0_bot_killed, force=True);
        self.sockutil.register_handler(
            'update_actor_hp', self.handle_update_actor_hp, force=True);
        self.sockutil.register_handler(
            'bot_transform_sync', self.handle_bot_transform_sync, force=True);
Exemplo n.º 7
0
    def test_basic(self):
        bot = level1.Bot(0, None)
        tile_map = level1.TileMap(map_text=r'''
        {
            "Stride":1,
            "Height":1.0,
            "ColumnCount":4,
            "RowCount":4,
            "Tiles":[
                0,0,0,0,
                0,0,0,0,
                0,0,0,0,
                0,0,0,0
            ]
        }
        ''')
        goto = level1.GotoBehavior(bot, tile_map)
        goto.set_destination(message.Vector3(x=3, y=0, z=3))

        self.assertTrue(goto.validate())
        goto.activate()

        self.assertTrue(goto._has_waypoint())
        self.assertFalse(goto._has_reached())

        self.assertFalse(goto.is_satisfied())
        self.assertFalse(goto.is_failed())

        for i in range(0, 400):
            goto.update()

        self.assertFalse(goto._has_waypoint())
        self.assertTrue(goto._has_reached())
        self.assertTrue(goto.is_satisfied())
Exemplo n.º 8
0
    def __init__(self, bot_id, target):
        self.bot_id = bot_id
        self.position = message.Vector3(x=0, y=0, z=0)
        self.rotation = 0
        self.explose_target = target  # TODO

        self.behavior = None

        self.dead = False
Exemplo n.º 9
0
 def find_path(self, start_pos, target_pos):
     path = self._find_path(start_pos, target_pos, smooth=True)
     if path is None:
         p = Path()
         p.tile_map = self
         return p
     else:
         p = Path()
         p.tile_map = self
         for point_index in range(len(path) - 1, -1, -1):
             index = path[point_index][0]
             x, y, z = self.get_center(index)
             p.waypoints.append(Waypoint(
                 index, message.Vector3(x=x, y=y, z=z)))
             # TODO: test
         p.waypoints.append(Waypoint((-1, -1), target_pos))
         return p
Exemplo n.º 10
0
def v3_rotate(v3, angle):
    """v3_rotate
    -> (cosT + (- angle), 0, sinT + (- angle))
    -> (cosT * cosAngle - sinT * sinAngle, sinT * cosAngle + cosT * sinAngle)
    >>> v = message.Vector3(x=0, y=0, z=1)
    >>> v2 = v3_rotate(v, 90)
    >>> int(v2.x), int(v2.z)
    (1, 0)
    >>> v3 = v3_rotate(v2, -90)
    >>> int(v3.x), int(v3.z)
    (0, 1)
    """
    angle = -math.radians(angle)
    x = v3.x
    z = v3.z
    cos_angle = math.cos(angle)
    sin_angle = math.sin(angle)
    new_x = x * cos_angle - z * sin_angle
    new_z = z * cos_angle + x * sin_angle
    return message.Vector3(x=new_x, y=0, z=new_z)
Exemplo n.º 11
0
    def _spawn_bot(self, bot_type,
                   x=0, y=0, z=0, rot_y=0):
        # create bot
        bot = Bot(self.bot_id, self.explose_target)
        bot.position = message.Vector3(x=x, y=y, z=z)
        bot.rotation = rot_y
        bot.sockutil = self.sockutil
        bot.client_sock = self.client_sock

        goto = GotoBehavior(bot, self.tile_map)
        goto.level1 = self

        # behavior
        if bot_type == 'spider_remote':
            destroy_tower = DestroyTowerBehavior(
                bot, self.explose_target.position, goto)
            destroy_tower.tile_map = self.tile_map
            destroy_tower.level1 = self
            destroy_tower.sockutil = self.sockutil
            destroy_tower.client_sock = self.client_sock

            bot.behavior = destroy_tower

            self.bots.append(bot)
        elif bot_type == 'spider_king':
            sensor = PlayerSensor(self.player)
            defense = DefenseBehavior(bot, sensor, 8, goto)
            defense.sockutil = self.sockutil
            defense.client_sock = self.client_sock
            defense.tile_map = self.tile_map

            bot.behavior = defense
        else:
            raise NotImplementedError('No such bot_type: %s' % bot_type)

        _remote_callback(
            self, 'spawn_bot', bot_id=self.bot_id, bot_type=bot_type,
            position=bot.position, rotation=bot.rotation)

        self.bot_id += 1
        return bot
Exemplo n.º 12
0
    def handle_enter_level(self):
        self.entered = True
        self.max_bot_count = 100 * 3
        self.killed = 0
        self.spawn_spot = [
            (19, 0, 8, 0),
            (18, 0, 9, 0),
            (20, 0, 8, 0),
        ]

        self.spawn_interval = 15
        self.time_since_start = time.clock()
        self.next_spawn_time = self.time_since_start + self.spawn_interval

        king_spot = (12, 0, 4, 90)
        self.spider_king = self._spawn_bot(
                'spider_king', x=king_spot[0], y=king_spot[1],
                z=king_spot[2], rot_y=king_spot[3])

        for spot in self.spawn_spot:
            self._spawn_bot('spider_remote', x=spot[0], y=spot[1],
                            z=spot[2], rot_y=spot[3])

        self.ammo_item = Item()
        self.ammo_item.position = message.Vector3(x=25.14, y=1.26, z=14.89)
        _remote(self, 'spawn_item', item_type=self.ammo_item.item_type,
                position=self.ammo_item.position)

        actor_level_info = message.ActorLevelInfo()
        actor_level_info.actor_id = self.actor.actor_id
        actor_level_info.level_id = self.level.level_id
        # actor_level_info.passed = True
        actor_level_info.star1 = False
        actor_level_info.star2 = False
        actor_level_info.star3 = self._is_third_task_ok()

        self.actor_level_info = actor_level_info
        _remote(self, 'actor_level_info_sync',
                actor_level_info=self.actor_level_info)
Exemplo n.º 13
0
def v3_euler_y(rot_y):
    """v3_euler_y -> vector3 (forward)
    rot_y: angle
    """
    return v3_rotate(message.Vector3(x=0, y=0, z=1), rot_y)
Exemplo n.º 14
0
def v3_minus(left, right):
    return message.Vector3(
        x=left.x - right.x,
        y=left.y - right.y,
        z=left.z - right.z)
Exemplo n.º 15
0
 def __init__(self):
     self.item_type = 'ammo'
     self.position = message.Vector3(x=0,y=0,z=0)
Exemplo n.º 16
0
 def __init__(self):
     self.position = message.Vector3(x=0, y=0, z=0)
     self.rotation = 0
     self.max_hp = 0
     self.hp = 0
Exemplo n.º 17
0
def v3_add(left, right):
    return message.Vector3(
        x=left.x + right.x,
        y=left.y + right.y,
        z=left.z + right.z)