Skip to content

Commit

Permalink
autocombat
Browse files Browse the repository at this point in the history
  • Loading branch information
ok-oldking committed Jun 20, 2024
1 parent eb1a3a0 commit 85ff7fb
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 86 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.
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.
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.
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.
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.
54 changes: 52 additions & 2 deletions assets/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
"height": 2160,
"id": 7,
"file_name": "images\\1433eace-21_13_50_556378_WindowsGraphicsCaptureMethod_3840x2160_title_None_Clie_z8GnYut.png"
},
{
"width": 3840,
"height": 2160,
"id": 8,
"file_name": "images\\9ed8b373-00_57_50_813872_WindowsGraphicsCaptureMethod_3840x2160_title_None_Clie_3jLoRJh.png"
},
{
"width": 3840,
"height": 2160,
"id": 9,
"file_name": "images\\e521850f-00_37_38_458841_Encore_liberation_0.274_original.png"
}
],
"categories": [
Expand Down Expand Up @@ -160,6 +172,14 @@
},
{
"id": 27,
"name": "edge_levitator"
},
{
"id": 28,
"name": "gray_combat_count_down"
},
{
"id": 29,
"name": "pick_up_f"
}
],
Expand Down Expand Up @@ -542,7 +562,7 @@
{
"id": 25,
"image_id": 7,
"category_id": 27,
"category_id": 29,
"segmentation": [],
"bbox": [
2503.364084708245,
Expand All @@ -553,6 +573,36 @@
"ignore": 0,
"iscrowd": 0,
"area": 749.9059299877902
},
{
"id": 26,
"image_id": 8,
"category_id": 27,
"segmentation": [],
"bbox": [
2938.5892304377853,
1889.8640796534446,
86.40993725371172,
84.73207439441629
],
"ignore": 0,
"iscrowd": 0,
"area": 7321.693231798345
},
{
"id": 27,
"image_id": 9,
"category_id": 28,
"segmentation": [],
"bbox": [
1748.3257980253275,
275.04182659424396,
58.93319960335,
54.079877283073856
],
"ignore": 0,
"iscrowd": 0,
"area": 3187.100202448065
}
],
"info": {
Expand All @@ -561,6 +611,6 @@
"description": "",
"contributor": "Label Studio",
"url": "",
"date_created": "2024-06-15 21:20:52.772035"
"date_created": "2024-06-19 01:31:47.083274"
}
}
15 changes: 8 additions & 7 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def calculate_pc_exe_path(running_path):
return None
return running_path


config = {
Expand All @@ -29,17 +29,18 @@ 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,
'can_bit_blt': False # default false, opengl games does not support bit_blt
},
'analytics': {
'report_url': 'https://okreport.ok-script.com/report'
},
# 'update': {
# 'releases_url': 'https://api.github.com/repos/ok-oldking/ok-baijing/releases?per_page=15',
# 'proxy_url': 'https://gh.ok-script.com/',
# 'exe_name': 'ok-baijing.exe',
# 'use_proxy': True
# },
'update': {
'releases_url': 'https://api.github.com/repos/ok-oldking/ok-wuthering-waves/releases?per_page=15',
'proxy_url': 'https://gh.ok-script.com/',
'exe_name': 'ok-baijing.exe',
'use_proxy': True
},
'about': """
<h3>OK-WW</h3>
<p>免费开源软件 <a href="https://github.com/ok-oldking/ok-baijing">https://github.com/ok-oldking/ok-baijing</></p>
Expand Down
2 changes: 1 addition & 1 deletion main_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

config = config
config['debug'] = True
config['click_screenshots_folder'] = "click_screenshots" # debug用 点击后截图文件夹]
# config['click_screenshots_folder'] = "click_screenshots" # debug用 点击后截图文件夹]
ok = OK(config)
ok.start()
83 changes: 62 additions & 21 deletions src/char/BaseChar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from enum import IntEnum
from enum import IntEnum, StrEnum

from ok.color.Color import white_color, calculate_colorfulness
from ok.logging.Logger import get_logger
Expand All @@ -14,6 +14,15 @@ class Priority(IntEnum):
NORMAL = 10


class Role(StrEnum):
DEFAULT = 'Default'
SUB_DPS = 'Sub DPS'
MAIN_DPS = 'Main DPS'
HEALER = 'Healer'


role_values = [role for role in Role]

char_lib_check_marks = ['char_1_lib_check_mark', 'char_2_lib_check_mark', 'char_3_lib_check_mark']

logger = get_logger(__name__)
Expand All @@ -33,7 +42,6 @@ def __init__(self, task, index, res_cd=0):
self.last_res = -1
self.has_intro = False
self.res_cd = res_cd
self.con_ready = False
self.is_current_char = False

@property
Expand All @@ -46,45 +54,50 @@ def __eq__(self, other):
return False

def perform(self):
self.is_current_char = True
self.wait_down()
self.do_perform()
logger.debug(f'set current char false {self.index}')
self.is_current_char = False

def wait_down(self):
clicked = False
start = time.time()
while self.flying():
if not clicked:
self.task.click()
clicked = True
self.sleep(0.001)
if self.has_intro:
waited = time.time() - start
self.task.info[f'{self} intro time'] = f'{waited:.2f}'
if waited < 0.2:
self.sleep(0.8 - waited)
self.task.log_info(f'sleep extra for task')

self.task.screenshot(
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()}')

def do_perform(self):
if self.liberation_available():
self.click_liberation()
self.sleep(2)
self.click_liberation()
if self.resonance_available():
self.click_resonance()
self.sleep(0.1)
elif self.echo_available():
self.sleep(0.2)
if self.echo_available():
self.click_echo()
self.sleep(0.2)
self.switch_next_char()
self.con_ready = False

def __repr__(self):
return self.__class__.__name__
return self.__class__.__name__ + ('_T' if self.is_current_char else '_F')

def switch_next_char(self, post_action=None):
self.normal_attack()
self.last_switch_time = self.task.switch_next_char(self, post_action=post_action)

def sleep(self, sec):
self.task.sleep(sec + self.sleep_adjust)

def click_resonance(self):
self.task.send_key('e')
logger.info(f'{self} click resonance')

def update_res_cd(self):
current = time.time()
Expand All @@ -93,9 +106,17 @@ def update_res_cd(self):

def click_echo(self):
self.task.send_key(self.get_echo_key())
logger.info(f'{self} click echo')

def click_liberation(self):
def click_liberation(self, wait_end=True):
self.task.send_key(self.get_liberation_key())
while self.liberation_available():
self.sleep(0.02)
self.task.send_key(self.get_liberation_key())
start = time.time()
while not self.task.in_team()[0]:
self.sleep(0.02)
self.task.info[f'{self} liberation time'] = f'{(time.time() - start):.2f}'

def get_liberation_key(self):
return self.task.config['Liberation Key']
Expand Down Expand Up @@ -128,11 +149,15 @@ def resonance_available(self):
return False
if self.base_resonance_white_percentage != 0:
return abs(self.base_resonance_white_percentage - snap1) < self.white_off_threshold
cd_text = self.task.ocr(box=self.task.get_box_by_name('box_resonance'), target_height=540)
if len(cd_text) == 0 or not cd_text[0].name.isdigit():
cd_text = self.task.ocr(box=self.task.get_box_by_name('box_resonance'), target_height=540, threshold=0.95)
if len(cd_text) == 0 or not is_float(cd_text[0].name):
self.base_resonance_white_percentage = snap1
logger.info(f'set base resonance to {self.base_resonance_white_percentage:.3f}')
if self.task.debug:
self.task.screenshot(f'{self}_resonance_{snap1:.3f}')
logger.info(f'{self} set base resonance to {self.base_resonance_white_percentage:.3f}')
return True
if cd_text:
logger.info(f'{self} set base resonance to has text {cd_text}')
else:
if self.res_cd > 0:
return time.time() - self.last_res > self.res_cd
Expand All @@ -143,9 +168,11 @@ def echo_available(self):
return False
if self.base_echo_white_percentage != 0:
return abs(self.base_echo_white_percentage - snap1) < self.white_off_threshold
cd_text = self.task.ocr(box=self.task.get_box_by_name('box_echo'), target_height=540)
if not cd_text:
cd_text = self.task.ocr(box=self.task.get_box_by_name('box_echo'), target_height=540, threshold=0.95)
if not cd_text or not cd_text[0].name.isdigit():
self.base_echo_white_percentage = snap1
if self.task.debug:
self.task.screenshot(f'{self}_echo_{snap1:.3f}')
logger.info(f'set base resonance to {self.base_echo_white_percentage:.3f}')
return True

Expand All @@ -172,10 +199,12 @@ def liberation_available(self):
return False
if self.base_liberation_white_percentage != 0:
return abs(self.base_liberation_white_percentage - snap1_lib) < self.white_off_threshold
cd_text = self.task.ocr(box=self.task.get_box_by_name('box_liberation'), target_height=540)
if not cd_text:
cd_text = self.task.ocr(box=self.task.get_box_by_name('box_liberation'), target_height=540, threshold=0.95)
if not cd_text or not cd_text[0].name.isdigit():
self.base_liberation_white_percentage = snap1_lib
logger.info(f'{self} set base liberation to {self.base_liberation_white_percentage:.3f}')
if self.task.debug:
self.task.screenshot(f'{self}_liberation_{self.base_liberation_white_percentage:.3f}')
return True
else:
logger.debug(
Expand Down Expand Up @@ -210,11 +239,23 @@ def current_liberation(self):
return self.task.calculate_color_percentage(white_color, self.task.get_box_by_name('box_liberation'))

def flying(self):
return self.current_resonance() == 0
return self.get_current_levitator() == 0

def get_current_levitator(self):
return self.task.calculate_color_percentage(white_color,
self.task.get_box_by_name('edge_levitator'))


forte_white_color = {
'r': (244, 255), # Red range
'g': (246, 255), # Green range
'b': (250, 255) # Blue range
}


def is_float(s):
try:
float(s)
return True
except ValueError:
return False
34 changes: 22 additions & 12 deletions src/char/Encore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,43 @@

class Encore(BaseChar):
def do_perform(self):
if self.has_intro:
logger.info('Encore has_intro sleep')
if self.has_intro and self.liberation_available():
logger.debug(
f'Encore_perform_{self.has_intro}_{self.echo_available()}_{self.resonance_available()}_{self.liberation_available()}')
if self.liberation_available():
self.click_liberation()
self.sleep(2)
self.n4()
self.click_resonance()
self.n4()
self.sleep(0.5)
self.task.right_click()
self.sleep(0.4)
self.n4()
self.click_resonance()
if self.is_forte_full():
logger.info('Encore is_forte_full cast')
self.sleep(2)
self.heavy_attack()
elif self.resonance_available():
self.click_resonance()
self.sleep(0.2)
elif self.echo_available():
self.click_echo()
self.sleep(0.2)
self.sleep(0.3)
self.click_echo()
self.sleep(0.2)
self.sleep(0.3)
self.click_echo()
self.sleep(0.2)
self.sleep(0.4)
elif self.is_forte_full():
self.heavy_attack()
else:
logger.info('Encore nothing is available')
self.switch_next_char()

def n4(self):
self.normal_attack()
self.sleep(.4)
self.sleep(.3)
self.normal_attack()
self.sleep(.4)
self.sleep(.3)
self.normal_attack()
self.sleep(.4)
self.sleep(.3)
self.normal_attack()
self.sleep(.4)
self.sleep(.8)
4 changes: 1 addition & 3 deletions src/char/HavocRover.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ def do_perform(self):
if self.is_forte_full() and self.liberation_available():
logger.info(f'forte_full, and liberation_available, heavy attack')
self.heavy_attack()
self.sleep(0.2)
if self.resonance_available():
self.sleep(0.4)
self.click_resonance()
self.sleep(0.2)
if self.liberation_available():
self.click_liberation()
self.sleep(2)
if self.echo_available():
self.click_echo()
self.sleep(0.1)
Expand Down
Loading

0 comments on commit 85ff7fb

Please sign in to comment.