Example #1
0
def StarterTown_house_basement_door_entrance(state):
    inv_list = [item.name for item in state.player.inventory]
    if "BasementKey" in inv_list:
        state.player.location = getattr(states, "StarterTown_house_basement")
        state.player.x = 23
        state.player.y = 47

        state.update_map()
    else:
        helper.popup(state.game_box, state, [
            "You try to open the door, but it is locked.",
            "You notice a sign on the door that reads:", "", "Door locked.",
            "Ask me if you need access", "[- Osk'Ghar]"
        ])
        state.player.x = 14
        state.player.y = 32
Example #2
0
def StarterTown_haunted_house_2_dungeon_door_right(state):
    if "HauntedHouse_dungeon_door_right_opened" in state.player.flags:
        return
    inv_list = [item.name for item in state.player.inventory]
    if "DungeonKeyHaunted" in inv_list:
        answer = helper.yes_no(
            state.game_box, state,
            ["Your key seems to fit perfect.", "", "Do you open the door?"])
        if answer:
            state.player.flags.append("HauntedHouse_dungeon_door_right_opened")
            state.player.x = 29
            state.player.y = 82
        else:
            state.player.x = 29
            state.player.y = 81

    else:
        helper.popup(state.game_box, state,
                     ["You try to open the door, but it is locked."])
        state.player.x = 29
        state.player.y = 81
Example #3
0
    def execute(self, player):
        answer = helper.two_options(
            player.state.stdscr, player.state,
            ["Recall to Waypoint?", "or", "Set new Waypoint?"],
            ["Recall", "Set"])

        if answer:
            if not player.recall["location"]:
                helper.popup(player.state.stdscr, player.state,
                             ["You have no [waypoint] set."])
                return
            events.go_to(player.state,
                         player.recall["location"],
                         x=player.recall["x"],
                         y=player.recall["y"])

        else:
            if player.location.raw_name == "RandomCave":
                helper.popup(player.state.stdscr, player.state,
                             ["You cannot set a [waypoint] here."])
                return
            player.recall["location"] = player.location.raw_name
            player.recall["x"] = player.x
            player.recall["y"] = player.y
Example #4
0
    def execute(self, player, opponent, state):
        charm = helper.select_charm(state)
        if not charm:
            helper.popup(state.stdscr, state, ["No charms available"])
            return {"damage": "back"}
        combat_text = []
        combat_variables = [f"sacrifices a {charm} to make a woodland charm"]
        combat_text.append("{} {}".format(player.name,
                                          random.choice(combat_variables)))

        if charm == "Deverberry Skin":
            for item in player.status_effects:
                if item.name == "StatBuff":
                    if item.origin == "WoodlandDeverberrySkin":
                        return {
                            "damage": self.damage,
                            "combat_text": ["This buff is already applied"]
                        }
            player.status_effects.append(WoodlandDeverberrySkin(5, player))
            player.status_effects.append(
                StatBuff(5,
                         "Strength",
                         player.stats["Strength"],
                         player,
                         origin="WoodlandDeverberrySkin"))

        if charm == "Desert Salt":
            for item in player.status_effects:
                if item.name == "WoodlandDesertSalt":
                    return {
                        "damage": self.damage,
                        "combat_text": ["This buff is already applied"]
                    }
            player.status_effects.append(WoodlandDesertSalt(5, player))

        return {"damage": self.damage, "combat_text": combat_text}
Example #5
0
def draw_menu(stdscr):
    locale.setlocale(locale.LC_ALL, "")
    k = 0
    cursor_x = 0
    cursor_y = 0
    name = ""

    curses.curs_set(0)
    curses.cbreak()
    curses.mousemask(curses.ALL_MOUSE_EVENTS)
    stdscr.keypad(1)

    game_box = stdscr.derwin(39, 99, 0, 1)
    command_box = stdscr.derwin(39, 48, 0, 101)

    last_mouse_x = 0
    last_mouse_y = 0

    direction = "right"

    state_handler = StateHandler(game_box, command_box, stdscr)
    state_handler.log_info(stdscr.getmaxyx())

    curses.start_color()

    curses.use_default_colors()
    for i in range(0, curses.COLORS - 1):
        curses.init_pair(i + 1, i, i - 1)

    curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_RED)
    curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_RED)
    curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_BLUE)
    curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_GREEN)
    curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
    curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW)
    curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_CYAN)

    #Color range 131 -> 147 reserved

    curses.init_pair(131, 232, 165)
    curses.init_pair(132, curses.COLOR_YELLOW, curses.COLOR_GREEN)
    curses.init_pair(133, curses.COLOR_RED, -1)
    curses.init_pair(134, curses.COLOR_GREEN, -1)
    curses.init_pair(135, curses.COLOR_CYAN, -1)
    curses.init_pair(136, curses.COLOR_YELLOW, -1)
    curses.init_pair(137, curses.COLOR_BLUE, -1)
    curses.init_pair(138, 130, -1)  # Enhanced Dialogue
    curses.init_pair(139, 238, 242)  #Cobblestone
    curses.init_pair(140, 237, 242)  #Fence
    curses.init_pair(141, 240, 40)  #Grass Fence
    curses.init_pair(142, 136, 40)  #Tree Bot
    curses.init_pair(143, 40, 22)  #Tree Top
    curses.init_pair(144, 220, 94)  #Beer
    curses.init_pair(145, 94, 52)  #Wooden Chair
    curses.init_pair(146, 237, 52)  #floor fence
    curses.init_pair(147, curses.COLOR_WHITE, -1)
    curses.init_pair(148, curses.COLOR_YELLOW, 238)  #Wall torch
    curses.init_pair(149, 94, -1)  #brown fg, black bg
    curses.init_pair(150, 242, -1)  #grey fg, black bg
    curses.init_pair(151, curses.COLOR_BLACK, 247)
    curses.init_pair(152, curses.COLOR_WHITE, curses.COLOR_RED)
    curses.init_pair(153, curses.COLOR_RED, 52)  #Farming patch not planted
    curses.init_pair(154, curses.COLOR_YELLOW, 52)  #Farming patch planted
    curses.init_pair(155, curses.COLOR_GREEN, 52)  #Farming patch planted
    curses.init_pair(156, curses.COLOR_YELLOW,
                     40)  #Yellow fg on grass bg (initally for AriamBush)
    curses.init_pair(157, curses.COLOR_YELLOW, 185)  #Wheat
    curses.init_pair(158, 208, 208)  # Fire?
    curses.init_pair(159, curses.COLOR_CYAN, curses.COLOR_CYAN)  #Window?
    curses.init_pair(160, 130, curses.COLOR_RED)
    curses.init_pair(161, curses.COLOR_WHITE, 238)  # Empty Bookcase
    curses.init_pair(162, curses.COLOR_WHITE, curses.COLOR_WHITE)
    curses.init_pair(163, curses.COLOR_BLACK, curses.COLOR_BLACK)

    height, width = state_handler.stdscr.getmaxyx()

    player_first_init = False

    while (k != ord('q')):
        stdscr.erase()

        game_box.border()
        command_box.border()
        if state_handler.player and state_handler.gamemap and not player_first_init:
            last_gamemap = state_handler.gamemap.name
            player_first_init = True
            #print("Player initialized")

        if state_handler.player is not False and state_handler.timer_started == False:
            state_handler.start_timer()

        if state_handler.map_screen == True:
            if state_handler.player.health <= 0:
                helper.popup(stdscr, state_handler, ["You have died"])
                state_handler.game_state = states.Intro(state_handler)
                state_handler.command_state = states.main_menu(state_handler)
                state_handler.map_screen = False
                state_handler.command_state.commands[0].active = True
                state_handler.player = False
                state_handler.first_time = True
                continue
            state_handler.player.turn += 1
            state_handler.check_overworld_status_effects()

            #if k == 9 and is_tab_enabled(state_handler):
            #    k = 1
            #    state_handler.change_map_screen()
            #    continue

            if state_handler.able_to_move == False:
                curses.halfdelay(2)
                for item in state_handler.gamemap.game_map.objects:
                    if item.type == "monster" and item.path_to_target:
                        item.color = 133
                        item.x, item.y = item.path_to_target[0]
                        item.path_to_target.pop(0)
                    if item.x == state_handler.player.x and item.y == state_handler.player.y:
                        curses.flash()
                        result = item.action()
                        if result:
                            if len([
                                    "a" for monster in
                                    state_handler.gamemap.game_map.objects
                                    if monster.type == "monster"
                                    and len(monster.path_to_target) > 0
                            ]) < 1:  #WTF
                                state_handler.able_to_move = True
                            if item.flag:
                                state_handler.player.flags.append(item.flag)
                            state_handler.gamemap.game_map.objects.remove(item)
                        else:
                            break

            if not state_handler.player:
                state_handler.able_to_move = True
                continue
            if state_handler.able_to_move == True:
                curses.cbreak()
                #curses.halfdelay(3)
                state_handler.timer.terminate()
                if k in [
                        curses.KEY_DOWN, curses.KEY_UP, curses.KEY_LEFT,
                        curses.KEY_RIGHT,
                        ord("w"),
                        ord("a"),
                        ord("s"),
                        ord("d")
                ]:
                    if state_handler.player.phaseshift:
                        state_handler.player.phaseshift -= 1

                    #state_handler.check_tall_grass()
                    name = ""

                if k == curses.KEY_DOWN or k == ord("s"):
                    #if direction == "down":
                    #    curses.flushinp()
                    direction = "down"
                    next_direction = state_handler.player.x + 1
                    next_tile = next_direction, state_handler.player.y
                    if state_handler.player.x < 37 and state_handler.check_collision(
                            next_tile):
                        state_handler.player.last_pos = state_handler.player.x, state_handler.player.y
                        state_handler.player.minion_pos.append(
                            state_handler.player.last_pos)
                        if len(state_handler.player.minion_pos
                               ) > state_handler.player.max_minions:
                            state_handler.player.minion_pos.pop(0)
                        state_handler.player.x = next_direction
                    k = 1
                elif k == curses.KEY_UP or k == ord("w"):
                    #if direction == "up":
                    #    curses.flushinp()
                    direction = "up"
                    next_direction = state_handler.player.x - 1
                    next_tile = next_direction, state_handler.player.y
                    if state_handler.player.x > 1 and state_handler.check_collision(
                            next_tile):
                        state_handler.player.last_pos = state_handler.player.x, state_handler.player.y
                        state_handler.player.minion_pos.append(
                            state_handler.player.last_pos)
                        if len(state_handler.player.minion_pos
                               ) > state_handler.player.max_minions:
                            state_handler.player.minion_pos.pop(0)
                        state_handler.player.x = next_direction
                    k = 1
                elif k == curses.KEY_LEFT or k == ord("a"):
                    #if direction == "left":
                    #    curses.flushinp()
                    direction = "left"
                    next_direction = state_handler.player.y - 1
                    next_tile = state_handler.player.x, next_direction
                    if state_handler.player.y > 1 and state_handler.check_collision(
                            next_tile):
                        state_handler.player.last_pos = state_handler.player.x, state_handler.player.y
                        state_handler.player.minion_pos.append(
                            state_handler.player.last_pos)
                        if len(state_handler.player.minion_pos
                               ) > state_handler.player.max_minions:
                            state_handler.player.minion_pos.pop(0)
                        state_handler.player.y = next_direction
                    k = 1
                elif k == curses.KEY_RIGHT or k == ord("d"):
                    #if direction == "right":
                    #    curses.flushinp()
                    direction = "right"
                    next_direction = state_handler.player.y + 1
                    next_tile = state_handler.player.x, next_direction
                    if state_handler.player.y < 96 and state_handler.check_collision(
                            next_tile):
                        state_handler.player.last_pos = state_handler.player.x, state_handler.player.y
                        state_handler.player.minion_pos.append(
                            state_handler.player.last_pos)
                        if len(state_handler.player.minion_pos
                               ) > state_handler.player.max_minions:
                            state_handler.player.minion_pos.pop(0)
                        state_handler.player.y = next_direction
                    k = 1

                elif k == ord(" "):
                    state_handler.check_action = True
                    state_handler.check_npc_action()

                if k != ord(" "):
                    #Check for when you are not on top of NPCS, so I can define actions in states.py
                    #for example over countertops at Hall of justice or shops
                    state_handler.check_action = False

            state_handler.gamemap.check_events()
            for item in state_handler.gamemap.game_map.objects:
                if item.type == "monster":
                    if state_handler.gamemap.cave:
                        break
                    if item.path_to_target or item.radar == False:
                        break
                    #check target
                    target_direction = False
                    breakable = False
                    _directions = {
                        "S": (1, 0),
                        "N": (-1, 0),
                        "W": (0, -1),
                        "E": (0, 1),
                        "SW": (1, -1),
                        "NW": (-1, -1),
                        "SE": (1, 1),
                        "NE": (-1, 1)
                    }
                    original_position = (item.x, item.y)
                    for key, v in _directions.items():
                        check = [original_position[0], original_position[1]]
                        if key in ["S", "N", "W", "E"]:
                            target_range = 5
                        else:
                            target_range = 4
                        if state_handler.player.phaseshift > 0:
                            target_range = 1
                        for i in range(target_range):
                            check[0] += v[0]
                            check[1] += v[1]
                            #if not state_handler.check_collision((check[0], check[1]), player_control=False):
                            #    breakable = True
                            #    break
                            if check[0] == state_handler.player.x and check[
                                    1] == state_handler.player.y:
                                target_direction = key
                                breakable = True
                                break
                        if breakable:
                            break

                    if breakable:
                        if not target_direction:
                            break
                        state_handler.able_to_move = False
                        check = [original_position[0], original_position[1]]
                        while check[0] != state_handler.player.x or check[
                                1] != state_handler.player.y:
                            item.path_to_target.append((check[0], check[1]))
                            check[0] += _directions[target_direction][0]
                            check[1] += _directions[target_direction][1]
                        item.path_to_target.append((check[0], check[1]))
                        curses.ungetch(curses.KEY_F0)

            for item in state_handler.gamemap.game_map.objects:
                if item.type == "monster" and state_handler.player.x == item.x and state_handler.player.y == item.y:
                    result = item.action()
                    if result:
                        if item.flag:
                            state_handler.player.flags.append(item.flag)
                        state_handler.gamemap.game_map.objects.remove(item)
                        curses.cbreak()

            #Rendering to screen
            state_handler.gamemap.draw()
            #draw_commands(state_handler.ingame_menu, state_handler.command_box)
            if last_gamemap != state_handler.gamemap.name:  #If we went to a new screen
                last_gamemap = state_handler.gamemap.name
                if state_handler.player:
                    state_handler.player.minion_pos = [
                        (state_handler.player.x, state_handler.player.y)
                    ] * state_handler.player.max_minions
            for idx, item in enumerate(state_handler.player.minions):
                stdscr.addch(state_handler.player.minion_pos[::-1][idx][0],
                             state_handler.player.minion_pos[::-1][idx][1] + 1,
                             state_handler.player.minions[idx])
            state_handler.player.draw(game_box)

            for x in range(len(state_handler.gamemap.game_map.background2)):
                for y in range(
                        len(state_handler.gamemap.game_map.background2[x])):
                    if state_handler.gamemap.game_map.background2[x][y].over:
                        if (state_handler.gamemap.game_map.background2[x][y].x,
                                state_handler.gamemap.game_map.background2[x]
                            [y].y) == (state_handler.player.x,
                                       state_handler.player.y):
                            char = "@"
                            if state_handler.player.phaseshift:
                                char = str(state_handler.player.phaseshift)
                            state_handler.gamemap.game_map.background2[x][
                                y].draw(state_handler,
                                        inverted=True,
                                        character=char)
                        else:
                            state_handler.gamemap.game_map.background2[x][
                                y].draw(state_handler)

            for item in state_handler.gamemap.game_map.objects:
                if (item.x, item.y) != (state_handler.player.x,
                                        state_handler.player.y
                                        ) and not state_handler.gamemap.fov:
                    item.draw(state_handler)

            #If adding pets or followers later, this is the "formula" for translating last pos to draw
            #stdscr.addch(state_handler.player.last_pos[0], state_handler.player.last_pos[1] + 1, "h")

            #Drawing 'player interface'
            #interface_start = 41
            #interface_end = 49
            stdscr.addch(39, 1, curses.ACS_ULCORNER, curses.color_pair(136))
            stdscr.addch(48, 1, curses.ACS_LLCORNER, curses.color_pair(136))
            stdscr.addch(39, 13, curses.ACS_URCORNER, curses.color_pair(136))
            stdscr.addch(48, 13, curses.ACS_LRCORNER, curses.color_pair(136))

            for idx, item in enumerate(art.draw_portrait_dwarf()):
                stdscr.addstr(40 + idx, 2, item)

            stdscr.addstr(39, 17, f"Name: {state_handler.player.name}")
            stdscr.addstr(
                40, 17,
                f"Type: {state_handler.player.race} {state_handler.player.vocation}"
            )
            stdscr.addstr(42, 17, f"Stats:", curses.color_pair(136))
            stdscr.addstr(
                43, 17,
                f"Strength: {state_handler.player.get_combined_stats()['Strength']}"
            )
            stdscr.addstr(
                44, 17,
                f"Agility: {state_handler.player.get_combined_stats()['Agility']}"
            )
            stdscr.addstr(
                45, 17,
                f"Intelligence: {state_handler.player.get_combined_stats()['Intelligence']}"
            )
            stdscr.addstr(
                46, 17,
                f"Charisma: {state_handler.player.get_combined_stats()['Charisma']}"
            )
            stdscr.addstr(
                47, 17,
                f"Alchemy: {state_handler.player.get_combined_stats()['Alchemy']}"
            )
            stdscr.addstr(48, 17,
                          f"Farming: {state_handler.player.stats['Farming']}")

            ppos = f"Player-Pos: X: {state_handler.player.x}  Y: {state_handler.player.y}"
            stdscr.addstr(45, int((150 - len(ppos)) / 2), ppos)

            turns = f"Turn: {state_handler.player.turn}"
            stdscr.addstr(46, int((150 - len(turns)) / 2), turns)

            info = f"Phaseshift = {state_handler.player.phaseshift}"
            stdscr.addstr(47, int((150 - len(info)) / 2), info)

            info_2 = f"Nr. of Status_effects = {len(state_handler.player.status_effects)}"
            stdscr.addstr(48, int((150 - len(info_2)) / 2), info_2)

            if state_handler.player.mindvision:
                state_handler.player.mindvision -= 1
                for item in state_handler.gamemap.game_map.objects:
                    item.draw(state_handler)

            for item in state_handler.player.flora:
                if item[1] + item[2] <= state_handler.timer.tid:
                    state_handler.player.flora.pop(
                        state_handler.player.flora.index(item))

            if last_mouse_x != 0:
                state_handler.game_box.addstr(last_mouse_y, last_mouse_x - 1,
                                              name)

        else:

            #if k == 9 and is_tab_enabled(state_handler):
            #    k = 1
            #    state_handler.change_map_screen()
            #    state_handler.command_state = state_handler.gamemap.menu_commands(state_handler)
            #    state_handler.command_state.commands[0].active = True
            #    continue
            if k == curses.KEY_DOWN:
                get_next(state_handler.command_state, command_box)
            elif k == curses.KEY_UP:
                get_prev(state_handler.command_state, command_box)
            elif k == curses.KEY_RIGHT:
                pass
            elif k == curses.KEY_LEFT:
                cursor_x = cursor_x - 1
            elif k == ord(" "):
                state_handler.game_state.execute()
                for item in state_handler.command_state.commands:
                    if item.active:
                        next_command_state = item.execute_command()
                        if next_command_state == False:
                            pass
                        else:
                            state_handler.command_state = next_command_state(
                                state_handler)
                            if hasattr(state_handler.command_state, "game"):
                                state_handler.command_state.commands[
                                    0].active = True
                            else:
                                state_handler.command_state.commands[
                                    0].active = True
                        next_game_state = item.execute_game()
                        if next_game_state == False:
                            pass
                        elif hasattr(state_handler.command_state, "game"):
                            state_handler.gamemap = state_handler.player.location(
                                state_handler)
                            state_handler.game_state = state_handler.gamemap.menu(
                                state_handler)
                            state_handler.ingame_menu = state_handler.gamemap.ingame_menu(
                                state_handler)
                        else:
                            if state_handler.player != False:
                                try:
                                    state_handler.gamemap = state_handler.player.location(
                                        state_handler)
                                except:
                                    state_handler.gamemap = state_handler.player.location(
                                        state_handler,
                                        state_handler.player.last_target)
                                state_handler.ingame_menu = state_handler.gamemap.ingame_menu(
                                    state_handler)
                                state_handler.game_state = state_handler.gamemap.menu(
                                    state_handler)
                                curses.ungetch(curses.KEY_F0)
                            else:
                                state_handler.game_state = next_game_state(
                                    state_handler)

            state_handler.game_state.draw()
            draw_commands(state_handler.command_state,
                          state_handler.command_box)

        cursor_x = max(0, cursor_x)
        cursor_x = min(width - 1, cursor_x)

        cursor_y = max(0, cursor_y)
        cursor_y = min(height - 1, cursor_y)

        if state_handler.player:
            cursor_y = state_handler.player.y
            cursor_x = state_handler.player.x

        #statusbarstr = "Mouse: x: {} , y: {} | Pos: {}, {} | {}x{} | Action: {}".format(last_mouse_x, last_mouse_y,cursor_x, cursor_y, width, height, state_handler.action)

        #stdscr.attron(curses.color_pair(3))
        #stdscr.addstr(height, 0, statusbarstr)
        #stdscr.attroff(curses.color_pair(3))
        stdscr.refresh()

        k = stdscr.getch()
        #curses.flushinp()

        if k == curses.KEY_MOUSE:
            unused_1, last_mouse_x, last_mouse_y, unused_2, unused_3 = curses.getmouse(
            )
            if last_mouse_x <= 97 and last_mouse_y <= 37 and state_handler.map_screen == True:
                for item in state_handler.gamemap.game_map.objects:
                    if item.y == (last_mouse_x - 1) and item.x == last_mouse_y:
                        name = item.name
                        break
                    else:
                        name = state_handler.gamemap.game_map.background2[
                            last_mouse_y - 1][last_mouse_x - 2].name
            else:
                last_mouse_y = 0
                last_mouse_x = 0
            k = 1

        if k == ord("e") and state_handler.player != False:
            inventory.view_equipment(state_handler.stdscr, state_handler)

        if k == ord("i") and state_handler.player != False:
            inventory.view_inventory_2(state_handler)

        if k == ord("p") and state_handler.player != False:
            inventory.view_spellbook(state_handler.stdscr, state_handler)

        if k == ord("l"):
            save_answer = helper.two_options(
                state_handler.stdscr, state_handler,
                ["Do you wish to [Save] the game?"], ["Yes", "No"])
            if save_answer:
                state_handler.save_player()

        if k == ord("o") and state_handler.player != False:
            if len(state_handler.player.minions
                   ) < state_handler.player.max_minions:
                state_handler.player.minions.append("W")

        if k == ord("c") and state_handler.player != False:
            battlemode = battle.Battle(state_handler,
                                       monster.CaveTroll(state_handler),
                                       battlefields.Battlefield("Dungeon"))
            battlemode.play()

        if k == ord("k") and state_handler.player != False:
            for var in dir(items):
                if var.startswith("__"):
                    continue
                elif var == "Item":
                    continue
                elif var == "abilities":
                    continue
                elif var == "random":
                    continue
                elif var == "art":
                    continue
                elif var == "helper":
                    continue
                elif var == "Sets":
                    continue
                else:
                    item_to_add = getattr(items, var)()
                    state_handler.player.inventory.append(item_to_add)

        if k == ord("1"):
            if direction == "up":
                state_handler.player.x -= 4
                if state_handler.player.x < 2:
                    state_handler.player.x = 2
            elif direction == "down":
                state_handler.player.x += 4
                if state_handler.player.x > 36:
                    state_handler.player.x = 36
            elif direction == "left":
                state_handler.player.y -= 4
                if state_handler.player.y < 2:
                    state_handler.player.y = 2
            elif direction == "right":
                state_handler.player.y += 4
                if state_handler.player.y > 95:
                    state_handler.player.y = 95

        if k == ord("2"):
            state_handler.player.hotkeys["2"].execute(state_handler.player)

        if k == ord("3"):
            actions.SpeakTerminal(state_handler.stdscr,
                                  state_handler).execute()

        if k == ord("4"):
            state_handler.player.ascii = not state_handler.player.ascii

        if k == ord("5"):
            #state_handler.player.status_effects.append(abilities.StatBuff(5,"Intelligence", 13, state_handler.player))
            helper.two_options(state_handler.stdscr, state_handler,
                               ["Teleport Home?"], ["yes", "no"])

        if k == ord("6"):
            #state_handler.timer.tid += 1209600
            #anim = animation.boat_animation()
            #animation.play(anim, state_handler)
            helper.popup(state_handler.stdscr, state_handler,
                         ["You arrive at [Port Avery, Blackcliff]"])
    state_handler.timer.terminate()
Example #6
0
    def play(self):
        """
            Main combat loop interface

            1. Add encounter start info to the update_log so it doesn't appear empty at start
            2. Loop begins
            3. Check if player dead.
            4. Check if opponent dead.
                4.1. If so, handle loot, and loot interface

            5. Render everything
            6. Player chooses command and command gets executed
            7. Opponent response
            8. Repeat until something dies.

            :return bool (if succesful or not)
        """
        #Give opponent knowledge of battlefield
        self.opponent.battlefield = self.battlefield
        
        self.update_log(["opponent", "{} encounters {} {}".format(self.player.name, self.opponent.before_name, self.opponent.readable_name)])
        opener = self.opponent.opener()
        if opener:
            for item in opener["combat_text"]:
                self.update_log(["opponent", item])
        self.update_log(["neutral", ""])
        k = -1
        selected_command = 0
        offset = 40

        opponent_offset = 15
        opponent_offset_y = 100
        opponent_art_offset = 2

        while k != ord("q"):
            self.screen.erase()
            if self.player.health <= 0:
                helper.popup(self.screen, self.state, ["You have died"])
                self.state.game_state = states.Intro(self.state)
                self.state.command_state = states.main_menu(self.state)
                self.state.map_screen = False
                self.state.command_state.commands[0].active = True
                self.state.player = False
                self.state.first_time = True
                break
            if self.opponent.health <= 0 and not self.opponent_killed:
                self.update_log(["opponent", "{} was killed.".format(self.opponent.readable_name)])
                self.update_log(["neutral", ""])
                random_loot = self.opponent.generate_loot()
                if random_loot:
                    self.loot_list = [helper.get_item(item)() for item in random_loot]
                else:
                    self.loot_list = []

                if self.loot_list:
                    for item in self.loot_list:
                        self.update_log(["loot", "{} dropped item: {}".format(self.opponent.readable_name, item.readable_name)])
                else:
                    self.update_log(["loot", "{} dropped no loot.".format(self.opponent.readable_name)])

                self.commands = [
                    "Loot and Exit",
                    "Exit"
                ]
                selected_command = 0
                self.opponent_killed = True
                # return True
            elif not self.opponent_killed:
                if not self.player.in_control:
                    self.commands = [
                        "You are not in control"
                    ]
                    selected_command = 0
                else:
                    self.commands = [
                        "Attack",
                        "Block",
                        "Spell",
                        "Item",
                    ]
                    

            combat_log_start = 0
            self.used_turns = []
            for item in self.combat_log:
                if item[2] not in self.used_turns:
                    self.screen.addstr(combat_log_start, 0, "Turn {}:".format(item[2]))
                    self.used_turns.append(item[2])
                self.screen.attron(curses.color_pair(self.combat_log_color[item[0]]))
                if item[0] == "opponent":
                    self.screen.addstr(combat_log_start, 14, item[1])
                else:
                    self.screen.addstr(combat_log_start, 10, item[1])
                self.screen.attroff(curses.color_pair(self.combat_log_color[item[0]]))

                combat_log_start += 1

            percent_health = round(self.player.health / self.player.max_health, 2) #hur många %
            percent_lost = 1 - percent_health # hur mycket som inte är HP
            self.screen.addstr(37, 0, "HP:") #Base
            self.screen.attron(curses.color_pair(5)) # På med grönt
            self.screen.addstr(37, 5, "{}".format(" " * int(100 * percent_health))) # hela rad = 100, så typ 0.6 * 100 = 60 rutor
            self.screen.attroff(curses.color_pair(5)) #Av med grönt
            self.screen.addstr(37, 5 + int(100 * percent_health), "{}".format(" " * int(100 * percent_lost)), curses.color_pair(2)) # Adda på percent_lost efter första addstr

            for i in range(len(self.commands)):
                if i == selected_command:
                    self.screen.attron(curses.color_pair(5))
                    self.screen.addstr(offset + i, 10, self.commands[i])
                    self.screen.attroff(curses.color_pair(5))
                else:
                    self.screen.addstr(offset + i, 10, self.commands[i])

            self.screen.attron(curses.color_pair(133))
            for idx, text in enumerate(self.opponent.art):
                self.screen.addstr(opponent_art_offset + idx, opponent_offset_y, text)
            self.screen.attroff(curses.color_pair(133))

            self.screen.addstr(opponent_offset, opponent_offset_y, "Opponent: {}".format(self.opponent.readable_name))
            for i, v in enumerate(self.opponent.description):
                self.screen.addstr(opponent_offset + i + 1, opponent_offset_y, v)
            
            # Todo REWORK
            #self.screen.addstr(opponent_offset + 5, opponent_offset_y, "HP: {} / {}".format(self.opponent.health, self.opponent.max_health))
            percentage = self.opponent.health / self.opponent.max_health
            if percentage == 1:
                keyword = "Great Health"
            elif percentage >= 0.7:
                keyword = "Fine"
            elif percentage >= 0.3:
                keyword = "Damaged"
            elif percentage >= 0.1:
                keyword = "Badly injured"
            else:
                keyword = "Barely hanging on"
            if self.opponent_killed:
                self.screen.addstr(opponent_offset + 5, opponent_offset_y, f"Shape: Dead")
            else:
                self.screen.addstr(opponent_offset + 5, opponent_offset_y, f"Shape: {keyword}")

            # TODO END

            self.screen.addstr(opponent_offset + 7, opponent_offset_y, "Debuffs:")
            # allocate 6 for status effects
            for i, status in enumerate(self.opponent.status_effects):
                self.screen.attron(curses.color_pair(status.color))
                self.screen.addstr(opponent_offset + 8 + i, 120, "{} ({})".format(status.type, status.turns_left))
                self.screen.attroff(curses.color_pair(status.color))

            for i, limb in enumerate(self.opponent.limbs):

                limb_name = limb.name.capitalize()
                if limb.vital:
                    limb_name = f"*{limb_name}"
                else:
                    limb_name = f" {limb_name}"

                limb_info = f"{limb_name}: {limb.health}/{limb.max_health}"
                if limb.held_item:
                    limb_info = f"{limb_info} : {limb.held_item.readable_name}"

                if limb.alive:
                    self.screen.addstr(opponent_offset + 14 + i, opponent_offset_y, limb_info)
                else:
                    self.screen.addstr(opponent_offset + 14 + i, opponent_offset_y, limb_info, curses.color_pair(133))

            k = self.screen.getch()

            if k == curses.KEY_UP:
                if selected_command != 0:
                    selected_command -= 1
                curses.ungetch(curses.KEY_F0)

            elif k == curses.KEY_DOWN:
                if selected_command != len(self.commands) - 1:
                    selected_command += 1
                curses.ungetch(curses.KEY_F0)

            elif k == ord(" "):
                self.turn += 1
                if self.commands[selected_command] == "You are not in control":
                    self.player_attack()
                if self.commands[selected_command] == "Attack":
                    self.player_attack()

                if self.commands[selected_command] == "Block":
                    self.player.health -= 100

                if self.commands[selected_command] == "Run":
                    self.update_log(["neutral", "Attempting to run away."])
                    run_successful = self.player_run()
                    if run_successful:
                        self.remove_temp_debuffs()
                        return False

                if self.commands[selected_command] == "Spell":
                    spell = self.select_spell()
                    if spell != "False":
                        res = self.player_spell(spell)
                        if not res:
                            continue
                    else:
                        continue
                if self.commands[selected_command] == "Loot and Exit":
                    self.loot(random_loot)
                    self.remove_temp_debuffs()
                    return True

                if self.commands[selected_command] == "Exit":
                    curses.ungetch(curses.KEY_F0)
                    self.remove_temp_debuffs()
                    return True

                if not self.opponent_killed:
                    self.check_effects()
                    self.check_player_effects()
                    self.check_opponent()
                    self.update_log(["neutral", ""])
                curses.ungetch(curses.KEY_F0)
        self.remove_temp_debuffs()
Example #7
0
    def select_spell(self):
        """
            Select spell from main combat menu

            :return Spell (if spell selected)
            :return False (if no spell selected)
        """

        k = -1
        start = 10
        offset = 15

        selected_item = self.selected_spell
        height, width = self.screen.getmaxyx()

        if self.player.spells:
            spell_list = [spell for spell in self.player.spells if spell is not False]
        else:
            spell_list = []

        while k != ord("q"):
            self.screen.erase()

            start = 10
            spell_text = "Select a spell to cast"
            self.screen.addstr(8, int((width / 2) - (len(spell_text) / 2)), spell_text)

            if spell_list:
                for i in range(len(spell_list)):
                    if selected_item == i:
                        self.screen.attron(curses.color_pair(5))
                    self.screen.addstr(start, offset, spell_list[i].readable_name)
                    if selected_item == i:
                        self.screen.attroff(curses.color_pair(5))
                    start += 1
            else:
                helper.popup(self.screen, self.state, ["No spells available"])
                return "False"

            if k == curses.KEY_DOWN:
                if len(spell_list) != 0:
                    selected_item += 1
                    if selected_item >= len(spell_list) - 1:
                        selected_item = len(spell_list) - 1
                curses.ungetch(curses.KEY_F0)

            if k == curses.KEY_UP:
                if len(spell_list) != 0:
                    selected_item -= 1
                    if selected_item <= 0:
                        selected_item = 0
                curses.ungetch(curses.KEY_F0)

            if k == ord(" "):
                if len(spell_list) != 0:
                    self.selected_spell = selected_item
                    return self.player.spells.index(spell_list[selected_item])
                curses.ungetch(curses.KEY_F0)

            k = self.screen.getch()
        return "False"
Example #8
0
    def execute(self, player, opponent, state):
        if len([x for x in player.inventory if x.subtype == "seed"]):
            seed = helper.pick_seed(state)
        else:
            helper.popup(state.stdscr, state, ["No seeds available"])
            return {"damage": "back"}
        combat_text = []
        combat_variables = [
            f"{player.name} plants a seed in {opponent.readable_name}",
            f"{player.name} infests {opponent.name} with a {seed}",
        ]
        combat_text.append(random.choice(combat_variables))
        if seed == "Barbura Seed":
            combat_variables_failure = [
                f"{opponent.readable_name} is already infested."
            ]
            list_of_effects = [
                effect.type for effect in opponent.status_effects
            ]
            if "Infested" in list_of_effects:
                combat_text.append(random.choice(combat_variables_failure))

                return {"damage": 0, "combat_text": combat_text}
            else:
                damage_done = random.randint(int(0.75 * self.damage),
                                             self.damage)
                combat_text.append("It ruptures immediately")
                for item in player.inventory:
                    if item.readable_name == seed:
                        player.inventory.pop(player.inventory.index(item))
                        break

        if seed == "Ariam Seed":
            damage = player.stats["Intelligence"] * 2
            combat_variables_failure = [
                f"{opponent.readable_name} is already infested."
            ]
            list_of_effects = [
                effect.type for effect in opponent.status_effects
            ]

            if "Infested" in list_of_effects:
                combat_text.append(random.choice(combat_variables_failure))

                return {"damage": 0, "combat_text": combat_text}

            else:
                opponent.status_effects.append(
                    InfestAriamSeed(5, damage, opponent))
                for item in player.inventory:
                    if item.readable_name == seed:
                        player.inventory.pop(player.inventory.index(item))
                        break

                return {"damage": 0, "combat_text": combat_text}

        if seed == "Dever Seed":
            damage = int(player.stats["Intelligence"] / 2)
            combat_variables_failure = [
                f"{opponent.readable_name} is already infested."
            ]
            list_of_effects = [
                effect.type for effect in opponent.status_effects
            ]
            self.no_direct_damage = True

            if "Infested" in list_of_effects:
                combat_text.append(random.choice(combat_variables_failure))

                return {"damage": 0, "combat_text": combat_text}

            else:
                opponent.status_effects.append(
                    InfestDeverSeed(5, damage, opponent))
                for item in player.inventory:
                    if item.readable_name == seed:
                        player.inventory.pop(player.inventory.index(item))
                        break

                return {"damage": 0, "combat_text": combat_text}

        if seed == "Firebloom Seed":
            damage = int(player.stats["Intelligence"] / 2)
            combat_variables_failure = [
                f"{opponent.readable_name} is already infested."
            ]
            list_of_effects = [
                effect.type for effect in opponent.status_effects
            ]
            self.no_direct_damage = True

            if "Infested" in list_of_effects:
                combat_text.append(random.choice(combat_variables_failure))

                return {"damage": 0, "combat_text": combat_text}

            else:
                opponent.status_effects.append(
                    InfestFirebloomSeed(5, damage, opponent))
                for item in player.inventory:
                    if item.readable_name == seed:
                        player.inventory.pop(player.inventory.index(item))
                        break

                return {"damage": 0, "combat_text": combat_text}

        return {"damage": 0, "combat_text": combat_text}
Example #9
0
def farming(state, identity):
    screen = state.stdscr
    player = state.player
    height, width = screen.getmaxyx()
    curses.halfdelay(3)
    k = -1

    offset_x = 20
    offset_y = int(width / 2)

    selected_item = 0
    planted = False
    ready = False
    no_seeds = False

    for item in player.active_farms:
        if item[0] == identity:
            planted = True

    while k != ord("q"):
        screen.erase()
        if planted:
            button_text = "Harvest"
        else:
            button_text = "Select seed to plant"

        if not planted:
            if no_seeds:
                screen.addstr(offset_x,
                              offset_y - int(len("You have no seeds.") / 2),
                              "You have no seeds.")
            else:
                screen.addstr(
                    offset_x, offset_y - int(
                        len("There is no seed planted in this farming patch.")
                        / 2),
                    "There is no seed planted in this farming patch.")
            screen.addstr(offset_x + 10, offset_y - int(len(button_text) / 2),
                          button_text, curses.color_pair(5))

        if planted:
            for item in player.active_farms:
                if item[0] == identity:
                    plant_name = item[1]
                    timer = item[2]
                    result = item[3]
                    harvest_time = item[4]
            screen.addstr(offset_x, offset_y - int(len(plant_name) / 2),
                          plant_name)

            date_planted = time.gmtime(timer)
            date_text = f"Planted at: {date_planted.tm_year - 1200}/{date_planted.tm_mon:02}/{date_planted.tm_mday:02}  {date_planted.tm_hour:02}:{date_planted.tm_min:02}"
            screen.addstr(offset_x + 2, offset_y - int(len(date_text) / 2),
                          date_text)

            date_harvested = time.gmtime(timer + harvest_time)
            harvest_text = f"Ready for harvest at: {date_harvested.tm_year - 1200}/{date_harvested.tm_mon:02}/{date_harvested.tm_mday:02}  {date_harvested.tm_hour:02}:{date_harvested.tm_min:02}"
            screen.addstr(offset_x + 3, offset_y - int(len(harvest_text) / 2),
                          harvest_text)

            if state.timer.tid >= timer + harvest_time:
                screen.addstr(offset_x + 10,
                              offset_y - int(len(button_text) / 2),
                              button_text, curses.color_pair(5))
                ready = True
            else:
                screen.addstr(offset_x + 10,
                              offset_y - int(len(button_text) / 2),
                              button_text, curses.color_pair(152))
                ready = False

        k = screen.getch()

        if k == ord(" "):
            if planted:
                if ready:
                    text = [
                        "You harvest the plant and gain",
                        "",
                        "",
                    ]
                    for item in result:
                        player.inventory.append(helper.get_item(item)())
                        text.append(item)
                    helper.popup(screen, state, text)
                    for item in player.active_farms:
                        if item[0] == identity:
                            player.active_farms.pop(
                                player.active_farms.index(item))
                    planted = False
                else:
                    answer = helper.yes_no(screen, state, [
                        "The plant is not done yet.", "",
                        "Harvesting this plant will kill it.", "",
                        "Are you sure?"
                    ])
                    if answer:
                        for item in player.active_farms:
                            if item[0] == identity:
                                player.active_farms.pop(
                                    player.active_farms.index(item))
                        planted = False
            else:
                seed_to_plant = select_ingredient(state)
                if seed_to_plant == "pressed_q":
                    pass
                elif not seed_to_plant:
                    no_seeds = True
                else:
                    player.active_farms.append([
                        identity, seed_to_plant.readable_name, state.timer.tid,
                        seed_to_plant.result, seed_to_plant.harvest_time
                    ])
                    planted = True
                    return