コード例 #1
0
def get_training_time():
    global Hero, From, To, Zuansheng
    total_exp = 0
    hi = HeroInfo()
    exp_speed = int(hi.get_exp_speed())
    if Zuansheng > 0:
        if From is None:
            From = 1
            To = 51
        else:
            To = From - From % 10 + 1
        print 'Will sum from level %d to level %d'%(From, To)
        for l in range(From, To):
            total_exp += get_time_by_level(l)
        for z in range(Zuansheng):
            To += 10
            To = min(To, 150)
            print 'Will sum from level %d to level %d'%(From, To)
            for l in range(From, To):
                total_exp += get_time_by_level(l)
    else:
        if Hero:
            hid = UID[Hero]
            exp_speed = hi.get_exp_speed_by_id(hid) * (1 + hi.get_expMulti_by_id(hid))
            if not From:
                From = int(hi.get_level_by_id(hid))
            if not To:
                To = min(int(hi.get_nextrebirthlevel_by_id(hid)), hi.get_maxLevel_by_id(hid))
        print 'Will sum from level %d to level %d'%(From, To)
        for l in range(From, To):
            total_exp += get_time_by_level(l)
        total_exp -= hi.calc_cur_exp_by_id(hid)
    print 'Exp Speed: %d'%(exp_speed)
    print 'Total Exp: %d'%(total_exp)
    t = total_exp / float(exp_speed)
    if t > 24:
        d = int(t / 24)
        h = t - 24 * d
        print 'Need Time: %d Days %.1f Hours'%(d, h)
    else:
        print 'Need Time: %.1f Hours'%(t)
コード例 #2
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))