All checks were successful
ci/woodpecker/push/check_format Pipeline was successful
99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
"""
|
|
Copyright (c) 2024 zhbaor <zhbaor@zhaozuohong.vip>
|
|
|
|
This file is part of mower-ng (https://git.zhaozuohong.vip/mower-ng/mower-ng).
|
|
|
|
Mower-ng is free software: you may copy, redistribute and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, version 3 or later.
|
|
|
|
This file is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
from datetime import timedelta
|
|
|
|
import cv2
|
|
|
|
from mower.utils import config
|
|
from mower.utils.email import notify
|
|
from mower.utils.image import cropimg
|
|
from mower.utils.scene import Scene
|
|
from mower.utils.solver import BaseSolver
|
|
from mower.utils.vector import sa, va
|
|
|
|
from .utils import index_entry
|
|
|
|
activity_name = "六周年庆典签到活动"
|
|
|
|
|
|
class SignIn(BaseSolver):
|
|
solver_name = "签到活动"
|
|
solver_max_duration = timedelta(minutes=2)
|
|
|
|
def run(self):
|
|
self.materiel_email = False
|
|
self.skin_email = False
|
|
self.finish_email = True
|
|
return super().run()
|
|
|
|
def transition(self) -> bool:
|
|
if (scene := self.scene()) == Scene.MATERIEL:
|
|
if self.materiel_email:
|
|
self.materiel_email = False
|
|
self.finish_email = False
|
|
self.sleep()
|
|
notify(f"{activity_name}奖励领取")
|
|
self.scene_graph_step(Scene.INDEX)
|
|
elif scene == Scene.INDEX:
|
|
if pos := index_entry("sign_in/entry", activity_name):
|
|
self.ctap(pos)
|
|
return
|
|
notify(f"未找到{activity_name}签到入口")
|
|
return True
|
|
elif scene == Scene.ANNOUNCEMENT:
|
|
if self.animation():
|
|
return
|
|
top_left = 680, 500
|
|
img = cropimg(config.recog.hsv, (top_left, (1800, 540)))
|
|
img = cv2.inRange(img, (85, 100, 100), (95, 255, 255))
|
|
contours, _ = cv2.findContours(
|
|
img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE
|
|
)
|
|
rect = [cv2.boundingRect(c) for c in contours]
|
|
rect = [r for r in rect if r[2] > 200]
|
|
if len(rect) == 0:
|
|
if self.finish_email:
|
|
notify(f"{activity_name}奖励已领完")
|
|
return True
|
|
rect.sort(key=lambda c: c[0])
|
|
x, y, w, h = rect[0]
|
|
scope = sa(((x, y), va((x, y), (w, h))), top_left)
|
|
if self.ctap(scope):
|
|
self.materiel_email = True
|
|
self.skin_email = True
|
|
self.finish_email = False
|
|
# if not self.find("sign_in/banner"):
|
|
# self.scene_graph_step(Scene.INDEX)
|
|
# return
|
|
# if pos := self.find("sign_in/collect"):
|
|
# if self.ctap(pos, 5):
|
|
# self.materiel_email = True
|
|
# self.skin_email = True
|
|
# self.finish_email = False
|
|
# return
|
|
# if self.finish_email:
|
|
# notify(f"{activity_name}奖励已领完")
|
|
# return True
|
|
elif scene == Scene.ROGUE_AGENT:
|
|
if self.skin_email:
|
|
self.skin_email = False
|
|
notify(f"{activity_name}时装领取")
|
|
self.scene_graph_step(Scene.INDEX)
|
|
else:
|
|
self.scene_graph_step(Scene.INDEX)
|