Beispiel #1
0
 def put(self, todo_id):
     item = get_item(todo_id)
     if not item:
         abort_if_todo_doesnt_exist(todo_id)
     args = parser.parse_args()
     status = args.get('completed')
     if status and update_status(todo_id, status):
         item = get_item(todo_id)
         return item
     return {'Fail': 'No status Parse. Please, use one of {}'}
Beispiel #2
0
def get_item(id):   
   # Get items from the helper
   item = helper.get_item(id)
   
   #Return 404 if item not found
   if item is None:
      response = Response("{'error': 'Item Not Found - "  + str(id) + "'}", status=404 , mimetype='application/json')
      return response

   response = Response(json.dumps(item), status=200, mimetype='application/json')
   return response
Beispiel #3
0
def get_item():
    item_name = request.args.get('name')
    status = helper.get_item(item_name)

    if status is None:
        response = Response("{'error'}: 'Item not found - %s'}" % item_name, status=400, mimetype='application.json')
        return response

    res_data = { 'status': status}

    response = Response(json.dumps(res_data), status=200, mimetype='application/json')
    return response
Beispiel #4
0
def get_item():
    item_name = request.args.get('name')
    status = helper.get_item(item_name)

    if status is None:
        response = Response(f"{{'error': 'Item Not Found - {item_name}'}}",
                            status=404,
                            mimetype='application/json')
        return response

    # Return status
    res_data = {'status': status}

    response = Response(json.dumps(res_data),
                        status=200,
                        mimetype='application/json')
    return response
Beispiel #5
0
def get_item():
    item_title = request.args.get('title')

    item = helper.get_item(item_title)

    # Return 404 if item not found
    if item is None:
        response = Response("{'error': 'Item Not Found - %s'}" % item_title,
                            status=404,
                            mimetype='application/json')
        return response

    res_data = item

    response = Response(json.dumps(res_data),
                        status=200,
                        mimetype='application/json')
    return response
Beispiel #6
0
def get_item():

    #get parameter from URL
    item_name = request.args.get('name')

    #get items from the helper
    status = helper.get_item(item_name)

    # Return 404 if no item found
    if status is None:
        response = Response("{'error': 'Item Not Found - %s'}" % item_name, status=404, mimetype='application/json')
        return Response

    res_data = {
        'status': status
    }

    response = Response(json.dumps(res_data), status=200, mimetype='application/json')
    return response
Beispiel #7
0
def get_item():
    # GET parameter from the url
    item_name = request.args.get('name')

    # Get items from the helper
    status = helper.get_item(item_name)

    #Return 4040 if item not found.
    if status is None:
        response = Response("{'error': 'Items Not found - %s'}" % item_name,
                            status=404,
                            mimetype='application/json')
        return response

    # Return status
    res_data = {'status': status}

    response = Response(json.dumps(res_data),
                        status=200,
                        mimetype='application/json')
    return response
Beispiel #8
0
def get_item():
    # Get parameter from the URL
    itemid = request.args.get('itemid')

    # Get items from the helper
    status = helper.get_item(itemid)

    # Return 404 if item not found
    if status is None:
        respuesta = {"error": "No se encontró el item " + str(itemid) + "."}
        response = Response(json.dumps(respuesta),
                            status=404,
                            mimetype='application/json')
        return response

    # Return status
    """res_data = {
        'status': status
    }"""

    response = Response(json.dumps(status),
                        status=200,
                        mimetype='application/json')
    return response
Beispiel #9
0
def get_item():
    # Get parameter from the URL
    item_name = request.args.get("name")

    # Get items from the helper
    status = helper.get_item(item_name)

    # Return 404 if item not found
    if status is None:
        response = Response(
            "{'error': 'Item Not Found - %s'}" % item_name,
            status=404,
            mimetype="application/json",
        )
        return response

    # Return status
    print("why")
    res_data = {"status": status}

    response = Response(json.dumps(res_data),
                        status=200,
                        mimetype="application/json")
    return response
Beispiel #10
0
    def load_player(self, quicksave=False):
        if not quicksave:
            with open("save.json", "r") as f:
                load_dict = json.load(f)
        else:
            with open("quicksave.json", "r") as f:
                load_dict = json.load(f)

        self.player = player.Player(load_dict)
        for item in load_dict["inventory"]:
            #self.player.inventory.append(items.item_dict[item["name"]]())
            self.player.inventory.append(helper.get_item(item)())

        for k, v in load_dict["equipment"].items():
            if v != False:
                #self.player.equipment[k] = items.item_dict[v["name"]]()
                self.player.equipment[k] = helper.get_item(v)()

        temp_spell_list = []
        for _, item in enumerate(load_dict["spells"]):
            if item != False:
                temp_spell_list.append(helper.get_spell(item)())
            else:
                temp_spell_list.append(False)
        self.player.spells = temp_spell_list

        temp_spellbook_list = []
        for item in load_dict["spellbook"]:
            temp_spellbook_list.append(helper.get_spell(item)())
        self.player.spellbook = temp_spellbook_list

        for k, v in load_dict["hotkeys"].items():
            if v != False:
                self.player.hotkeys[k] = helper.get_spell(v)()

        for item in load_dict["recipes"]:
            #self.player.inventory.append(items.item_dict[item["name"]]())
            self.player.recipes.append(helper.get_recipe(item)())

        for item in load_dict["active_farms"]:
            self.player.active_farms.append(item)

        for item in load_dict["flora"]:
            self.player.flora.append(item)

        for item in load_dict["status_effects"]:
            self.player.status_effects.append(
                helper.get_status_effects(item[0])(item[1], item[2], item[3]))

        self.player.time = load_dict["time"]
        self.player.seed = load_dict["seed"]
        self.player.last_target = load_dict["last_target"]
        self.player.turn = load_dict["turn"]
        self.player.ascii = load_dict["ascii"]

        # If the player saves in a RandomCave
        # We need to update player.last_target to get the exits of the cave

        if self.player.location.__name__ == "RandomCave":
            if len(self.player.last_target) > 1:
                second_target = [
                    self.get_event(x) for x in self.player.last_target[1:]
                ]
                full_target = [
                    self.get_event(self.player.last_target[0]), second_target
                ]
            else:
                full_target = [self.get_event(self.player.last_target[0])]

            self.player.last_target = full_target

        self.player._populate_gear_stats()
        self.player.state = self
Beispiel #11
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()
Beispiel #12
0
def search(request, id):
    data = helper.get_item(request, id)
    return dump_and_render_json(request,data)
Beispiel #13
0
 def delete(self, todo_id):
     item = get_item(todo_id)
     if not item:
         abort_if_todo_doesnt_exist(todo_id)
     delete_item(todo_id)
     return get_all_items()
Beispiel #14
0
 def get(self, todo_id):
     item = get_item(todo_id)
     if not item:
         abort_if_todo_doesnt_exist(todo_id)
     return item
Beispiel #15
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
Beispiel #16
0
def search(request, id):
    data = helper.get_item(request, id)
    return dump_and_render_json(request, data)