Exemplo n.º 1
0
	def update_battle(self, now, gameConf):		
		"""
		更新战斗
		"""
		if is_same_day(self.last_update_time, now):
			return
	
		email.send_ladder_email(self.damage_ladder, '4')
		email.send_ladder_email(self.prestige_ladder, '4')
		for roleid in self.battle.keys():
			battleRemoveList = []
			for battle in self.battle[roleid]:
				quality = battle['quality']
				if infection_arena.battle_is_escape(battle, now, gameConf):					
					if not is_same_day(battle['create_time'] + gameConf['infection_quality'][quality]['escape_time'], now):
						battleRemoveList.append(battle)
				elif infection_arena.battle_is_clear(battle):
					hit_time = battle['user'][battle['last_hit']]['last_hit_time']
					if not is_same_day(hit_time, now):
						battleRemoveList.append(battle)						
			for rb in battleRemoveList:
				self.battle[roleid].remove(rb)			
			if not self.battle[roleid]:
				del self.battle[roleid]
		self.last_update_time = now
Exemplo n.º 2
0
    def update_garcha(usr, now):
        """
		更新求将
		"""
        if not is_same_day(now, usr.garcha['garcha10']['last_time']):
            usr.garcha['garcha10']['count'] = 0
        if not is_same_day(now, usr.garcha['garcha100']['last_time']):
            usr.garcha['garcha100']['count'] = 0
        if not is_same_day(now, usr.garcha['garcha10000']['last_time']):
            usr.garcha['garcha10000']['count'] = 0
        usr.save()
Exemplo n.º 3
0
	def update_garcha(usr, now):
		"""
		更新求将
		"""
		if not is_same_day(now, usr.garcha['garcha10']['last_time']):
			usr.garcha['garcha10']['count'] = 0
		if not is_same_day(now, usr.garcha['garcha100']['last_time']):
			usr.garcha['garcha100']['count'] = 0
		if not is_same_day(now, usr.garcha['garcha10000']['last_time']):
			usr.garcha['garcha10000']['count'] = 0			
		usr.save()
Exemplo n.º 4
0
	def update_prestige(self, roleid, now):
		"""
		更新声望
		"""
		if not is_same_day(self.user[roleid]['last_hit_time'], now):
			self.user[roleid]['prestige'] = 0
			self.user[roleid]['prestige_score'] = 0
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
0
    def isCycleDay(usr):
        """
		是否循环天
		"""
        return is_same_day(
            usr.luckycat['bless_cycle_begin_time'],
            currentTime()) or (usr.luckycat['bless_cycle_begin_time'] == 0)
Exemplo n.º 8
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')}
Exemplo n.º 9
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	
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
	def is_continue_award_already_get(usr):
		"""
		连续登陆奖励是否已领
		"""
		now = currentTime()		
		if not usr.signin['continue_award_time']:
			return True
		
		for award_time in usr.signin['continue_award_time']:
			if is_same_day(award_time, now):
				return True		
		return False
Exemplo n.º 13
0
    def is_continue_award_already_get(usr):
        """
		连续登陆奖励是否已领
		"""
        now = currentTime()
        if not usr.signin['continue_award_time']:
            return True

        for award_time in usr.signin['continue_award_time']:
            if is_same_day(award_time, now):
                return True
        return False
Exemplo n.º 14
0
	def play(usr):
		"""
		玩老虎机
		"""
		now = currentTime()
		
		gameConf = config.getConfig('game')
		
		isAvailable = True
		
		for ts in gameConf['slot_machine_open_time']:
			t = str_to_date_time(ts)
			if is_same_day(now, t):
				isAvailable = True
				break
				
		if not isAvailable:
			return {'msg':'slotmachine_not_available'}
						
		slotmachineConf = config.getConfig('slotmachine')
				
		times = len(usr.slotmachine['play_time'])
		
		if len(slotmachineConf['price']) <= times:		
			return {'msg':'slotmachine_max_time'}
				
		gemCost = slotmachineConf['price'][times]
				
		if usr.gem < gemCost:
			return {'msg':'gem_not_enough'}
		
		usr.gem = usr.gem - gemCost
		
		rd = randint()
				
		benefit = 1
		for bf in slotmachineConf['rate']:
			if rd > bf['probability']:
				rd = rd - bf['probability']
			else:
				benefit = bf['benefit']
				
		gem = int(gemCost * benefit)
		
		usr.gem = usr.gem + gem
		
		usr.slotmachine['play_time'].append(now)
		usr.save()
		
		
		return {'benefit':gem, 'gem':usr.gem}
Exemplo n.º 15
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']
Exemplo n.º 16
0
    def rollBless(usr, isUseGem):
        """
		抽取祝福
		"""
        if not usr.luckycat:
            return {'msg': 'luckycat_not_available'}

        if isUseGem and (not vip.canBuyLuckycatBless(usr)):
            return {'msg': 'luckycat_vip_required'}

        luckycat.updateBless(usr)
        luckycatBlessConf = config.getConfig('luckycat_bless')
        now = currentTime()
        if is_same_day(now, usr.luckycat['bless_roll_last_time']):
            if not isUseGem:
                return {'msg': 'luckycat_roll_bless_already_today'}
        else:
            if isUseGem:
                return {'msg': 'gem_not_necessary'}

        roll = randint()
        blessConf = {}
        for blessid in luckycatBlessConf:
            b = luckycatBlessConf[blessid]
            if b['probability'] < roll:
                roll = roll - b['probability']
            else:
                blessConf = b
                break

        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) or isUseGem:
                usr.luckycat['bless'][blessid]['spread'] = True

        usr.luckycat['bless_roll_last_time'] = now
        usr.save()
        return {
            'luckycat_roll_bless':
            blessid,
            'luckycat_roll_bless_spread':
            usr.luckycat['bless'][blessid].has_key('spread')
        }
Exemplo n.º 17
0
	def dayIsAvailable(self, usr, qid, questInfo, questConf):
		"""
		是否有效的每日任务
		"""
		if questInfo['level'] > usr.level:
			return False
		
		if not quest.isActive(questInfo):
			return False
		alreadyFinishPre = questInfo['isFirst']			
			
		if not alreadyFinishPre:
			for fqid in self.finish:
				finishQuestInfo = questConf[fqid]
				if finishQuestInfo['nextId'] == qid:
					if not is_same_day(self.finish[qid]['create_time'], currentTime()):
						return True
		return False 
Exemplo n.º 18
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']
Exemplo n.º 19
0
	def dayUpdate(usr, now):
		"""
		每日更新
		"""
		if not is_same_day(usr.tower['last_update'], now):
			if usr.tower['current']:
				usr.tower['record'].append(usr.tower['current'])
			usr.tower['max_floor'] = 0
			floor = 0
			point = 0
			for rd in usr.tower['record']:
				if rd['floor'] > floor:
					usr.tower['last_max_floor'] = rd['floor']
				if rd['point'] > point:
					usr.tower['last_max_point'] = rd['point']
			usr.tower['current'] = {}
			usr.tower['record'] = []				
			usr.tower['times'] = 0
			usr.tower['max_floor'] = 0
			usr.tower['last_update'] = now
			usr.tower['floor_point'] = []
Exemplo n.º 20
0
	def rollBless(usr, isUseGem):
		"""
		抽取祝福
		"""
		if not usr.luckycat:
			return {'msg':'luckycat_not_available'}
		
		if isUseGem and (not vip.canBuyLuckycatBless(usr)):
			return {'msg':'luckycat_vip_required'}
						
		luckycat.updateBless(usr)
		luckycatBlessConf = config.getConfig('luckycat_bless')
		now = currentTime()		
		if is_same_day(now, usr.luckycat['bless_roll_last_time']):
			if not isUseGem:
				return {'msg':'luckycat_roll_bless_already_today'}
		else: 
			if isUseGem:
				return {'msg':'gem_not_necessary'}
				
		roll = randint()		
		blessConf = {}
		for blessid in luckycatBlessConf:
			b = luckycatBlessConf[blessid] 
			if b['probability'] < roll:
				roll = roll - b['probability']				
			else:
				blessConf = b
				break
		
		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) or isUseGem:
				usr.luckycat['bless'][blessid]['spread'] = True
				
		usr.luckycat['bless_roll_last_time'] = now
		usr.save()
		return {'luckycat_roll_bless':blessid, 'luckycat_roll_bless_spread':usr.luckycat['bless'][blessid].has_key('spread')}
Exemplo n.º 21
0
	def addFriendRequest(self, friend):
		"""
		添加好友请求
		"""
		
		friendRoleid = str(friend.roleid)
		if self.request_list.has_key(friendRoleid):
			if is_same_day(currentTime(), self.request_list[friendRoleid]):
				return {'msg':'friend_already_request'}
		self.request_list[friendRoleid] = currentTime()
		
		data = self.user.getFriendData()
		friendNw = friend.getNetwork()
		requestid = str(friendNw.sequenceid)
		friendNw.sequenceid = friendNw.sequenceid + 1
		data.update({'id':requestid})		
		friendNw.friend_request[requestid] = data		
		friendNw.save()
		if not friend.notify.has_key('notify_friend_request'):
			friend.notify['notify_friend_request'] = {}
		friend.notify['notify_friend_request'][requestid] = data
		friend.save()
		self.save()
		return data
Exemplo n.º 22
0
    def addFriendRequest(self, friend):
        """
		添加好友请求
		"""

        friendRoleid = str(friend.roleid)
        if self.request_list.has_key(friendRoleid):
            if is_same_day(currentTime(), self.request_list[friendRoleid]):
                return {'msg': 'friend_already_request'}
        self.request_list[friendRoleid] = currentTime()

        data = self.user.getFriendData()
        friendNw = friend.getNetwork()
        requestid = str(friendNw.sequenceid)
        friendNw.sequenceid = friendNw.sequenceid + 1
        data.update({'id': requestid})
        friendNw.friend_request[requestid] = data
        friendNw.save()
        if not friend.notify.has_key('notify_friend_request'):
            friend.notify['notify_friend_request'] = {}
        friend.notify['notify_friend_request'][requestid] = data
        friend.save()
        self.save()
        return data
Exemplo n.º 23
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
Exemplo n.º 24
0
	def isCycleDay(usr):
		"""
		是否循环天
		"""
		return is_same_day(usr.luckycat['bless_cycle_begin_time'], currentTime()) or (usr.luckycat['bless_cycle_begin_time'] == 0)
Exemplo n.º 25
0
    def have_signin(usr, now):
        """
		是否已经签到
		"""
        return is_same_day(usr.signin['last_signin_time'], now)
Exemplo n.º 26
0
    def login(usr):
        """
		登陆
		"""
        now = currentTime()
        gameConf = config.getConfig('game')
        signinConf = config.getConfig('signin')
        dd = day_diff(now, usr.signin['last_login_time'])
        if dd == 1:
            usr.signin['login_count'] = usr.signin['login_count'] + 1
        elif dd > 1:
            usr.signin['login_count'] = 1
        usr.signin['last_login_time'] = currentTime()

        data = {}
        data['signin_index'] = (usr.signin['login_count'] -
                                1) % len(signinConf)
        data['have_signin'] = signin.have_signin(usr, now)

        t1 = [
            str_to_day_time(gameConf['meal_time1'][0]),
            str_to_day_time(gameConf['meal_time1'][1])
        ]
        t2 = [
            str_to_day_time(gameConf['meal_time2'][0]),
            str_to_day_time(gameConf['meal_time2'][1])
        ]

        b1 = False
        b2 = False

        if len(usr.signin['last_meal_time']) > 2:
            usr.signin['last_meal_time'] = usr.signin['last_meal_time'][-2:-1]

        if len(usr.signin['last_meal_time']) > 1:
            if is_in_day_period(
                    t1[0], t1[1],
                    usr.signin['last_meal_time'][-2]) or is_in_day_period(
                        t1[0], t1[1], usr.signin['last_meal_time'][-1]):
                b1 = True
            if is_in_day_period(t2[0], t2[1],
                                usr.signin['last_meal_time'][-1]):
                b2 = True
        elif len(usr.signin['last_meal_time']) > 0:
            if is_in_day_period(t1[0], t1[1],
                                usr.signin['last_meal_time'][-1]):
                b1 = True
            if is_in_day_period(t2[0], t2[1],
                                usr.signin['last_meal_time'][-1]):
                b2 = True
        data['last_meal_time'] = [b1, b2]
        if len(usr.signin['continue_award_time']) == 2:
            data['continue_award_time'] = [True, True]
        elif len(usr.signin['continue_award_time']) == 0:
            data['continue_award_time'] = [True, False]
        elif day_diff(now, usr.signin['continue_award_time'][-1]) == 1:
            data['continue_award_time'] = [True, False]
        else:
            data['continue_award_time'] = [False, False]
        data['continue_award'] = usr.signin['continue_award_time']
        data['draw_award'] = []
        data['have_draw_award'] = True
        for d in usr.signin['draw_award_time']:
            if d:
                data['draw_award'] = True
                t = 0
                if isinstance(d, dict):
                    t = d['time']
                else:
                    t = d
                if is_same_day(t, now):
                    data['have_draw_award'] = False
            else:
                data['draw_award'] = False
        data['draw_award'] = usr.signin['draw_award_time']
        usr.save()
        return data
Exemplo n.º 27
0
	def have_signin(usr, now):
		"""
		是否已经签到
		"""
		return is_same_day(usr.signin['last_signin_time'], now)
Exemplo n.º 28
0
	def login(usr):
		"""
		登陆
		"""
		now = currentTime()
		gameConf = config.getConfig('game')
		signinConf = config.getConfig('signin')
		dd = day_diff(now, usr.signin['last_login_time'])
		if dd == 1:
			usr.signin['login_count'] = usr.signin['login_count'] + 1
		elif dd > 1:
			usr.signin['login_count'] = 1		
		usr.signin['last_login_time'] = currentTime()
		
		data = {}
		data['signin_index'] = (usr.signin['login_count'] - 1) % len(signinConf)
		data['have_signin'] = signin.have_signin(usr, now)
		
		t1 = [str_to_day_time(gameConf['meal_time1'][0]), str_to_day_time(gameConf['meal_time1'][1])]
		t2 = [str_to_day_time(gameConf['meal_time2'][0]), str_to_day_time(gameConf['meal_time2'][1])]
		
		b1 = False
		b2 = False
		
		if  len(usr.signin['last_meal_time']) > 2:
			usr.signin['last_meal_time'] =  usr.signin['last_meal_time'][-2:-1]
		
		if len(usr.signin['last_meal_time']) > 1:
			if is_in_day_period(t1[0], t1[1], usr.signin['last_meal_time'][-2]) or is_in_day_period(t1[0], t1[1], usr.signin['last_meal_time'][-1]):
				b1 = True
			if is_in_day_period(t2[0], t2[1], usr.signin['last_meal_time'][-1]):
				b2 = True			
		elif len(usr.signin['last_meal_time']) > 0:
			if is_in_day_period(t1[0], t1[1], usr.signin['last_meal_time'][-1]):
				b1 = True
			if is_in_day_period(t2[0], t2[1], usr.signin['last_meal_time'][-1]):
				b2 = True
		data['last_meal_time'] = [b1, b2]
		if len(usr.signin['continue_award_time']) == 2:
			data['continue_award_time'] = [True, True]
		elif len(usr.signin['continue_award_time']) == 0:
			data['continue_award_time'] = [True, False]
		elif day_diff(now, usr.signin['continue_award_time'][-1]) == 1:
			data['continue_award_time'] = [True, False]
		else:
			data['continue_award_time'] = [False, False]
		data['continue_award'] = usr.signin['continue_award_time']
		data['draw_award'] = []
		data['have_draw_award'] = True
		for d in usr.signin['draw_award_time']:
			if d:
				data['draw_award'] = True
				t = 0
				if isinstance(d, dict):
					t = d['time']
				else:
					t =d
				if is_same_day(t, now):
					data['have_draw_award'] = False			
			else: 
				data['draw_award'] = False
		data['draw_award'] = usr.signin['draw_award_time']
		usr.save()		
		return data