예제 #1
0
 def run(self):
     global FirstTime, Times
     logger.info('zengzanThread start')
     if Delay_Time > 0:
         logger.info('I will start zengzan at ' + util.next_time(Delay_Time))
         time.sleep(Delay_Time)
     while True:
         ni = self.getNpcInfo()
         remain_times = ni.getNumber()
         if remain_times > 0:
             time.sleep(2)
             res = self.zengzan(Npc_String, remain_times + 100)
             if res.has_key('exception'):
                 msg = res['exception']['message']
                 logger.info('zengzan exception: %s'%(msg))
                 if msg == 'waittingOrder':
                     gi = GeneralInfo()
                     sp = util.get_sleep_time(gi.get_mobility_CDTime(), gi.get_localTime()-gi.get_serverTime())
                     logger.info('I will sleep for mobility CD to %s'%(util.next_time(sp)))
                     time.sleep(sp)
                     FirstTime = True
                     continue
                 elif msg == 'lessMobility':
                     return
                 else:
                     time.sleep(2)
                     FirstTime = True
                     continue
         nrt = util.get_next_refresh_time(ni.getServerTime())
         sp = util.get_sleep_time(nrt, ni.getLocalTime()-ni.getServerTime()) + 1
         logger.info('I will sleep till time %s'%(util.next_time(sp)))
         time.sleep(sp)
예제 #2
0
 def run(self):
     global g_previous_armyid
     logger.info('pozen Thread start, will pozen campaign %s'%(str(Campaign)))
     if Delay_Time > 0:
         logger.info('I will start pozen at ' + util.next_time(Delay_Time))
         time.sleep(Delay_Time)
     #self.bianzhen('yanxing')
     time.sleep(2)
     for campaignid in Campaign:
         while True:
             try:
                 #res = self.get_pozen_info(2)
                 #print json.dumps(res, sort_keys = False, indent = 4)
                 #return
                 armyid = self.get_next_id(campaignid)
                 if armyid is None:
                     logger.info('pozen network error')
                     time.sleep(2)
                     continue
                 elif armyid == -1:
                     logger.info('pozen %d finished'%(campaignid))
                     break
                 elif armyid == g_previous_armyid:
                     logger.info('pozen %d falied, %d lose'%(campaignid,  armyid))
                     return
                 g_previous_armyid = armyid
                 time.sleep(2)
                 logger.info('pozen army %d'%(armyid))
                 res = self.do_pozen(armyid)
                 if res.has_key('exception'):
                     logger.error('Got Exception "%s"'%(res['exception']['message']))
                     if 'waittingOrder' == res['exception']['message']:
                         gi = GeneralInfo()
                         sp = util.get_sleep_time(gi.get_mobility_CDTime(), gi.get_localTime()-gi.get_serverTime())
                         logger.info('I will sleep for mobility CD to %s'%(util.next_time(sp)))
                         time.sleep(sp)
                         g_previous_armyid = 0
                         continue
                     return
                 time.sleep(2)
             except:
                 logger.info(traceback.format_exc())
                 time.sleep(10)
예제 #3
0
    def run(self):
        logger.info('BossThread start')
        if Delay_Time > 0:
            logger.info('I will start attack at ' + util.next_time(Delay_Time))
            time.sleep(Delay_Time)

        gi = GeneralInfo()
        start_time = util.get_xiongsou_refresh_time(gi.get_serverTime())
        ls_diff = gi.get_localTime() - gi.get_serverTime()
        sp = util.get_sleep_time(start_time, ls_diff) + 1
        if sp > 0:
            logger.info('I will sleep till start time, will attack at %s'%(util.next_time(sp)))
            time.sleep(sp)
        else:
            time.sleep(2)

        times = 0
        while True:
            times += 1
            if times > Times:
                logger.info('already attack %d times, exit'%(Times))
                break

            res = self.do_attack()
            if res.has_key('exception'):
                logger.error('Got Exception "%s"'%(res['exception']['message']))
                if 'attackCoolTime' == res['exception']['message']:
                    times -= 1
                else:
                    break
            logger.info('attacked %d times'%(times))

            gi = GeneralInfo()
            cd = gi.get_xiongsou_CDTime()
            stime = gi.get_serverTime()
            if cd > stime:
                sp = cd - stime + 1
                logger.info('I will sleep CD, will attack at %s'%(util.next_time(sp)))
                time.sleep(sp)
            else:
                time.sleep(2)
예제 #4
0
 def run(self):
     global Max_Level
     logger.info('TrainingThread start, Max_Level is %d'%(Max_Level))
     logger.info('I will training heroes: ' + ' '.join(Hero_List))
     if Delay_Time > 0:
         logger.info('I will start training at ' + util.next_time(Delay_Time))
         time.sleep(Delay_Time)
     inteval = 100
     sp = 7200 - (len(Hero_List)-1) * inteval + 2 * len(Hero_List)
     cnt = 1
     while True:
         tpsp = sp
         for i in range(len(Hero_List)):
             self.do_training(Hero_List[i])
             try:
                 # get hero info
                 hid = UID[Hero_List[i]]
                 hi = HeroInfo()
                 level = int(hi.get_level_by_id(hid))
                 next_rebirth_level = int(hi.get_nextrebirthlevel_by_id(hid))
                 name = hi.get_name_by_id(hid)
                 trainingEndTime = int(hi.get_trainingEndTime_by_id(hid))
                 nextUpgrade = int(hi.get_nextUpgrade_by_id(hid))
                 serverTime = int(hi.data['serverTime'])
                 localTime = hi.local_time
                 max_level = Max_Level
                 if max_level <= 0 :
                     max_level = next_rebirth_level
                 if level >= int(hi.get_maxLevel_by_id(hid)):
                     msg = 'Hero %s already reach maxLevel %d, will exit'%(name, level)
                     logger.info(msg)
                     util.notify(msg)
                     return
                 if level >= max_level:
                     if Auto_Rebirth:
                         self.rebirth(Hero_List[i])
                         msg = 'Hero %s already reach maxLevel %d, will rebirth'%(name, level)
                         logger.info(msg)
                         util.notify(msg)
                     else:
                         msg = 'Hero %s already reach maxLevel %d, will exit'%(name, level)
                         logger.info(msg)
                         util.notify(msg)
                         return
                 else:
                     total_exp = 0
                     for l in range(level, max_level):
                         total_exp += get_time_by_level(l)
                     total_exp -= hi.calc_cur_exp_by_id(hid)
                     exp_speed = hi.get_exp_speed_by_id(hid)
                     army = int(hi.get_currUnit_by_id(hid))
                     t = total_exp / float(exp_speed)
                     msg = 'Hero %s current level %d, army %d, max level %d, '%(name, level, army, max_level)
                     if t > 24: 
                         d = int(t / 24) 
                         h = t - 24 * d 
                         msg = msg + 'still need %d days %.1f hours'%(d, h)
                     else:
                         msg = msg + 'still need %.1f hours'%(t)
                     logger.info(msg)
                 if level == max_level - 1:
                     if trainingEndTime > nextUpgrade:
                         logger.info('Hero %s will reach level %d in the end of this round'%(name, max_level))
                         sp = util.get_sleep_time(nextUpgrade, localTime-serverTime)
                         time.sleep(sp)
                         if Auto_Rebirth:
                             self.rebirth(Hero_List[i])
                             msg = 'Hero %s already reach maxLevel %d, do rebirth'%(name, level+1)
                             logger.info(msg)
                             util.notify(msg)
                         else:
                             msg = 'Hero %s already reach maxLevel %d'%(name, level+1)
                             logger.info(msg)
                             util.notify(msg)
                         tpsp = trainingEndTime - nextUpgrade + 1
                         continue
                 tpsp = trainingEndTime - serverTime + 1
             except:
                 logger.error(traceback.format_exc())
             if i < len(Hero_List) - 1:
                 time.sleep(inteval)
         logger.info('sleeping %d seconds in %d time'%(tpsp, cnt))
         logger.info('next round will start at ' + util.next_time(tpsp))
         cnt += 1
         time.sleep(max(tpsp, 0))