分离action开始的前置条件
This commit is contained in:
parent
c9f56c2435
commit
456539d7a5
1 changed files with 64 additions and 8 deletions
|
@ -28,9 +28,11 @@ class AutoFight(SceneGraphSolver):
|
|||
self.speed = 1 # 一倍/二倍速
|
||||
self.loading = True # 等待加载
|
||||
self.playing = True # 暂停/继续
|
||||
self.Skill_Daemon = False # 开始挂机使用技能
|
||||
self.condition_satified = False # 前置条件是否满足
|
||||
self.operators = {} # 可部署的干员
|
||||
self.location = {} # 干员部署坐标
|
||||
|
||||
self.post_delay = 0 # 行动后等待时间
|
||||
self.watching = {} # 需要开技能的干员
|
||||
for op in opers:
|
||||
name = op["name"]
|
||||
|
@ -87,6 +89,53 @@ class AutoFight(SceneGraphSolver):
|
|||
logger.debug(kills)
|
||||
return kills
|
||||
|
||||
def CD(self) -> int:
|
||||
"获取进入CD的干员数量"
|
||||
config.recog.update()
|
||||
y = 887
|
||||
img = cropimg(config.recog.gray, ((0, y), (1920, 905)))
|
||||
threshold = 0.7
|
||||
c = loadres("fight/c", True)
|
||||
mask = loadres("fight/c_mask", True)
|
||||
result = cv2.matchTemplate(img, c, cv2.TM_CCOEFF_NORMED, None, mask)[0]
|
||||
op = []
|
||||
for i in argrelmax(result, order=50)[0]:
|
||||
if result[i] > threshold:
|
||||
op.append(i)
|
||||
self.operators = {}
|
||||
number = 0
|
||||
for x in op:
|
||||
# 看最下方条的颜色判断是否正在转CD
|
||||
bar_scope = sa(((-20, 187), (10, 190)), (x, y))
|
||||
img = cropimg(config.recog.img, bar_scope)
|
||||
img = cv2.inRange(img, (1, 0, 0), (3, 255, 255))
|
||||
count = cv2.countNonZero(img)
|
||||
logger.debug(count)
|
||||
if count > 50:
|
||||
number += 1
|
||||
return number
|
||||
|
||||
def sleep_post_delay(self):
|
||||
self.sleep(self.post_delay)
|
||||
self.post_delay = 0
|
||||
|
||||
def check_condition(self) -> bool:
|
||||
if "kills" in self.action and self.action["kills"] > self.kills():
|
||||
return False
|
||||
if "costs" in self.action and self.action["costs"] > self.cost():
|
||||
return False
|
||||
if "cooling" in self.action and self.action["cooling"] > self.CD():
|
||||
return False
|
||||
if "cost_changes" in self.action:
|
||||
s = self.cost()
|
||||
while self.cost() - s < self.action["cost_changes"]:
|
||||
self.sleep(0.5)
|
||||
if "pre_delay" in self.action:
|
||||
self.sleep(self.action["pre_delay"] / 1000)
|
||||
if "post_delay" in self.action:
|
||||
self.pre_delay = self.action["post_delay"] / 1000
|
||||
return True
|
||||
|
||||
def skill_ready(self, x: int, y: int) -> bool:
|
||||
"""指定坐标的干员技能是否可以开启
|
||||
|
||||
|
@ -149,6 +198,9 @@ class AutoFight(SceneGraphSolver):
|
|||
def complete_action(self):
|
||||
"完成当前行动"
|
||||
self.actions.pop(0)
|
||||
self.condition_satified = False
|
||||
if self.post_delay > 0:
|
||||
self.sleep_post_delay()
|
||||
|
||||
def toggle_play(self):
|
||||
"切换暂停与继续"
|
||||
|
@ -194,8 +246,6 @@ class AutoFight(SceneGraphSolver):
|
|||
|
||||
def deploy(self):
|
||||
"部署干员"
|
||||
if "kills" in self.action and self.action["kills"] < self.kills():
|
||||
return
|
||||
name = self.action["name"]
|
||||
if name not in self.operators:
|
||||
self.update_operators()
|
||||
|
@ -247,10 +297,11 @@ class AutoFight(SceneGraphSolver):
|
|||
|
||||
def withdraw(self):
|
||||
"撤下干员"
|
||||
if "kills" in self.action and self.action["kills"] < self.kills():
|
||||
return
|
||||
if "name" in self.action:
|
||||
name = self.action["name"]
|
||||
x, y = self.location[name]
|
||||
else:
|
||||
x, y = self.action["location"]
|
||||
self.select(x, y)
|
||||
sleep(0.5)
|
||||
pos = self.calc.get_with_draw_screen_pos(x, y)
|
||||
|
@ -290,7 +341,12 @@ class AutoFight(SceneGraphSolver):
|
|||
if d["skill_times"] <= 0:
|
||||
del self.watching[w]
|
||||
return
|
||||
|
||||
if self.action is None:
|
||||
self.sleep(1)
|
||||
return
|
||||
if not self.condition_satified:
|
||||
self.condition_satified = self.check_condition()
|
||||
return
|
||||
if self.action["type"] == "SpeedUp":
|
||||
self.toggle_speed()
|
||||
elif self.action["type"] == "Deploy":
|
||||
|
|
Loading…
Reference in a new issue