コード例 #1
0
    def doTryTapAction(self,
                       action: str,
                       showMsg: bool = True,
                       caputureScreen: bool = False):
        btnActionModel = btnEnModelMap[action]
        if caputureScreen:
            self.screenshot()
        if showMsg:
            fprint(f'执行动作:{btnActionModel.toString()}')
        if isinstance(btnActionModel, ImgBtnTapModel):
            flag = self.tryBtnTap(btnActionModel.btnEnName,
                                  btnActionModel.btnCnName,
                                  btnActionModel.stage, btnActionModel.sleep,
                                  btnActionModel.acceptableConfidence)
            self.tiggerEvent('doFindAction', target=self)
            return flag
        elif isinstance(btnActionModel, PosBtnTapModel):
            tapPos = [
                btnActionModel.posX + random.randint(-4, 4),  # 模拟人为非固定点击
                btnActionModel.posY + random.randint(-4, 4)
            ]
            self.adbDevice.tap(tapPos)
            fprint(f'{btnActionModel.btnCnName}按钮 tap:{tapPos} confidence:1')

            self.tiggerEvent('doFindAction', target=self)
            return True
コード例 #2
0
    def tryBtnTap(self,
                  btnName,
                  btnCnName=None,
                  stage="screen",
                  sleep=0.05,
                  acceptableConfidence=0.90):
        self.tryBtnLock.acquire()
        try:
            recRes = self.recognitionImg(btnName, stage)
            if recRes and recRes.get('confidence') > acceptableConfidence:
                confidence = recRes.get('confidence')
                w = [recRes['rectangle'][0][0], recRes['rectangle'][2][0]]
                h = [recRes['rectangle'][0][1], recRes['rectangle'][1][1]]
                tapPos = [
                    random.randint(w[0], w[1]),
                    random.randint(h[0], h[1])
                ]  # 随机,模拟人为点击位置不固定
                self.adbDevice.tap(tapPos)

                self.tiggerEvent('tryBtnTap', target=self)

                if btnCnName == None: btnCnName = btnName
                fprint(f'{btnCnName}按钮 tap:{tapPos} confidence:{confidence}')

                if sleep != 0:
                    time.sleep(sleep)
                return True
            return False
        except Exception as e:
            # raise e
            pass
        finally:
            self.tryBtnLock.release()
コード例 #3
0
    def startGame(self, gameMode: GameStopCondition = GameStopCondition.FOREVER,  # 游戏模式
                  restrictValue: int = None,  # 对应模式的限制值
                  gameActionMonitorFreq: float = 0.01  # 游戏行为检测频率
                  ):
        if self.__selectGameList__.isSelectGameOpt(SelectGameList.MAO_XIAN_WAN_FA):  # 冒险玩法
            self.__gameProxy__ = PlayMaoXianWanFaProxy(self.__deviceEmulator__,
                                                       gameMode, restrictValue, gameActionMonitorFreq)
        elif self.__selectGameList__.isSelectGameOpt(SelectGameList.LIU_GUO_YUAN_ZHEN):  # 六国远征
            self.__gameProxy__ = PlayLiuGuoYuanZhenProxy(self.__deviceEmulator__,
                                                         gameMode, restrictValue, gameActionMonitorFreq)
        else:
            fprint('请选择游戏才进行游戏!')
            return

        # 监听显示最新数据事件
        self.__gameProxy__.addListener('showInCome', self.gameScreen.updateTextInfo)

        self.__gameProxy__.start()
        if self.__isShowGUI__:
            self.gameScreen.mainloop()
        else:
            try:
                self.__gameProxy__.join()
            except KeyboardInterrupt:
                sys.exit(0)
コード例 #4
0
    def __init__(self,
                 device: DeviceEmulator = None,  # 游戏设备
                 gameMode: GameStopCondition = GameStopCondition.FOREVER,  # 游戏模式
                 restrictValue: int = None,  # 对应模式的限制值
                 gameActionMonitorFreq: float = 0.5  # 游戏行为检测频率
                 ):
        threading.Thread.__init__(self)
        EventObservable.__init__(self)

        # 根据游戏模式,设置限制值
        self.restrictPlayTimeSec = None
        self.restrictPlayCount = None
        self.restrictCoins = None
        self.restrictExpr = None
        if gameMode == GameStopCondition.FOREVER:
            pass  # 一直执行,无限制
        elif gameMode == GameStopCondition.TIME_SECOND:
            self.restrictPlayTimeSec = restrictValue
        elif gameMode == GameStopCondition.TIMES:
            self.restrictPlayCount = restrictValue
        elif gameMode == GameStopCondition.COINS:
            self.restrictCoins = restrictValue
        elif gameMode == GameStopCondition.EXPR:
            self.restrictExpr = restrictValue
        else:
            fprint("非法游戏模式!")
            exit(1)
        self.device = device
        self.gameMode = gameMode
        self.gameActionMonitorFreq = gameActionMonitorFreq
コード例 #5
0
 def isContinue(self) -> bool:
     isContinue: bool = True
     # 游戏完毕后做什么
     if self.gameMode == GameStopCondition.FOREVER:
         pass  # 无限制,继续战!
     elif self.gameMode == GameStopCondition.TIME_SECOND:
         if math.floor(time.time() - self.__firstProxyPlayTime__
                       ) >= self.restrictPlayTimeSec:
             fprint('温馨提示::已经玩了很久了,已经超过限制时间了!~')
             isContinue = False
     elif self.gameMode == GameStopCondition.TIMES:
         if self.__proxyPlayTimes__ >= self.restrictPlayCount:
             fprint('温馨提示::不能继续玩了,已经达到了限制次数!~')
             isContinue = False
     elif self.gameMode == GameStopCondition.COINS:
         if self.__proxyPlayTimes__ * self.gameInCoinsPer >= self.restrictCoins:
             fprint('温馨提示::已经达到了最高限制金币,继续往下玩可能没有金币收益哦!~')
             isContinue = False
     elif self.gameMode == GameStopCondition.EXPR:
         if self.__proxyPlayTimes__ * self.gameInExpPer >= self.restrictExpr:
             fprint('温馨提示::已经达到了最高限制经验,继续往下玩可能没有经验收益哦!~')
             isContinue = False
     else:
         fprint('目前不支持该模式!')
     return isContinue
コード例 #6
0
 def __init__(self):
     EventObservable.__init__(self)
     fprint("开始监听手机屏幕,请确保手机已经打开USB调试")
     # adb设备
     self.adbDevice = AdbDevice()
     # 保证设备可用
     self.adbDevice.connect()
コード例 #7
0
 def isGameOver(self):  # 检测当局是否已经结束
     flag1 = self.device.doTryTapAction('clickcontinue2', showMsg=False)  # 点击继续
     flag2 = self.device.doTryTapAction('zaicitiaozhan', showMsg=False)  # 再次挑战
     flag3 = self.device.doTryTapAction('gameFail', showMsg=False)  # 游戏失败
     if flag3:  # 游戏失败返回
         fprint('游戏失败!~')
         self.device.doTryTapActionList(['clickcontinue2', 'continue'])
     self.device.doTryTapAction('continue', showMsg=False)
     time.sleep(2)
     return flag1 or flag2 or flag3
コード例 #8
0
 def isGameOver(self):  # 检测当局是否已经结束
     flag1 = self.device.doTryTapAction('clickcontinue', showMsg=False)  # 点击继续
     flag2 = self.device.doTryTapAction('zaicitiaozhan', showMsg=False)  # 再次挑战
     flag3 = self.device.doTryTapAction('gameFail', showMsg=False)  # 游戏失败
     if flag3:  # 游戏失败返回
         fprint('游戏失败!~')
         time.sleep(1)  # 游戏失败后要等一会儿才会出按钮
         self.device.doTryTapActionList(['backBtnYellow', 'nextStep'])
         # TODO:: 失败应该不记录场次和金币经验,这个可以通过返回不同的游戏状态来做处理
     return flag1 or flag2 or flag3
コード例 #9
0
    def __printInCome(self):
        inComeStr = '\n===============结算信息================='
        inComeStr += f'\n游戏次数:{self.__proxyPlayTimes__}'
        inComeStr += f'\n大约累计金币:{self.__proxyPlayTimes__ * self.gameInCoinsPer}'
        inComeStr += f'\n大约累计经验:{self.__proxyPlayTimes__ * self.gameInExpPer}'
        inComeStr += f'\n已经玩游戏{getGameTimeFormat(math.floor(time.time() - self.__firstProxyPlayTime__))}了'
        inComeStr += '\n======================================'

        # 显示收入信息
        self.tiggerEvent('showInCome', msg = inComeStr)
        fprint(inComeStr)
コード例 #10
0
def doFindAction(action: str,
                 showMsg: bool = True,
                 caputureScreen: bool = False) -> bool:
    btnActionModel = btnEnModelMap[action]
    if caputureScreen:
        adbDevice.cutScreen()
    if showMsg:
        fprint(f'执行动作:{btnActionModel.toString()}')
    recRes = recognitionImg(btnActionModel.btnEnName, btnActionModel.stage)
    isFind = recRes and recRes.get(
        'confidence') > btnActionModel.acceptableConfidence
    return isFind
コード例 #11
0
    def doFindAction(self,
                     action: str,
                     showMsg: bool = True,
                     caputureScreen: bool = False) -> bool:
        btnActionModel = btnEnModelMap[action]
        if caputureScreen:
            self.screenshot()
        if showMsg:
            fprint(f'执行动作:{btnActionModel.toString()}')
        recRes = self.recognitionImg(btnActionModel.btnEnName,
                                     btnActionModel.stage)
        isFind = recRes and recRes.get(
            'confidence') > btnActionModel.acceptableConfidence

        self.tiggerEvent('doFindAction', target=self)

        return isFind
コード例 #12
0
 def cutScreen(self):
     self.deviceLock.acquire()
     try:
         cp = subprocess.run("adb shell screencap -p /sdcard/screen.png",
                             capture_output=True,
                             shell=True)
         if cp.returncode == 0:
             cp = subprocess.run("adb pull /sdcard/screen.png ./res/stage/",
                                 capture_output=True,
                                 shell=True)
             if cp.returncode == 0:
                 # fprint("截图成功")
                 return True
         fprint(f"截图失败!{cp.stderr}")
     finally:
         self.deviceLock.release()
     return False
コード例 #13
0
def doTryTapAction(action: str,
                   showMsg: bool = True,
                   caputureScreen: bool = False):
    btnActionModel = btnEnModelMap[action]
    if caputureScreen:
        adbDevice.cutScreen()
    if showMsg:
        fprint(f'执行动作:{btnActionModel.toString()}')
    if isinstance(btnActionModel, ImgBtnTapModel):
        return tryBtnTap(btnActionModel.btnEnName, btnActionModel.btnCnName,
                         btnActionModel.stage, btnActionModel.sleep,
                         btnActionModel.acceptableConfidence)
    elif isinstance(btnActionModel, PosBtnTapModel):
        tapPos = [
            btnActionModel.posX + random.randint(-4, 4),  # 模拟人为非固定点击
            btnActionModel.posY + random.randint(-4, 4)
        ]
        adbDevice.tap(tapPos)
        fprint(f'{btnActionModel.btnCnName}按钮 tap:{tapPos} confidence:1')
        return True
コード例 #14
0
    def run(self) -> None:
        shp = SkipHealthProtection(self.device)
        shp.start()  # 启动健康系统
        self.__gaming__ = False
        self.__firstProxyPlayTime__ = time.time()  # 首次开始时间
        fprint('进入游戏场景...')
        enterSucc = self.enterGame()  # 进入游戏场景
        if not enterSucc:
            fprint('进入游戏场景失败,停止运行!~')
            # TODO 停止整个程序
            return
        fprint('进入游戏场景完毕,进入游戏...')
        self.__gaming__ = True

        self.loadGame()  # 加载游戏
        self.__proxyPlayTimes__ = 1  # 代打次数

        while self.__gaming__ == True:  # 游戏内监测
            self.device.screenshot() # 截屏大概需要两秒
            self.playGaming()  # 游戏内玩游戏
            if self.isGameOver():  # 判定游戏是否结束
                self.__gaming__ = False
                fprint('单局游戏结束!,正在结算...')
                self.__printInCome()  # 打印收入信息

                self.gamePerEndHandle()  # 单局游戏后处理

                # 判断是否再战!
                if self.isContinue():
                    fprint('再战一局!')
                    self.playAgain()  # 再次玩游戏
                    self.__proxyPlayTimes__ += 1
                    self.__gaming__ = True
            # 休息片刻,再次进行下一轮监测
            time.sleep(self.gameActionMonitorFreq)
        # 停止健康系统
        shp.reqStop()
コード例 #15
0
 def run(self) -> None:
     fprint('提示:健康系统监测线程已经启动!~')
     while self.flag:
         # 由于代理玩游戏线程一直在捕捉画面,所以这里不截图,直接识别
         # 保护眼睛
         if (self.device.doTryTapAction('baohuyanjing', showMsg=False)):
             self.device.doTryTapAction('baohuyanjingok')
         # 禁赛
         if (self.device.doTryTapAction('baohujinshai', showMsg=False)):
             fprint('提示:健康系统监测线程已经关闭!~')
             fprint('已经被系统禁止比赛,程序退出(这里还有问题,不知道为啥这里停止不了)')
             # TODO:: 这里还有问题,不知道为啥这里停止不了
             self.reqStop()
             # self.gamePlayProxy.reqStop()
         # 检测频率(这个任务实时性不高,长一点都可以)
         time.sleep(5)
     fprint('提示:健康系统监测线程已经关闭!~')
コード例 #16
0
ファイル: main.py プロジェクト: apple006/playWangZheRongYao
import sys

from tconsole import fprint
from wzryProxy import PlayMaoXianWanFaProxy, PlayLiuGuoYuanZhenProxy, GameStopCondition

if __name__ == '__main__':
    fprint("程序启动,开始监听手机屏幕,请确保手机已经打开USB调试")

    ######## 冒险挑战 ######
    gameProxy = PlayMaoXianWanFaProxy(
    )  # 无限制,一直打下去(提示:腾讯有健康时长,久了会禁赛,金币每周也是有上限的)
    # gameProxy = PlayMaoXianWanFaProxy(GameStopCondition.TIMES, 1000) # 玩1000把游戏
    # gameProxy = PlayMaoXianWanFaProxy(GameStopCondition.COINS, 5000) # 打5000金币
    # gameProxy = PlayMaoXianWanFaProxy(GameStopCondition.EXPR, 10000) # 打10000经验
    # gameProxy = PlayMaoXianWanFaProxy(GameStopCondition.TIME_SECOND, 6 * 60 * 60) # 玩6个小时游戏

    ######## 六国远征 ######
    # gameProxy = PlayLiuGuoYuanZhenProxy()
    gameProxy.start()
    try:
        gameProxy.join()
    except KeyboardInterrupt:
        sys.exit(0)
コード例 #17
0
 def loadGame(self):
     fprint('正在加载游戏...')
     time.sleep(8)  # 假定游戏加载界面进行了8秒
     fprint('加载游戏完毕,开始玩游戏')
コード例 #18
0
 def __printInCome(self):
     fprint('===============结算信息=================')
     fprint(f'游戏次数:{self.__proxyPlayTimes__}')
     fprint(f'大约累计金币:{self.__proxyPlayTimes__ * self.gameInCoinsPer}')
     fprint(f'大约累计经验:{self.__proxyPlayTimes__ * self.gameInExpPer}')
     fprint(
         f'已经玩游戏{getGameTimeFormat(math.floor(time.time() - self.__firstProxyPlayTime__))}了'
     )
     fprint('======================================')