Beispiel #1
0
def add_choice(prompt_id, index, choice):
    with session_scope() as Session:
        prompt = Session.query(Prompt).get(prompt_id)
        if 0 <= index <= prompt.max_index:
            prompt.expressions[index].choices.append(PChoice(choice))
        else:
            raise PromptIndexError(index, prompt.max_index)
Beispiel #2
0
def remove_item(adventurer_uid, item_name, count):
    with session_scope() as Session:
        adventurer = Session.query(Adventurer).get(adventurer_uid)
        inventory = adventurer.inventory
        match = list(filter(lambda i: i.name == item_name, inventory))
        if match:
            match[0].count -= count
            if match[0].count <= 0:
                inventory.remove(match[0])
Beispiel #3
0
def give_item(adventurer_uid, item_name, description, count, attributes=[]):
    item = Item(item_name, description, count, attributes)
    with session_scope() as Session:
        adventurer = Session.query(Adventurer).get(adventurer_uid)
        inventory = adventurer.inventory
        match = list(filter(lambda i: i.name == item.name, inventory))
        if match:
            match[0].count += item.count
        else:
            adventurer.inventory.append(item)
Beispiel #4
0
def add_location(place):
    with session_scope() as Session:
        Session.add(Location(place))
Beispiel #5
0
def solve_objective(objective_id):
    with session_scope() as Session:
        objective = Session.query(Objective).get(objective_id)
        objective.is_solved = True
Beispiel #6
0
def get_current_objectives():
    with session_scope() as Session:
        objective = Session.query(Objective).filter_by(is_solved=False).all()
    return objective
Beispiel #7
0
def get_objective_by_id(objective_id):
    with session_scope() as Session:
        objective = Session.query(Objective).get(objective_id)
    return objective
Beispiel #8
0
def add_objective(name, description):
    with session_scope() as Session:
        Session.add(Objective(name, description))
Beispiel #9
0
def get_all_prompts():
    with session_scope() as Session:
        prompts = Session.query(Prompt).all()
    return prompts
Beispiel #10
0
def get_adventurer(uid):
    with session_scope() as Session:
        adventurer = Session.query(Adventurer).get(uid)
    return adventurer
Beispiel #11
0
def add_adventurer(uid, name):
    with session_scope() as Session:
        Session.add(Adventurer(uid, name))
Beispiel #12
0
def get_pending_prompts():
    with session_scope() as Session:
        prompts = Session.query(Prompt).filter_by(approved=False).all()
    return prompts
Beispiel #13
0
def get_accepted_prompts():
    with session_scope() as Session:
        prompts = Session.query(Prompt).filter_by(approved=True).all()
    return prompts
Beispiel #14
0
def get_current_location():
    with session_scope() as Session:
        location = Session.query(Location).order_by(
            Location.location_id.desc()).first()
    return location
Beispiel #15
0
def get_inventory(adventurer_uid):
    with session_scope() as Session:
        adventurer = Session.query(Adventurer).get(adventurer_uid)
        inventory = adventurer.inventory
    return inventory
Beispiel #16
0
def add_prompt(max_index, prompt):
    with session_scope() as Session:
        Session.add(Prompt(max_index, prompt))
Beispiel #17
0
def get_prompt(prompt_id):
    with session_scope() as Session:
        prompt = Session.query(Prompt).get(prompt_id)
    return prompt