def update_all_missions(data, now): """更新一遍所有任务的状态 """ mission_list = data.mission_list.get_all() user = data.user.get(True) #是否删除超过7天的开服七天任务 now_time = utils.get_start_second(now) create_time = utils.get_start_second(user.create_time) if (now_time - create_time) / utils.SECONDS_OF_DAY > 7: day7_mission_overtime = True else: day7_mission_overtime = False #由于删除了任务,特殊处理:任务逻辑不存在时,删除原任务数据 #TODO to_delete = [] for mission in mission_list: method = MissionPool().get_mission_method(mission.basic_id) if method is None: to_delete.append(mission.id) continue # raise Exception("unknown mission id[id=%d]" % mission.basic_id) if mission.is_day7_type() and day7_mission_overtime: to_delete.append(mission.id) continue method(data, mission) for mission_id in to_delete: data.mission_list.delete(mission_id)
def create(user_id, basic_id, basic_activity, basic_steps, now): """创建 """ id = ActivityInfo.generate_id(user_id, basic_id) info = basic_activity if info.start_time == "": start_time = 0 else: start_time = utils.get_start_second_by_timestring(info.start_time) #开始时间为5点 start_time = utils.get_start_second(start_time + 1) if info.end_time == "": end_time = 0 else: end_time = utils.get_end_second_by_timestring(info.end_time) if now != 0 and info.start_day != 0: start_time = utils.get_start_second(now + 86400 * (info.start_day - 1)) if info.end_day != 0: end_time = utils.get_end_second(now + 86400 * (info.end_day - 1)) progress = [0] * len(info.get_steps()) progress = utils.join_to_string(progress) target = [] for step_id in info.get_steps(): for basic_step in basic_steps: if step_id == basic_step.id: target.append(basic_step.target) break target = utils.join_to_string(target) status = [] for step_id in info.get_steps(): default_lock = False for basic_step in basic_steps: if step_id == basic_step.id: default_lock = basic_step.default_lock break if default_lock: status.append(ActivityInfo.REWARD_LOCKED) else: status.append(ActivityInfo.REWARD_AVAILABLE) status = utils.join_to_string(status) activity = ActivityInfo(id, user_id, basic_id, start_time, end_time, 0, progress, target, status) return activity
def arise(self, now, boss_id, start_time, end_time, total_soldier_num, description, user_level): """世界boss触发了 """ self.kills_num = 0 self.merit = 0 self.boss_id = boss_id self.arise_time = utils.get_start_second(now) self.start_time = start_time self.end_time = end_time self.total_soldier_num = total_soldier_num self.current_soldier_num = total_soldier_num arrays = [] mod = user_level % 5 self.level = user_level - mod #阵容key的形式为bossId_level_index arrays.append("%s_%s_%s" % (self.boss_id, self.level, 1)) arrays.append("%s_%s_%s" % (self.boss_id, self.level, 2)) arrays.append("%s_%s_%s" % (self.boss_id, self.level, 3)) self.arrays_id = utils.join_to_string(arrays) self.description = description self.calc_can_attack_array_index(0, 0) logger.debug("Arise worldboss[boss_id=%d][arise_time=%d][start_time=%d][end_time=%d][user_level=%d]"\ % (self.boss_id, self.arise_time, self.start_time, self.end_time, user_level)) return True
def _calc_card_deadline(self, deadline, duration_day, now): """计算月卡截止期 """ seconds = duration_day * 86400 if deadline == 0: #当前用户无月卡,从今天起始(5点)开始计时 start = utils.get_start_second(now) return start + seconds else: #当前用户有月卡,延长相应时间 return deadline + seconds
def reset(self, now): """重置anneal相关信息 Returns: None """ self.buy_num = 0 anneal_max_floor = int( float(data_loader.AnnealConfInfo_dict['anneal_max_floor'].value)) array = [0] * anneal_max_floor self.hard_attack_num = utils.join_to_string(array) self.hard_reset_num = utils.join_to_string(array) tomorrow = now + utils.SECONDS_OF_DAY self.next_refresh_time = utils.get_start_second(tomorrow)
def reset(self, now): """重置energy相关信息 Returns: None """ self.buy_num = 0 self.trigger_scout_num = 0 self.trigger_tax_num = 0 self.trigger_farm_num = 0 self.trigger_mining_num = 0 self.trigger_gold_num = 0 self.trigger_jungle_num = 0 self.trigger_dungeon_num = 0 self.trigger_visit_num = 0 self.trigger_search_num = 0 self.trigger_deep_mining_num = 0 self.trigger_hermit_num = 0 tomorrow = now + utils.SECONDS_OF_DAY self.next_refresh_time = utils.get_start_second(tomorrow)
def calc_next_refresh_time(self, now): tomorrow = now + utils.SECONDS_OF_DAY self.next_refresh_time = utils.get_start_second(tomorrow)
def pack_worldboss_info(worldboss, user, message, now): """打包世界boss信息 """ open_flags = account_business.get_flags() if "is_server_open_worldboss" not in open_flags: message.status = WorldBossInfo.DISABLE return True if not worldboss.is_unlock(): message.status = WorldBossInfo.LOCKED message.limit_level = int(float(data_loader.OtherBasicInfo_dict["unlock_worldboss_level"].value)) return message.kill_user_name = base64.b64decode(worldboss.kill_user_name) message.kill_user_id = worldboss.kill_user_id if not worldboss.is_arised(): message.status = WorldBossInfo.INACTIVE message.end_time = 3600 #当前没有boss,一小时后再访问,以免当天更新了boss return else: if now < worldboss.start_time: message.status = WorldBossInfo.BEFORE_BATTLE message.end_time = worldboss.start_time - now + (user.id % 220) elif now > worldboss.end_time: message.status = WorldBossInfo.AFTER_BATTLE message.end_time = utils.get_start_second(now) + 86400 - now#第二天的开始时间即为当天的结束时间 else: message.status = WorldBossInfo.IN_BATTLE message.end_time = worldboss.end_time - now + (user.id % 220) message.total_soldier_num = worldboss.total_soldier_num message.current_soldier_num = worldboss.current_soldier_num message.description = base64.b64decode(worldboss.description) #若未开启,不需要传其他内容 if message.status == WorldBossInfo.BEFORE_BATTLE: return with_detail = True if message.status == WorldBossInfo.AFTER_BATTLE: with_detail = False #if worldboss.is_killed(): # return #阵容 teams = worldboss_business.generate_array_detail(worldboss, user) for i in range(3): team = message.first_teams.add() team.index = i team = message.second_teams.add() team.index = i team = message.third_teams.add() team.index = i for i in range(len(teams[0])): team = message.first_teams[i/3] pack_hero_info(teams[0][i], team.heroes.add(), now, False, with_detail) for i in range(len(teams[1])): team = message.second_teams[i/3] pack_hero_info(teams[1][i], team.heroes.add(), now, False, with_detail) for i in range(len(teams[2])): team = message.third_teams[i/3] pack_hero_info(teams[2][i], team.heroes.add(), now, False, with_detail) #阵容是否可被攻击 for can_attack in worldboss.get_can_attack_arrays_index(): message.can_attack_teams_index.append(can_attack) #阵容的战功系数 for ratio in worldboss.get_arrays_merit_ratio(): message.teams_coefficient.append(ratio)