Skip to content

Commit

Permalink
#17 二倍速和自动战斗的判断变严格了
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Oct 28, 2023
1 parent 2ef3d52 commit 8f79d52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
14 changes: 8 additions & 6 deletions config/world_patrol/P03_XZLF/R07_GZS_R01_RJFTD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ route:
data: [779, 450]
- op: 'patrol'
- op: 'move'
data: [800, 408]
data: [779, 407]
- op: 'move'
data: [821, 408]
data: [821, 407]
- op: 'move'
data: [869, 408]
data: [869, 407]
- op: 'move'
data: [867, 357]
- op: 'move'
Expand All @@ -43,12 +43,14 @@ route:
- op: 'move'
data: [880, 305]
- op: 'move'
data: [880, 321]
data: [880, 315]
- op: 'patrol'
- op: 'move'
data: [802, 255]
data: [880, 258]
- op: 'move'
data: [773, 259]
data: [802, 258]
- op: 'move'
data: [778, 258]
- op: 'interact'
data: '入画'
- op: 'wait'
Expand Down
9 changes: 7 additions & 2 deletions src/sr/image/sceenshot/battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def is_character_icon_at_right_top(screen: MatLike, im: ImageMatcher):
def is_auto_battle_on(screen: MatLike, im: ImageMatcher):
"""
通过右上角自动战斗图标是否点亮 判断是否开启了自动战斗
1. 直接看是否已经存在自动战斗激活的图标 存在则返回 True
2. 如果1不存在 看是否存在暂停按键 不存在则返回 True 部分动画过程三个按键都会消失
:param screen: 屏幕截图
:param im: 图片匹配器
:return: 是否已经开启了自动战斗 部分情况画面没加载完毕 认为已经默认开启
Expand All @@ -67,9 +69,12 @@ def is_auto_battle_on(screen: MatLike, im: ImageMatcher):
def is_fast_battle_on(screen: MatLike, im: ImageMatcher):
"""
通过右上角二倍速图标是否点亮 判断是否开启了二倍速
1. 直接看是否已经存在快速战斗的图标 存在则返回 True
2. 如果1不存在 看是否存在禁止改变二倍速的图标 存在则返回 True 部分动画过程禁止改变二倍速
3. 如果2不存在 看是否存在暂停按键 不存在则返回 True 部分动画过程三个按键都会消失
:param screen: 屏幕截图
:param im: 图片匹配器
:return: 是否已经开启了二倍速 部分情况画面没加载完毕 认为已经默认开启
:return: 是否已经开启了二倍速
"""
on: bool = match_battle_ctrl(screen, im, 'battle_ctrl_03', rect=FAST_BATTLE_RECT) is not None
if on:
Expand Down Expand Up @@ -101,7 +106,7 @@ def match_battle_ctrl(screen: MatLike, im: ImageMatcher, template_id: str, rect=

# 找到亮的部分
mask = np.zeros((part.shape[0], part.shape[1]), dtype=np.uint8)
lower = 170 if is_on else 100
lower = 230 if is_on else 100
if lower_color is not None:
lower = lower_color
mask[np.where(b > lower)] = 255
Expand Down
6 changes: 3 additions & 3 deletions src/sr/operation/unit/enable_auto_fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from basic.img.os import save_debug_image
from basic.log_utils import log
from sr.context import Context
from sr.image.sceenshot import battle
from sr.image.sceenshot import battle, fill_uid_black
from sr.operation import Operation


Expand All @@ -25,7 +25,7 @@ def run(self) -> int:
if not battle.is_auto_battle_on(screen, self.ctx.im):
log.info('检测到未启动自动战斗')
if os_utils.is_debug():
save_debug_image(screen, prefix='no_auto')
save_debug_image(fill_uid_black(screen), prefix='no_auto')
r = battle.match_battle_ctrl(screen, self.ctx.im, 'battle_ctrl_02', is_on=False)
if r is not None:
log.info('启动自动战斗')
Expand All @@ -36,7 +36,7 @@ def run(self) -> int:
if not battle.is_fast_battle_on(screen, self.ctx.im):
log.info('检测到未启动二倍速战斗')
if os_utils.is_debug():
save_debug_image(screen, prefix='no_fast')
save_debug_image(fill_uid_black(screen), prefix='no_fast')
r = battle.match_battle_ctrl(screen, self.ctx.im, 'battle_ctrl_03', is_on=False)
if r is not None:
log.info('启动二倍速战斗')
Expand Down
Binary file added test/resources/images/battle/all_on_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions test/src/sr/image/screenshot/battle_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import cv2

from basic.img import cv2_utils
from basic.img.os import get_test_image
from sr.image.cv2_matcher import CvImageMatcher
Expand Down Expand Up @@ -28,6 +26,8 @@ def _test_is_auto_battle_on():
assert battle.is_auto_battle_on(screen, im) # true
screen = get_test_image('all_on_3', sub_dir='battle')
assert battle.is_auto_battle_on(screen, im) # true
screen = get_test_image('all_on_4', sub_dir='battle')
assert battle.is_auto_battle_on(screen, im) # true


def _test_is_fast_battle_on():
Expand All @@ -43,8 +43,12 @@ def _test_is_fast_battle_on():
assert battle.is_fast_battle_on(screen, im) # true
screen = get_test_image('all_on_3', sub_dir='battle')
assert battle.is_fast_battle_on(screen, im) # true
screen = get_test_image('all_on_4', sub_dir='battle')
assert battle.is_fast_battle_on(screen, im) # true


if __name__ == '__main__':
im = CvImageMatcher()
_test_is_auto_battle_on()
_test_get_battle_status()
_test_is_auto_battle_on()
_test_is_fast_battle_on()

0 comments on commit 8f79d52

Please sign in to comment.