def success_capture(self, flag, old_reward=None): if self.config.teams: teamval = "team's " else: teamval = "" user = self.get_current_user() old_reward = flag.value if old_reward is None else old_reward reward_dialog = flag.name + " answered correctly. " if self.config.banking: reward_dialog += "$" + str(old_reward) + " has been added to your " + teamval + "account." else: reward_dialog += str(old_reward) + " points added to your " + teamval + "score." success = [reward_dialog] # Check for Box Completion boxcomplete = True box = flag.box for boxflag in box.flags: if not boxflag in user.team.flags: boxcomplete = False break if boxcomplete: success.append("Congratulations! You have completed " + box.name + ".") # Check for Level Completion level = GameLevel.by_id(box.game_level_id) level_progress = len(user.team.level_flags(level.number)) / float(len(level.flags)) if level_progress == 1.0 and level not in user.team.game_levels: reward_dialog = "" if level._reward > 0: user.team.money += level._reward self.dbsession.add(user.team) self.dbsession.flush() self.dbsession.commit() if self.config.banking: reward_dialog += "$" + str(level._reward) + " has been added to your " + teamval + "account." else: reward_dialog += str(level._reward) + " points added to your " + teamval + "score." success.append("Congratulations! You have completed " + str(level.name) + ". " + reward_dialog) # Unlock next level if based on Game Progress next_level = GameLevel.by_id(level.next_level_id) if next_level and next_level._type == "progress" and level_progress * 100 >= next_level.buyout and next_level not in user.team.game_levels: logging.info("%s (%s) unlocked %s" % ( user.handle, user.team.name, next_level.name )) user.team.game_levels.append(next_level) self.dbsession.add(user.team) self.dbsession.commit() self.event_manager.level_unlocked(user, next_level) success.append("Congratulations! You have unlocked " + str(next_level.name)) return success
def to_dict(self): ''' Returns editable data as a dictionary ''' corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) return { 'name': self.name, 'uuid': self.uuid, 'corporation': corp.uuid, 'description': self._description, 'difficulty': self.difficulty, 'game_level': game_level.uuid, }
def flag_captured(self, team, flag): """ Callback for when a flag is captured """ if len(GameLevel.all()) > 1: message = "%s has captured the '%s' flag in %s (Lvl %s)" % ( team.name, flag.name, flag.box.name, GameLevel.by_id(flag.box.game_level_id).number, ) else: message = "%s has captured the '%s' flag in %s" % ( team.name, flag.name, flag.box.name, ) Notification.create_broadcast(team, "Flag Capture", message, SUCCESS) self.io_loop.add_callback(self.push_broadcast) self.io_loop.add_callback(self.push_scoreboard)
def to_dict(self): ''' Returns editable data as a dictionary ''' corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) cat = Category.by_id(self.category_id) if cat: category = cat.uuid else: category = "" return { 'name': self.name, 'uuid': self.uuid, 'corporation': corp.uuid, 'category': category, 'operating_system': self.operating_system, 'description': self._description, 'difficulty': self.difficulty, 'game_level': game_level.uuid, 'flaglist': self.flaglist(self.id) }
def to_dict(self): ''' Returns editable data as a dictionary ''' corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) cat = Category.by_id(self.category_id) if cat: category = cat.uuid else: category = "" return { 'name': self.name, 'uuid': self.uuid, 'corporation': corp.uuid, 'category': category, 'operating_system': self.operating_system, 'description': self._description, 'difficulty': self.difficulty, 'game_level': game_level.uuid, 'flag_submission_type': self.flag_submission_type, 'flaglist': self.flaglist(self.id) }
def to_dict(self): """ Returns editable data as a dictionary """ corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) cat = Category.by_id(self.category_id) if cat: category = cat.uuid else: category = "" return { "name": self.name, "uuid": self.uuid, "corporation": corp.uuid, "category": category, "operating_system": self.operating_system, "description": self._description, "difficulty": self.difficulty, "game_level": game_level.uuid, "flag_submission_type": self.flag_submission_type, "flaglist": self.flaglist(self.id), }
def flag_penalty(self, user, flag): """ Callback for when a flag is captured """ if options.teams: message = "%s was penalized on '%s' in %s" % ( user.handle, flag.name, flag.box.name, ) else: message = "%s was penalized on '%s' in %s" % ( user.team.name, flag.name, flag.box.name, ) if len(GameLevel.all()) > 1: message = message + " (%s)" % ( GameLevel.by_id(flag.box.game_level_id).name, ) Notification.create_team(user.team, "Flag Penalty", message, WARNING) self.io_loop.add_callback(self.push_team, user.team.id) self.io_loop.add_callback(self.push_scoreboard)
def success_capture(self, flag, old_reward=None): if self.config.teams: teamval = "team's " else: teamval = "" user = self.get_current_user() old_reward = flag.dynamic_value( user.team) if old_reward is None else old_reward reward_dialog = flag.name + " answered correctly. " if self.config.banking: reward_dialog += ("$" + str(old_reward) + " has been added to your " + teamval + "account.") else: reward_dialog += (str(old_reward) + " points added to your " + teamval + "score.") success = [reward_dialog] # Fire capture webhook send_capture_webhook(user, flag, old_reward) # Check for Box Completion box = flag.box if box.is_complete(user): if box.value > 0: user.team.money += box.value self.dbsession.add(user.team) self.dbsession.flush() self.dbsession.commit() dialog = str( box.value) + " points added to your " + teamval + "score." reward_dialog += dialog success.append("Congratulations! You have completed " + box.name + ". " + dialog) # Fire box complete webhook send_box_complete_webhook(user, box) else: success.append("Congratulations! You have completed " + box.name + ".") # Check for Level Completion level = GameLevel.by_id(box.game_level_id) level_progress = old_div(len(user.team.level_flags(level.number)), float(len(level.flags))) if level_progress == 1.0 and level not in user.team.game_levels: reward_dialog = "" if level._reward > 0: user.team.money += level._reward self.dbsession.add(user.team) self.dbsession.flush() self.dbsession.commit() if self.config.banking: reward_dialog += ("$" + str(level._reward) + " has been added to your " + teamval + "account.") else: reward_dialog += (str(level._reward) + " points added to your " + teamval + "score.") success.append("Congratulations! You have completed " + level.name + ". " + reward_dialog) # Fire level complete webhook send_level_complete_webhook(user, box) # Unlock next level if based on Game Progress next_level = GameLevel.by_id(level.next_level_id) if next_level and next_level not in user.team.game_levels: if level_progress == 1.0 or ( next_level._type == "progress" and level_progress * 100 >= next_level.buyout): logging.info("%s (%s) unlocked %s" % (user.handle, user.team.name, next_level.name)) user.team.game_levels.append(next_level) self.dbsession.add(user.team) self.dbsession.commit() self.event_manager.level_unlocked(user, next_level) success.append("Congratulations! You have unlocked " + next_level.name) self.event_manager.push_score_update() return success
def game_level(self): return GameLevel.by_id(self.game_level_id)
def success_capture(self, flag, old_reward=None): if self.config.teams: teamval = "team's " else: teamval = "" user = self.get_current_user() old_reward = flag.value if old_reward is None else old_reward reward_dialog = flag.name + " answered correctly. " if self.config.banking: reward_dialog += "$" + str( old_reward) + " has been added to your " + teamval + "account." else: reward_dialog += str( old_reward) + " points added to your " + teamval + "score." success = [reward_dialog] # Check for Box Completion boxcomplete = True box = flag.box for boxflag in box.flags: if not boxflag in user.team.flags: boxcomplete = False break if boxcomplete: success.append("Congratulations! You have completed " + box.name + ".") # Check for Level Completion level = GameLevel.by_id(box.game_level_id) level_progress = len(user.team.level_flags(level.number)) / float( len(level.flags)) if level_progress == 1.0 and level not in user.team.game_levels: reward_dialog = "" if level._reward > 0: user.team.money += level._reward self.dbsession.add(user.team) self.dbsession.flush() self.dbsession.commit() if self.config.banking: reward_dialog += "$" + str( level._reward ) + " has been added to your " + teamval + "account." else: reward_dialog += str( level._reward ) + " points added to your " + teamval + "score." success.append("Congratulations! You have completed " + str(level.name) + ". " + reward_dialog) # Unlock next level if based on Game Progress next_level = GameLevel.by_id(level.next_level_id) if next_level and next_level._type == "progress" and level_progress * 100 >= next_level.buyout and next_level not in user.team.game_levels: logging.info("%s (%s) unlocked %s" % (user.handle, user.team.name, next_level.name)) user.team.game_levels.append(next_level) self.dbsession.add(user.team) self.dbsession.commit() self.event_manager.level_unlocked(user, next_level) success.append("Congratulations! You have unlocked " + str(next_level.name)) return success