mirror of
https://github.com/ok-oldking/ok-wuthering-waves.git
synced 2025-04-24 08:25:16 +00:00
optimize autocombat
This commit is contained in:
parent
f5b118b04e
commit
81704f60f0
@ -105,15 +105,22 @@ class BaseChar:
|
||||
if current - self.last_res > self.res_cd: # count the first click only
|
||||
self.last_res = time.time()
|
||||
|
||||
def click_echo(self):
|
||||
def click_echo(self, sleep_time=0):
|
||||
self.check_combat()
|
||||
echo_available = self.echo_available()
|
||||
self.task.send_key(self.get_echo_key())
|
||||
while True:
|
||||
if not echo_available:
|
||||
echo_available = self.echo_available()
|
||||
current_echo = self.current_echo()
|
||||
if current_echo > 0 and abs(
|
||||
current_echo - self.base_echo_white_percentage) > self.white_off_threshold:
|
||||
if echo_available:
|
||||
self.sleep(sleep_time)
|
||||
break
|
||||
self.sleep(0.05)
|
||||
self.sleep(0.02)
|
||||
self.task.click()
|
||||
self.sleep(0.02)
|
||||
self.task.send_key(self.get_echo_key())
|
||||
logger.info(f'{self} click echo')
|
||||
|
||||
|
@ -10,12 +10,8 @@ class Taoqi(BaseChar):
|
||||
self.normal_attack()
|
||||
self.sleep(.4)
|
||||
self.normal_attack()
|
||||
if self.liberation_available():
|
||||
self.click_liberation()
|
||||
if self.resonance_available():
|
||||
self.click_resonance()
|
||||
if self.echo_available():
|
||||
self.sleep(0.3)
|
||||
self.click_echo()
|
||||
self.sleep(0.3)
|
||||
self.sleep(.4)
|
||||
self.click_liberation()
|
||||
self.click_resonance()
|
||||
self.click_echo(sleep_time=0.1)
|
||||
self.switch_next_char()
|
||||
|
@ -13,7 +13,7 @@ class Yinlin(BaseChar):
|
||||
self.sleep(0.4)
|
||||
elif self.resonance_available():
|
||||
self.click_resonance()
|
||||
self.sleep(.1)
|
||||
# self.sleep(.1)
|
||||
elif self.echo_available():
|
||||
echo_key = self.get_echo_key()
|
||||
self.task.send_key_down(echo_key)
|
||||
|
@ -42,7 +42,8 @@ class CombatCheck:
|
||||
current = cv2.Canny(current, 100, 200)
|
||||
res = cv2.matchTemplate(current, self.boss_lv_edge, cv2.TM_CCOEFF_NORMED)
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
|
||||
if max_val < 0.70:
|
||||
if max_val < 0.5:
|
||||
logger.debug(f'boss lv not detected by edge {res}')
|
||||
if not self.find_boss_lv_text(): # double check by text
|
||||
self.boss_lv_box.confidence = max_val
|
||||
self.draw_boxes('enemy_health_bar_red', self.boss_lv_box, color='red')
|
||||
@ -131,7 +132,7 @@ class CombatCheck:
|
||||
self.boss_lv_box = boss_lv_texts[0]
|
||||
self.boss_lv_edge = cv2.cvtColor(self.boss_lv_box.crop_frame(self.frame), cv2.COLOR_BGR2GRAY)
|
||||
self.boss_lv_edge = cv2.Canny(self.boss_lv_edge, 100, 200)
|
||||
self.screenshot_boss_lv(self.boss_lv_edge, 'found_boss_lv')
|
||||
# self.screenshot_boss_lv(self.boss_lv_edge, 'found_boss_lv')
|
||||
return True
|
||||
|
||||
|
||||
|
@ -1,13 +1,7 @@
|
||||
import time
|
||||
|
||||
from ok.feature.FindFeature import FindFeature
|
||||
from ok.logging.Logger import get_logger
|
||||
from ok.ocr.OCR import OCR
|
||||
from ok.task.TriggerTask import TriggerTask
|
||||
from ok.util.list import safe_get
|
||||
from src.char import BaseChar
|
||||
from src.char.BaseChar import Priority, role_values
|
||||
from src.char.CharFactory import get_char_by_pos
|
||||
from src.combat.CombatCheck import CombatCheck
|
||||
from src.task.BaseCombatTask import BaseCombatTask, NotInCombatException
|
||||
|
||||
@ -16,24 +10,6 @@ logger = get_logger(__name__)
|
||||
|
||||
class AutoCombatTask(BaseCombatTask, TriggerTask, FindFeature, OCR, CombatCheck):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.chars = [None, None, None]
|
||||
self.char_texts = ['char_1_text', 'char_2_text', 'char_3_text']
|
||||
self.default_config.update({
|
||||
'Echo Key': 'q',
|
||||
'Liberation Key': 'r',
|
||||
'Resonance Key': 'e',
|
||||
'Character 1 Role': 'Default',
|
||||
'Character 2 Role': 'Default',
|
||||
'Character 3 Role': 'Default',
|
||||
})
|
||||
self.config_type["Character 1 Role"] = {'type': "drop_down", 'options': role_values}
|
||||
self.config_type["Character 2 Role"] = {'type': "drop_down", 'options': role_values}
|
||||
self.config_type["Character 3 Role"] = {'type': "drop_down", 'options': role_values}
|
||||
|
||||
self.char_texts = ['char_1_text', 'char_2_text', 'char_3_text']
|
||||
|
||||
def run(self):
|
||||
while self.in_combat():
|
||||
try:
|
||||
@ -41,118 +17,9 @@ class AutoCombatTask(BaseCombatTask, TriggerTask, FindFeature, OCR, CombatCheck)
|
||||
self.get_current_char().perform()
|
||||
except NotInCombatException:
|
||||
logger.info('out of combat break')
|
||||
break
|
||||
|
||||
def trigger(self):
|
||||
if self.in_combat():
|
||||
self.load_chars()
|
||||
return True
|
||||
|
||||
def switch_next_char(self, current_char, post_action=None):
|
||||
max_priority = Priority.MIN
|
||||
switch_to = None
|
||||
has_intro = current_char.is_con_full()
|
||||
for i, char in enumerate(self.chars):
|
||||
if char == current_char:
|
||||
priority = Priority.CURRENT_CHAR
|
||||
else:
|
||||
priority = char.get_switch_priority(current_char, has_intro)
|
||||
logger.info(f'switch priority: {char} {priority}')
|
||||
if priority > max_priority:
|
||||
max_priority = priority
|
||||
switch_to = char
|
||||
if switch_to == current_char:
|
||||
logger.warning(f"can't find next char to switch to, maybe switching too fast, sleep and wait")
|
||||
return
|
||||
switch_to.has_intro = has_intro
|
||||
current_char.is_current_char = False
|
||||
self.send_key(switch_to.index + 1)
|
||||
while True:
|
||||
self.click()
|
||||
_, current_index = self.in_team()
|
||||
if current_index != switch_to.index:
|
||||
self.send_key(switch_to.index + 1)
|
||||
logger.info(f'switch not detected, try click again {current_index} {switch_to}')
|
||||
else:
|
||||
switch_time = time.time()
|
||||
switch_to.is_current_char = True
|
||||
break
|
||||
|
||||
if post_action:
|
||||
post_action()
|
||||
return switch_time
|
||||
|
||||
def get_current_char(self):
|
||||
for char in self.chars:
|
||||
if char.is_current_char:
|
||||
return char
|
||||
self.log_error('can find current char!!')
|
||||
return None
|
||||
|
||||
def sleep(self, timeout):
|
||||
if not self.in_combat():
|
||||
raise NotInCombatException('not in combat')
|
||||
super().sleep(timeout)
|
||||
|
||||
def load_chars(self):
|
||||
in_team, current_index = self.in_team()
|
||||
if not in_team:
|
||||
return
|
||||
self.log_info('load chars')
|
||||
char = get_char_by_pos(self, self.get_box_by_name('box_char_1'), 0)
|
||||
old_char = safe_get(self.chars, 0)
|
||||
if (type(char) is BaseChar and old_char is None) or type(char) is not BaseChar:
|
||||
self.chars[0] = char
|
||||
logger.info(f'update char1 to {char.name} {type(char)} {type(char) is not BaseChar}')
|
||||
|
||||
char = get_char_by_pos(self, self.get_box_by_name('box_char_2'), 1)
|
||||
old_char = safe_get(self.chars, 1)
|
||||
if (type(char) is BaseChar and old_char is None) or type(char) is not BaseChar:
|
||||
self.chars[1] = char
|
||||
logger.info(f'update char2 to {char.name}')
|
||||
|
||||
char = get_char_by_pos(self, self.get_box_by_name('box_char_3'), 2)
|
||||
old_char = safe_get(self.chars, 2)
|
||||
if (type(char) is BaseChar and old_char is None) or type(char) is not BaseChar:
|
||||
self.chars[2] = char
|
||||
logger.info(f'update char3 to {char.name}')
|
||||
|
||||
for char in self.chars:
|
||||
if char.index == current_index:
|
||||
char.is_current_char = True
|
||||
else:
|
||||
char.is_current_char = False
|
||||
|
||||
self.log_info(f'load chars success {self.chars}')
|
||||
|
||||
def box_resonance(self):
|
||||
return self.get_box_by_name('box_resonance_cd')
|
||||
|
||||
def get_resonance_cd_percentage(self):
|
||||
return self.calculate_color_percentage(white_color, self.get_box_by_name('box_resonance_cd'))
|
||||
|
||||
def get_resonance_percentage(self):
|
||||
return self.calculate_color_percentage(white_color, self.get_box_by_name('box_resonance'))
|
||||
|
||||
def in_team(self):
|
||||
c1 = self.find_one('char_1_text')
|
||||
c2 = self.find_one('char_2_text')
|
||||
c3 = self.find_one('char_3_text')
|
||||
arr = [c1, c2, c3]
|
||||
current = -1
|
||||
exist_count = 0
|
||||
for i in range(len(arr)):
|
||||
if arr[i] is None:
|
||||
current = i
|
||||
else:
|
||||
exist_count += 1
|
||||
if exist_count == 2:
|
||||
return True, current
|
||||
else:
|
||||
return False, -1
|
||||
|
||||
|
||||
white_color = {
|
||||
'r': (253, 255), # Red range
|
||||
'g': (253, 255), # Green range
|
||||
'b': (253, 255) # Blue range
|
||||
}
|
||||
|
@ -56,11 +56,17 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
||||
return
|
||||
switch_to.has_intro = has_intro
|
||||
current_char.is_current_char = False
|
||||
logger.info(f'switch {current_char} -> {switch_to}')
|
||||
self.send_key(switch_to.index + 1)
|
||||
while True:
|
||||
self.click()
|
||||
_, current_index = self.in_team()
|
||||
in_team, current_index = self.in_team()
|
||||
if not in_team:
|
||||
logger.error('not in team while switching chars')
|
||||
raise NotInCombatException('not in team while switching chars')
|
||||
if current_index != switch_to.index:
|
||||
if self.debug:
|
||||
self.screenshot(f'switch_not_detected_{current_char}_to_{switch_to}')
|
||||
self.click()
|
||||
self.send_key(switch_to.index + 1)
|
||||
logger.info(f'switch not detected, try click again {current_index} {switch_to}')
|
||||
else:
|
||||
@ -79,8 +85,11 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
||||
for char in self.chars:
|
||||
if char.is_current_char:
|
||||
return char
|
||||
self.log_error('can find current char!!')
|
||||
return None
|
||||
if not self.in_team()[0]:
|
||||
self.log_error('can find current char!!')
|
||||
raise NotInCombatException('can find current char!!')
|
||||
self.load_chars()
|
||||
return self.get_current_char()
|
||||
|
||||
def sleep_check_combat(self, timeout):
|
||||
if not self.in_combat():
|
||||
@ -153,6 +162,7 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
||||
c2 = self.find_one('char_2_text')
|
||||
c3 = self.find_one('char_3_text')
|
||||
arr = [c1, c2, c3]
|
||||
logger.debug(f'in_team check {arr}')
|
||||
current = -1
|
||||
exist_count = 0
|
||||
for i in range(len(arr)):
|
||||
|
Loading…
x
Reference in New Issue
Block a user