Beispiel #1
0
    def drunk_move(mv_handler, mv_owner, move_type, game_map, mobs,
                   curr_state):

        if curr_state.value != State.PLAYER_TURN:
            return OperationLog()

        dx, dy = mv_handler.mv_types[move_type]

        if game_map.is_cell_blocked(mv_owner.x + dx, mv_owner.y + dy):
            return OperationLog()

        victim = mv_owner.who_blocks(mobs[1:], mv_owner.x + dx,
                                     mv_owner.y + dy)

        if victim:
            return mv_owner.stats.attack_target(victim)
        else:
            # делаем случайны ход по диагонали в направлении движения игрока
            if rnd.random() < 0.5:
                if move_type in [MoveType.LEFT, MoveType.RIGHT]:
                    mv_owner.update_pos((dx, dy + 1), game_map)
                elif move_type in [MoveType.UP, MoveType.DOWN]:
                    mv_owner.update_pos((dx + 1, dy), game_map)
            else:
                if move_type in [MoveType.LEFT, MoveType.RIGHT]:
                    mv_owner.update_pos((dx, dy - 1), game_map)
                elif move_type in [MoveType.UP, MoveType.DOWN]:
                    mv_owner.update_pos((dx - 1, dy), game_map)

        curr_state.value = State.MOB_TURN

        print(mv_owner.x, mv_owner.y)

        return OperationLog()
    def drop_item(self, entities, item_entity):
        operation_log = OperationLog()

        item_entity.x = self.owner.x
        item_entity.y = self.owner.y
        entities.append(item_entity)

        self.del_item(item_entity)
        operation_log.add_item(
            {'message': Message(f'You dropped {item_entity.name}', tc.yellow)})

        return operation_log
Beispiel #3
0
    def inventory_keys(engine, key):
        if key in [tc.event.K_ESCAPE, tc.event.K_i, tc.event.K_d]:
            if engine.prev_state.value:
                engine.curr_state.value = engine.prev_state.value
            else:
                engine.curr_state.value = State.PLAYER_TURN
            return OperationLog()

        if key == tc.event.K_1:
            return OperationLog([{'inv_index': 0}])
        if key == tc.event.K_2:
            return OperationLog([{'inv_index': 1}])
        if key == tc.event.K_3:
            return OperationLog([{'inv_index': 2}])

        return OperationLog()
Beispiel #4
0
    def act(self, mob, target, fov_map, game_map, mobs):
        operation_log = OperationLog()

        if not fov_map or tc.map_is_in_fov(fov_map, mob.x, mob.y):

            dist = mob.get_dist(target)
            if CowardStrategy.min_dist_from_target <= dist <= CowardStrategy.max_dist_from_target:
                if mob.x - target.x < 0:
                    if mob.y - target.y < 0:
                        mob.update_pos(MoveCoords.DOWN_LEFT, game_map)
                    elif mob.y - target.y == 0:
                        mob.update_pos(MoveCoords.LEFT, game_map)
                    else:
                        mob.update_pos(MoveCoords.UP_LEFT, game_map)
                elif mob.x - target.x == 0:
                    if mob.y - target.y < 0:
                        mob.update_pos(MoveCoords.DOWN, game_map)
                    elif mob.y - target.y == 0:
                        mob.update_pos(MoveCoords.UP_LEFT, game_map)
                    else:
                        mob.update_pos(MoveCoords.UP, game_map)
                else:
                    if mob.y - target.y < 0:
                        mob.update_pos(MoveCoords.DOWN_RIGHT, game_map)
                    else:
                        mob.update_pos(MoveCoords.UP_RIGHT, game_map)

        return operation_log
Beispiel #5
0
    def attack_target(self, target):
        operation_log = OperationLog()

        if not target.stats:
            return operation_log

        damage = self.force

        if damage > 0:
            if isinstance(target, Player) or target.item is None:
                operation_log.add_item({
                    'message':
                    Message(
                        f'{self.owner.name} damaged {target.name} in {damage} hps.',
                        tc.white)
                })
                operation_log.log.extend(target.stats.decrease_hp(damage).log)

        return operation_log
    def activate_item(self, item_entity):
        operation_log = OperationLog()

        if item_entity.item is not None:
            if item_entity.item.type == ItemType.ARMOUR_I:
                if self.owner.stats.armour:
                    self.items.append(self.owner.stats.armour)
                    self.owner.stats.max_defense -= self.owner.stats.armour.item.max_defense
                    self.owner.color = self.owner.main_color
                    self.owner.stats.armour = None

                self.owner.stats.armour = item_entity
                self.owner.main_color = self.owner.color
                self.owner.color = item_entity.item.color
                self.owner.stats.max_defense += item_entity.item.max_defense
                operation_log.add_item(
                    {'message': Message('Armour activated.', tc.yellow)})

                self.items.remove(item_entity)

        return operation_log
Beispiel #7
0
    def act(self, mob, target, fov_map, game_map, mobs):
        operation_log = OperationLog()

        if not fov_map or tc.map_is_in_fov(fov_map, mob.x, mob.y):
            if AggressiveStrategy.min_dist_from_target <= mob.get_dist(target) \
                    <= AggressiveStrategy.max_dist_from_target:
                mob.move_astar(target, game_map, mobs)
            elif mob.stats and mob.get_dist(target) < 2 and target.stats.hp > 0:
                res = mob.stats.attack_target(target)
                operation_log.log.extend(res.log)

        return operation_log
Beispiel #8
0
    def decrease_hp(self, delta):
        operation_log = OperationLog()

        if self.armour and self.armour.item.defense > 0:
            self.armour.item.defense -= delta
            if self.armour.item.defense <= 0:
                delta = (-1) * self.armour.item.defense
                self.owner.color = self.owner.main_color
                self.max_defense -= self.armour.item.max_defense

                operation_log.add_item({
                    'message':
                    Message('Armour destroyed.', self.armour.item.color)
                })
                self.armour = None
            else:
                delta = 0

        if self.defense > 0:
            self.defense -= delta
            if self.defense < 0:
                delta = (-1) * self.defense
                self.defense = 0
            else:
                delta = 0

        self.hp -= delta

        if self.hp <= 0:
            operation_log.add_item({'dead': self.owner})

        return operation_log
Beispiel #9
0
    def move(self, mv_type, game_map, mobs, curr_state):
        print(curr_state.value)
        if curr_state.value != State.PLAYER_TURN:
            return OperationLog()

        dx, dy = self.mv_types[mv_type]

        if game_map.is_cell_blocked(self.owner.x + dx, self.owner.y + dy):
            return OperationLog()

        victim = self.owner.who_blocks(mobs[1:], self.owner.x + dx, self.owner.y + dy)

        if victim:
            return self.owner.stats.attack_target(victim)
        else:
            self.owner.update_pos(self.mv_types[mv_type], game_map)

        curr_state.value = State.MOB_TURN

        print(self.owner.x, self.owner.y)

        return OperationLog()
Beispiel #10
0
    def get_item(self, entities):
        operation_log = OperationLog()

        for entity in entities:
            if entity.x == self.x and entity.y == self.y:
                if isinstance(entity, Mob) and entity.item is not None:
                    operation_log = OperationLog()
                    if not self.inventory.add_item(entity):
                        operation_log.add_item({
                            'new_item':
                            None,
                            'message':
                            Message('Inventory is full.', tc.yellow)
                        })
                    else:
                        operation_log.add_item({
                            'new_item':
                            entity,
                            'message':
                            Message(f'New item {entity.name}!', tc.light_azure)
                        })
                    break

        return operation_log
Beispiel #11
0
def kill_mob(mob):
    name = mob.name
    mob.char = ord('#')
    mob.color = tc.dark_grey
    mob.is_blocking = False
    mob.stats = None
    mob.act = lambda *args, **kwargs: OperationLog()
    mob.name = 'died ' + mob.name
    mob.render_order = RenderOrder.DEAD_ENTITY

    if mob.item is not None:
        if mob.item.type == ItemType.HP_PTN:
            mob.char = ord(' ')
            return Message('', tc.fuchsia), State.HEALTH_UP

        if mob.item.type == ItemType.INTOX_PTN:
            mob.char = ord(' ')
            return Message('', tc.fuchsia), State.INTOXICATE

    if name == 'Aggr':
        return Message(f'{name} is dead!', tc.yellow)

    return Message(f'{name} is dead!', tc.yellow)
Beispiel #12
0
    def pick_item(self, item):
        operation_log = OperationLog()

        if item.item.type == ItemType.HP_PTN:
            operation_log.add_item({
                'message':
                Message(f'+{item.item.hp_up} HP potion!', tc.green)
            })
            self.stats.increase_hp(5)
            self.inventory.del_item(item)

        elif item.item.type == ItemType.INTOX_PTN:
            operation_log.add_item(
                {'message': Message('You\'re intoxicated!', tc.fuchsia)})
            if self.mv_handler.intox_start_time:
                self.mv_handler.intox_start_time += item.item.intox_time
            else:
                self.mv_handler.set_intox_start_time(time.time())

            self.inventory.del_item(item)

        return operation_log
Beispiel #13
0
    def user_input(engine):
        for event in tc.event.get():
            # debug
            if engine.info.DEBUG:
                if event.type != "MOUSEMOTION":
                    print(event)
            # quit
            if event.type == "QUIT":
                engine.IS_GAME = False
            # нажатие клавивиши
            if event.type == "KEYDOWN":
                # передача управления в инвентарь
                if engine.curr_state.value != State.PLAYER_DEAD and \
                        engine.curr_state.value in [State.SHOWING_MENU, State.DROP_ITEM]:
                    return Command(KeysHandler.inventory_keys, engine,
                                   event.sym)

                if event.sym == tc.event.K_ESCAPE:
                    # выход из инвентаря
                    if engine.curr_state.value == (State.SHOWING_MENU,
                                                   State.DROP_ITEM):
                        engine.curr_state.value = engine.prev_state.value
                    else:
                        # выход из игры
                        engine.IS_GAME = False
                if engine.curr_state.value != State.PLAYER_DEAD:
                    if event.sym == tc.event.K_UP:
                        return KeysHandler.create_command(engine, MoveType.UP)
                    if event.sym == tc.event.K_DOWN:
                        return KeysHandler.create_command(
                            engine, MoveType.DOWN)
                    if event.sym == tc.event.K_LEFT:
                        return KeysHandler.create_command(
                            engine, MoveType.LEFT)
                    if event.sym == tc.event.K_RIGHT:
                        return KeysHandler.create_command(
                            engine, MoveType.RIGHT)
                    if event.sym == tc.event.K_g:
                        return Command(engine.player.get_item,
                                       engine.get_entities())
                    if event.sym == tc.event.K_i:
                        # выход из меню инвентаря
                        if engine.curr_state.value == State.SHOWING_MENU:
                            engine.curr_state.value = engine.prev_state.value
                            return Command(lambda arg: arg, OperationLog())
                        # вход в меню инвентаря
                        return Command(lambda arg: arg,
                                       OperationLog([{
                                           'show_menu': True
                                       }]))
                    if event.sym == tc.event.K_d:
                        # выход из drop меню инвентаря
                        if engine.curr_state.value == State.DROP_ITEM:
                            engine.curr_state.value = engine.prev_state.value
                            return Command(lambda arg: arg, OperationLog())
                        # вход в drop меню инвентаря
                        return Command(lambda arg: arg,
                                       OperationLog([{
                                           'drop_menu': True
                                       }]))

        return Command(lambda arg: arg, OperationLog())
Beispiel #14
0
 def act(self, *args, **kwargs):
     return OperationLog()