add:填充干员
This commit is contained in:
parent
c1b23205ee
commit
e7973867ce
5 changed files with 264 additions and 2 deletions
BIN
mower/resources/choose_agent/battle_filter.png
(Stored with Git LFS)
Normal file
BIN
mower/resources/choose_agent/battle_filter.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
mower/resources/choose_agent/battle_filter_close.png
(Stored with Git LFS)
Normal file
BIN
mower/resources/choose_agent/battle_filter_close.png
(Stored with Git LFS)
Normal file
Binary file not shown.
126
mower/solvers/fight/battle_choose/battle_fill_choose.py
Normal file
126
mower/solvers/fight/battle_choose/battle_fill_choose.py
Normal file
|
@ -0,0 +1,126 @@
|
|||
import math
|
||||
|
||||
import numpy as np
|
||||
|
||||
from mower.solvers.fight.battle_choose.battle_filter import BattleFilterSolver
|
||||
from mower.utils import config
|
||||
from mower.utils.character_recognize import segment_team_select
|
||||
from mower.utils.graph.utils import SceneGraphSolver
|
||||
from mower.utils.image import cmatch, cropimg
|
||||
from mower.utils.scene import Scene
|
||||
from mower.utils.vector import va
|
||||
|
||||
|
||||
# 按需填充干员
|
||||
class BattleAgentChooseSolver(SceneGraphSolver):
|
||||
def __init__(self) -> None:
|
||||
self.labels = [
|
||||
"获取时间",
|
||||
"信赖值",
|
||||
"生命上限",
|
||||
"攻击",
|
||||
"防御",
|
||||
"法术抗性",
|
||||
"再部署",
|
||||
"部署费用",
|
||||
"阻挡数",
|
||||
"攻击速度",
|
||||
"等级",
|
||||
"稀有度",
|
||||
]
|
||||
|
||||
self.profession = [
|
||||
"PIONEER",
|
||||
"WARRIOR",
|
||||
"TANK",
|
||||
"SNIPER",
|
||||
"CASTER",
|
||||
"MEDIC",
|
||||
"SUPPORT",
|
||||
"SPECIAL",
|
||||
]
|
||||
|
||||
def run(self, label: str, number: int) -> None:
|
||||
self.mode = None
|
||||
# 0是非职业的筛选,如信赖值或等级
|
||||
if label in self.labels:
|
||||
self.mode = 0
|
||||
# 1是干员职业的筛选
|
||||
elif label in self.profession:
|
||||
self.mode = 1
|
||||
else:
|
||||
raise KeyError(f"BattleAgentChooseSolver:填充干员标签错误{label}")
|
||||
self.label = label
|
||||
self.filter_done = False
|
||||
self.number = number
|
||||
super().run()
|
||||
pass
|
||||
|
||||
def tag_choosed(self, profession: str = "ALL"):
|
||||
str = "choose_agent/profession/" + profession
|
||||
if pos := self.find(str):
|
||||
if arrow := self.find("choose_agent/profession/choose_arrow"):
|
||||
if (
|
||||
math.sqrt(
|
||||
math.pow(pos[0][0] - arrow[0][0], 2)
|
||||
+ math.pow(pos[0][1] - arrow[0][1], 2)
|
||||
)
|
||||
< 100
|
||||
):
|
||||
return False
|
||||
else:
|
||||
self.tap(pos[0], interval=0.2)
|
||||
return True
|
||||
else:
|
||||
self.tap(pos[0], interval=0.2)
|
||||
return True
|
||||
|
||||
def filter(self):
|
||||
if pos := self.find("choose_agent/open_profession"):
|
||||
self.tap(pos, interval=0.1)
|
||||
return
|
||||
|
||||
if self.mode == 1:
|
||||
return self.tag_choosed(self.label)
|
||||
elif self.mode == 0:
|
||||
if BattleFilterSolver().run(self.label):
|
||||
# 选全部干员
|
||||
if self.find("choose_agent/foldup"):
|
||||
return True
|
||||
else:
|
||||
return self.tag_choosed()
|
||||
return
|
||||
|
||||
def fill_agent(self):
|
||||
segments = segment_team_select(config.recog.img)
|
||||
for i in segments:
|
||||
segment = [va(i[0], (0, -95)), va(i[1], (0, -190))]
|
||||
img = cropimg(config.recog.img, segment)
|
||||
template = np.zeros((5, 5, 3), dtype=np.uint8)
|
||||
template[:] = [120, 190, 220]
|
||||
if cmatch(img, template, thresh=50):
|
||||
continue
|
||||
self.tap(i, interval=0.1)
|
||||
|
||||
config.recog.update()
|
||||
img = cropimg(config.recog.img, segment)
|
||||
if cmatch(img, template, thresh=50):
|
||||
self.number = self.number - 1
|
||||
else:
|
||||
return
|
||||
if self.number == 0:
|
||||
return True
|
||||
|
||||
if self.number > 0:
|
||||
self.swipe_noinertia((1000, 540), (-1900, 0))
|
||||
return
|
||||
|
||||
def transition(self) -> bool:
|
||||
if self.scene() == Scene.OPERATOR_AGENT_SELECT:
|
||||
if self.filter_done is False:
|
||||
if self.filter():
|
||||
self.filter_done = True
|
||||
return
|
||||
return self.fill_agent()
|
||||
else:
|
||||
return False
|
129
mower/solvers/fight/battle_choose/battle_filter.py
Normal file
129
mower/solvers/fight/battle_choose/battle_filter.py
Normal file
|
@ -0,0 +1,129 @@
|
|||
import math
|
||||
from re import I
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from mower.utils import config
|
||||
from mower.utils.graph.utils import SceneGraphSolver
|
||||
from mower.utils.image import cropimg
|
||||
from mower.utils.log import logger
|
||||
from mower.utils.scene import Scene
|
||||
|
||||
|
||||
class BattleFilterSolver(SceneGraphSolver):
|
||||
def __init__(self) -> None:
|
||||
self.labels = [
|
||||
"获取时间",
|
||||
"信赖值",
|
||||
"生命上限",
|
||||
"攻击",
|
||||
"防御",
|
||||
"法术抗性",
|
||||
"再部署",
|
||||
"部署费用",
|
||||
"阻挡数",
|
||||
"攻击速度",
|
||||
]
|
||||
self.orders = [
|
||||
"等级",
|
||||
"稀有度",
|
||||
"自定义",
|
||||
]
|
||||
|
||||
def run(self, tag: str, ascending: bool = True) -> None:
|
||||
if tag not in self.labels and tag not in self.orders:
|
||||
raise KeyError
|
||||
|
||||
self.tag = tag
|
||||
self.ascending = ascending
|
||||
self.label = "自定义"
|
||||
self.tag_choose_done = False
|
||||
|
||||
if self.tag in self.orders:
|
||||
self.tag_choose_done = True
|
||||
self.in_label = False
|
||||
self.label = self.tag
|
||||
|
||||
super().run()
|
||||
|
||||
return True
|
||||
|
||||
def get_now_filter(self):
|
||||
image = cropimg(config.recog.img, [(1500, 90), (1900, 1080)])
|
||||
hsv_image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
|
||||
mask = cv2.inRange(hsv_image, (0, 200, 100), (140, 255, 255))
|
||||
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
for contour in contours:
|
||||
_, y, _, h = cv2.boundingRect(contour)
|
||||
return f"{self.labels[ int((y + h / 2) / 90) ]}"
|
||||
|
||||
def tag_choosed(self, profession: str = "ALL"):
|
||||
str = "choose_agent/profession/" + profession
|
||||
if pos := self.find(str):
|
||||
if arrow := self.find("choose_agent/profession/choose_arrow"):
|
||||
if (
|
||||
math.sqrt(
|
||||
math.pow(pos[0][0] - arrow[0][0], 2)
|
||||
+ math.pow(pos[0][1] - arrow[0][1], 2)
|
||||
)
|
||||
< 100
|
||||
):
|
||||
return False
|
||||
else:
|
||||
self.tap(pos[0], interval=0.2)
|
||||
return True
|
||||
else:
|
||||
self.tap(pos[0], interval=0.2)
|
||||
return True
|
||||
|
||||
def detect_arrange_order(self):
|
||||
x_list = (1280, 1430, 1575)
|
||||
y = 64
|
||||
hsv = cv2.cvtColor(config.recog.img, cv2.COLOR_RGB2HSV)
|
||||
mask = cv2.inRange(hsv, (99, 200, 0), (100, 255, 255))
|
||||
for idx, x in enumerate(x_list):
|
||||
if np.count_nonzero(mask[y : y + 3, x : x + 5]):
|
||||
return (self.orders[idx], True)
|
||||
if np.count_nonzero(mask[y + 10 : y + 13, x : x + 5]):
|
||||
return (self.orders[idx], False)
|
||||
|
||||
def switch_arrange_order(self, name, ascending=False):
|
||||
name_x = {"等级": 1280, "稀有度": 1430, "自定义": 1575}
|
||||
if isinstance(name, int):
|
||||
name = list(name_x.keys())[name - 1]
|
||||
if isinstance(ascending, str):
|
||||
ascending = ascending == "true"
|
||||
name_y = 60
|
||||
self.tap((name_x[name], name_y), interval=0.5)
|
||||
|
||||
def choose_tag(self):
|
||||
if self.tag_choose_done:
|
||||
if self.find("choose_agent/battle_filter_close"):
|
||||
self.tap((1750, 60), interval=0.1)
|
||||
return
|
||||
n, s = self.detect_arrange_order()
|
||||
if n != self.label or s != self.ascending:
|
||||
self.switch_arrange_order(self.label, self.ascending)
|
||||
return
|
||||
|
||||
return True
|
||||
|
||||
if not self.find("choose_agent/battle_filter_close"):
|
||||
self.tap_element("choose_agent/battle_filter")
|
||||
return
|
||||
|
||||
self.tap((1750, (self.labels.index(self.tag)) * 90 + 135), interval=0.1)
|
||||
|
||||
config.recog.update()
|
||||
if str := self.get_now_filter():
|
||||
if str == self.tag:
|
||||
self.tag_choose_done = True
|
||||
|
||||
return
|
||||
|
||||
def transition(self) -> bool:
|
||||
if self.scene() == Scene.OPERATOR_AGENT_SELECT:
|
||||
return self.choose_tag()
|
||||
else:
|
||||
return False
|
|
@ -57,7 +57,7 @@ def segment_team(img: tp.Image) -> list[tp.Scope]:
|
|||
|
||||
def segment_team_select(img: tp.Image) -> list[tp.Scope]:
|
||||
"作战编队和训练位选干员"
|
||||
line1 = cropimg(img, ((600, 510), (1920, 511)))
|
||||
line1 = cropimg(img, ((600, 476), (1920, 477)))
|
||||
hsv = cv2.cvtColor(line1, cv2.COLOR_RGB2HSV)
|
||||
mask = cv2.inRange(hsv, (98, 140, 200), (102, 255, 255))
|
||||
line1 = cv2.cvtColor(line1, cv2.COLOR_RGB2GRAY)
|
||||
|
@ -69,8 +69,9 @@ def segment_team_select(img: tp.Image) -> list[tp.Scope]:
|
|||
name_x = []
|
||||
for i in range(1, line1.shape[1]):
|
||||
curr = last_line[i]
|
||||
if prev == 0 and curr == 255 and start and i - start > 96:
|
||||
if prev == 0 and curr == 255 and start and i - start > 70:
|
||||
name_x.append((i + 415, i + 590))
|
||||
# name_x.append((i+460, i + 640))
|
||||
elif prev == 255 and curr == 0:
|
||||
start = i
|
||||
prev = curr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue