Skip to content

Commit

Permalink
try fix farm echo
Browse files Browse the repository at this point in the history
  • Loading branch information
ok-oldking committed Jul 1, 2024
1 parent 2f0a148 commit 95642d2
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 357 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
770 changes: 423 additions & 347 deletions assets/_annotations.coco.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from ok.interaction.PostMessageInteraction import PostMessageInteraction
from ok.util.path import get_path_in_package
from src.task.AutoCombatTask import AutoCombatTask
from src.task.FarmEchoTask import FarmEchoTask
Expand Down Expand Up @@ -31,8 +32,13 @@ def calculate_pc_exe_path(running_path):
'windows': { # required when supporting windows game
'exe': 'Client-Win64-Shipping.exe',
'calculate_pc_exe_path': calculate_pc_exe_path,
'interaction': PostMessageInteraction,
'can_bit_blt': False # default false, opengl games does not support bit_blt
},
'supported_resolution': {
'ratio': '16:9',
'min_size': (1280, 720)
},
'analytics': {
'report_url': 'https://okreport.ok-script.com/report'
},
Expand Down
10 changes: 7 additions & 3 deletions src/char/BaseChar.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def wait_down(self):
f'{self}_down_finish_{(time.time() - start):.2f}_f:{self.is_forte_full()}_e:{self.resonance_available()}_r:{self.echo_available()}_q:{self.liberation_available()}_i{self.has_intro}')

def do_perform(self):
if self.click_liberation(con_less_than=1):
return self.switch_next_char()
self.click_liberation(con_less_than=1)
if self.click_resonance()[0]:
return self.switch_next_char()
if self.click_echo():
Expand All @@ -107,7 +106,7 @@ def has_cd(self, box_name):
big_area_count += 1
if left > 0 and top > 0 and left + width < box.width and top + height < box.height:
self.logger.debug(f"{box_name} Area of connected component {i}: {area} pixels {width}x{height}")
if 20 / 3840 / 2160 <= area / self.task.frame.shape[0] / self.task.frame.shape[
if 16 / 3840 / 2160 <= area / self.task.frame.shape[0] / self.task.frame.shape[
1] <= 60 / 3840 / 2160 and abs(width - height) / (width + height) < 0.3:
has_dot = True
elif 25 / 2160 <= height / self.task.screen_height <= 45 / 2160 and 5 / 2160 <= width / self.task.screen_height <= 35 / 2160:
Expand Down Expand Up @@ -181,6 +180,11 @@ def click_resonance(self, post_sleep=0, has_animation=False, send_click=True):
last_op = 'resonance'
self.send_resonance_key()
last_click = now
if time.time() - resonance_click_time > 10:
self.logger.error(f'click_resonance too long, breaking')
self.task.screenshot(self.task.get_box_by_name('box_resonance').crop(self.task.frame),
'click_resonance too long, breaking')
break
self.task.next_frame()
if clicked:
self.sleep(post_sleep)
Expand Down
1 change: 1 addition & 0 deletions src/char/Jinhsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def handle_intro(self):
self.logger.info(f'handle_intro start')
last = None
start = time.time()
self.send_resonance_key()
while not self.has_cd('resonance'):
if last != 'resonance' or time.time() - start < 1:
if self.send_resonance_key(interval=0.1):
Expand Down
14 changes: 11 additions & 3 deletions src/task/BaseCombatTask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
import time

from ok.feature.FindFeature import FindFeature
Expand Down Expand Up @@ -106,6 +107,12 @@ def switch_next_char(self, current_char, post_action=None, free_intro=False, tar
logger.info(f'switch_next_char end {(switch_time - start):.3f}s')
return switch_time

def click(self, x=-1, y=-1, move_back=False, name=None, interval=-1):
if x == -1 and y == -1:
x = self.width_of_screen(random.uniform(0.4, 0.6))
y = self.height_of_screen(random.uniform(0.4, 0.6))
return super().click(x, y, move_back, name, interval)

def wait_in_team(self, time_out=10):
self.wait_until(lambda: self.in_team()[0], time_out=time_out)

Expand All @@ -129,10 +136,11 @@ def check_combat(self):
self.raise_not_in_combat('combat check not in combat')

def walk_until_f(self, time_out=0, raise_if_not_found=True):
if not self.find_one('pick_up_f', horizontal_variance=0.02, vertical_variance=0.02, use_gray_scale=True):
if not self.find_one('pick_up_f', horizontal_variance=0.02, vertical_variance=0.2, threshold=0.8,
use_gray_scale=True):
self.send_key_down('w')
f_found = self.wait_feature('pick_up_f', horizontal_variance=0.02, vertical_variance=0.02,
use_gray_scale=True,
use_gray_scale=True, threshold=0.8,
wait_until_before_delay=0, time_out=time_out, raise_if_not_found=False)
self.send_key_up('w')
if not f_found:
Expand Down Expand Up @@ -198,7 +206,7 @@ def get_resonance_percentage(self):
return self.calculate_color_percentage(white_color, self.get_box_by_name('box_resonance'))

def in_team(self):
start = time.time()
# start = time.time()
c1 = self.find_one('char_1_text', use_gray_scale=True)
c2 = self.find_one('char_2_text', use_gray_scale=True)
c3 = self.find_one('char_3_text', use_gray_scale=True)
Expand Down
41 changes: 37 additions & 4 deletions src/task/FarmEchoTask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from ok.logging.Logger import get_logger
from src.task.BaseCombatTask import BaseCombatTask, NotInCombatException

Expand Down Expand Up @@ -34,14 +36,23 @@ def run(self):

# loop here
count = 0
i = -1
while count < self.config.get("Repeat Farm Count", 0):
count += 1
self.wait_until(lambda: self.in_team()[0], time_out=40)
self.walk_until_f()
self.wait_click_feature('gray_crownless_battle', raise_if_not_found=True, use_gray_scale=True)
self.wait_click_feature('gray_button_challenge', raise_if_not_found=True, use_gray_scale=True)
self.wait_click_feature('gray_start_battle', relative_x=-1, raise_if_not_found=True, use_gray_scale=True)
self.wait_until(lambda: self.in_combat(), time_out=40)
self.wait_ocr(0.75, 0.02, 0.85, 0.09, match=re.compile('240'), raise_if_not_found=True)
i = self.choose_level(0)
if i == -1:
self.log_error('Can not find a level to enter', notify=True)
return
# self.wait_click_feature('gray_crownless_battle', raise_if_not_found=True, use_gray_scale=True,
# box=self.box_of_screen(0.05, 0.12, 0.11, 0.22), threshold=0.7)
# self.click_relative(0.15, 0.17)
# self.sleep(1)
#

self.wait_until(lambda: self.in_combat(), time_out=40, raise_if_not_found=True)
self.load_chars()
while True:
try:
Expand All @@ -57,3 +68,25 @@ def run(self):
self.wait_click_feature('gray_confirm_exit_button', relative_x=-1, raise_if_not_found=True,
use_gray_scale=True)
self.wait_in_team(time_out=40)

def choose_level(self, start):
y = 0.17
x = 0.15
distance = 0.08
for i in range(4):
if i < start:
continue
self.click_relative(x, y + i * distance)
self.sleep(1)
self.wait_click_feature('gray_button_challenge', raise_if_not_found=True, use_gray_scale=True)
self.sleep(1)
cancel_button = self.find_one('cancel_button', use_gray_scale=True, threshold=0.7)
self.screenshot(f'cancel_{cancel_button}')
if not cancel_button:
self.wait_click_feature('gray_start_battle', relative_x=-1, raise_if_not_found=True,
use_gray_scale=True)
return i
else:
self.click(cancel_button)
self.sleep(1)
return -1

0 comments on commit 95642d2

Please sign in to comment.