コード例 #1
0
async def load_active_quests(p):
    p.active_quests = await Quest.load(tasks=QuestTask,
                                       items=QuestAwardItem,
                                       furniture=QuestAwardFurniture,
                                       pet=QuestAwardPuffleItem,
                                       complete=PenguinQuestTask.on((PenguinQuestTask.penguin_id == p.data.id) &
                                                                    (PenguinQuestTask.task_id == QuestTask.id) &
                                                                    (PenguinQuestTask.complete == False))).gino.all()
コード例 #2
0
async def init_all_quests(p):
    query = Quest.load(tasks=QuestTask,
                       complete=PenguinQuestTask.on((PenguinQuestTask.penguin_id == p.data.id) &
                                                    (QuestTask.id == PenguinQuestTask.task_id))).gino

    async with db.transaction():
        async for quest in query.iterate():
            for task in quest.tasks:
                if task.id not in quest.in_progress.union(quest.complete):
                    await PenguinQuestTask.create(task_id=task.id, penguin_id=p.data.id)

    await load_active_quests(p)
コード例 #3
0
async def get_player_quest_status(p):
    query = Quest.load(tasks=QuestTask,
                       items=QuestAwardItem,
                       furniture=QuestAwardFurniture,
                       pet=QuestAwardPuffleItem,
                       complete=PenguinQuestTask.on(
                           (PenguinQuestTask.penguin_id == p.id)
                           & (QuestTask.id == PenguinQuestTask.task_id))).gino

    def has_award(quest):
        for award in quest.items:
            if award.item_id not in p.inventory:
                return False
        for award in quest.furniture:
            if award.furniture_id not in p.furniture:
                return False
        for award in quest.pet:
            if award.puffle_item_id not in p.puffle_items:
                return False
        return True

    def encode_quest(quest):
        tasks_complete = [task.id in quest.complete for task in quest.tasks]
        quest_status = 'prize claimed' if has_award(quest) else 'complete' if all(tasks_complete) else 'available' \
            if quest.in_progress else 'not available'
        return {
            'id': quest.id,
            'status': quest_status,
            'tasks': tasks_complete
        }

    async with db.transaction():
        player_quest_status = {
            'quests': [encode_quest(quest) async for quest in query.iterate()]
        }

    return ujson.dumps(player_quest_status)