Skip to content

Commit

Permalink
optimize chars
Browse files Browse the repository at this point in the history
  • Loading branch information
ok-oldking committed Jun 15, 2024
1 parent 43bafae commit eb1a3a0
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 35 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 26 additions & 1 deletion assets/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"height": 2160,
"id": 6,
"file_name": "images\\934f0ca6-17_53_47_840123_WindowsGraphicsCaptureMethod_3840x2160_title_None_Clie_aJQVINN.png"
},
{
"width": 3840,
"height": 2160,
"id": 7,
"file_name": "images\\1433eace-21_13_50_556378_WindowsGraphicsCaptureMethod_3840x2160_title_None_Clie_z8GnYut.png"
}
],
"categories": [
Expand Down Expand Up @@ -151,6 +157,10 @@
{
"id": 26,
"name": "char_yinlin"
},
{
"id": 27,
"name": "pick_up_f"
}
],
"annotations": [
Expand Down Expand Up @@ -528,6 +538,21 @@
"ignore": 0,
"iscrowd": 0,
"area": 13153.856997415667
},
{
"id": 25,
"image_id": 7,
"category_id": 27,
"segmentation": [],
"bbox": [
2503.364084708245,
1208.9597073673308,
27.039938641537265,
27.7332704015765
],
"ignore": 0,
"iscrowd": 0,
"area": 749.9059299877902
}
],
"info": {
Expand All @@ -536,6 +561,6 @@
"description": "",
"contributor": "Label Studio",
"url": "",
"date_created": "2024-06-15 19:26:37.889387"
"date_created": "2024-06-15 21:20:52.772035"
}
}
24 changes: 20 additions & 4 deletions src/char/BaseChar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ def __eq__(self, other):

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
while self.flying():
if not clicked:
self.task.click()
clicked = True
self.sleep(0.001)

def do_perform(self):
if self.liberation_available():
self.click_liberation()
Expand Down Expand Up @@ -149,11 +158,11 @@ def is_con_full(self):
return True

def is_forte_full(self):
box = self.task.box_of_screen(2170 / 3840, 1998 / 2160, 2174 / 3840, 2007 / 2160, name='forte_full')
colorfulness = calculate_colorfulness(self.task.frame, box)
box.confidence = colorfulness
box = self.task.box_of_screen(2251 / 3840, 1993 / 2160, 2271 / 3840, 2016 / 2160, name='forte_full')
white_percent = self.task.calculate_color_percentage(forte_white_color, box)
box.confidence = white_percent
self.task.draw_boxes('forte_full', box)
if colorfulness > 0.1:
if white_percent > 0.2:
return True

def liberation_available(self):
Expand Down Expand Up @@ -202,3 +211,10 @@ def current_liberation(self):

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


forte_white_color = {
'r': (244, 255), # Red range
'g': (246, 255), # Green range
'b': (250, 255) # Blue range
}
33 changes: 25 additions & 8 deletions src/char/Encore.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
from ok.logging.Logger import get_logger

from src.char.BaseChar import BaseChar

logger = get_logger(__name__)


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():
self.click_liberation()
self.sleep(2)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.n4()
self.click_resonance()
self.n4()
self.sleep(0.5)
elif self.resonance_available():
self.click_resonance()
self.sleep(0.2)
elif self.echo_available():
self.click_echo()
self.sleep(0.3)
self.sleep(0.2)
self.click_echo()
self.sleep(0.2)
self.click_echo()
self.sleep(0.2)
self.switch_next_char()

def n4(self):
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.sleep(.4)
9 changes: 4 additions & 5 deletions src/char/Jianxin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ class Jianxin(BaseChar):
def do_perform(self):
if self.has_intro:
self.sleep(0.8)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
self.sleep(.4)
self.normal_attack()
if self.liberation_available():
self.click_liberation()
self.sleep(2)
if self.is_forte_full():
self.task.mouse_down()
self.sleep(6)
self.task.mouse_up()
if self.resonance_available():
self.click_resonance()
if self.echo_available():
Expand Down
3 changes: 2 additions & 1 deletion src/char/Sanhua.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def do_perform(self):
self.sleep(0.3)
else:
self.task.mouse_down()
self.sleep(1)
self.sleep(.7)
self.task.mouse_up()
self.sleep(0.2)

self.switch_next_char()
24 changes: 12 additions & 12 deletions src/task/AutoCombatTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,26 @@ def check_in_combat(self):
self._in_combat = self.in_team() and self.check_health_bar()

def check_health_bar(self):
min_height = self.height_of_screen(10 / 2160)
max_height = min_height * 3
min_width = self.width_of_screen(40 / 3840)
if self._in_combat:
min_height = self.height_of_screen(10 / 2160)
max_height = min_height * 3
min_width = self.width_of_screen(20 / 3840)
else:
min_height = self.height_of_screen(12 / 2160)
max_height = min_height * 3
min_width = self.width_of_screen(100 / 3840)

boxes = find_color_rectangles(self.frame, enemy_health_color_red, min_width, min_height, max_height=max_height)

if len(boxes) > 0:
self.draw_boxes('enemy_health_bar_red', boxes, color='blue')
return True
else:
boxes = find_color_rectangles(self.frame, enemy_health_color_black, min_width, min_height,
max_height=max_height)
boxes = find_color_rectangles(self.frame, boss_health_color, min_width, min_height * 1.4,
box=self.box_of_screen(1269 / 3840, 58 / 2160, 2533 / 3840, 192 / 2160))
if len(boxes) > 0:
self.draw_boxes('enemy_health_black', boxes, color='blue')
self.draw_boxes('boss_health', boxes, color='blue')
return True
else:
boxes = find_color_rectangles(self.frame, boss_health_color, min_width, min_height * 1.5,
box=self.box_of_screen(1269 / 3840, 58 / 2160, 2533 / 3840, 192 / 2160))
if len(boxes) > 0:
self.draw_boxes('boss_health', boxes, color='blue')
return True

def load_chars(self):
if not self.in_team():
Expand Down
12 changes: 8 additions & 4 deletions src/task/SkipDialogTask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import time

from ok.feature.FindFeature import FindFeature
from ok.logging.Logger import get_logger
Expand All @@ -15,6 +16,7 @@ def __init__(self):
self.skip = None
self.confirm_dialog_checked = False
self.check_trigger_interval = 0.2
self.has_eye_time = 0

def run(self):
pass
Expand All @@ -38,12 +40,14 @@ def trigger(self):
self.screenshot('dialog')
logger.info('confirm dialog does not exist')
self.confirm_dialog_checked = True
btn_dialog_close = self.find_one('btn_dialog_close', use_gray_scale=True, threshold=0.8)
if btn_dialog_close:
self.click(btn_dialog_close, move_back=True)
return
if time.time() - self.has_eye_time < 2:
btn_dialog_close = self.find_one('btn_dialog_close', use_gray_scale=True, threshold=0.8)
if btn_dialog_close:
self.click(btn_dialog_close, move_back=True)
return
btn_dialog_eye = self.find_one('btn_dialog_eye', use_gray_scale=True)
if btn_dialog_eye:
self.has_eye_time = time.time()
btn_auto_play_dialog = self.find_one('btn_auto_play_dialog', use_gray_scale=True)
if btn_auto_play_dialog:
self.click_box(btn_auto_play_dialog, move_back=True)
Expand Down

0 comments on commit eb1a3a0

Please sign in to comment.