Ejemplo n.º 1
0
	def arena_update(usr):
		"""
		竞技场更新
		"""
		if not is_same_day(usr.arena['last_update_time'], currentTime()):		
			usr.arena['times'] = 0
		usr.arena['last_update_time'] = currentTime()
Ejemplo n.º 2
0
	def draw_award(usr, position):
		"""
		开服奖励
		"""
		openAwardConf = config.getConfig('open_award')
		drawidx = []
		
		for t in usr.signin['draw_award_time']:
			if is_same_day(t, currentTime()):
				return {'msg':'open_award_already_get'}
		
		for idx, ad in enumerate(openAwardConf['draw_award']):
			 if len(usr.signin['draw_award_time']) > idx and not usr.signin['draw_award_time'][idx]:
			 	continue
			 if ad['day'] > len(usr.signin['draw_award_time']):
			 	continue			 	
			 drawidx.append(idx)
			 
		if not drawidx:
			return {'msg':'open_award_already_get'}
			
		adidx = random.sample(drawidx, 1)[0]
		ad = openAwardConf['draw_award'][adidx]
		awd = {}
		awd = drop.open(usr, ad['dropid'], awd)
		while len(usr.signin['draw_award_time']) <= adidx:
			usr.signin['draw_award_time'].append({})
		usr.signin['draw_award_time'][adidx] = {'time':currentTime(), 'position': position}
		usr.save()
		data = drop.makeData(awd, {})
		
		return data	
Ejemplo n.º 3
0
    def arena_update(usr):
        """
		竞技场更新
		"""
        if not is_same_day(usr.arena['last_update_time'], currentTime()):
            usr.arena['times'] = 0
        usr.arena['last_update_time'] = currentTime()
Ejemplo n.º 4
0
	def updateReinforce(self):
		now = currentTime()
		tmLast = time.localtime(self.last_reinforce_time)
		tmNow = time.localtime(now)
		if tmLast.tm_year != tmNow.tm_year or tmLast.tm_mon != tmNow.tm_mon or tmLast.tm_mday != tmNow.tm_mday:
			self.reinforced_list = []
			last_reinforce_time = currentTime()
Ejemplo n.º 5
0
	def updateFeed(usr):
		gameConf = config.getConfig('game')		
		if is_expire(gameConf['luckycat_beckon_count_reset_time'], usr.luckycat['feed_self_last_time']):
			usr.luckycat['feed_self_count'] = 0
			usr.luckycat['feed_self_last_time'] = currentTime()
		if is_expire(gameConf['luckycat_beckon_count_reset_time'], usr.luckycat['feed_other_last_time']):
			usr.luckycat['feed_other_count'] = 0
			usr.luckycat['feed_oter_last_time'] = currentTime()
Ejemplo n.º 6
0
    def beckon_cooldown(usr):
        """
		招财冷却
		"""
        now = currentTime()
        if usr.luckycat['beckon_cooldown'] + usr.luckycat[
                'beckon_last_update_time'] > now:
            return usr.luckycat['beckon_cooldown'] + usr.luckycat[
                'beckon_last_update_time'] - currentTime()
        return 0
Ejemplo n.º 7
0
    def updateReinforce(self):
        """
		更新援军
		"""
        now = currentTime()
        tmLast = time.localtime(self.last_reinforce_time)
        tmNow = time.localtime(now)
        if tmLast.tm_year != tmNow.tm_year or tmLast.tm_mon != tmNow.tm_mon or tmLast.tm_mday != tmNow.tm_mday:
            self.reinforced_list = []
            last_reinforce_time = currentTime()
Ejemplo n.º 8
0
	def send_gift(usr, item, friendid):
		"""
		送礼
		"""
		giftConf = config.getConfig('gift')
		if not giftConf.has_key(item):
			return {'msg':'gift_not_exist'}
		
		giftInfo = giftConf[item]
		
		usrNw = usr.getNetwork()
		goldCost = giftInfo['gold']
		if usr.gold < goldCost:
			return {'msg': 'gold_not_enough'}
		gemCost = giftInfo['gem']
		if usr.gem < gemCost:
			return {'msg': 'gem_not_enough'}
				
		usr.gold = usr.gold - goldCost
		usr.gem = usr.gem - gemCost
		
		friend = usr.__class__.get(friendid)
		if not friend:
			return {'msg':'usr_not_exist'}
		
		friendNw = friend.getNetwork()

		if not usrNw.gift.has_key(item):
			usrNw.gift[item] = {'receive_count':0, 'send_count':0}
		
		if not friendNw.gift.has_key(item):
			friendNw.gift[item] = {'receive_count':0, 'send_count':0}
		
		friendNw.gift[item]['receive_count'] = friendNw.gift[item]['receive_count'] + 1
		usrNw.gift[item]['send_count'] = usrNw.gift[item]['send_count'] + 1
		friendNw.charm = friendNw.charm + giftInfo['charm']				
		usrNw.tuhao = usrNw.tuhao + giftInfo['tuhao']
		gift.notify_new_gift(friend, item)
		
		usrNw.send_gift_record.append({'roleid':friendid, 'send_time':currentTime(), 'item':item})
		friendNw.receive_gift_record.append({'roleid':usr.roleid, 'receive_time':currentTime(), 'item':item})
	
		
		gameConf = config.getConfig('game')
		gift.update_send_gift_list(usr, gameConf)
		gift.update_receive_gift_list(friend, gameConf)
		
		usr.save()
		usrNw.save()
		friend.save()
		friendNw.save()
		gift.send_gift_recored(usrNw.roleid, friend.roleid)
		return {'tuhao':usrNw.tuhao, 'gold':usr.gold, 'gem': usr.gem}
Ejemplo n.º 9
0
    def updateFeed(usr):
        """
		更新喂养
		"""
        gameConf = config.getConfig('game')
        now = currentTime()
        if is_expire(gameConf['luckycat_beckon_count_reset_time'],
                     usr.luckycat['feed_self_last_time']):
            usr.luckycat['feed_self_count'] = 0
            usr.luckycat['feed_self_last_time'] = currentTime()
        if is_expire(gameConf['luckycat_beckon_count_reset_time'],
                     usr.luckycat['feed_other_last_time']):
            usr.luckycat['feed_other_count'] = 0
            usr.luckycat['feed_oter_last_time'] = currentTime()
Ejemplo n.º 10
0
	def make():
		"""
		制做
		"""
		data = {}
		data['level'] = 1
		data['exp'] = 0
		data['critical_point_list'] = []
		data['beckon_count'] = 0
		data['beckon_gem_count'] = 0
		data['beckon_last_update_time'] = currentTime()
		data['beckon_cooldown'] = 0
		data['critical_point_list'] = []
		data['feed_self_count'] = 0
		data['feed_self_last_time'] = 0
		data['feed_other_count'] = 0
		data['feed_other_last_time'] = 0		
		data['fatigue'] = 0
		data['bless_roll_last_time'] = 0
		data['bless_cycle_begin_time'] = 0
		data['bless'] = {}
		data['record'] = []
		data['feed_candidate_list'] = []
		data['feed_request_list'] = []
		return data
Ejemplo n.º 11
0
	def beckon_once(usr, costGem, beckonGold, luckycatBlessConf, gameConf):
		"""
		招财一次
		"""
		blessid = []
		for i in range(3):
			bid = luckycat.rollBeckonBless(usr, luckycatBlessConf)
			if bid:
				blessid.append(bid)		
		beckonGold, gem, beckonCount, beckonCD = luckycat.beckonBless(usr, beckonGold, blessid, luckycatBlessConf)		
		usr.luckycat['beckon_count'] = beckonCount
		usr.luckycat['beckon_cooldown'] = beckonCD
		
		beckonGold = beckonGold * luckycat.currentLuckycatFortune()
		beckonCritical = False
		if luckycat.isCritical(usr):
			beckonGold = beckonGold * 2		
			beckonCritical = True
		usr.gold = usr.gold + beckonGold
		usr.gem = usr.gem - costGem
		usr.gem = usr.gem + gem
		
		if costGem:
			usr.luckycat['beckon_count'] = usr.luckycat['beckon_count'] + 1
			usr.luckycat['fatigue'] = usr.luckycat['fatigue'] + 1
			if usr.luckycat['fatigue'] > gameConf['luckycat_fatigue_max']:
				usr.luckycat['fatigue'] = gameConf['luckycat_fatigue_max']
			usr.luckycat['beckon_cooldown'] = int(usr.luckycat['beckon_cooldown'] + (gameConf['luckycat_cooldown_base'] * (1 + usr.luckycat['fatigue'] / 9.4)))
			usr.luckycat['beckon_last_update_time'] = currentTime()
		return beckonCritical, blessid
Ejemplo n.º 12
0
	def cancelRequest(usr, friendid):
		"""
		取消请求
		"""
		if friendid not in usr.luckycat['feed_request_list']:
			return {'msg':'luckycat_request_not_exist'}

				
		luckycat.updateFeed(usr)
		now = currentTime()
		usr.luckycat['feed_self_count'] = usr.luckycat['feed_self_count'] - 1
		usr.luckycat['feed_self_last_time'] = now
		
		usr.luckycat['feed_request_list'].remove(friendid)
		
		friend = usr.__class__.get(friendid)
		if not friend:
			usr.save()
			return {'msg':'usr_not_exist'}
				
		if usr.roleid in friend.luckycat['feed_candidate_list']:
			friend.luckycat['feed_candidate_list'].remove(usr.roleid)
			friend.save()
		usr.save()				
		return {'delete_luckycat_request':friendid, 'luckycat_feed_self_count': usr.luckycat['feed_self_count']}
Ejemplo n.º 13
0
    def isCycleDay(usr):
        """
		是否循环天
		"""
        return is_same_day(
            usr.luckycat['bless_cycle_begin_time'],
            currentTime()) or (usr.luckycat['bless_cycle_begin_time'] == 0)
Ejemplo n.º 14
0
    def beckon_reset(usr):
        """
		重置招财
		"""
        if not usr.luckycat:
            return {'msg': 'luckycat_not_available'}

        gameConf = config.getConfig('game')
        costGem = gameConf['luckycat_beckon_reset_price']['gem']
        costGold = gameConf['luckycat_beckon_reset_price']['gold']

        if usr.gem < costGem:
            return {'msg': 'gem_not_enough'}
        if usr.gold < costGold:
            return {'msg': 'gold_not_enough'}

        usr.gem = usr.gem - costGem
        usr.gold = usr.gold - costGold

        usr.luckycat['beckon_cooldown'] = 0
        usr.luckycat['beckon_last_update_time'] = currentTime()

        usr.save()
        return {
            'gold': usr.gold,
            'gem': usr.gem,
            'luckycat_beckon_cooldown': luckycat.beckon_cooldown(usr)
        }
Ejemplo n.º 15
0
    def beckon_once(usr, costGem, beckonGold, luckycatBlessConf, gameConf):
        """
		招财一次
		"""
        blessid = []
        for i in range(3):
            bid = luckycat.rollBeckonBless(usr, luckycatBlessConf)
            if bid:
                blessid.append(bid)
        beckonGold, gem, beckonCount, beckonCD = luckycat.beckonBless(
            usr, beckonGold, blessid, luckycatBlessConf)
        usr.luckycat['beckon_count'] = beckonCount
        usr.luckycat['beckon_cooldown'] = beckonCD

        beckonGold = beckonGold * luckycat.currentLuckycatFortune()
        beckonCritical = False
        if luckycat.isCritical(usr):
            beckonGold = beckonGold * 2
            beckonCritical = True
        usr.gold = usr.gold + beckonGold
        usr.gem = usr.gem - costGem
        usr.gem = usr.gem + gem

        if costGem:
            usr.luckycat['beckon_count'] = usr.luckycat['beckon_count'] + 1
            usr.luckycat['fatigue'] = usr.luckycat['fatigue'] + 1
            if usr.luckycat['fatigue'] > gameConf['luckycat_fatigue_max']:
                usr.luckycat['fatigue'] = gameConf['luckycat_fatigue_max']
            usr.luckycat['beckon_cooldown'] = int(
                usr.luckycat['beckon_cooldown'] +
                (gameConf['luckycat_cooldown_base'] *
                 (1 + usr.luckycat['fatigue'] / 9.4)))
            usr.luckycat['beckon_last_update_time'] = currentTime()
        return beckonCritical, blessid
Ejemplo n.º 16
0
    def make():
        """
		制做
		"""
        data = {}
        data['level'] = 1
        data['exp'] = 0
        data['critical_point_list'] = []
        data['beckon_count'] = 0
        data['beckon_gem_count'] = 0
        data['beckon_last_update_time'] = currentTime()
        data['beckon_cooldown'] = 0
        data['critical_point_list'] = []
        data['feed_self_count'] = 0
        data['feed_self_last_time'] = 0
        data['feed_other_count'] = 0
        data['feed_other_last_time'] = 0
        data['fatigue'] = 0
        data['bless_roll_last_time'] = 0
        data['bless_cycle_begin_time'] = 0
        data['bless'] = {}
        data['record'] = []
        data['feed_candidate_list'] = []
        data['feed_request_list'] = []
        return data
Ejemplo n.º 17
0
	def getClientData(usr, gameConf):
		"""
		得到客户端数据
		"""
		data = {}
		data['garcha'] = {}
		cooldown = 0
		now = currentTime()
		data['garcha']['10'] = {}
		data['garcha']['10']['count'] = usr.garcha['garcha10']['count']
		cooldown = gameConf['garcha_10_times'] - (now - usr.garcha['garcha10']['last_time'])
		data['garcha']['10']['cooldown'] = cooldown
		if cooldown < 0:
			data['garcha']['10']['cooldown'] = 0
		data['garcha']['100'] = {}
		data['garcha']['100']['count'] = usr.garcha['garcha100']['count']
		cooldown = gameConf['garcha_100_times'] - (now - usr.garcha['garcha100']['last_time'])
		data['garcha']['100']['cooldown'] = cooldown
		if cooldown < 0:
			data['garcha']['100']['cooldown'] = 0
		data['garcha']['10000'] = {}
		data['garcha']['10000']['count'] = usr.garcha['garcha10000']['count']
		cooldown = gameConf['garcha_10000_times'] - (now - usr.garcha['garcha10000']['last_time'])
		data['garcha']['10000']['cooldown'] = cooldown
		if cooldown < 0:
			data['garcha']['10000']['cooldown'] = 0
		return data
Ejemplo n.º 18
0
    def cancelRequest(usr, friendid):
        """
		取消请求
		"""
        if friendid not in usr.luckycat['feed_request_list']:
            return {'msg': 'luckycat_request_not_exist'}

        luckycat.updateFeed(usr)
        now = currentTime()
        usr.luckycat['feed_self_count'] = usr.luckycat['feed_self_count'] - 1
        usr.luckycat['feed_self_last_time'] = now

        usr.luckycat['feed_request_list'].remove(friendid)

        friend = usr.__class__.get(friendid)
        if not friend:
            usr.save()
            return {'msg': 'usr_not_exist'}

        if usr.roleid in friend.luckycat['feed_candidate_list']:
            friend.luckycat['feed_candidate_list'].remove(usr.roleid)
            friend.save()
        usr.save()
        return {
            'delete_luckycat_request': friendid,
            'luckycat_feed_self_count': usr.luckycat['feed_self_count']
        }
Ejemplo n.º 19
0
def set_nickname(request):
	"""
	ÉèÖÃêdzÆ
	"""
	nickname = request.GET['nickname']
	gender = request.GET['gender']
	avatar = request.GET['avatar']
	gameConf = conf.getConfig('game')
	
	if gender != 'male' and gender != 'female':
		return HttpResponse(json.dumps({'msg':'gender_out_of_except'}))	
	try:
		acc = getAccount(request, account)		
		acc.gender = gender
		usr = acc.makeUserAndBind(nickname, avatar, gender)		
		loginData = onUserLogin(request, usr)
	except NotLogin:
		return HttpResponse(json.dumps({'msg':'login_not'}))
	except DuplicateNickname:
		return HttpResponse(json.dumps({'msg':'nickname_duplicate'}))
	if acc.nickname:
		return HttpResponse(json.dumps({'msg':'nickname_already_have'}))
	
	acc.nickname = nickname
	usr.last_login = currentTime()
	gameConf = conf.getConfig('game')
	data = usr.getLoginData(gameConf)
	data['login'] = loginData
	usr.notify = {}
	usr.save()	
	return HttpResponse(json.dumps(data))
Ejemplo n.º 20
0
	def sendMail(self, toUser, mail):
		"""
		发送邮件
		"""
		toUserNw = toUser.getNetwork()					
		ntInfo = self.user.getNtInfoData()	
		requestid = str(toUserNw.sequenceid)
		toUserNw.sequenceid = toUserNw.sequenceid + 1
		fromUserId = str(self.user.roleid)
		msgData = {'mail':mail, 'send_time': currentTime(), 'id': str(requestid) + str(fromUserId), 'roleid':fromUserId}	
		if not toUserNw.mail.has_key(fromUserId):
			toUserNw.mail[fromUserId] = []
		toUserNw.mail[fromUserId].append(msgData)
		toUserNw.nt_info[fromUserId] = ntInfo
		if not toUser.notify.has_key('notify_mail'):
			toUser.notify['notify_mail'] = {}
		toUser.notify['notify_mail'][str(requestid) + str(fromUserId)] = dict({'new_mail':msgData}, **ntInfo)
		toUser.save()
		toUserNw.save()
				
		fromUser = self.user
		fromNw = self
		toNtInfo = toUser.getNtInfoData()
		toUserId = str(toUser.roleid)
		fromNw.nt_info[toUserId] = toNtInfo
		if not fromNw.mail.has_key(toUserId):
			fromNw.mail[toUserId] = []
		fromNw.mail[toUserId].append(msgData)
		if not fromUser.notify.has_key('notify_mail'):
			fromUser.notify['notify_mail'] = {}
		fromUser.notify['notify_mail'][str(requestid) + str(fromUserId)] = dict({'new_mail':msgData}, **toNtInfo)
		fromNw.save()
		fromUser.save()
Ejemplo n.º 21
0
	def continue_award(usr):
		"""
		连续登陆
		"""
		openAwardConf = config.getConfig('open_award')
		if not signin.is_continue_award_available(openAwardConf):
			return {'msg':'open_award_not_available'}
							
		if signin.is_continue_award_already_get(usr):
			return {'msg':'open_award_already_get'}
		
		now = currentTime()
		if not usr.signin['continue_award_time']:
			if day_diff(now, usr.signin['continue_award_time'][-1]) != 1:
				usr.signin['continue_award_time'] = []
				
		usr.signin['continue_award_time'].append(now)
		
		
		cardid = openAwardConf['continue_award'][len(usr.signin['continue_award_time']) - 1]
		
		inv = usr.getInventory()
		c = inv.addCard(cardid)
		inv.save()
		usr.save()
		data = {}
		data['add_card'] = c
		return data
Ejemplo n.º 22
0
	def stand(self, roleid):
		"""
		站上天梯
		"""
		usr = user.get(roleid)
		
		if not usr:
			return {'msg':'user_not_exist'}	
				
		md = medal_arena.instance()
		md.role_level(usr.roleid, usr.level)
		md.save()
		
		if not self.item.has_key(roleid):			
			rd = {}
			rd['roleid'] = roleid
			rd['name'] = usr.name
			rd['level'] = usr.level
			rd['last_update'] = currentTime()
			rd['score'] = 0
			rd['avatar_id'] = usr.avatar_id
			self.item[roleid] = rd
			self.rank.append(roleid)
			self.save()
			return {'position':(len(self.rank) -1)}
		return {'msg':'arena_ladder_already_stand'}
Ejemplo n.º 23
0
	def update_exp(usr, gameConf):		
		"""
		更新经验
		"""
		petConf = config.getConfig('pet')
		petLevelConf = config.getConfig('pet_level')		
		inv = usr.getInventory()
				
		now = currentTime()
		eduCard = []
		for edu_slot in usr.educate['edu_slot']:
			if edu_slot and edu_slot.has_key('start_time'):
				educateGradeConf = config.getConfig('educate_grade')		
				educateEndTime = edu_slot['start_time'] + gameConf['educate_duration']
				educateDuration = now - edu_slot['last_update_time']				
				if now > educateEndTime:
					educateDuration = educateEndTime - edu_slot['last_update_time']
					del edu_slot['start_time']
					del edu_slot['last_update_time']
				else:
					edu_slot['last_update_time'] = now
				rate = educateGradeConf[edu_slot['edt']]['rate']
				exp = edu_slot['expptm'] * educateDuration / 3600 * rate + edu_slot['fraction']
				edu_slot['fraction'] = exp - int(exp)
				exp = int(exp)
				if exp:
					card = inv.getCard(edu_slot['card_id'])
					pet.gainExp(usr, card, int(exp), petConf, petLevelConf, gameConf)					
					eduCard.append(card)		
		inv.save()
		usr.save()	
Ejemplo n.º 24
0
	def getEduSlots(usr, gameConf):
		"""
		得到训练栏位
		"""
		now = currentTime()		
		edu_slot = usr.educate['edu_slot']
		data = {}
		data = []
		for slot in edu_slot:
			if slot.has_key('start_time'):
				s = educate.make_open_edu_slot(slot['edt'])
				countdown = gameConf['educate_duration'] - (now - slot['start_time'])
				if countdown < 0:
					countdown = 0
				s['expptm'] = slot['expptm']
				s['finish_countdown'] = countdown
				s['card_id'] = slot['card_id']
				data.append(s)
			elif slot:
				s = educate.make_open_edu_slot(slot['edt'])
				if slot.has_key('card_id'):
					s['card_id'] = slot['card_id']
				data.append(s)
			else:
				data.append({})
			
		return data
Ejemplo n.º 25
0
    def continue_award(usr):
        """
		连续登陆
		"""
        openAwardConf = config.getConfig('open_award')
        if not signin.is_continue_award_available(openAwardConf):
            return {'msg': 'open_award_not_available'}

        if signin.is_continue_award_already_get(usr):
            return {'msg': 'open_award_already_get'}

        now = currentTime()
        if not usr.signin['continue_award_time']:
            if day_diff(now, usr.signin['continue_award_time'][-1]) != 1:
                usr.signin['continue_award_time'] = []

        usr.signin['continue_award_time'].append(now)

        cardid = openAwardConf['continue_award'][
            len(usr.signin['continue_award_time']) - 1]

        inv = usr.getInventory()
        c = inv.addCard(cardid)
        inv.save()
        usr.save()
        data = {}
        data['add_card'] = c
        return data
Ejemplo n.º 26
0
    def getEduSlots(usr, gameConf):
        """
		得到训练栏位
		"""
        now = currentTime()
        edu_slot = usr.educate['edu_slot']
        data = {}
        data = []
        for slot in edu_slot:
            if slot.has_key('start_time'):
                s = educate.make_open_edu_slot(slot['edt'])
                countdown = gameConf['educate_duration'] - (now -
                                                            slot['start_time'])
                if countdown < 0:
                    countdown = 0
                s['expptm'] = slot['expptm']
                s['finish_countdown'] = countdown
                s['card_id'] = slot['card_id']
                data.append(s)
            elif slot:
                s = educate.make_open_edu_slot(slot['edt'])
                if slot.has_key('card_id'):
                    s['card_id'] = slot['card_id']
                data.append(s)
            else:
                data.append({})

        return data
Ejemplo n.º 27
0
    def stand(self, roleid):
        """
		站上天梯
		"""
        usr = user.get(roleid)

        if not usr:
            return {'msg': 'user_not_exist'}

        md = medal_arena.instance()
        md.role_level(usr.roleid, usr.level)
        md.save()

        if not self.item.has_key(roleid):
            rd = {}
            rd['roleid'] = roleid
            rd['name'] = usr.name
            rd['level'] = usr.level
            rd['last_update'] = currentTime()
            rd['score'] = 0
            rd['avatar_id'] = usr.avatar_id
            self.item[roleid] = rd
            self.rank.append(roleid)
            self.save()
            return {'position': (len(self.rank) - 1)}
        return {'msg': 'arena_ladder_already_stand'}
Ejemplo n.º 28
0
	def rollBless(usr):
		if not usr.luckycat:
			return {'msg':'luckycat_not_available'}
		luckycat.updateBless(usr)
		luckycatBlessConf = config.getConfig('luckycat_bless')
		now = currentTime()		
		if is_same_day(now, usr.luckycat['bless_roll_last_time']):
			return {'msg':'roll_bless_already_today'}
		
		roll = randint()
		blessConf = {}
		for blessid in luckycatBlessConf:
			b = luckycatBlessConf[blessid] 
			if b['probability'] < roll:
				roll = roll - b['probability']
			else:
				blessConf = b		
		
		blessid = blessConf['blessid']
		if not usr.luckycat['bless'].has_key(blessid):
			usr.luckycat['bless'][blessid] = {}
			usr.luckycat['bless'][blessid]['blessid'] = blessid
			if luckycat.isCycleDay(usr):
				usr.luckycat['bless'][blessid]['spread'] = True				
		return {'luckycat_roll_bless':blessid, 'luckycat_roll_bless_spread':usr.luckycat['bless'][blessid].has_key('spread')}
Ejemplo n.º 29
0
    def getClientData(usr, gameConf):
        """
		得到客户端数据
		"""
        data = {}
        data['garcha'] = {}
        cooldown = 0
        now = currentTime()
        data['garcha']['10'] = {}
        data['garcha']['10']['count'] = usr.garcha['garcha10']['count']
        cooldown = gameConf['garcha_10_times'] - (
            now - usr.garcha['garcha10']['last_time'])
        data['garcha']['10']['cooldown'] = cooldown
        if cooldown < 0:
            data['garcha']['10']['cooldown'] = 0
        data['garcha']['100'] = {}
        data['garcha']['100']['count'] = usr.garcha['garcha100']['count']
        cooldown = gameConf['garcha_100_times'] - (
            now - usr.garcha['garcha100']['last_time'])
        data['garcha']['100']['cooldown'] = cooldown
        if cooldown < 0:
            data['garcha']['100']['cooldown'] = 0
        data['garcha']['10000'] = {}
        data['garcha']['10000']['count'] = usr.garcha['garcha10000']['count']
        cooldown = gameConf['garcha_10000_times'] - (
            now - usr.garcha['garcha10000']['last_time'])
        data['garcha']['10000']['cooldown'] = cooldown
        if cooldown < 0:
            data['garcha']['10000']['cooldown'] = 0
        return data
Ejemplo n.º 30
0
	def update_exp(usr, gameConf):		
		
		petConf = config.getConfig('pet')
		petLevelConf = config.getConfig('pet_level')		
		inv = usr.getInventory()
				
		now = currentTime()
		eduCard = []
		for edu_slot in usr.educate['edu_slot']:
			if edu_slot and edu_slot.has_key('start_time'):
				educateDuration = now - edu_slot['last_update_time']
				if educateDuration > gameConf['educate_duration']:
					educateDuration = gameConf['educate_duration']
					del edu_slot['start_time']
					del edu_slot['last_update_time']
				else: 
					exp = edu_slot['expptm'] * (now - edu_slot['last_update_time']) / 600 * edu_slot['rate'] + edu_slot['fraction']
				edu_slot['fraction'] = exp - int(exp)
				exp = int(exp)
				if exp:
					card = inv.getCard(edu_slot['card_id'])
					pet.gainExp(card, int(exp), petConf, petLevelConf, gameConf)
					edu_slot['last_update_time'] = now
					eduCard.append(card)		
		inv.save()		
Ejemplo n.º 31
0
	def saveLogin(self):
		"""
		保存登入
		"""
		self.last_login = currentTime()
		conn = DBConnection.getConnection()
		conn.excute("UPDATE account SET lastlogin = %s WHERE id = %s", [time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(self.last_login)), self.id])
Ejemplo n.º 32
0
	def encounter(self, roleid, name):		
		"""
		遇敌
		"""
		gameConf = config.getConfig('game')
		now = currentTime()		
		self.update_battle(now, gameConf)
		if self.battle.has_key(roleid):
			battle = self.battle[roleid][-1]
			if battle and (not infection_arena.battle_is_finish(battle, now, gameConf)):
				return {'msg': 'infection_battle_not_finish'}
			
		rd = randint()
		quality = -1
		for (i, qualityInfo) in enumerate(gameConf['infection_quality']):
			if rd > qualityInfo['probability']:
				rd = rd - qualityInfo['probability']
			else:
				quality = i
				
		if quality < 0:
			return {'msg':'infection_bad_quality'}
		
		if not self.user.has_key(roleid):
			self.user[roleid] = infection_arena.make_user(name)		
				
		level = self.user[roleid]['level']		
		self.update_prestige(roleid, now)
				
		infectionBattleConf = config.getConfig('infection_battle')
		infectionBattleInfo = infectionBattleConf[str(quality)][level - 1]
		if not infectionBattleInfo:
			return {'msg':'infection_battle_not_exist'}
		
		battle = {}
		battle['monster'] = []
		
		totalhp = 0
		monsterConf = config.getConfig('monster')		
		for monsterid in infectionBattleInfo['monster']:
			monsterInfo = monsterConf[monsterid]			
			monster = {}
			monster['monsterid'] = monsterid
			monster['hp'] = monsterInfo['hp']
			totalhp = totalhp + monsterInfo['hp']
			battle['monster'].append(monster)
		battle['monster_total_hp'] = totalhp
		battle['quality'] = quality
		battle['level'] = level
		battle['roleid'] = roleid
		battle['create_time'] = now
		battle['user'] = {}
		battle['rolename'] = name
		self.battle[roleid] = []
		self.battle[roleid].append(battle)
		
		self.user[roleid]['infection_list'].append(infection_arena.make_relief(battle))
		self.save()
		return {'battle':self.battle[roleid]}
Ejemplo n.º 33
0
	def updatemass(self):
		"""
		刷新世界聊天
		"""
		gameConf = config.getConfig('game')		
		expire = gameConf['yell_expiry_period']
		now = currentTime()
		self.record = filter(lambda r: r['create_time'] + expire >= now, self.record)
Ejemplo n.º 34
0
	def defeat(self, offenceRoleid, defenceRoleid):
		offencePosition = self.rank.index(offenceRoleid)
		defencePosition = self.rank.index(defenceRoleid)
		
		self.rank.remove(offencePosition)
		self.insert(defencePosition, offenceRoleid)
		for i in range(defencePosition, offencePosition):
			self.update(i, self.rank[i], currentTime())
Ejemplo n.º 35
0
	def updateFatigue(self):
		"""
		更新体力
		"""
		gameConf = config.getConfig('game')
		if is_expire(gameConf['fatigue_reset_time'], self.fatigue):
			self.fatigue = 0
			fatigue_last_time = currentTime()
Ejemplo n.º 36
0
    def medallevelup(usr, medalid):
        """
		勋章升级
		"""
        medalConfig = config.getConfig('medal')
        medalInfo = medalConfig[medalid]
        medalLevelConfig = config.getConfig('medal_level')
        medalLevelInfo = medalLevelConfig[medalid]
        gameConf = config.getConfig('game')
        now = currentTime()

        medal.update_medal_levelup(usr, now, medalInfo, gameConf)

        if not medal.is_time_to_medal_levelup_finish(usr, now, gameConf):
            return {'msg': 'medal_levelup_not_finish'}

        inv = usr.getInventory()
        mroleid = inv.roleid
        if not inv.medal.has_key(medalid):
            return {'msg': 'medal_not_exist'}

        medalLevel = inv.medal[medalid]['level']
        medalLevelMax = len(medalLevelConfig[medalid])
        if medalLevelMax <= medalLevel:
            return {'msg': 'medal_level_max'}

        for c in inv.medal[medalid]['chip']:
            if c < 1:
                return {'msg': 'medal_chip_not_complete'}

        usr.medal['levelup_last_time'] = currentTime()
        usr.medal['levelup_medalid'] = medalid

        if usr.medal['levelup_count'] < gameConf[
                'medal_levelup_wink_finish_count']:
            medal.medal_levelup_finish(usr, now, medalInfo, medalLevelInfo,
                                       gameConf)
            res = medal.levelupMedal(usr.roleid, medalid)
            if res.has_key('msg'):
                return res
            inv.save()
            usr.save()
            return inv.medal[medalid]
        inv.save()
        usr.save()
        return {'medal_levelup_cooldown': gameConf['medal_levelup_cooldown']}
Ejemplo n.º 37
0
	def updateBless(usr):
		"""
		更新祝福
		"""
		now = currentTime()
		gameConf = config.getConfig('game')
		if usr.luckycat['bless_cycle_begin_time'] and (day_diff(usr.luckycat['bless_cycle_begin_time'], now) > gameConf['luckycat_bless_cycle_day']):
			usr.luckycat['bless_cycle_begin_time'] = 0
Ejemplo n.º 38
0
	def updateBlacklist(self):
		"""
		更新好友列表
		"""
		gameConf = config.getConfig('game')
		expire = gameConf['blacklist_expiry_period']
		now = currentTime()		
		self.blacklist = filter(lambda ban: ban['create_time'] + exp > now, self.blacklist)
Ejemplo n.º 39
0
	def updateMessage(self):
		"""
		更新消息
		"""
		now = currentTime()
		gameConf = config.getConfig('game')
		expire = gameConf['message_expiry_period']
		self.message = dict((k, v) for k,v in self.message.items() if (v['send_time'] + expire) > now)		
Ejemplo n.º 40
0
	def beckon_cooldown(usr):
		"""
		招财冷却
		"""
		now = currentTime()
		if usr.luckycat['beckon_cooldown'] + usr.luckycat['beckon_last_update_time'] > now:			
			return usr.luckycat['beckon_cooldown'] + usr.luckycat['beckon_last_update_time'] - currentTime()		
		return 0
Ejemplo n.º 41
0
	def dailyRecored(self, battleid, fieldid):
		"""
		每日记录
		"""
		
		if not is_same_day(self.daily_recored_last_time, currentTime()):
			self.daily_recored = {}
			self.daily_recored_last_time = currentTime()
			self.fatigue = 0
		
		if not self.daily_recored.has_key(battleid):
			self.daily_recored[battleid] = {}
		if not self.daily_recored[battleid].has_key(fieldid):
			self.daily_recored[battleid][fieldid] = {'count':0, 'vip_reset':False}
		self.daily_recored[battleid][fieldid]['count'] = self.daily_recored[battleid][fieldid]['count'] + 1
		self.daily_recored_last_time = currentTime()
		return self.daily_recored[battleid][fieldid]['count']
Ejemplo n.º 42
0
    def updateBlacklist(self):
        """
		更新好友列表
		"""
        gameConf = config.getConfig('game')
        expire = gameConf['blacklist_expiry_period']
        now = currentTime()
        self.blacklist = filter(lambda ban: ban['create_time'] + exp > now,
                                self.blacklist)
Ejemplo n.º 43
0
    def updatemass(self):
        """
		刷新世界聊天
		"""
        gameConf = config.getConfig('game')
        expire = gameConf['yell_expiry_period']
        now = currentTime()
        self.record = filter(lambda r: r['create_time'] + expire >= now,
                             self.record)
Ejemplo n.º 44
0
	def updateEquipmentStrengthCooldown(self):
		"""
		更新强化装备冷却时间
		"""
		now = currentTime()
		elapse = now - self.equipment_strength_last_time
		self.equipment_strength_cooldown = self.equipment_strength_cooldown - elapse
		if self.equipment_strength_cooldown < 0:
			self.equipment_strength_cooldown = 0			
Ejemplo n.º 45
0
    def ban(self, ben_roleid, ben_name):
        """
		阻止玩家
		"""
        self.blacklist.append({
            'roleid': ben_roleid,
            'name': ben_name,
            'create_time': currentTime()
        })
Ejemplo n.º 46
0
    def update_explore(usr):
        """
		更新探险时间
		"""
        now = currentTime()
        if not is_same_day(usr.explore['last_update_times_time'], now):
            usr.explore['times'] = 0
            usr.explore['last_update_times_time'] = 0
            usr.explore['critical_count'] = 0
Ejemplo n.º 47
0
    def on_user_levelup(usr):
        """
		用户升级
		"""
        usr.explore['times'] = usr.explore['times'] - 12
        if usr.explore['times'] < 0:
            usr.explore['times'] = 0
        usr.explore['last_update_times_time'] = currentTime()
        explore.notify_explore_times(usr)
Ejemplo n.º 48
0
    def updateMessage(self):
        """
		更新消息
		"""
        now = currentTime()
        gameConf = config.getConfig('game')
        expire = gameConf['message_expiry_period']
        self.message = dict((k, v) for k, v in self.message.items()
                            if (v['send_time'] + expire) > now)
Ejemplo n.º 49
0
	def generateName(self, perfix):
		serveridLen = len(str(serverid))
		roleidLen = len(str(self.roleid))
		tm = time.gmtime(currentTime())
		ts = time.strftime('%Y%m%d%H%M%S', tm)
		no = str(self.user.getCardNo())
		noLen = len(no)
		name = ''.join([perfix, str(serveridLen), str(serverid), str(roleidLen), str(self.roleid), ts, str(noLen), no])
		self.user.save()	#save card no
		return name
Ejemplo n.º 50
0
    def updateBless(usr):
        """
		更新祝福
		"""
        now = currentTime()
        gameConf = config.getConfig('game')
        if usr.luckycat['bless_cycle_begin_time'] and (day_diff(
                usr.luckycat['bless_cycle_begin_time'],
                now) > gameConf['luckycat_bless_cycle_day']):
            usr.luckycat['bless_cycle_begin_time'] = 0
Ejemplo n.º 51
0
	def updateVip(usr):
		"""
		更新vip
		"""
		now = currentTime()
		if not is_same_day(usr.vip['vip_last_update_time'], now):
			usr.vip['buy_stamina_count'] = 0
			usr.vip['buy_sp_count'] = 0
			usr.vip['buy_arena_times'] = 0
			usr.vip['vip_last_update_time'] = now
Ejemplo n.º 52
0
	def __init__(self):
		"""
		构造函数
		"""
		gcuser.__init__(self)
		self.id = 0
		self.roleid = 0
		self.name = ''
		self.level = 0
		self.stamina = 0
		self.gem = 0
		self.gold = 0
		self.exp = 0
		self.sp = 0
		self.stamina_last_recover = 0
		self.sp_last_recover = 0
		self.last_card_no = 0
		self.leader = ''		
		self.last_login = currentTime()
		self.dun = None
		self.inv = None
		self.network = None
		self.almanac = None
		self.quest = None
		self.garcha = garcha.make()
		self.notify = {}
		self.gender = 'male'
		self.equipment_strength_cooldown = 0
		self.equipment_strength_last_time = 0
		self.train_prd = {}
		self.fatigue = 0
		self.fatigue_last_time = 0		
		self.yell_hear_id = 0
		self.extend_columns.append({'name' :'avatar_id', 'value':''})
		self.luckycat = luckycat.make()
		self.educate = educate.make()
		self.signin = signin.make()
		self.levelup = levelup.make()
		self.trp = 0
		self.stv = stone.make_stv()
		self.arena = arena.make()
		self.avatar = ''
		self.longitude = 0.0
		self.latitude = 0.0
		self.tower = tower.make()
		self.medal = medal.make()
		self.practice = practice.make()
		self.slotmachine = slotmachine.make()
		self.vip = vip.make()
		self.invite = invite.make()
		self.infection = infection.make()
		self.born_card = pet.make_born_card()
		self.ip = 0
		self.ip_last_recover = 0
		self.explore = explore.make()
Ejemplo n.º 53
0
    def getClientData(usr, gameConf):
        """
		得到 client data
		"""
        data = {}
        data['medal_protect_time'] = usr.medal['protect_time']
        data['medal_levelup_countdown'] = gameConf[
            'medal_levelup_cooldown'] - currentTime(
            ) - usr.medal['levelup_last_time']
        if data['medal_levelup_countdown'] < 0:
            data['medal_levelup_countdown'] = 0
        return data