def get_today_copy_info(self,dungeon_type,floor_id,room_id): ''' * miaoyichao * 获取今日可打副本的次数和总共打的次数 ''' #real_config实际的配置信息 # if dungeon_type == 'special': # real_config = self.game_config.special_dungeon_config if dungeon_type == 'daily': real_config = self.game_config.daily_dungeon_config else: real_config = self.game_config.normal_dungeon_config #判断战场类型 计算正常情况下可以打多少次 默认10次 if dungeon_type == 'daily': #每日战场是根据 floor 信息进行确认打多少次的 cur_can_in = real_config[floor_id].get('can_make_copy_cn',10) else: cur_can_in = real_config[floor_id]['rooms'][room_id].get('can_make_copy_cn',10) #获取战场当前已经打的信息 dungeon_repeat_info = self.dungeon_repeat_info #获取当天信息 today_str = utils.get_today_str() if today_str == dungeon_repeat_info['today_str']: if dungeon_type == 'daily': try: #去找该floor已经打过多少次 has_repeat_times = dungeon_repeat_info[dungeon_type][floor_id] except: #没有找到的时候就知道该战场没有被打过 那么就直接返回0即可 has_repeat_times = 0 elif dungeon_type == 'normal': try: #去找该room已经打过多少次 has_repeat_times = dungeon_repeat_info[dungeon_type][floor_id][room_id] except: #没有找到的时候就知道该战场没有被打过 那么就直接返回0即可 has_repeat_times = 0 else: #日期过期重置 dungeon_repeat_info = { 'today_str':utils.get_today_str(), } self.put() has_repeat_times = 0 #格式化要返回的参数 all_times = cur_can_in left_times = all_times - has_repeat_times data = {} data['all_times'] = all_times data['left_times'] = left_times return data
def get_recover_times(self): ''' * 获取今日可回复次数 miaoyichao ''' data = {} all_dungeon = ['normal', 'daily', 'special'] #获取vip等级 vip_lv = self.vip_cur_level vip_conf = self.game_config.user_vip_config user_config = vip_conf.get(str(vip_lv), {}) today_str = utils.get_today_str() recover_list = [ 'recover_stamina', 'recover_pvp_stamina', 'recover_mystery_store' ] recover_times = self.property_info['recover_times'] if recover_times['today_str'] == today_str: for recover in recover_list: data[recover] = user_config['can_' + recover + '_cnt'] - recover_times[recover] data['recover_copy'] = {} for i in all_dungeon: data['recover_copy'][i] = user_config['can_recover_copy_cnt'][ i] - recover_times['recover_copy'][i] else: self.reset_recover_times() data = self.property_info['recover_times'] return data
def reset_daily_info(self): ''' 主要是判断日期,做一下重置 ''' data = {} daily_task = game_config.task_config['daily_task'] today_str = utils.get_today_str() if today_str != self.daily_info['today']: # 重置任务 # 检查一下是否有未领取的宝箱,有的话发邮件 self.__send_yesterday_mail() # 重置数据 for k, v in daily_task.items(): data[k] = {'current': 0, 'clear': False} self.daily_info['tasks'] = data self.daily_info['today'] = today_str self.daily_info['points'] = 0 self.daily_info['has_got'] = { 'copper': False, 'silver': False, 'gold': False, } self.put() else: data = self.daily_info['tasks'] return data
def __init__(self): """初始化用户好友信息 Args: uid: 平台用户ID """ self.uid = None self.friends = {} self.requests = {} self.self_requests = {} self.lock_friends = [] self.friend_gift = { 'upd_time':utils.get_today_str(), 'send_fids':[],#已经送出的好友列表 'receive_fids':[],#已经收到的好友列表 'want_gift':['','',''],#想要的礼物 'gift_award':{},#收到的礼物 } self.invite_info = { 'inviter':'', 'got_invite_award':[], 'invite_users':{}, 'total_invited_usernum':0, 'reset_invite_date': '2013', }
def __init__(self): """类初期化函数 Args: uid: string 用户ID return: 无返回值 """ self.uid = '' self.dungeon_info = {} #记录失败获取的信息,失败会触发送相应礼物 self.dungeon_fail_list = [] #记录用户当天的战场重复进入次数的信息 self.dungeon_repeat_info = { 'today_str':utils.get_today_str(), 'special':{}, 'weekly':{}, 'daily':{}, 'normal':{}, } #记录用户已经打过的战场信息 self.has_played_info = { 'normal':{}, 'special':{}, 'weekly':{}, 'daily':{}, }
def __init__(self): """初始化用户好友信息 Args: uid: 平台用户ID """ self.uid = None self.friends = {} self.requests = {} self.self_requests = {} self.lock_friends = [] self.friend_gift = { 'upd_time': utils.get_today_str(), 'send_fids': [], #已经送出的好友列表 'receive_fids': [], #已经收到的好友列表 'want_gift': ['', '', ''], #想要的礼物 'gift_award': {}, #收到的礼物 } self.invite_info = { 'inviter': '', 'got_invite_award': [], 'invite_users': {}, 'total_invited_usernum': 0, 'reset_invite_date': '2013', }
def _install(cls, uid): """为新用户初始安装好友信息 Args: uid: 用户ID Returns: friend: 用户好友信息对象实例 """ friend = cls() friend.uid = uid friend.friends = {} friend.requests = {} friend.self_requests = {} friend.lock_friends = [] friend.friend_gift = { 'upd_time': utils.get_today_str(), 'send_fids': [], #已经送出的好友列表 'receive_fids': [], #已经收到的好友列表 'want_gift': ['', '', ''], #想要的礼物 'gift_award': {}, #收到的礼物 } friend.invite_info = { 'inviter': '', 'got_invite_award': [], 'invite_users': {}, 'total_invited_usernum': 0, } friend.put() return friend
def check_limit_recover(rk_user, where, dtype='', floor_id=''): """根据用户的vip等级判断用户当天是否达到回复次数""" user_property_obj = rk_user.user_property vip_lv = str(user_property_obj.vip_cur_level) today_str = utils.get_today_str() now_recover_times = 0 if today_str == user_property_obj.property_info['recover_times']['today_str']: if where in ['recover_stamina', 'recover_mystery_store']: # 回复体力的处理 max_recover_times = game_config.user_vip_config[vip_lv].get('can_'+where+'_cnt', 0) now_recover_times = user_property_obj.property_info['recover_times'][where] if max_recover_times <= now_recover_times: raise GameLogicError('user','max_times') elif where == 'recover_copy': # 重置战场的处理 if dtype == 'normal': max_recover_times = game_config.user_vip_config[vip_lv]['can_recover_copy_cnt']['normal'] now_recover_times = user_property_obj.property_info['recover_times']['recover_copy']['normal'] elif dtype == 'daily': max_recover_times = game_config.user_vip_config[vip_lv]['can_recover_copy_cnt']['daily'][floor_id] now_recover_times = user_property_obj.property_info['recover_times']['recover_copy']['daily'].get(floor_id, 0) if max_recover_times <= now_recover_times: raise GameLogicError('user','max_times') else: # 重置时间和副本次数 user_property_obj.reset_recover_times() return now_recover_times
def check_limit_recover(rk_user, where, dtype='', floor_id=''): """根据用户的vip等级判断用户当天是否达到回复次数""" user_property_obj = rk_user.user_property vip_lv = str(user_property_obj.vip_cur_level) today_str = utils.get_today_str() now_recover_times = 0 if today_str == user_property_obj.property_info['recover_times'][ 'today_str']: if where in ['recover_stamina', 'recover_mystery_store']: # 回复体力的处理 max_recover_times = game_config.user_vip_config[vip_lv].get( 'can_' + where + '_cnt', 0) now_recover_times = user_property_obj.property_info[ 'recover_times'][where] if max_recover_times <= now_recover_times: raise GameLogicError('user', 'max_times') elif where == 'recover_copy': # 重置战场的处理 if dtype == 'normal': max_recover_times = game_config.user_vip_config[vip_lv][ 'can_recover_copy_cnt']['normal'] now_recover_times = user_property_obj.property_info[ 'recover_times']['recover_copy']['normal'] elif dtype == 'daily': max_recover_times = game_config.user_vip_config[vip_lv][ 'can_recover_copy_cnt']['daily'][floor_id] now_recover_times = user_property_obj.property_info[ 'recover_times']['recover_copy']['daily'].get(floor_id, 0) if max_recover_times <= now_recover_times: raise GameLogicError('user', 'max_times') else: # 重置时间和副本次数 user_property_obj.reset_recover_times() return now_recover_times
def show_open_server_gift(rk_user, params): ''' 返回开服奖励的礼包 ''' ug = rk_user.user_gift ul = rk_user.user_login add_time = utils.timestamp_toDatetime(rk_user.add_time) now = datetime.datetime.now() today = utils.get_today_str() # 初始化 if not ug.open_server_record['gifts']: # 'gifts'按领取天数记录奖励是否领取,比如登录过10天,但只领过一次,这时gifts记录的是['1']['has_got']=True ,其他为False # 因为每天只能领取一次,'date_info'用来按日期记录哪天是否已领过一次 #ug.open_server_record = {'gifts': {}, 'date_info': {}} for day in range(1, 32): ug.open_server_record['gifts'].setdefault(str(day), {})['has_got'] = False ug.put() data = {'gifts': {}} # 账号注册已达45天(包括注册当天),或者全部领取了,则清空全部开服礼包 if (now - add_time).days + 1 > 45 or ug.has_got_all_open_server_gifts(): return 0, data awards = game_config.loginbonus_config['open_server_gift'].get('awards', {}) for days, award in awards.items(): data['gifts'].setdefault(days, {})['awards'] = award data['gifts'][days]['has_got'] = ug.open_server_record['gifts'][days]['has_got'] # 给前端现实能否领取,不需存在model中 if int(days) == ug.total_open_days+1 and not ug.open_server_record['date_info'].get(today, False): data['gifts'][days]['can_get'] = True else: data['gifts'][days]['can_get'] = False return 0, data
def get_open_server_gift(rk_user, params): ''' 领取开服礼包中的奖励 参数 params['day'] 第几次领 ''' day = params['day'] ug = rk_user.user_gift ul = rk_user.user_login awards = game_config.loginbonus_config['open_server_gift'].get('awards', {}) if day not in awards.keys(): return 11, {'msg': utils.get_msg('gift', 'gift_not_exist')} the_gift = ug.open_server_record['gifts'][day] if the_gift['has_got']: return 11, {'msg': utils.get_msg('gift', 'gift_has_got')} # 一天只能领一次 today = utils.get_today_str() if ug.open_server_record['date_info'].get(today, False): return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')} # 按顺序领取 if int(day) != ug.total_open_days+1: return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')} this_award = awards[day] data = tools.add_things( rk_user, [{"_id": goods, "num": this_award[goods]} for goods in this_award if goods], where="open_server_gift" ) the_gift['has_got'] = True # 因为每天只能领取一次,'date_info'用来按日期记录哪天是否已领过一次 ug.open_server_record['date_info'][today] = True ug.put() return 0, data
def show_open_server_gift(rk_user, params): ''' 返回开服奖励的礼包 ''' ug = rk_user.user_gift ul = rk_user.user_login add_time = utils.timestamp_toDatetime(rk_user.add_time) now = datetime.datetime.now() today = utils.get_today_str() # 初始化 if not ug.open_server_record: # 'gifts'按领取天数记录奖励是否领取,比如登录过10天,但只领过一次,这时gifts记录的是['1']['has_got']=True ,其他为False # 因为每天只能领取一次,'date_info'用来按日期记录哪天是否已领过一次 ug.open_server_record = {'gifts': {}, 'date_info': {}} for day in range(1, 32): ug.open_server_record['gifts'].setdefault(str(day), {})['has_got'] = False ug.do_put() # 账号注册已达45天(包括注册当天),或者全部领取了,则清空全部开服礼包 if (now - add_time).days + 1 > 45 or ug.has_got_all_open_server_gifts(): ug.clear_open_server_gift() return 11, {'msg': utils.get_msg('gift','clear_open_server')} awards = game_config.loginbonus_config['open_server_gift'].get('awards', {}) data = {'gifts': {}} for days, award in awards.items(): data['gifts'].setdefault(days, {})['awards'] = award #data['gifts'][days]['has_got'] = ug.open_server_record.setdefault(days, {}).setdefault('has_got', False) data['gifts'][days]['has_got'] = ug.open_server_record['gifts'][days]['has_got'] # 给前端现实能否领取,不需存在model中 #data['gifts'][days]['can_get'] = True if ul.total_login_num >= int(days) else False if int(days) == _got_days(ug)+1 and not ug.open_server_record['date_info'].get(today, False): data['gifts'][days]['can_get'] = True else: data['gifts'][days]['can_get'] = False ug.do_put() return 0, data
def _install(cls,uid): """为新用户初始安装好友信息 Args: uid: 用户ID Returns: friend: 用户好友信息对象实例 """ friend = cls() friend.uid = uid friend.friends = {} friend.requests = {} friend.self_requests = {} friend.lock_friends = [] friend.friend_gift = { 'upd_time':utils.get_today_str(), 'send_fids':[],#已经送出的好友列表 'receive_fids':[],#已经收到的好友列表 'want_gift':['','',''],#想要的礼物 'gift_award':{},#收到的礼物 } friend.invite_info = { 'inviter':'', 'got_invite_award':[], 'invite_users':{}, 'total_invited_usernum':0, } friend.put() return friend
def get_open_server_gift(rk_user, params): ''' 领取开服礼包中的奖励 参数 params['day'] 第几次领 ''' #day = params['day'] day = '5' ug = rk_user.user_gift ul = rk_user.user_login awards = game_config.loginbonus_config['open_server_gift'].get('awards', {}) if day not in awards.keys(): return 11, {'msg': utils.get_msg('gift', 'gift_not_exist')} the_gift = ug.open_server_record['gifts'][day] if the_gift['has_got']: return 11, {'msg': utils.get_msg('gift', 'gift_has_got')} today = utils.get_today_str() if ug.open_server_record['date_info'].get(today, False): return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')} # 按顺序领取 if int(day) != _got_days(ug)+1: return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')} data = tools.add_things( rk_user, [{"_id": goods, "num": awards[goods]} for goods in awards if goods], where="open_server_gift" ) the_gift['has_got'] = True # 因为每天只能领取一次,'date_info'用来按日期记录哪天是否已领过一次 ug.open_server_record['date_info'][today] = True ug.do_put() return 0, data
def get_explore_times(self): #获取可探索的次数 today_str = utils.get_today_str() if 'today_str' not in self.explore or today_str != self.explore['today_str']: self.reset_explore_times() explore_copy = copy.deepcopy(self.explore) explore_copy.pop('today_str') return explore_copy
def create(cls,uid): up = cls() up.uid = uid up.charge_award_info = {} up.consume_award_info = {} up.property_info = { 'exp':0,#经验值 'lv':1, 'gold':0, 'coin':0, 'stamina':0, 'card_exp_point': 1000, # 拥有的武将经验点数 'fight_soul': 0, #战魂 'stamina_upd_time': int(time.time()), 'newbie': False, # 是否新手 'newbie_steps':0, # 已完成的新手步骤 'bind_award':True, 'has_bought_vip_package':[], #Vip等级所购买的vip礼包 只可以买一次 'charge_coins': 0, # 总共充值的人民币 'charge_money': 0, # 总共购买过元宝数 'charge_item_bought_times': {}, # 每种充值商品已购买次数 'monthCard_remain_days': {}, # 每种月卡剩余使用天数 'monthCard30': 29 "update_award":[], #版本更新奖励 'charged_user':False,#是否付费用户,包含大礼包 'recover_times':{ 'today_str':utils.get_today_str(), 'recover_stamina':0, #回复体力次数 'recover_pvp_stamina':0, #回复PVP次数 'recover_mystery_store':0, #刷新神秘商店的次数 'recover_copy':{ 'normal':0, 'special':0, 'daily': {}, }, #刷新副本次数 }, #使用元宝购买回复的次数 'wipe_out_times': 0, # 当天已扫荡次数 } # 初始化每个试炼战场回复次数都为0 daily_floods = up.game_config.daily_dungeon_config.keys() for daily_flood in daily_floods: up.property_info['recover_times']['recover_copy']['daily'][daily_flood] = 0 # 用户初始化 体力值 userLevelMod = UserLevelMod.get(str(up.property_info['lv']), game_config=up.game_config) up.property_info['stamina'] = userLevelMod.stamina # 用户初始化 铜钱 元宝等 user_info_init = up.game_config.user_init_config["init_user_info"] up.property_info.update(user_info_init) up.put() return up
def refresh_info(self): """ 刷新信息 """ today_str = utils.get_today_str() if today_str != self.friend_gift['upd_time']: self.friend_gift['upd_time'] = today_str self.friend_gift['send_fids'] = [] self.friend_gift['receive_fids'] = [] self.put()
def refresh_daily_info(self): """ 每日根据当天日期,决定是否要刷新数据 """ today = utils.get_today_str() if today != self.dungeon_info.get('today'): self.__reset_once_daily_and_open_special() self.dungeon_info['free_stamina_cnt'] = 0 self.dungeon_info['today'] = today self.put()
def create(cls, uid): user_gift_obj = UserGift() user_gift_obj.uid = uid user_gift_obj.gift_list = {} user_gift_obj.today = utils.get_today_str() user_gift_obj.gift_code_type = [] user_gift_obj.gift_code_info = { 'lv_up': {}, } user_gift_obj.has_got_gift_code = {} return user_gift_obj
def create(cls,uid): user_gift_obj = UserGift() user_gift_obj.uid = uid user_gift_obj.gift_list = {} user_gift_obj.today = utils.get_today_str() user_gift_obj.gift_code_type = [] user_gift_obj.gift_code_info = { 'lv_up':{}, } user_gift_obj.has_got_gift_code = {} return user_gift_obj
def reset_explore_times(self): #重置可探索的次数 self.explore = {} self.explore['today_str'] = utils.get_today_str() explore_times_config = self.game_config.operat_config.get('can_explore_times',{}) #重置次数 for explore_type in ['gold','silver','copper']: self.explore[explore_type] = explore_times_config.get(explore_type,3) #结果保存 self.put() return self.explore
def create(cls, uid): up = cls() up.uid = uid up.charge_award_info = {} up.consume_award_info = {} up.property_info = { 'exp': 0, #经验值 'lv': 1, 'gold': 0, 'coin': 0, 'stamina': 0, 'card_exp_point': 1000, # 拥有的武将经验点数 'fight_soul': 0, #战魂 'stamina_upd_time': int(time.time()), 'newbie': False, # 是否新手 'newbie_steps': 0, # 已完成的新手步骤 'bind_award': True, 'has_bought_vip_package': [], #Vip等级所购买的vip礼包 只可以买一次 'charge_coins': 0, # 总共充值的人民币 'charge_money': 0, # 总共购买过元宝数 'charge_item_bought_times': {}, # 每种充值商品已购买次数 'monthCard_remain_days': {}, # 每种月卡剩余使用天数 'monthCard30': 29 "update_award": [], #版本更新奖励 'charged_user': False, #是否付费用户,包含大礼包 'recover_times': { 'today_str': utils.get_today_str(), 'recover_stamina': 0, #回复体力次数 'recover_pvp_stamina': 0, #回复PVP次数 'recover_mystery_store': 0, #刷新神秘商店的次数 'recover_copy': { 'normal': 0, 'special': 0, 'daily': {}, }, #刷新副本次数 }, #使用元宝购买回复的次数 'wipe_out_times': 0, # 当天已扫荡次数 } # 初始化每个试炼战场回复次数都为0 daily_floods = up.game_config.daily_dungeon_config.keys() for daily_flood in daily_floods: up.property_info['recover_times']['recover_copy']['daily'][ daily_flood] = 0 # 用户初始化 体力值 userLevelMod = UserLevelMod.get(str(up.property_info['lv']), game_config=up.game_config) up.property_info['stamina'] = userLevelMod.stamina # 用户初始化 铜钱 元宝等 user_info_init = up.game_config.user_init_config["init_user_info"] up.property_info.update(user_info_init) up.put() return up
def refresh_info(self): """ 要刷新数据,过期数据清除 """ today = utils.get_today_str() if today != self.today: self.today = today gift_list = self.gift_list gift_list_copy = copy.deepcopy(gift_list) now = datetime.datetime.now() for _index in gift_list_copy: upd_time = gift_list[_index]['upd_time'] has_got = gift_list_copy[_index].get('has_got',0) #奖励已经领过,并且过期7天则删除 if has_got and now >= utils.timestamp_toDatetime(upd_time) + datetime.timedelta(days=7): gift_list.pop(_index) self.put()
def refresh_info(self): """ 要刷新数据,过期数据清除 """ today = utils.get_today_str() if today != self.today: self.today = today gift_list = self.gift_list gift_list_copy = copy.deepcopy(gift_list) now = datetime.datetime.now() for _index in gift_list_copy: upd_time = gift_list[_index]['upd_time'] has_got = gift_list_copy[_index].get('has_got', 0) #奖励已经领过,并且过期7天则删除 if has_got and now >= utils.timestamp_toDatetime( upd_time) + datetime.timedelta(days=7): gift_list.pop(_index) self.put()
def get_recover_times(): while True: data = {} all_dungeon = ['normal','daily','special'] #获取vip等级 up = UserProperty.get_instance(uid) vip_lv = up.vip_cur_level vip_conf = game_config.user_vip_conf user_config = vip_conf.get(str(vip_lv),{}) today_str = utils.get_today_str() recover_list = ['recover_stamina','recover_pvp_stamina','recover_mystery_store'] recover_times = up.property_info['recover_times'] if recover_times['today_str'] == today_str: for recover in recover_list: data[recover] = user_config['can_'+recover+'_cnt'] - recover_times[recover] data['recover_copy'] = {} for i in all_dungeon: data['recover_copy'][i] = user_config['can_recover_copy_cnt'][i] - recover_times['recover_copy'][i] else: up.reset_recover_times() data = self.property_info['recover_times'] return data
def reset_recover_times(self): ''' 重置回复次数 input None output None ''' #将所有的回复次数全部清空 代表着新的一天 self.property_info['recover_times']['today_str'] = utils.get_today_str() self.property_info['recover_times']['recover_stamina'] = 0 self.property_info['recover_times']['recover_pvp_stamina'] = 0 self.property_info['recover_times']['recover_mystery_store'] = 0 self.property_info['recover_times']['recover_copy'] = {} self.property_info['recover_times']['recover_copy'] = { 'normal':0, 'special':0, 'daily': {}, } # 初始化每个试炼战场回复次数都为0 daily_floods = self.game_config.daily_dungeon_config.keys() for daily_flood in daily_floods: self.property_info['recover_times']['recover_copy']['daily'][daily_flood] = 0 self.put()
def get_recover_times(self): ''' * 获取今日可回复次数 miaoyichao ''' data = {} all_dungeon = ['normal','daily','special'] #获取vip等级 vip_lv = self.vip_cur_level vip_conf = self.game_config.user_vip_config user_config = vip_conf.get(str(vip_lv),{}) today_str = utils.get_today_str() recover_list = ['recover_stamina','recover_pvp_stamina','recover_mystery_store'] recover_times = self.property_info['recover_times'] if recover_times['today_str'] == today_str: for recover in recover_list: data[recover] = user_config['can_'+recover+'_cnt'] - recover_times[recover] data['recover_copy'] = {} for i in all_dungeon: data['recover_copy'][i] = user_config['can_recover_copy_cnt'][i] - recover_times['recover_copy'][i] else: self.reset_recover_times() data = self.property_info['recover_times'] return data
def reset_recover_times(self): ''' 重置回复次数 input None output None ''' #将所有的回复次数全部清空 代表着新的一天 self.property_info['recover_times']['today_str'] = utils.get_today_str( ) self.property_info['recover_times']['recover_stamina'] = 0 self.property_info['recover_times']['recover_pvp_stamina'] = 0 self.property_info['recover_times']['recover_mystery_store'] = 0 self.property_info['recover_times']['recover_copy'] = {} self.property_info['recover_times']['recover_copy'] = { 'normal': 0, 'special': 0, 'daily': {}, } # 初始化每个试炼战场回复次数都为0 daily_floods = self.game_config.daily_dungeon_config.keys() for daily_flood in daily_floods: self.property_info['recover_times']['recover_copy']['daily'][ daily_flood] = 0 self.put()
def check_limit_dungeon(self,rk_user,params): """ * 检查每天战场可以打多少次 * miaoyichao * 2014-03-27 * ture can fight flase can not fight """ dungeon_type = params['dungeon_type'] floor_id = params['floor_id'] room_id = params['room_id'] dungeon_repeat_info_obj = copy.deepcopy(self.dungeon_repeat_info) today_str = utils.get_today_str() if today_str == dungeon_repeat_info_obj['today_str']: #获取今日战场的类型信息 try: #获取征战多少次 #获取战场类型 db_dungeon_type = dungeon_repeat_info_obj.get(dungeon_type,{}) if dungeon_type == 'normal': #获取floor的id db_floor_id = db_dungeon_type.get(floor_id,{}) if not len(db_floor_id): db_dungeon_type[floor_id] = {} #获取房间id db_room_id = db_dungeon_type[floor_id].get(room_id,0) if not db_room_id: db_dungeon_type[floor_id][room_id] = 0 #因为每日战场的可打次数是整个 floor 的不是每个 room 的 所以要区别对待 if dungeon_type == 'daily': if floor_id not in db_dungeon_type: db_dungeon_type[floor_id] = 0 has_already_conquer = db_dungeon_type[floor_id] else: has_already_conquer = db_dungeon_type[floor_id][room_id] if has_already_conquer: #有征战过该战场 ''' * 根据不同的战场获取不同战场的配置信息中的可以打的次数 * miaoyichao ''' if dungeon_type == 'normal': cur_can_in = self.game_config.normal_dungeon_config[floor_id]['rooms'][room_id].get('can_make_copy_cn',10) elif dungeon_type == 'daily': cur_can_in = self.game_config.daily_dungeon_config[floor_id].get('can_make_copy_cn',10) elif dungeon_type == 'weekly': cur_can_in = self.game_config.weekly_dungeon_config[floor_id]['rooms'][room_id].get('can_make_copy_cn',10) # elif dungeon_type == 'special': # cur_can_in = self.game_config.special_dungeon_config[floor_id]['rooms'][room_id].get('can_make_copy_cn',10) else: cur_can_in = 10 max_repeat = cur_can_in if has_already_conquer>=max_repeat: return False else: return True else: #没有征战过该战场 if dungeon_type == 'daily': #处理每日战场 try: dungeon_repeat_info_obj[dungeon_type][floor_id] = 0 except: dungeon_repeat_info_obj[dungeon_type] = {} dungeon_repeat_info_obj[dungeon_type][floor_id] = 0 else: #处理普通战场 try: dungeon_repeat_info_obj[dungeon_type][floor_id][room_id] = 0 except: dungeon_repeat_info_obj[dungeon_type] = {} dungeon_repeat_info_obj[dungeon_type][floor_id] = {} dungeon_repeat_info_obj[dungeon_type][floor_id][room_id] = 0 except : traceback.print_exc() return False #更新该次操作的信息 self.dungeon_repeat_info.update(dungeon_repeat_info_obj) #保存 self.put() return True else: #战场信息过期 重置战场信息 self.dungeon_repeat_info = { 'today_str':utils.get_today_str(), 'special':{}, 'daily':{}, 'normal':{}, } self.put() return True
def openserver_can_get(self): '''判断今天是否可领取开服礼包''' today_str = utils.get_today_str() return not self.open_server_record['date_info'].get(today_str, False)
def _install(cls, uid): """生成类对象 Args: uid: string 用户ID return: UserDungeon:类对象 """ obj = cls() obj.uid = uid #根据配置生成用户的战场信息 obj.dungeon_info = { 'today':utils.get_today_str(), 'free_stamina_cnt':0, 'normal_current':{ 'floor_id':'1', 'room_id':'1', 'status':0, }, 'last':{}, } # #每周的活动战场数据 # weekly_dungeon = {} # weekly_dungeon_conf = obj.game_config.weekly_dungeon_config # for week_key,week_value in weekly_dungeon_conf.iteritems(): # week_temp = { # 'status':0, # 'rooms':{}, # } # for room_id in week_value['rooms']: # week_temp['rooms'][room_id] = 0 # weekly_dungeon[week_key] = week_temp # obj.dungeon_info['weekly'] = weekly_dungeon #每日的活动战场数据 daily_dungeon = {} daily_dungeon_conf = obj.game_config.daily_dungeon_config for daily_key,daily_value in daily_dungeon_conf.iteritems(): daily_temp = { 'status':0, 'rooms':{}, } for room_id in daily_value['rooms']: daily_temp['rooms'][room_id] = 0 daily_dungeon[daily_key] = daily_temp obj.dungeon_info['daily'] = daily_dungeon #特殊活动的战场数据 # special_dungeon_conf = obj.game_config.special_dungeon_config # special_dungeon = {} # now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # for special_key,special_value in special_dungeon_conf.iteritems(): # if (now_str > special_value['end_time'] or now_str < special_value['start_time']): # continue # special_temp = { # 'status':0, # 'rooms':{}, # } # for room_id in special_value['rooms']: # special_temp['rooms'][room_id] = 0 # special_dungeon[special_key] = special_temp # obj.dungeon_info['special'] = special_dungeon # obj.dungeon_info['record'] = { # 'special':{}, # } obj.put() return obj