Esempio n. 1
0
def join(request, id=None):
    """ Joins the Game without specifying a team (adding the user to the pool
        of interested players)
    """
    game = get_object_or_404(Game, id=id) if id else Game.current()
    player = get_object_or_404(Player, user=request.user)
    Membership.objects.get_or_create(game=game, player=player)
    return redirect('teams')
Esempio n. 2
0
def index(request):
    """ Displays a list of all teams """
    game = Game.current()
    return TemplateResponse(request, 'console/teams/teams.html', {
        'teams': Team.objects.filter(game=game, staff=False),
        'staff_teams': Team.objects.filter(game=game, staff=True),
        'joined': request.user.is_authenticated() and Membership.objects\
            .filter(player__user=request.user, game=game).exists()
    })
Esempio n. 3
0
    def handle(self, *args, **options):
        game = Game.current()
        number, name = options.get('number'), options.get('name')
        if number:
            print "Unlocking %s ..." % number
            team = game.teams.get(number=number)
        elif name:
            print "Unlocking %s ... " % name
            team = game.teams.get(name__iexact=name)
        else:
            raise ValueError('You must provide a number or name')

        for puzzle in game.puzzles.all():
            p = PuzzleProgress.objects.get_or_create(puzzle=puzzle,
                team=team)[0]
            if puzzle.hidden:
                p.open()
            print p
        print "Done\n"
def current_game(request):
    return {'game': Game.current()}
Esempio n. 5
0
    def handle(self, *args, **options):
        print ""
        if options.get('finished', False):
            playtests = Game.objects.filter(name__contains=' (PLAYTEST)')
            count = playtests.count()
            playtests.all().delete()
            game = Game.current()
            if count > 1:
                print "Deleted %s playtest games" % count
            elif count == 1:
                print "Deleted playtest game"
            else:
                print "No active playtests found"
            print "Current game is now %s (id %s)\n" % (game, game.id)

        else:
            game = Game.current()
            print "Creating a new game based on %s" % game
            print "===================================================="
            teams = list(game.teams.filter(staff=True))
            puzzles = list(game.puzzles.all())
            videos = list(game.videos.all())
            game.name += ' (PLAYTEST)'
            game.pk = None
            # Grab the old start / stop time
            start = game.start
            stop = game.end
            game.save()

            new_start = now()

            def to_playtest_time(time):
                old_duration = (stop - start).total_seconds()
                new_duration = options.get('duration', 1) * 60 * 60
                progress = float((time - start).total_seconds()) / old_duration
                return new_start + timedelta(seconds=progress * new_duration)

            print "\nCopying staff teams ------------------------------"
            for team in teams:
                players = list(team.players.all())
                team.pk = None
                team.game = game
                team.save()
                print "%s ..." % team,

                for p in players:
                    Membership.objects.create(game=game, player=p, team=team)
                print "%s players" % len(players)

            print "\nCopying puzzles ----------------------------------"
            for puzzle in puzzles:
                clues = list(puzzle.clues.all())
                code = puzzle.code
                code.pk = None
                code.save()
                puzzle.game = game
                puzzle.code = code
                puzzle.open = to_playtest_time(puzzle.open)
                puzzle.close = to_playtest_time(puzzle.close)
                puzzle.pk = None
                puzzle.save()
                print "\n"
                print "%s ~~~~~~~~~~" % puzzle
                print "\nHints:"
                for clue in clues:
                    clue.puzzle = puzzle
                    clue.pk = None
                    clue.save()
                    print "  @ %s: %s" % (clue.show_at, clue.text)
                print ""

            print "\nCopying videos -----------------------------------"
            for video in videos:
                video.game = game
                video.open = to_playtest_time(video.open or game.start)
                video.close = to_playtest_time(video.close or game.end)
                video.pk = None
                video.save()
                print video

            print "\nNew default game %s created with id %s" % (game, game.id)
            print "Game will be open from %s to %s" % (new_start,
                new_start + timedelta(hours=options.get('duration', 1)))
            print "Be sure to unlock a team to start playtesting\n"