Skip to content

Commit

Permalink
perf(tasks): ocochi done !
Browse files Browse the repository at this point in the history
  • Loading branch information
runhey committed Jul 4, 2023
1 parent 6e0a6fc commit 217a68f
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 12 deletions.
33 changes: 33 additions & 0 deletions tasks/Component/GeneralBattle/general_battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,36 @@ def run_general_battle_back(self, config: dict=None) -> bool:
return True


def exit_battle(self, skip_first: bool=False) -> bool:
"""
在战斗的时候强制退出战斗
:return:
"""
if skip_first:
self.screenshot()

if not self.appear(self.I_EXIT):
return False

# 点击返回
logger.info(f"Click {self.I_EXIT.name}")
while 1:
self.screenshot()
if self.appear_then_click(self.I_EXIT, interval=1.5):
continue
if self.appear(self.I_EXIT_ENSURE):
break

# 点击返回确认
while 1:
self.screenshot()
if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
continue
if self.appear_then_click(self.I_FALSE, interval=1.5):
continue
if not self.appear(self.I_EXIT):
break

return True


4 changes: 4 additions & 0 deletions tasks/Component/GeneralInvite/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class GeneralInviteAssets:
I_GI_EMOJI_1 = RuleImage(roi_front=(25,538,50,56), roi_back=(25,538,50,56), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_emoji_1.png")
# description
I_GI_EMOJI_2 = RuleImage(roi_front=(21,632,53,64), roi_back=(21,632,53,64), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_emoji_2.png")
# 判断是不是在庭院界面
I_GI_HOME = RuleImage(roi_front=(359,44,34,46), roi_back=(359,44,34,46), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_home.png")
# 判断是不是在探索界面
I_GI_EXPLORE = RuleImage(roi_front=(1138,119,41,48), roi_back=(1138,119,41,48), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_explore.png")


# Ocr Rule Assets
Expand Down
82 changes: 75 additions & 7 deletions tasks/Component/GeneralInvite/general_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# @author runhey
# github https://github.com/runhey
import time

import numpy as np

from enum import Enum
from cached_property import cached_property
from datetime import timedelta, time

from module.base.timer import Timer
from tasks.base_task import BaseTask
Expand Down Expand Up @@ -175,12 +175,13 @@ def ensure_enter(self) -> bool:
return False

# 判断是否在房间里面
def is_in_room(self) -> bool:
def is_in_room(self, is_screenshot: bool = True) -> bool:
"""
判断是否在房间里面
:return:
"""
self.screenshot()
if is_screenshot:
self.screenshot()
if self.appear(self.I_GI_EMOJI_1):
return True
if self.appear(self.I_GI_EMOJI_2):
Expand Down Expand Up @@ -555,19 +556,86 @@ def check_and_invite(self, default_invite: bool=True) -> bool:



def accept_invite(self) -> bool:
def check_then_accept(self) -> bool:
"""
队员接受邀请, 保持在庭院界面
队员接受邀请
:return:
"""
if not self.appear(self.I_I_ACCEPT):
return False
logger.info('Click accept')
while 1:
self.screenshot()
if self.appear(self.I_GI_BUFF):
break
if self.is_in_room():
return True
if self.appear_then_click(self.I_I_NO_DEFAULT, interval=1):
continue
if self.appear_then_click(self.I_GI_SURE, interval=1):
continue
if self.appear_then_click(self.I_I_ACCEPT_DEFAULT, interval=1):
continue
if self.appear_then_click(self.I_I_ACCEPT, interval=1):
continue
return True

def wait_battle(self, wait_time: time) -> bool:
"""
在房间等待,(要求保证在房间里面) 队长开启战斗
如果队长跑路了,或者的等待了很久还没开始
:return: 如果成功进入战斗(反正就是不在房间 )返回 True
如果失败了,(退出房间)返回 False
"""
self.timer_emoji = Timer(15)
self.timer_emoji.start()
wait_second = wait_time.second + wait_time.minute * 60
self.timer_wait = Timer(wait_second)
self.timer_wait.start()
logger.info(f'Wait battle {wait_second} seconds')
success = True
while 1:
self.screenshot()

# 如果自己在探索界面或者是庭院,那就是房间已经被销毁了
if self.appear(self.I_GI_HOME) or self.appear(self.I_GI_EXPLORE):
logger.warning('Room destroyed')
success = False
break


if self.timer_wait.reached():
logger.warning('Wait battle time out')
success = False
break

# 如果队长跑路了,自己变成了队长: 自己也要跑路
if self.appear(self.I_FIRE) or self.appear(self.I_FIRE_SEA):
logger.warning('Leader run away while wait battle and become leader now')
success = False
break

# 判断是否进入战斗
if self.is_in_room(is_screenshot=False):
if self.timer_emoji.reached():
self.timer_emoji.reset()
self.appear_then_click(self.I_GI_EMOJI_1)
self.appear_then_click(self.I_GI_EMOJI_2)
else:
break


# 调出循环只有这些可能性:
# 1. 进入战斗(ui是战斗)
# 2. 队长跑路(自己还是在房间里面)
# 3. 等待时间到没有开始(还是在房间里面)
# 4. 房间的时间到了被迫提出房间(这个时候来到了探索界面)
if not success:
logger.info('Leave room')
self.exit_room()

return success




if __name__ == '__main__':
from module.config.config import Config
Expand Down
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 tasks/Component/GeneralInvite/gi/gi_gi_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tasks/Component/GeneralInvite/gi/member.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,23 @@
"method": "Template matching",
"threshold": 0.8,
"description": "description"
},
{
"itemName": "gi_home",
"imageName": "gi_gi_home.png",
"roiFront": "359,44,34,46",
"roiBack": "359,44,34,46",
"method": "Template matching",
"threshold": 0.8,
"description": "判断是不是在庭院界面"
},
{
"itemName": "gi_explore",
"imageName": "gi_gi_explore.png",
"roiFront": "1138,119,41,48",
"roiBack": "1138,119,41,48",
"method": "Template matching",
"threshold": 0.8,
"description": "判断是不是在探索界面"
}
]
2 changes: 1 addition & 1 deletion tasks/GameUi/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GameUiAssets:

# Image Rule Assets
# description
I_CHECK_MAIN = RuleImage(roi_front=(54,228,38,37), roi_back=(30,205,1033,96), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_main.png")
I_CHECK_MAIN = RuleImage(roi_front=(801,109,38,37), roi_back=(49,98,1033,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_main.png")
# description
I_MAIN_GOTO_EXPLORATION = RuleImage(roi_front=(493,116,45,75), roi_back=(243,100,933,211), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_exploration.png")
# description
Expand Down
Binary file modified tasks/GameUi/page/page_check_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tasks/GameUi/page/page_img.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"itemName": "check_main",
"imageName": "page_check_main.png",
"roiFront": "54,228,38,37",
"roiBack": "30,205,1033,96",
"roiFront": "801,109,38,37",
"roiBack": "49,98,1033,61",
"method": "Template matching",
"threshold": 0.8,
"description": "description"
Expand Down
44 changes: 42 additions & 2 deletions tasks/Orochi/script_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def run(self) -> bool:
success = True
match config.orochi_config.user_status:
case UserStatus.LEADER: success = self.run_leader()
case UserStatus.MEMBER: self.run_member()
case UserStatus.MEMBER: success = self.run_member()
case UserStatus.ALONE: self.run_alone()
case UserStatus.WILD: self.run_wild()
case _: logger.error('Unknown user status')
Expand Down Expand Up @@ -196,7 +196,47 @@ def run_leader(self):
return True

def run_member(self):
pass
logger.info('Start run member')
self.ui_get_current_page()
self.ui_goto(page_soul_zones)
self.orochi_enter()
self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)

# 进入战斗流程
while 1:
self.screenshot()

if self.current_count >= self.limit_count:
logger.info('Orochi count limit out')
break
if datetime.now() - self.start_time >= self.limit_time:
logger.info('Orochi time limit out')
break

if self.check_then_accept():
continue

if self.is_in_room():
if self.wait_battle(wait_time=self.config.orochi.invite_config.wait_time):
self.run_general_battle(config=self.config.orochi.general_battle_config)
else:
break

while 1:
# 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
if self.appear(self.I_GI_HOME) or self.appear(self.I_GI_EXPLORE):
break
# 如果可能在房间就退出
if self.exit_room():
pass
# 如果还在战斗中,就退出战斗
if self.exit_battle():
pass


self.ui_get_current_page()
self.ui_goto(page_main)
return True

def run_alone(self):
logger.info('Start run alone')
Expand Down

0 comments on commit 217a68f

Please sign in to comment.