Example #1
0
def do_time_line():
    global time_line, res, petst        # dummy
    events = filter(lambda k: k< now(), time_line.keys())
    for keys in events:
        if key not in time_line:
            continue  # fix
        dowhat, parms = time_line[keys]
        print dowhat, parms, 
        if dowhat== 'STEAL':
            print u"[偷鱼]:",
            while True:
                petst = req_safe(gameService, "getPetStatusAMF", uid, *parms)
                if petst['status']== u'b' and (not petst['is_stolen']):
                    res = req_safe(gameService, "stealAMF", uid, *parms)
                    if res.get('fish', 0):
                        print_fish(res['fish'])
                        break
                    else:
                        print u"失败"
                        break
                elif petst['status']== u'c' and ((petst['rest_time'] or 1)<= 120):
                    print '.',
                    sys.stdout.flush()
                    time.sleep(0.8)
                    continue
                else:
                    print u"失败"
                    break
        elif dowhat== 'SHOCK':
            tank = req_safe(productsService, "getMyFishTankObjectListAMF", uid, *parms) # f['id']. tk['id']
            is_worth_shock, is_need_feed =  worth_shock(tank)
            if is_worth_shock:
                print u"[电鱼]:",  #{'error': u'no remain time error'}
                if is_need_feed:
                    print u"(喂食2)",
                    req_fail(productsService, "feedAMF", uid, *(list(parms)+[2]))
                    time.sleep(0.1)
                while True:
                    res = req_safe(productsService, "shockAMF", uid, *parms)
                    if res.get('get_shells', 0):
                        print u"获得", res['get_shells'], u"贝壳",
                        time_line[now()+240*60-random.randint(0, 3)-20] = ('SHOCK', parms) # need fix
                        print "[EVENT Registered]"
                        break
                    else:
                        if res.get('remain_time', 1000)<= 2:
                            print ".",
                            sys.stdout.flush()
                            if parms[0]== 16: # 本句代码送给可爱的管理员
                                time.sleep(0.1)
                            else:
                                time.sleep(5)
                            continue
                        print u"失败", res
                        time_line[now()+ res.get('remain_time', 240)*60 - 60] = ('SHOCK', parms)
                        break
        elif dowhat== 'HARVEST':
            pet_dispath()
        elif dowhat== 'SYNTH':
            print u"[合成]:",
            # here can't assert always right, but bug
            res = req_safe(syntheticService, "getSynthesizeInfoAMF", uid) # dummy?
            res = syntheticService.compeleteSynthesizeAMF(uid, *parms)
            if res.get('error', False):
                print u"某错误发生. 重设所有合成鱼事件."
                for k in [i for i in time_line if time_line[i][0]== 'SYNTH']:
                    del time_line[k]
                res = req_safe(syntheticService, "getSynthesizeInfoAMF", uid)
                process_synthetic_info(res)
                continue                # noneed to go on and del
            elif res['result']:           # success
                print u"获得%s %d经验" % (res['fish_name'], res['get_exp'])
            else:
                print u"合成失败, 渔民杯具了"
            res = req_safe(syntheticService, "addSynthesizeAMF", uid,  formula_id) 
            tl = [e for e in time_line if time_line[e][0]== 'SYNTH'] # bad, but Works
            t = max(tl) if tl else now()
            res = req_safe(syntheticService, "getSynthesizeInfoAMF", uid) # 上条多次重试时会导致出错,故加入
            if res.get('synth_list', []):
                time_line[t+5+res['synth_list'][-1]['need_time']] = ('SYNTH', (res['synth_list'][-1]['synth_id'],))
                print u"[EVENT Registered]"
            else:
                print u"自动合成出错, 可能是材料不足"
        else:
            print u"错误"
        del time_line[keys]
Example #2
0
     print u"-> 电鱼机会不足"
     continue
 # 喂鱼
 if f['id'] in ['your_feedee']:
     is_worth_feed, how_many_need = worth_feed(tank)
     if is_worth_feed:
         print u"喂鱼: 喂食%d" % int(how_many_need/2),
         for _ in xrange(int(how_many_need/2)):
             res = req_safe(productsService, "feedAMF", uid, f['id'], tk['id'], how_many_need)
             if res:
                 userinfo['user_info'] = res['user_info']['user_info']
                 tank.update(res['obj_list']) # update here
                 if res.get('get_food', 0):
                     print "*",
 # 电鱼
 is_worth_shock, is_need_feed =  worth_shock(tank)
 if is_worth_shock:
     print u"电鱼:",
     if tank['fish_tank']['is_shocked']:
         res = req_safe(productsService, "shockAMF", uid, f['id'], tk['id'])
         time_line[now()+ res.get('remain_time', 240)*60] = ('SHOCK', (f['id'], tk['id']))
         print '[EVENT Registered]'
         continue                # fixed
     if is_need_feed:
         print u"(喂食2)",
         req_fail(productsService, "feedAMF", uid, f['id'], tk['id'], 2)
     time.sleep(0.1)
     res = req_safe(productsService, "shockAMF", uid, f['id'], tk['id'])
     if res.get('get_shells', 0):
         print u"获得", res['get_shells'], u"贝壳",
         print '[EVENT Registered]',