Skip to content

Commit

Permalink
✨ 新增单人日轮副本,优化组队御魂选择逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
AquamarineCyan committed Jan 20, 2025
1 parent cc6c449 commit 3a80000
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 175 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- 完善后台交互,包括截图、点击、键盘事件
- 支持在任务结束后提示接到的悬赏封印数量
- `斗技自动上阵`支持`段位上升``周奖励`界面
- 新增`单人日轮副本`,优化组队御魂选择逻辑

### 优化

Expand Down
6 changes: 4 additions & 2 deletions src/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .juexing import JueXing
from .liudaozhimen import LiuDaoZhiMen
from .qiling import QiLing
from .rilun import RiLun
from .rilun import RiLun, RiLunSingle,RiLunTeam
from .tansuo import TanSuo
from .xuanshangfengyin import XuanShangFengYin, task_xuanshangfengyin
from .yeyuanhuo import YeYuanHuo
Expand All @@ -32,6 +32,8 @@
"LiuDaoZhiMen",
"QiLing",
"RiLun",
"RiLunSingle",
"RiLunTeam",
"TanSuo",
# "XuanShangFengYin",
"task_xuanshangfengyin",
Expand Down Expand Up @@ -66,5 +68,5 @@ def get_package_resource_list():
YongShengZhiHai,
YuHun,
YuLing,
ZhaoHuan
ZhaoHuan,
]
241 changes: 189 additions & 52 deletions src/package/rilun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from ..utils.event import event_thread
from ..utils.exception import GUIStopException
from ..utils.function import finish_random_left_right, sleep
from ..utils.image import RuleImage, check_image_once
from ..utils.image import check_image_once
from ..utils.log import logger
from ..utils.paddleocr import RuleOcr
from .utils import Package


Expand All @@ -13,16 +14,35 @@ class RiLun(Package):

scene_name = "日轮副本"
resource_path = "rilun"

@log_function_call
def __init__(self, n) -> None:
super().__init__(n)

def load_asset(self):
self.IMAGE_FIGHTING = self.get_image_asset("fighting")

@log_function_call
def start(self) -> None:
"""挑战"""
logger.ui("开始挑战")
if isinstance(self, RiLunTeam):
self.check_click(self.global_assets.IMAGE_START_TEAM, timeout=3)
elif isinstance(self, RiLunSingle):
self.check_click(self.global_assets.IMAGE_START_SINGLE, timeout=3)


class RiLunTeam(RiLun):
"""组队日轮副本"""

resource_list: list = [
"fighting", # 对局进行中
]
STATE_READY = 1
STATE_RUNNING = 2

@log_function_call
def __init__(
self, n: int = 0, flag_driver: bool = False, flag_passengers: int = 2
) -> None:
def __init__(self, n: int = 0, flag_driver: bool = False, flag_passengers: int = 2) -> None:
super().__init__(n)
self.flag_driver: bool = flag_driver # 是否为司机(默认否)
self.flag_passengers: bool = flag_passengers # 组队人数
Expand All @@ -31,87 +51,204 @@ def __init__(

@staticmethod
def description() -> None:
logger.ui("日轮副本")
logger.ui("组队日轮副本")

def load_asset(self):
self.IMAGE_FIGHTING = self.get_image_asset("fighting")
@log_function_call
def wait_finish(self):
"""等待结束
def check_title(self) -> bool:
"""场景"""
msg_title = True
while True:
if bool(event_thread):
raise GUIStopException
掉落物大体分为2种情况:
if RuleImage(self.global_image.IMAGE_XIEZHANDUIWU).match():
self.flag_driver_start = True
return
elif RuleImage(self.IMAGE_FIGHTING).match():
self.flag_fighting = True
return
elif msg_title:
self.title_error_msg()
msg_title = False
1.正常情况,达摩蛋能被识别
def finish(self) -> None: # TODO 重构
"""结束"""
2.掉落过多情况(指神罚一排紫蛇皮),达摩蛋被遮挡,此时贪吃鬼必定(可能)出现
"""
_flag_first = True
self.check_result()
sleep(1.5, 3)
finish_random_left_right()
sleep(0.4, 0.8)
# 结算
finish_random_left_right(is_multiple_drops_x=True)
Mouse.click(wait=0.5)

while True:
if bool(event_thread):
raise GUIStopException

Mouse.click(wait=0.5)
if self.check_result():
while True:
if bool(event_thread):
raise GUIStopException
# 检测到任一图像
result = check_image_once(
[
self.global_assets.IMAGE_FINISH,
self.global_assets.IMAGE_TANCHIGUI,
]
)

sleep()
Mouse.click()
sleep()
if not RuleImage(self.global_image.IMAGE_FINISH).match():
break
break
sleep(0.4, 0.8)
# 直到第一次识别到
if _flag_first and result is None:
continue

if result:
logger.info(f"current scene: {result.name}")
Mouse.click()
_flag_first = False
sleep(0.6, 1)

# 所有图像都未检测到,退出循环
else:
logger.ui("结束")
return

def run(self) -> None:
# self.check_title()
msg_title: bool = True
msg_fighting: bool = True

self.current_asset_list = [
self.global_assets.IMAGE_XIEZHANDUIWU,
self.global_assets.IMAGE_FIGHTING,
self.global_assets.IMAGE_ACCEPT_INVITATION,
]

if self.flag_driver:
self.current_asset_list.append(self.global_image.IMAGE_START_TEAM)
msg_title: bool = True
self.current_asset_list.append(self.global_assets.IMAGE_START_TEAM)

while self.n < self.max:
if bool(event_thread):
raise GUIStopException

msg_fighting = True
result = check_image_once(self.current_asset_list)
if result is None:
# 判断是否在战斗中
result = RuleOcr(self.global_assets.OCR_AUTO_FIGHT)
if result.match():
if msg_fighting:
logger.ui("自动战斗中")
msg_fighting = False

self.wait_finish()
self.done()
msg_title = False
sleep()

if msg_title:
self.title_error_msg()
msg_title = False

continue

match result.name:
case "xiezhanduiwu":
logger.ui("组队界面准备中")
case self.global_assets.IMAGE_XIEZHANDUIWU.name:
logger.scene("组队界面准备中")
if self.flag_driver:
self.wait_passengers_on_position(self.flag_passengers)
sleep(1.5)
self.start()
sleep()
msg_title = False
case "fighting":
logger.ui("对局进行中")
self.finish()
self.done()
sleep()
msg_title = False
case "accept_invitation":
# TODO 新设备第一次接受邀请会有弹窗,需手动勾选“不再提醒”

case self.global_assets.IMAGE_ACCEPT_INVITATION.name:
logger.ui("接受邀请")
Mouse.click(result.center_point())

case _:
if msg_title:
self.title_error_msg()
msg_title = False


class RiLunSingle(RiLun):
"""单人日轮副本"""

scene_name = "单人日轮副本"
resource_list = [
"title_3", # 三层
"title_4", # 日蚀
]

@log_function_call
def __init__(self, n: int = 0):
super().__init__(n)

def load_asset(self):
super().load_asset()
self.IMAGE_TITLE_3 = self.get_image_asset("title_3")
self.IMAGE_TITLE_4 = self.get_image_asset("title_4")

def run(self):
msg_title: bool = True # 标题消息
msg_fighting: bool = True # 自动战斗中消息
flag_soul_overflow: bool = False # 御魂上限标志

self.current_asset_list = [
self.IMAGE_TITLE_3,
self.IMAGE_TITLE_4,
self.global_assets.IMAGE_START_SINGLE,
self.global_assets.IMAGE_FAIL,
self.global_assets.IMAGE_FINISH,
self.global_assets.IMAGE_VICTORY,
self.global_assets.IMAGE_SOUL_OVERFLOW,
]

while self.n < self.max:
if bool(event_thread):
raise GUIStopException

msg_fighting = True
result = check_image_once(self.current_asset_list)
if result is None:
# 判断是否在战斗中
result = RuleOcr(self.global_assets.OCR_AUTO_FIGHT)
if result.match() and msg_fighting:
logger.ui("自动战斗中")
msg_fighting = False

if msg_title:
self.title_error_msg()
msg_title = False

continue

match result.name:
case self.IMAGE_TITLE_3.name | self.IMAGE_TITLE_4.name:
match result.name:
case self.IMAGE_TITLE_3.name:
logger.scene("日轮叁层")
case self.IMAGE_TITLE_4.name:
logger.scene("日轮日蚀")
self.start()
msg_title = False
sleep(2)

case self.global_assets.IMAGE_START_SINGLE.name: # 一般在上一级case中已经处理
logger.ui("开始挑战")
Mouse.click(result.center_point())
msg_title = False

case self.global_assets.IMAGE_FAIL.name:
logger.ui_warn("失败,需要手动处理")
break

case self.global_assets.IMAGE_VICTORY.name:
logger.ui("胜利")
sleep() # 等待结算

case self.global_assets.IMAGE_FINISH.name:
logger.ui("结束")

if flag_soul_overflow:
sleep(1)
if self.check_click(self.global_assets.IMAGE_SOUL_OVERFLOW, timeout=2, duration=0.75):
logger.ui_warn("御魂上限")
flag_soul_overflow = True

finish_random_left_right()
self.done()
msg_fighting = False
sleep(3) # 等待过场图

case self.global_assets.IMAGE_SOUL_OVERFLOW.name: # 正常情况下会在结束界面点击,这是备用方案
logger.ui_warn("御魂上限")
Mouse.click(result.center_point(), duration=0.75)
flag_soul_overflow = True

case _:
if msg_title:
self.title_error_msg()
Expand Down
10 changes: 8 additions & 2 deletions src/resource/rilun/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"current_path": "rilun",
"image_data": [
{
"name": "fighting",
"file": "fighting.png",
"name": "title_3",
"file": "title_3.png",
"region": [0, 0, 0, 0],
"score": "0.8"
},
{
"name": "title_4",
"file": "title_4.png",
"region": [0, 0, 0, 0],
"score": "0.8"
}
Expand Down
Binary file removed src/resource/rilun/fighting.png
Binary file not shown.
Binary file added src/resource/rilun/title_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/resource/rilun/title_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3a80000

Please sign in to comment.