def getEventsByPlayer(player, fields): if self.cur_player and self.cur_player['login_utc_offset']: utc_offset = self.cur_player['login_utc_offset'] else: utc_offset = self.core.server_utc_offset events = self.model.events.getEvents( player_id=player['_id'], query={'upcoming': 1}, fields={ 'start_date': 1, 'guild_side_name': 1, 'sides_names': 1, 'target_name': 1, '_id': 1, 'finish_date': 1, 'type': 1 } ) current_time = time() for event in events: event.update({'start_date_f': getRelativeDate(int(event['start_date']) + utc_offset)}) if event['start_date'] <= current_time <= event['finish_date']: fields.update({ 'in_progress_event': event }) fields.update({'events': events})
def getNearestFactionEvent(fields): if 'login_faction' in fields: event = self.model.events.getFactionEventsByID(fields['login_faction'], limit=1, fields={ 'sides': 1, 'sides_names': 1, 'start_date': 1, '_id': 1, 'type': 1 }) if event: event[0]['start_date'] = getRelativeDate(event[0]['start_date'] + fields['login_utc_offset']) fields.update({'nearest_faction_event': event[0]})
def getNearestGuildEvent(fields): if 'login_guild' in fields and fields['login_guild']: event = self.model.events.getGuildEventsByID(fields['login_guild'], limit=1, fields={ 'target_name': 1, 'guild_side_name': 1, 'start_date': 1, '_id': 1, 'type': 1 }) if event: if event[0]['start_date'] < time.time(): event[0].update({'in_progress': 1}) event[0]['start_date'] = getRelativeDate(event[0]['start_date'] + fields['login_utc_offset']) fields.update({'nearest_guild_event': event[0]})
def printEventDetail(self, fields, params): def getPlayersData(players, event): for player in players: if event['author'] == player['_id']: event.update({ 'author_name': player['name'], 'author_lead': player['stat']['lead']['current'] }) player.update({ 'class_name': self.balance.classes[str(player['class'])], 'race_name': self.balance.races[player['faction']][player['race']], }) if event['status'] in ['fail', 'complete']: try: player.update({ 'performance': int( float(event['combat_log'][str( player['_id'])]['count']) / 10 * 100) }) except Exception: pass return players def getSidesPlayersData(players, target_guild, self_guild, event): target_players = [] self_players = [] for player in players: if event['author'] == player['_id']: event.update({ 'author_name': player['name'], 'author_lead': player['stat']['lead']['current'] }) player.update({ 'class_name': self.balance.classes[str(player['class'])], 'race_name': self.balance.races[player['faction']][player['race']], }) try: if 'combat_log' in event: str_id = str(player['_id']) if str_id in event['combat_log'][event['target_name']]: player['performance'] = int(event['combat_log'][ event['target_name']][str_id]['performance']) elif str_id in event['combat_log'][ event['guild_side_name']]: player['performance'] = int( event['combat_log'][event['guild_side_name']] [str_id]['performance']) except Exception: player['performance'] = 0 if player['_id'] in target_guild['people']: target_players.append(player) elif player['_id'] in self_guild['people']: self_players.append(player) return {'self': self_players, 'target': target_players} def getFactionsPlayersData(players, event): sides_players = [[], [], []] if players: for player in players: player.update({ 'class_name': self.balance.classes[str(player['class'])], 'race_name': self.balance.races[player['faction']][player['race']], }) sides_players[player['faction']].append(player) return { 'side_1': sides_players[event['sides'][0]], 'side_2': sides_players[event['sides'][1]] } def checkOperations(event): if event['start_date'] <= time.time() and not event['status'] in [ 'complete', 'fail' ]: event['status'] = 'progress' operation = 'not_allowed' else: operation = 'not_joined' if self.cur_player and self.cur_player['login_id'] in event[ 'people']: operation = 'joined' if event['type'] == 'raid': if self.cur_player and event['lvl_min'] > self.cur_player[ 'login_lvl']: operation = 'lvl' if len(event['people']) >= event['people_count_max']: operation = 'full' if self.cur_player and self.model.events.getPlayerActiveEventsCount( self.cur_player['login_id'] ) >= self.sbuilder.balance.max_events: if operation != 'joined': operation = 'not_allowed' if not operation in ['not_allowed', 'lvl', 'full']: event['can_join'] = True return operation fields.update({self.title: 'Event'}) event = self.model.events.getEventData(params['event_UID'], full=True) players = self.model.events._getEventMembers(event['_id']) if self.cur_player and self.cur_player['login_utc_offset']: utc_offset = self.cur_player['login_utc_offset'] else: utc_offset = self.core.server_utc_offset if self.cur_player: display = True if event['guild_run']: display = event['guild_side_name'] == self.cur_player[ 'login_guild'] event['guild_run_can_join'] = display if event['type'] == 'raid': raid = self.model.events.getRaidDungeonById(event['target']) event.update({ 'where_name': raid['name'], 'people_count_max': raid['max_players'], 'players': getPlayersData(players, event) }) if event['status'] in ['fail', 'complete']: event['total_performance'] = int( float(event['result_points']) / raid['power'] * 100) elif event['type'] == 'war': target_guild = self.model.guilds.getGuildByID(event['target']) self_guild = self.model.guilds.getGuildByID(event['guild_side']) if self.cur_player: event['guild_run_can_join'] = self.cur_player[ 'login_id'] in self_guild['people'] or self.cur_player[ 'login_id'] in target_guild['people'] sides = getSidesPlayersData(players, target_guild, self_guild, event) event.update({ 'where_img': self.core.GUILDS_AVATAR_FOLDER + target_guild['img'], 'where_name': target_guild['name'], 'self_players': sides['self'], 'target_players': sides['target'] }) elif event['type'] == 'fvf': sides = getFactionsPlayersData(players, event) event.update({ 'where_name': '', 'side_1_players': sides['side_1'], 'side_2_players': sides['side_2'] }) operation = checkOperations(event) event.update({ 'people_count': len(event['people']), 'start_date_f': getRelativeDate(int(event['start_date']), utc_offset - self.core.server_utc_offset), 'finish_date_f': getRelativeDate(int(event['finish_date']), utc_offset - self.core.server_utc_offset), 'operation': operation }) fields.update({'event': event}) tmp_name = 'event_page' if event['type'] == 'war': tmp_name = 'event_page_gvg' return basic.defaultController._printTemplate(self, tmp_name, fields)
def getFormattedEvents(self, player_id=None, player_guild=False, query={}): if self.cur_player and self.cur_player['login_utc_offset']: utc_offset = self.cur_player['login_utc_offset'] else: utc_offset = self.core.server_utc_offset raids = self.model.events.getRaidDungeons() if not player_id: events = self.model.events.getEvents(query=query, guild=player_guild) else: events = self.model.events.getEvents(player_id=player_id, query=query, guild=player_guild) people = [] for event in events: if 'author' in event: people.append(event['author']) if people: players = self.model.players.getPlayersList( people, ['_id', 'name', 'stat.lead.current']) for event in events: display = True if event['guild_run']: display = player_guild and event[ 'guild_side_name'] == player_guild event['guild_run_can_join'] = display if event['type'] == 'raid': for raid in raids: if raid['UID'] == event['target']: event.update({ 'where_name': raid['name'], 'people_count_max': raid['max_players'] }) elif event['type'] == 'war': del event['lvl_min'] if 'author' in event: for player in players: if event['author'] == player['_id']: event.update({ 'author_name': player['name'], 'lead': player['stat']['lead']['current'] }) if not 'finished' in query: if event['start_date'] <= time.time(): event['status'] = 'progress' operation = 'not_allowed' else: operation = 'not_joined' if self.cur_player and self.cur_player[ 'login_id'] in event['people']: operation = 'joined' else: operation = 'not_joined' event.update({ 'people_count': len(event['people']), 'start_date_f': getRelativeDate( int(event['start_date']) + utc_offset - self.core.server_utc_offset), 'operation': operation }) return events
def printEventDetail(self, fields, params): def getPlayersData(players, event): for player in players: if event['author'] == player['_id']: event.update({ 'author_name': player['name'], 'author_lead': player['stat']['lead']['current'] }) player.update({ 'class_name': self.balance.classes[str(player['class'])], 'race_name': self.balance.races[player['faction']][player['race']], }) if event['status'] in ['fail', 'complete']: try: player.update({ 'performance': int(float(event['combat_log'][str(player['_id'])]['count'])/10*100) }) except Exception: pass return players def getSidesPlayersData(players, target_guild, self_guild, event): target_players = [] self_players = [] for player in players: if event['author'] == player['_id']: event.update({ 'author_name': player['name'], 'author_lead': player['stat']['lead']['current'] }) player.update({ 'class_name': self.balance.classes[str(player['class'])], 'race_name': self.balance.races[player['faction']][player['race']], }) try: if 'combat_log' in event: str_id = str(player['_id']) if str_id in event['combat_log'][event['target_name']]: player['performance'] = int(event['combat_log'][event['target_name']][str_id]['performance']) elif str_id in event['combat_log'][event['guild_side_name']]: player['performance'] = int(event['combat_log'][event['guild_side_name']][str_id]['performance']) except Exception: player['performance'] = 0 if player['_id'] in target_guild['people']: target_players.append(player) elif player['_id'] in self_guild['people']: self_players.append(player) return { 'self': self_players, 'target': target_players } def getFactionsPlayersData(players, event): sides_players = [[],[],[]] if players: for player in players: player.update({ 'class_name': self.balance.classes[str(player['class'])], 'race_name': self.balance.races[player['faction']][player['race']], }) sides_players[player['faction']].append(player) return { 'side_1': sides_players[event['sides'][0]], 'side_2': sides_players[event['sides'][1]] } def checkOperations(event): if event['start_date'] <= time.time() and not event['status'] in ['complete', 'fail']: event['status'] = 'progress' operation = 'not_allowed' else: operation = 'not_joined' if self.cur_player and self.cur_player['login_id'] in event['people']: operation = 'joined' if event['type'] == 'raid': if self.cur_player and event['lvl_min'] > self.cur_player['login_lvl']: operation = 'lvl' if len(event['people']) >= event['people_count_max']: operation = 'full' if self.cur_player and self.model.events.getPlayerActiveEventsCount(self.cur_player['login_id']) >= self.sbuilder.balance.max_events: if operation != 'joined': operation = 'not_allowed' if not operation in ['not_allowed', 'lvl', 'full']: event['can_join'] = True return operation fields.update({self.title: 'Event'}) event = self.model.events.getEventData(params['event_UID'], full=True) players = self.model.events._getEventMembers(event['_id']) if self.cur_player and self.cur_player['login_utc_offset']: utc_offset = self.cur_player['login_utc_offset'] else: utc_offset = self.core.server_utc_offset if self.cur_player: display = True if event['guild_run']: display = event['guild_side_name'] == self.cur_player['login_guild'] event['guild_run_can_join'] = display if event['type'] == 'raid': raid = self.model.events.getRaidDungeonById(event['target']) event.update({ 'where_name': raid['name'], 'people_count_max': raid['max_players'], 'players': getPlayersData(players, event) }) if event['status'] in ['fail', 'complete']: event['total_performance'] = int(float(event['result_points'])/raid['power']*100) elif event['type'] == 'war': target_guild = self.model.guilds.getGuildByID(event['target']) self_guild = self.model.guilds.getGuildByID(event['guild_side']) if self.cur_player: event['guild_run_can_join'] = self.cur_player['login_id'] in self_guild['people'] or self.cur_player['login_id'] in target_guild['people'] sides = getSidesPlayersData(players, target_guild, self_guild, event) event.update({ 'where_img': self.core.GUILDS_AVATAR_FOLDER+target_guild['img'], 'where_name': target_guild['name'], 'self_players': sides['self'], 'target_players': sides['target'] }) elif event['type'] == 'fvf': sides = getFactionsPlayersData(players, event) event.update({ 'where_name': '', 'side_1_players': sides['side_1'], 'side_2_players': sides['side_2'] }) operation = checkOperations(event) event.update({ 'people_count': len(event['people']), 'start_date_f': getRelativeDate(int(event['start_date']), utc_offset - self.core.server_utc_offset), 'finish_date_f': getRelativeDate(int(event['finish_date']), utc_offset - self.core.server_utc_offset), 'operation': operation }) fields.update({'event': event}) tmp_name = 'event_page' if event['type'] == 'war': tmp_name = 'event_page_gvg' return basic.defaultController._printTemplate(self, tmp_name, fields)
def getFormattedEvents(self, player_id=None, player_guild = False, query = {}): if self.cur_player and self.cur_player['login_utc_offset']: utc_offset = self.cur_player['login_utc_offset'] else: utc_offset = self.core.server_utc_offset raids = self.model.events.getRaidDungeons() if not player_id: events = self.model.events.getEvents(query=query, guild=player_guild) else: events = self.model.events.getEvents(player_id=player_id, query=query, guild=player_guild) people = [] for event in events: if 'author' in event: people.append(event['author']) if people: players = self.model.players.getPlayersList(people, ['_id', 'name', 'stat.lead.current']) for event in events: display = True if event['guild_run']: display = player_guild and event['guild_side_name'] == player_guild event['guild_run_can_join'] = display if event['type'] == 'raid': for raid in raids: if raid['UID'] == event['target']: event.update({'where_name': raid['name'], 'people_count_max': raid['max_players']}) elif event['type'] == 'war': del event['lvl_min'] if 'author' in event: for player in players: if event['author'] == player['_id']: event.update({ 'author_name': player['name'], 'lead': player['stat']['lead']['current'] }) if not 'finished' in query: if event['start_date'] <= time.time(): event['status'] = 'progress' operation = 'not_allowed' else: operation = 'not_joined' if self.cur_player and self.cur_player['login_id'] in event['people']: operation = 'joined' else: operation = 'not_joined' event.update({ 'people_count': len(event['people']), 'start_date_f': getRelativeDate(int(event['start_date'])+utc_offset-self.core.server_utc_offset), 'operation': operation }) return events