def refresh_lv(self,version): """ 刷新等级 """ max_lv = max([int(i) for i in self.game_config.user_level_config.keys()]) new_lv = 1 old_lv = self.lv for next_lv in range(1,max_lv + 1): userLevelMod = UserLevelMod.get(next_lv) if self.property_info['exp'] >= userLevelMod.exp: new_lv = next_lv else: break if old_lv != new_lv: self.property_info['lv'] = new_lv userLevelMod = UserLevelMod.get(new_lv) self.property_info['stamina'] = userLevelMod.stamina #将用户写入新级别对应的用户列表中 subarea = self.user_base.subarea LevelUser.get_instance(subarea, self.lv_region).add_user(self.uid) self.put()
def refresh_lv(self, version): """ 刷新等级 """ max_lv = max( [int(i) for i in self.game_config.user_level_config.keys()]) new_lv = 1 old_lv = self.lv for next_lv in range(1, max_lv + 1): userLevelMod = UserLevelMod.get(next_lv) if self.property_info['exp'] >= userLevelMod.exp: new_lv = next_lv else: break if old_lv != new_lv: self.property_info['lv'] = new_lv userLevelMod = UserLevelMod.get(new_lv) self.property_info['stamina'] = userLevelMod.stamina #将用户写入新级别对应的用户列表中 subarea = self.user_base.subarea LevelUser.get_instance(subarea, self.lv_region).add_user(self.uid) self.put()
def add_exp(self, exp, where=''): ''' 添加用户的经验 不管是加还是扣经验都会触发等级变化 返回: 是否升级, {} ''' #保存变化前的exp from apps.models.user_gift import UserGift old_exp = self.property_info['exp'] old_lv = self.lv new_lv = self.lv self.property_info['exp'] = self.property_info['exp'] + exp while True: new_lv += 1 userLevelMod = UserLevelMod.get(new_lv) if not userLevelMod.exp or self.property_info[ 'exp'] < userLevelMod.exp: new_lv -= 1 break if new_lv > old_lv: #有升级的话就写日志和重新排名 #写日志 log_data = {} log_data['old_exp'] = old_exp log_data['old_lv'] = old_lv log_data['add_exp'] = exp log_data['new_lv'] = new_lv log_data['new_exp'] = self.property_info['exp'] log_data['where'] = where data_log_mod.set_log('UserLevelHistory', self, **log_data) #新等级 self.property_info['lv'] = new_lv userLevelMod = UserLevelMod.get(new_lv) #获取前20000名对应的分数 rank_lv = lv_top_model.get_score(20000) #只有等级能到达50000名的才会进入排行榜 if not rank_lv or new_lv > rank_lv: lv_top_model.set(self.uid, new_lv) #更新体力,cost self.property_info['stamina'] += userLevelMod.lv_stamina #将用户写入新级别对应的用户列表中 subarea = self.user_base.subarea LevelUser.get_instance(subarea, self.lv_region).add_user(self.uid) inviter_uid = Friend.get(self.uid).inviter if inviter_uid: inviter_friend = Friend.get(inviter_uid) else: inviter_friend = None #升级时,检查是否有礼品码的升级奖励 user_gift_obj = UserGift.get_instance(self.uid) user_gift_obj.get_giftcode_lv_up_award() #升级时,检查是否有升级奖励 msg = utils.get_msg('user', 'lv_up_award', self) for lv in range(old_lv + 1, new_lv + 1): if 'award' in self.game_config.user_level_config[str(lv)]: user_gift_obj.add_gift( self.game_config.user_level_config[str(lv)]['award'], msg % lv) #用户升级后,将自己信息写入邀请者 if inviter_friend: inviter_friend.record_invited_user(self.uid, lv) self.user_cards.set_slot_num(new_lv) self.put() return new_lv > old_lv, {}
def add_exp(self, exp, where=''): ''' 添加用户的经验 不管是加还是扣经验都会触发等级变化 返回: 是否升级, {} ''' #保存变化前的exp from apps.models.user_gift import UserGift old_exp = self.property_info['exp'] old_lv = self.lv new_lv = self.lv self.property_info['exp'] = self.property_info['exp'] + exp while True: new_lv += 1 userLevelMod = UserLevelMod.get(new_lv) if not userLevelMod.exp or self.property_info['exp'] < userLevelMod.exp: new_lv -= 1 break if new_lv > old_lv: #有升级的话就写日志和重新排名 #写日志 log_data = {} log_data['old_exp'] = old_exp log_data['old_lv'] = old_lv log_data['add_exp'] = exp log_data['new_lv'] = new_lv log_data['new_exp'] = self.property_info['exp'] log_data['where'] = where data_log_mod.set_log('UserLevelHistory', self, **log_data) #新等级 self.property_info['lv'] = new_lv userLevelMod = UserLevelMod.get(new_lv) #获取前20000名对应的分数 rank_lv = lv_top_model.get_score(20000) #只有等级能到达50000名的才会进入排行榜 if not rank_lv or new_lv>rank_lv: lv_top_model.set(self.uid,new_lv) #更新体力,cost self.property_info['stamina'] += userLevelMod.lv_stamina #将用户写入新级别对应的用户列表中 subarea = self.user_base.subarea LevelUser.get_instance(subarea, self.lv_region).add_user(self.uid) inviter_uid = Friend.get(self.uid).inviter if inviter_uid: inviter_friend = Friend.get(inviter_uid) else: inviter_friend = None #升级时,检查是否有礼品码的升级奖励 user_gift_obj = UserGift.get_instance(self.uid) user_gift_obj.get_giftcode_lv_up_award() #升级时,检查是否有升级奖励 msg = utils.get_msg('user','lv_up_award', self) for lv in range(old_lv + 1, new_lv + 1): if 'award' in self.game_config.user_level_config[str(lv)]: user_gift_obj.add_gift(self.game_config.user_level_config[str(lv)]['award'],msg % lv) #用户升级后,将自己信息写入邀请者 if inviter_friend: inviter_friend.record_invited_user(self.uid, lv) self.user_cards.set_slot_num(new_lv) self.put() return new_lv > old_lv, {}