Exemplo n.º 1
0
 def buyout(self):
     ''' Buyout and unlock a level '''
     form = Form(uuid="Level parameter missing")
     user = self.get_current_user()
     if form.validate(self.request.arguments):
         level = GameLevel.by_uuid(self.get_argument('uuid', ''))
         if level is not None and user is not None:
             if level.buyout < user.team.money:
                 user.team.game_levels.append(level)
                 user.team.money -= level.buyout
                 dbsession.add(user.team)
                 self.event_manager.unlocked_level(user, level)
                 self.redirect("/user/missions")
             else:
                 self.render("missions/view.html",
                     team=user.team,
                     errors=[
                         "You do not have enough money to unlock this level"
                     ]
                 )
         else:
             self.render("missions/view.html",
                 team=user.team,
                 errors=["Level does not exist"]
             )
     else:
         self.render("missions/view.html",
             team=user.team,
             errors=form.errors
         )
Exemplo n.º 2
0
 def buyout(self):
     ''' Buyout and unlock a level '''
     form = Form(uuid="Level parameter missing")
     user = self.get_current_user()
     if form.validate(self.request.arguments):
         level = GameLevel.by_uuid(self.get_argument('uuid', ''))
         if level is not None and user is not None:
             if level.buyout < user.team.money:
                 logging.info("%s (%s) payed buyout for level #%d" % (
                     user.handle, user.team.name, level.number
                 ))
                 user.team.game_levels.append(level)
                 user.team.money -= level.buyout
                 dbsession.add(user.team)
                 event = self.event_manager.create_unlocked_level_event(user, level)
                 self.new_events.append(event)
                 self.redirect("/user/missions")
             else:
                 self.render("missions/view.html",
                     team=user.team,
                     errors=[
                         "You do not have enough money to unlock this level"
                     ]
                 )
         else:
             self.render("missions/view.html",
                 team=user.team,
                 errors=["Level does not exist"]
             )
     else:
         self.render("missions/view.html",
             team=user.team,
             errors=form.errors
         )
Exemplo n.º 3
0
 def box_level(self):
     ''' Changes a boxs level '''
     form = Form(box_uuid="No box selected", level_uuid="No level selected")
     if form.validate(self.request.arguments):
         errors = []
         box = Box.by_uuid(self.get_argument('box_uuid'))
         level = GameLevel.by_uuid(self.get_argument('level_uuid'))
         if box is not None and level is not None:
             box.game_level_id = level.id
             dbsession.add(box)
             dbsession.flush()
         elif box is None:
             errors.append("Box does not exist")
         elif level is None:
             errors.append("GameLevel does not exist")
         self.render("admin/view/game_levels.html", errors=errors)
     else:
         self.render("admin/view/game_levels.html", errors=form.errors)
Exemplo n.º 4
0
 def box_level(self):
     ''' Changes a boxs level '''
     form = Form(box_uuid="No box selected", level_uuid="No level selected")
     if form.validate(self.request.arguments):
         errors = []
         box = Box.by_uuid(self.get_argument('box_uuid'))
         level = GameLevel.by_uuid(self.get_argument('level_uuid'))
         if box is not None and level is not None:
             box.game_level_id = level.id
             dbsession.add(box)
             dbsession.flush()
         elif box is None:
             errors.append("Box does not exist")
         elif level is None:
             errors.append("GameLevel does not exist")
         self.render("admin/view/game_levels.html", errors=errors)
     else:
         self.render("admin/view/game_levels.html", errors=form.errors)
Exemplo n.º 5
0
 def edit_game_level(self):
     ''' Update game level objects '''
     form = Form(
         uuid="Select an object",
         number="Enter a level number",
         buyout="Enter a buyout value",
     )
     if form.validate(self.request.arguments):
         errors = []
         level = GameLevel.by_uuid(self.get_argument('uuid'))
         try:
             new_number = int(self.get_argument('number', 'NaN'))
             new_buyout = int(self.get_argument('buyout', 'NaN'))
             if level.number != new_number and GameLevel.by_number(
                     new_number) is None:
                 level.number = new_number
                 dbsession.add(level)
                 dbsession.flush()
                 # Fix the linked-list
                 game_levels = sorted(GameLevel.all())
                 index = 0
                 for game_level in game_levels[:-1]:
                     game_level.next_level_id = game_levels[index + 1].id
                     dbsession.add(game_level)
                     index += 1
                 game_levels[0].number = 0
                 dbsession.add(game_levels[0])
                 game_levels[-1].next_level_id = None
                 dbsession.add(game_levels[-1])
                 dbsession.flush()
             if GameLevel.by_number(new_number) is not None:
                 errors.append("GameLevel number is not unique")
             if level.buyout != new_buyout:
                 level.buyout = new_buyout
                 dbsession.add(level)
                 dbsession.flush()
         except ValueError:
             errors.append(
                 "That was not a number ... maybe you should go back to school"
             )
         self.render("admin/view/game_levels.html", errors=errors)
     else:
         self.render("admin/view/game_levels.html", errors=form.errors)
Exemplo n.º 6
0
 def edit_game_level(self):
     ''' Update game level objects '''
     form = Form(
         uuid="Select an object",
         number="Enter a level number",
         buyout="Enter a buyout value",
     )
     if form.validate(self.request.arguments):
         errors = []
         level = GameLevel.by_uuid(self.get_argument('uuid'))
         try:
             new_number = int(self.get_argument('number', 'NaN'))
             new_buyout = int(self.get_argument('buyout', 'NaN'))
             if level.number != new_number and GameLevel.by_number(new_number) is None:
                 level.number = new_number
                 dbsession.add(level)
                 dbsession.flush()
                 # Fix the linked-list
                 game_levels = sorted(GameLevel.all())
                 index = 0
                 for game_level in game_levels[:-1]:
                     game_level.next_level_id = game_levels[index + 1].id
                     dbsession.add(game_level)
                     index += 1
                 game_levels[0].number = 0
                 dbsession.add(game_levels[0])
                 game_levels[-1].next_level_id = None
                 dbsession.add(game_levels[-1])
                 dbsession.flush()
             if GameLevel.by_number(new_number) is not None:
                 errors.append("GameLevel number is not unique")
             if level.buyout != new_buyout:
                 level.buyout = new_buyout
                 dbsession.add(level)
                 dbsession.flush()
         except ValueError:
             errors.append(
                 "That was not a number ... maybe you should go back to school"
             )
         self.render("admin/view/game_levels.html", errors=errors)
     else:
         self.render("admin/view/game_levels.html", errors=form.errors)