def banquet_info(rk_user, params): """ * 获取美味大餐的相关内容 * 获取探索的相关内容 * 获得成长礼包的信息 """ ua = rk_user.user_activity user_banquet_info = ua.banquet_info now = datetime.datetime.now() now_date_day = now.strftime('%Y-%m-%d') now_hour_min = now.strftime('%H:%M') banquet_info = {'banquet_msgs': [], 'can_get': False, 'desc': {}} banquet_info['banquet_interval'] = [] open_time_gaps = game_config.operat_config.get('open_stamina_banquet_gaps', []) #获取开放的时间 设置标志位 for gap in open_time_gaps: time_msg = gap[0] + ' -- ' + gap[1] + ':' if user_banquet_info.get(gap): open_msg = utils.get_msg('active', 'already_banquet') elif gap[0] <= now_hour_min <= gap[1]: open_msg = utils.get_msg('active', 'in_time') banquet_info['can_get'] = True else: open_msg = utils.get_msg('active', 'not_in_time') banquet_info['banquet_msgs'].append(time_msg + open_msg) banquet_info['desc'][time_msg[:-1]] = open_msg time_start = '%s %s:00' % (now_date_day, str(gap[0])) time_end = '%s %s:00' % (now_date_day, str(gap[1])) start_time = utils.string_toTimestamp(time_start) end_time = utils.string_toTimestamp(time_end) banquet_info['banquet_interval'].append(start_time) banquet_info['banquet_interval'].append(end_time) time_lists = sorted( [str(time_list) for time_list in banquet_info['banquet_interval']]) banquet_info['am_start'] = time_lists[0] banquet_info['am_end'] = time_lists[1] banquet_info['pm_start'] = time_lists[2] banquet_info['pm_end'] = time_lists[3] banquet_info.pop('banquet_interval') banquet_info['am_flag'] = user_banquet_info.get(banquet_info['am_start'], False) banquet_info['pm_flag'] = user_banquet_info.get(banquet_info['pm_start'], False) # 获取探索的相关内容 # explore_info = get_explore_info(rk_user) # 获取成长礼包相关内容 growup_info = get_growup_info(rk_user, params) # 判断新手引导 newbie_step = int(params.get('newbie_step', 0)) if newbie_step: rk_user.user_property.set_newbie_steps(newbie_step, "banquet_info") return { 'banquet_info': banquet_info, # 'explore_info': explore_info, 'growup_info': growup_info, }
def banquet_info(rk_user, params): """ * 获取美味大餐的相关内容 * 获取探索的相关内容 * 获得成长礼包的信息 """ ua = rk_user.user_activity user_banquet_info = ua.banquet_info now = datetime.datetime.now() now_date_day = now.strftime('%Y-%m-%d') now_hour_min = now.strftime('%H:%M') banquet_info = {'banquet_msgs': [], 'can_get': False,'desc':{}} banquet_info['banquet_interval'] = [] open_time_gaps = game_config.operat_config.get('open_stamina_banquet_gaps', []) #获取开放的时间 设置标志位 for gap in open_time_gaps: time_msg = gap[0] + ' -- ' + gap[1] + ':' if user_banquet_info.get(gap): open_msg = utils.get_msg('active', 'already_banquet') elif gap[0] <= now_hour_min <= gap[1]: open_msg = utils.get_msg('active', 'in_time') banquet_info['can_get'] = True else: open_msg = utils.get_msg('active', 'not_in_time') banquet_info['banquet_msgs'].append(time_msg + open_msg) banquet_info['desc'][time_msg[:-1]] = open_msg time_start = '%s %s:00'%(now_date_day,str(gap[0])) time_end = '%s %s:00'%(now_date_day,str(gap[1])) start_time = utils.string_toTimestamp(time_start) end_time = utils.string_toTimestamp(time_end) banquet_info['banquet_interval'].append(start_time) banquet_info['banquet_interval'].append(end_time) time_lists = sorted([str(time_list) for time_list in banquet_info['banquet_interval']]) banquet_info['am_start'] = time_lists[0] banquet_info['am_end'] = time_lists[1] banquet_info['pm_start'] = time_lists[2] banquet_info['pm_end'] = time_lists[3] banquet_info.pop('banquet_interval') banquet_info['am_flag'] = user_banquet_info.get(banquet_info['am_start'],False) banquet_info['pm_flag'] = user_banquet_info.get(banquet_info['pm_start'],False) # 获取探索的相关内容 # explore_info = get_explore_info(rk_user) # 获取成长礼包相关内容 growup_info = get_growup_info(rk_user, params) # 判断新手引导 newbie_step = int(params.get('newbie_step', 0)) if newbie_step: rk_user.user_property.set_newbie_steps(newbie_step, "banquet_info") return { 'banquet_info': banquet_info, # 'explore_info': explore_info, 'growup_info': growup_info, }
def get_banquet_stamina(): """ 开始宴席 params: click_num: 玩家点击次数,据此来算玩家回体数 """ open_time_gaps = game_config.operat_config.get('open_stamina_banquet_gaps', []) now = datetime.datetime.now() now_date_day = now.strftime('%Y-%m-%d') now_hour_min = now.strftime('%H:%M') this_time_gap = utils.between_gap(now_hour_min, open_time_gaps) if not this_time_gap: return 11,{'msg':utils.get_msg('active', 'not_in_time')} #获取时间区间的最小值 time_start = '%s %s:00'%(now_date_day,str(this_time_gap[0])) start_time = utils.string_toTimestamp(time_start) #查询是否已经领取体力 ul = UserLogin.get_instance(uid) ul.banquet_info[str(start_time)] = False ul.do_put() banquet_info = ul.banquet_info if banquet_info.get(str(start_time), False): return 11, {'msg':utils.get_msg('active', 'already_banquet')} #根据点击次数获取可以领取多少体力 click_num = 30 click_num_awards_conf = game_config.operat_config.get('banquet_click_num_awards', {}) suitable_gap = utils.between_gap(click_num, click_num_awards_conf) get_stamina = click_num_awards_conf.get(suitable_gap, 0) user_property = UserProperty.get_instance(uid) user_property.add_stamina(get_stamina) print get_stamina return {'add_stamina': get_stamina}
def get_banquet_stamina(rk_user, params): """ 开始宴席 """ open_time_gaps = game_config.operat_config.get('open_stamina_banquet_gaps', []) now = datetime.datetime.now() now_date_day = now.strftime('%Y-%m-%d') now_hour_min = now.strftime('%H:%M') this_time_gap = utils.between_gap(now_hour_min, open_time_gaps) if not this_time_gap: return 11,{'msg':utils.get_msg('active', 'not_in_time')} # 获取时间区间的最小值 time_start = '%s %s:00'%(now_date_day,str(this_time_gap[0])) start_time = utils.string_toTimestamp(time_start) #查询是否已经领取体力 ua = rk_user.user_activity banquet_info = ua.banquet_info if banquet_info.get(str(start_time), False): return 11, {'msg':utils.get_msg('active', 'already_banquet')} # 获取可以领取多少体力 get_stamina = game_config.operat_config.get('banquet_click_get_stamina', 50) # 运营活动 特定时间内收益翻倍 multiply_income_conf = rk_user.game_config.operat_config.get("multiply_income", {}).get("banquet", {}) get_stamina = get_stamina * multiply_income(multiply_income_conf) ua.banquet_info[str(start_time)] = True ua.put() rk_user.user_property.add_stamina(get_stamina) return 0, {'add_stamina': get_stamina}
def auto_refresh_store(self): """ 根据 next_auto_refresh_time 判断是否刷新商品, 重置每日可刷新次数 """ now = datetime.datetime.now() now_timestamp = utils.datetime_toTimestamp(now) if now_timestamp > self.next_auto_refresh_time: # 时间点到,自动刷新pk商店 now_date = now.strftime('%Y-%m-%d') now_time = now.strftime('%H:%M:%S') tomorrow_now = now + datetime.timedelta(days=1) tomorrow_date = tomorrow_now.strftime('%Y-%m-%d') pk_store_config = self.game_config.pk_store_config refresh_time = pk_store_config.get('auto_refresh_time', '22:00:00') if now_time > refresh_time: next_refresh_time_str = '%s %s' % (tomorrow_date, refresh_time) else: next_refresh_time_str = '%s %s' % (now_date, refresh_time) # 更新自动刷新时间 next_refresh_time = utils.string_toTimestamp(next_refresh_time_str) self.next_auto_refresh_time = next_refresh_time # 重置可刷新次数 self.manual_refresh_times = 0 self.put() # 自动刷新时间,刷新商店物品 self.refresh_store_goods() return self.store_info()
def get_honor_award(self): data = {} user_real_pvp = UserRealPvp.get_instance(self.uid) r = user_real_pvp.yesterday_pvp_rank( ) # 变量名r和配置里的一致.pk_config 'get_honor':'1400-4*(r-50)' rank_conf = user_real_pvp.get_pvp_rank_conf(r) if not rank_conf: return data get_honor = eval(str(rank_conf['get_honor'])) now = datetime.datetime.now() now_timestamp = utils.datetime_toTimestamp(now) # 能够得到功勋奖励,刷新时间并放入奖励 if now_timestamp > user_real_pvp.pvp_info.get('next_refresh_time', 0): now_date = now.strftime('%Y-%m-%d') now_time = now.strftime('%H:%M:%S') tomorrow_now = now + datetime.timedelta(days=1) tomorrow_date = tomorrow_now.strftime('%Y-%m-%d') refresh_time = self.game_config.pk_store_config.get( 'auto_refresh_time', '22:00:00') if now_time > refresh_time: next_refresh_time_str = '%s %s' % (tomorrow_date, refresh_time) else: next_refresh_time_str = '%s %s' % (now_date, refresh_time) next_refresh_time = utils.string_toTimestamp(next_refresh_time_str) user_real_pvp.pvp_info['next_refresh_time'] = next_refresh_time user_real_pvp.put() data['honor_award'] = { 'title': u'pvp奖励', 'content': u'功勋奖励', 'award': { 'honor': get_honor } } return data
def store_info(self): """ 返回玩家所有神秘商店信息,以便前端显示 """ user_property_obj = self.user_property refresh_hours_gap = self.game_config.mystery_store_config[ "refresh_hours_gap"] now = datetime.datetime.now() cur_vip_lv = self.user_property.vip_cur_level vip_conf = self.game_config.user_vip_config max_free_fresh_cnt = vip_conf[str(cur_vip_lv)].get( 'max_free_fresh_mystery_store_cnt', 4) # 如果已近达到最大免费刷新数, next_auto_refresh_time为 0 if self.free_refresh_cnt >= max_free_fresh_cnt: next_auto_refresh_time = 0 else: next_refresh_hour = ( (now.hour / refresh_hours_gap) + 1) * refresh_hours_gap % 24 day_num = now.day if next_refresh_hour else now.day + 1 next_auto_refresh_time_str = str( datetime.datetime(now.year, now.month, day_num, next_refresh_hour)) next_auto_refresh_time = utils.string_toTimestamp( next_auto_refresh_time_str) mystery_store_info = { "store": self.store, "fight_soul": user_property_obj.get_fight_soul, "next_auto_refresh_time": next_auto_refresh_time, "free_refresh_cnt": self.free_refresh_cnt, } return mystery_store_info
def get_banquet_stamina(rk_user, params): """ 开始宴席 """ open_time_gaps = game_config.operat_config.get('open_stamina_banquet_gaps', []) now = datetime.datetime.now() now_date_day = now.strftime('%Y-%m-%d') now_hour_min = now.strftime('%H:%M') this_time_gap = utils.between_gap(now_hour_min, open_time_gaps) if not this_time_gap: return 11, {'msg': utils.get_msg('active', 'not_in_time')} # 获取时间区间的最小值 time_start = '%s %s:00' % (now_date_day, str(this_time_gap[0])) start_time = utils.string_toTimestamp(time_start) #查询是否已经领取体力 ua = rk_user.user_activity banquet_info = ua.banquet_info if banquet_info.get(str(start_time), False): return 11, {'msg': utils.get_msg('active', 'already_banquet')} # 获取可以领取多少体力 get_stamina = game_config.operat_config.get('banquet_click_get_stamina', 50) # 运营活动 特定时间内收益翻倍 multiply_income_conf = rk_user.game_config.operat_config.get( "multiply_income", {}).get("banquet", {}) get_stamina = get_stamina * multiply_income(multiply_income_conf) ua.banquet_info[str(start_time)] = True ua.put() rk_user.user_property.add_stamina(get_stamina) return 0, {'add_stamina': get_stamina}
def get_honor_award(self): data = {} user_real_pvp = UserRealPvp.get_instance(self.uid) r = user_real_pvp.yesterday_pvp_rank() # 变量名r和配置里的一致.pk_config 'get_honor':'1400-4*(r-50)' rank_conf = user_real_pvp.get_pvp_rank_conf(r) if not rank_conf: return data get_honor = eval(str(rank_conf['get_honor'])) now = datetime.datetime.now() now_timestamp = utils.datetime_toTimestamp(now) # 能够得到功勋奖励,刷新时间并放入奖励 if now_timestamp > user_real_pvp.pvp_info.get('next_refresh_time', 0): now_date = now.strftime('%Y-%m-%d') now_time = now.strftime('%H:%M:%S') tomorrow_now = now + datetime.timedelta(days=1) tomorrow_date = tomorrow_now.strftime('%Y-%m-%d') refresh_time = self.game_config.pk_store_config.get('auto_refresh_time', '22:00:00') if now_time > refresh_time: next_refresh_time_str = '%s %s' % (tomorrow_date, refresh_time) else: next_refresh_time_str = '%s %s' % (now_date, refresh_time) next_refresh_time = utils.string_toTimestamp(next_refresh_time_str) user_real_pvp.pvp_info['next_refresh_time'] = next_refresh_time user_real_pvp.put() data['honor_award'] = { 'title': u'pvp奖励', 'content': u'功勋奖励', 'award': {'honor': get_honor} } return data
def store_info(self): """ 返回玩家所有神秘商店信息,以便前端显示 """ user_property_obj = self.user_property refresh_hours_gap = self.game_config.mystery_store_config["refresh_hours_gap"] now = datetime.datetime.now() cur_vip_lv = self.user_property.vip_cur_level vip_conf = self.game_config.user_vip_config max_free_fresh_cnt = vip_conf[str(cur_vip_lv)].get('max_free_fresh_mystery_store_cnt', 4) # 如果已近达到最大免费刷新数, next_auto_refresh_time为 0 if self.free_refresh_cnt >= max_free_fresh_cnt: next_auto_refresh_time = 0 else: next_refresh_hour = ((now.hour / refresh_hours_gap) + 1) * refresh_hours_gap % 24 day_num = now.day if next_refresh_hour else now.day + 1 next_auto_refresh_time_str = str(datetime.datetime(now.year, now.month, day_num, next_refresh_hour)) next_auto_refresh_time = utils.string_toTimestamp(next_auto_refresh_time_str) mystery_store_info = { "store": self.store, "fight_soul": user_property_obj.get_fight_soul, "next_auto_refresh_time": next_auto_refresh_time, "free_refresh_cnt": self.free_refresh_cnt, } return mystery_store_info
def look_diff(): now = datetime.datetime.now() now_date_day = now.strftime('%Y-%m-%d') now_hour_min = now.strftime('%H:%M') time_start = '%s %s:00'%(now_date_day,'10:00') time_end = '%s %s:00'%(now_date_day,'15:00') start_time =datetime.datetime.strptime(time_start,'%Y-%m-%d %H:%M:%S') end_time =datetime.datetime.strptime(time_end,'%Y-%m-%d %H:%M:%S') start_time = int(time.mktime(start_time.timetuple())) end_time = int(time.mktime(end_time.timetuple())) print start_time, end_time print '*'*100 start_time = utils.string_toTimestamp(time_start) end_time = utils.string_toTimestamp(time_end) print start_time, end_time