From 6758781f3e65db9f5b7f770c797bd5cf6c00a0eb Mon Sep 17 00:00:00 2001 From: DogeAS Date: Fri, 9 May 2025 23:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9A=E4=BA=86=E6=A8=A1=E5=BC=8F=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=92=8C=E6=9C=89=E6=95=88=E6=A3=80=E6=B5=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DGConfig.py | 5 ++-- DoGeasLAB.py | 35 +++++++++++++++++++++------ __pycache__/DGConfig.cpython-312.pyc | Bin 0 -> 362 bytes 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 __pycache__/DGConfig.cpython-312.pyc diff --git a/DGConfig.py b/DGConfig.py index 0acbc40..13c5c5e 100644 --- a/DGConfig.py +++ b/DGConfig.py @@ -1,5 +1,6 @@ interval = 0.1 wakeSignalStrength=20 -defalutStrength=10 +defalutStrength=5 max_retries = 3 # 最大重试次数 -retry_delay = 1 # 重试间隔时间(秒) \ No newline at end of file +retry_delay = 1 # 重试间隔时间(秒) +indicators_url = "http://localhost:8111/indicators" \ No newline at end of file diff --git a/DoGeasLAB.py b/DoGeasLAB.py index cede187..3b2d225 100644 --- a/DoGeasLAB.py +++ b/DoGeasLAB.py @@ -17,6 +17,7 @@ calculatedStB=0 dglab_instance=pydglab.dglab_v3() data={} dataGot=False +gameMode=0#0=tank 1=air #连接主机 async def connect(): @@ -41,13 +42,15 @@ async def connect(): #抓取数据 async def getData(): global data,dataGot - indicators_url = "http://localhost:8111/indicators" dataGot=True #获取数据 try: - response=requests.get(indicators_url) + response=requests.get(cfg.indicators_url) response.raise_for_status() data=response.json() + #如果是海军 + if data.get("valid")==False: + dataGot=False #获取失败 except requests.exceptions.RequestException as e: print(f"获取数据失败 :{e}") @@ -61,11 +64,24 @@ async def getData(): #强度计算 async def setStrength(): #计算 - global data,currentStA,currentStB,calculatedStA,calculatedStB - calculatedStA=data.get("crew_total")*4 - calculatedStA=round(calculatedStA) - #if calculatedStA<15: - #calculatedStA+=5 + global data,currentStA,currentStB,calculatedStA,calculatedStB,gameMode + + #陆战计算 + if dataGot and data.get("army")=="tank": + if gameMode==1: + gameMode=0 + calculatedStA=data.get("crew_total")*4 + #最后记得取整 + calculatedStA=round(calculatedStA) + #空战计算 + elif dataGot and data.get("army")=="air": + if gameMode==0: + gameMode=1 + calculatedStA=cfg.defalutStrength + if calculatedStA<15: + calculatedStA+=2 + else: + calculatedStA=cfg.defalutStrength #主逻辑 async def main(): @@ -90,7 +106,10 @@ async def main(): if(calculatedStA!=currentStA or calculatedStB!=currentStB): print(f"强度修改为:{calculatedStA},{calculatedStB}") await dglab_instance.set_strength_sync(calculatedStA, calculatedStB) - await asyncio.sleep(cfg.interval) + await asyncio.sleep(cfg.interval) + else: + await dglab_instance.set_strength_sync(currentStA, currentStB) + await asyncio.sleep(cfg.interval) return if __name__ == "__main__": diff --git a/__pycache__/DGConfig.cpython-312.pyc b/__pycache__/DGConfig.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f574e205b08fc7455c0fe6de4c9409e0a1c8812f GIT binary patch literal 362 zcmX@j%ge<81hEQo8ApKhV-N=h7@>^MGC;<3h7^V&lE=o-; zi1E)$bt%d$ON|LmF3Kz@DUNZ^1QIU!?x~5zK8Z=X;UO_D?#}snX_@JI1(mlrY;yBc zN^?@}iui%1fxK0$0wg{#Gcq#X;O1-KxFIZhfkEhofM5gv4L<$`ZU`Z0+{jnN3seXI DUwv-% literal 0 HcmV?d00001