Ejemplo n.º 1
0
def nonlinear_coordination(request, quest):
    player = request.user
    if request.method == 'POST':
        mission = get_object_or_404(Mission, pk=request.POST['mission_id'])
        if quest.started and not quest.is_game_over and not mission.is_completed(player):
            form = KeyForm(request.POST, quest=quest)
            if form.is_valid():
                key = form.cleaned_data["key"]
                right_key = mission.key
                is_right = len(right_key) > 0 and right_key == key
                keylog = Keylog(key=key, fix_time=timezone.now(), player=player,
                                mission=mission, is_right=is_right)
                if is_right:
                    keylog.points = mission.points
                keylog.save()
        if mission.order_number > 1:
            url = '{0}#m{1}'.format(resolve_url('coordination:quest_coordination', quest_id=quest.id),
                                    mission.order_number - 1)
        else:
            url = resolve_url('coordination:quest_coordination', quest_id=quest.id)
        return redirect(url)
    else:
        rest_quest = None
        missions = None
        mission_start = None
        mission_finish = None
        display_hints = None
        rest_hints = None
        form = None
        if quest.not_started:
            mission_start = quest.start_mission()
        else:
            if quest.started and not quest.is_game_over:
                rest_quest = get_timedelta(quest.game_over)
            form = KeyForm(quest=quest)
            count = 0
            missions = quest.missions().filter(order_number__gt=0, is_finish=False)
            for mission in missions:
                mission.wrong_keys = Keylog.wrong_keylogs_format(player, mission)
                is_completed = mission.is_completed(request.user)
                mission.is_completed = is_completed
                if not is_completed:
                    count += 1
            if missions and count == 0 or quest.is_game_over or quest.ended:
                mission_finish = quest.finish_mission()
            display_hints, rest_hints = Mission.hints_in_nl(quest, missions)
        points = Keylog.total_points(quest, player)
        messages = quest.messages().filter(is_show=True)
        context = {'quest': quest, 'messages': messages, 'missions': missions, 'mission_finish': mission_finish,
                   'mission_start': mission_start, 'rest_quest': rest_quest, 'points': points, 'form': form,
                   'display_hints': display_hints, 'rest_hints': rest_hints}
        return render(request, 'coordination/quests/coordination/nonlinear.html', context)
Ejemplo n.º 2
0
def multilinear_coordination(request, quest):
    player = request.user
    if request.method == 'POST':
        mission = get_object_or_404(Mission, pk=request.POST['mission_id'])
        if quest.started and not quest.is_game_over and not mission.is_completed(player):
            form = KeyForm(request.POST, quest=quest)
            if form.is_valid():
                key = form.cleaned_data["key"]
                right_key = mission.key
                is_right = len(right_key) > 0 and right_key == key
                keylog = Keylog(key=key, fix_time=timezone.now(), player=player, mission=mission, is_right=is_right)
                if is_right:
                    keylog.points = mission.points
                    line = mission.quest
                    next_mission = Mission.objects.filter(quest=line, order_number=mission.order_number + 1).first()
                    current_mission = get_object_or_404(CurrentMission, mission__quest=line, player=player)
                    current_mission.mission = next_mission
                    current_mission.start_time = keylog.fix_time
                    current_mission.save()
                keylog.save()
        url = '{0}#m{1}'.format(resolve_url('coordination:quest_coordination', quest_id=quest.id), mission.id)
        return redirect(url)
    else:
        rest_quest = None
        lines = None
        mission_start = None
        mission_finish = None
        form = None
        if quest.not_started:
            mission_start = quest.start_mission()
        else:
            if quest.started and not quest.is_game_over:
                rest_quest = get_timedelta(quest.game_over)
            form = KeyForm(quest=quest)
            lines = quest.lines()
            for line in lines:
                current_mission = get_object_or_404(CurrentMission, mission__quest=line, player=player)
                line.mission = current_mission.mission
            if quest.is_game_over or quest.ended:
                mission_finish = quest.finish_mission()
        points = Keylog.total_points(quest, player)
        messages = quest.messages().filter(is_show=True)
        context = {'quest': quest, 'messages': messages, 'lines': lines, 'mission_finish': mission_finish,
                   'mission_start': mission_start, 'rest_quest': rest_quest, 'points': points, 'form': form}
        return render(request, 'coordination/quests/coordination/multilinear.html', context)
Ejemplo n.º 3
0
def linear_coordination(request, quest):
    player = request.user
    current_mission = get_object_or_404(CurrentMission, mission__quest=quest, player=player)
    mission = current_mission.mission
    if request.method == 'POST':
        if quest.started and not mission.is_finish:
            form = KeyForm(request.POST, quest=quest)
            if form.is_valid():
                key = form.cleaned_data["key"]
                next_missions = Mission.objects.filter(quest=quest, order_number=mission.order_number + 1)
                if quest.linear:
                    right_key = mission.key
                    next_mission = next_missions.first()
                    is_right = len(right_key) > 0 and right_key == key
                else:
                    next_mission = next_missions.filter(key=key).first()
                    is_right = next_mission is not None
                keylog = Keylog(key=key, fix_time=timezone.now(), player=player, mission=mission, is_right=is_right)
                keylog.save()
                if is_right:
                    current_mission.mission = next_mission
                    current_mission.start_time = keylog.fix_time
                    current_mission.save()
        return redirect('coordination:quest_coordination', quest_id=quest.id)
    else:
        hints = current_mission.display_hints()
        next_hint_time = current_mission.next_hint_time()
        delay = get_timedelta(next_hint_time) if next_hint_time else None
        completed_missions = Mission.completed_missions(quest, player)
        form = None
        wrong_keys_str = None
        messages = quest.messages().filter(is_show=True)
        if quest.started and not mission.is_finish:
            form = KeyForm(quest=quest)
            wrong_keys_str = Keylog.wrong_keylogs_format(player, mission)
        context = {'quest': quest, 'mission': mission, 'hints': hints, 'form': form, 'messages': messages,
                   'wrong_keys': wrong_keys_str, 'delay': delay, 'completed_missions': completed_missions}
        return render(request, 'coordination/quests/coordination/general.html', context)