示例#1
0
文件: level50.py 项目: kimbaol/libMA
def main():
    # remove_friends(get_app(my_loginId, my_password, init=True),
    #                (get_app(loginId, password, init=True) for loginId in b_loginIds))
    # return
    #root = get_app(my_loginId, my_password)
    users = list(get_app(loginId, password) for loginId, password in root_users)
    #users = [get_app(loginId, password)]
    #users = [root]
    # add_friends(get_app(my_loginId, my_password, init=True), users)
    while True:
        for user in users:
            try:
                # import pdb;pdb.set_trace()
                if len(user.cards) > 180:
                    logic.update_ap_bc(user, all_ap=True)
                    logic.gacha_buy(user, keep_point=9000)
                    logic.card_sell(user)
                user.logger.debug(user_info(user))
                if not check_fairy(user):
                    find_fairy(user)
                else:
                    time.sleep(30 * b())
            except HeaderError, e:
                user.logger.error("%s %s sleep for 15sec" % (e.code, e.message))
                time.sleep(15 * b())
                continue
            except Exception, e:
                user.logger.error("出错:%s. %s" % (e.message, traceback.format_exc()))
                time.sleep(15 * b())
            except KeyboardInterrupt:
                save_app(user)
                break
示例#2
0
文件: win.py 项目: kimbaol/libMA
def battle_battle(user, battle_id, cards, desk_cost):
    global battle_time
    data = user.get("menu/playerinfo", dict(user_id=battle_id, kind=1))

    _user = data[0].response.body.player_info.user
    if _user.town_level == 4 and _user.next_exp == 80 and _user.card_num == 7:
        user.logger.info(user_info(user))
        if check_fairy(user) and user.ap < user.ap_max * 2 / 3:
            time.sleep(LOCKER_TIME)
        else:
            if find_fairy(user):
                time.sleep(LOCKER_TIME)
        user.logger.info(u"user %s: %s ap%s bc%s " % (_user.name, battle_id, user.ap, user.bc))
        if user.cost != desk_cost or user._roundtable.leader_card != cards[0]:
            while len(cards) < 12:
                cards.append("empty")
            data = user.get("cardselect/savedeckcard", dict(C=",".join(map(str, cards)), lr=str(cards[0])))
        _time = LOCKER_TIME - (time.time() - battle_time)
        if _time > 0:
            user.logger.debug(u"wait for battle lock %s" % _time)
            time.sleep(_time)
        battle_time = time.time()
        data = user.get("battle/battle", dict(user_id=battle_id, lake_id=0, parts_id=0))
        result = data.response.body.battle_result
        winner_ = result.winner == 1
        user.logger.info(
            "%s %s E+%s, sleep 20s"
            % ("winner" if winner_ else "failed", battle_id, result.before_exp - result.after_exp)
        )

        with open(RESULT_FILE, "ab") as wf:
            if winner_:
                wf.write("win,%s\n" % battle_id)
            else:
                with open("resource/battle_%s_%s_%s.xml" % (winner_, battle_id, user.login_id), "wb") as fp:
                    fp.write(user.last_xml)
                wf.write("failed,%s\n" % battle_id)
            wf.flush()

        if result.before_level != result.after_level:
            logic.update_ap_bc(user, all_bc=True)
        return winner_