Ejemplo n.º 1
0
def get_new_avatar(dir, forceteam=False):
    avatar = default_avatar(dir)
    avatars = filter_avatars(dir)
    if len(avatars) == 0:
        return avatar
    if dir == "team" or forceteam:
        from models.Team import Team

        cmplist = Team.all()
    elif dir == "user":
        from models.User import User

        cmplist = User.all()
    else:
        from models.Box import Box

        cmplist = Box.all()
    dblist = []
    for item in cmplist:
        if item._avatar:
            dblist.append(item._avatar)
    for image in avatars:
        if not image in dblist:
            return image
    return avatars[randint(0, len(avatars) - 1)]
Ejemplo n.º 2
0
 def render_page(self, errors=None):
     ''' Addes extra params to render() '''
     user = self.get_current_user()
     boxes = filter(lambda box: box.source_code is not None, Box.all())
     self.render('upgrades/source_code_market.html',
         user=user, boxes=boxes, errors=errors
     )
Ejemplo n.º 3
0
 def render_page(self, errors=None):
     """ Addes extra params to render() """
     user = self.get_current_user()
     boxes = [box for box in Box.all() if box.source_code is not None]
     self.render(
         "upgrades/source_code_market.html", user=user, boxes=boxes, errors=errors
     )
Ejemplo n.º 4
0
 def render_page(self, errors=None):
     ''' Addes extra params to render() '''
     user = self.get_current_user()
     boxes = filter(lambda box: box.source_code is not None, Box.all())
     self.render('upgrades/source_code_market.html',
                 user=user,
                 boxes=boxes,
                 errors=errors)
Ejemplo n.º 5
0
def get_new_avatar(dir, forceteam=False):
    avatar = default_avatar(dir)
    avatars = filter_avatars(dir)
    if len(avatars) == 0:
        return avatar
    if dir == 'team' or forceteam:
        from models.Team import Team
        cmplist = Team.all()
    elif dir == 'user':
        from models.User import User
        cmplist = User.all()
    else:
        from models.Box import Box
        cmplist = Box.all()
    dblist = []
    for item in cmplist:
        if item._avatar:
            dblist.append(item._avatar)
    for image in avatars:
        if not image in dblist:
            return image
    return avatars[randint(0, len(avatars)-1)]
Ejemplo n.º 6
0
    def update_gamestate(self, app):
        game_state = {
            "teams": {},
            "levels": {},
            "boxes": {},
            "hint_count": len(Hint.all()),
            "flag_count": len(Flag.all()),
            "box_count": len(Box.all()),
            "level_count": len(GameLevel.all()),
        }
        teams = Team.ranks()
        for team in teams:
            if len(team.members) > 0:
                millis = int(round(time.time() * 1000))
                game_state["teams"][team.name] = {
                    "uuid": team.uuid,
                    "flags": [str(flag) for flag in team.flags],
                    "game_levels": [str(lvl) for lvl in team.game_levels],
                    "members_count": len(team.members),
                    "hints_count": len(team.hints),
                    "bot_count":
                    BotManager.instance().count_by_team(team.name),
                    "money": team.money,
                }

                highlights = {"money": 0, "flag": 0, "bot": 0, "hint": 0}
                for item in highlights:
                    value = team.get_score(item)
                    game_state["teams"][team.name][item] = value
                    game_history = app.settings["scoreboard_history"]
                    if team.name in game_history:
                        prev = game_history[team.name][item]
                        if prev < value:
                            highlights[item] = millis
                        else:
                            highlights[item] = game_history[
                                team.name]["highlights"][item]
                highlights["now"] = millis
                game_state["teams"][team.name]["highlights"] = highlights
                app.settings["scoreboard_history"][
                    team.name] = game_state["teams"].get(team.name)
        for level in GameLevel.all():
            game_state["levels"][level.name] = {
                "type": level.type,
                "number": level.number,
                "teams": {},
                "boxes": {},
                "box_count": len(level.boxes),
                "flag_count": len(level.flags),
            }
            for team in teams:
                game_state["levels"][level.name]["teams"][team.name] = {
                    "lvl_count": len(team.level_flags(level.number)),
                    "lvl_unlock": level in team.game_levels,
                }
            for box in level.boxes:
                game_state["levels"][level.name]["boxes"][box.uuid] = {
                    "name": box.name,
                    "teams": {},
                    "flag_count": len(box.flags),
                }
                for team in teams:
                    game_state["levels"][level.name]["boxes"][
                        box.uuid]["teams"][team.name] = {
                            "box_count": len(team.box_flags(box))
                        }
        app.settings["scoreboard_state"] = game_state