mower-ng/mower/solvers/stronghold_protocol.py

80 lines
2.9 KiB
Python

import cv2
from mower.solvers.fight.mixin import FightMixin
from mower.utils import config
from mower.utils.graph import SceneGraphSolver
from mower.utils.image import cropimg, thres2
from mower.utils.scene import Scene
from mower.utils.vector import va
class StrongholdProtocol(SceneGraphSolver, FightMixin):
solver_name = "卫戍协议"
def read_money(self) -> bool:
if self.find("stronghold_protocol/money3"):
money = 3
elif self.find("stronghold_protocol/money5"):
money = 5
else:
return False
self.sleep()
return self.find(f"stronghold_protocol/money{money}") == money
def transition(self):
if (scene := self.scene()) == Scene.TERMINAL_MAIN:
self.terminal_entry("stronghold_protocol/entry.jpg")
elif scene == Scene.SP_MAIN:
if pos := self.find("stronghold_protocol/stop"):
if not self.find("stronghold_protocol/round1"):
self.tap(pos)
return
self.tap((1664, 911))
elif scene == Scene.SP_DEFENCE:
if pos := self.find("stronghold_protocol/start"):
self.tap(pos)
return
self.tap((383, 948))
elif scene == Scene.SP_ACTION:
# 第二轮退出
img = cropimg(config.recog.gray, ((1045, 24), (1063, 46)))
img = cv2.bitwise_not(thres2(img, 127))
if config.recog.num.number_int("secret_front", img=img) >= 2:
self.back()
return
# 购买干员
if pos := self.find("stronghold_protocol/buy1"):
if self.find("stronghold_protocol/medic"):
self.tap((804, 513))
return
self.tap(pos)
return
if pos := self.find("stronghold_protocol/buy2"):
if self.find("stronghold_protocol/medic"):
self.tap((875, 431))
return
self.tap(pos)
return
if pos := self.find("stronghold_protocol/buy3"):
self.tap(pos)
return
if self.find("stronghold_protocol/empty"):
if self.find("stronghold_protocol/money0") or self.find(
"stronghold_protocol/money2"
):
self.tap((1827, 93)) # 开始作战
return
self.tap((407, 540)) # 购买干员
return
# 放置干员
pos = (1058, 746) if self.find("stronghold_protocol/block") else (1475, 524)
for _ in range(3):
self.swipe_ext([(1602, 989), pos], [500], 100, 0.3)
if self.drag_success():
self.swipe_ext([pos, va(pos, (300, 0))], [200], 100)
break
else:
self.scene_graph_step(Scene.TERMINAL_MAIN)