Skip to content

Commit 14fcc51

Browse files
committed
2 parents 3f2248b + ab25196 commit 14fcc51

File tree

1 file changed

+159
-89
lines changed

1 file changed

+159
-89
lines changed

src/char/Jinhsi.py

Lines changed: 159 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,123 +4,193 @@
44

55

66
class Jinhsi(BaseChar):
7-
87
def __init__(self, *args, **kwargs):
98
super().__init__(*args, **kwargs)
109
self.last_free_intro = 0 # free intro every 25 sec
1110
self.has_free_intro = False
12-
self.incarnation = False
13-
self.incarnation_cd = False
11+
self.incarnation = 0
1412
self.last_fly_e_time = 0
13+
self.e2_last = 0
1514

16-
def do_perform(self):
17-
if self.incarnation:
15+
def do_perform(self):
16+
self.has_free_intro = False
17+
if self.has_intro:
18+
if self.incarnation == 0:
19+
self.e2_last = time.time()
20+
self.sleep(0.8)
21+
self.click_echo()
22+
if self.incarnation == 2:
1823
self.handle_incarnation()
19-
return self.switch_next_char()
20-
elif self.has_intro or self.incarnation_cd:
24+
return self.switch_next_char(free_intro=self.has_free_intro)
25+
if (self.time_elapsed_accounting_for_freeze(self.e2_last) < 4.5 and self.incarnation == 0) or self.resonance_light() or self.incarnation == 1:
2126
self.handle_intro()
22-
return self.switch_next_char()
23-
self.click_echo()
24-
return self.switch_next_char()
27+
return self.switch_next_char(free_intro=self.has_free_intro)
28+
if self.check_team_con() and not self.need_fast_perform() and self.resonance_available() and self.time_elapsed_accounting_for_freeze(self.last_fly_e_time) > 12:
29+
if self.attack_until_resonance():
30+
self.e2_last = time.time()
31+
self.handle_intro()
32+
return self.switch_next_char(free_intro=self.has_free_intro)
33+
self.continues_normal_attack(0.1)
34+
self.switch_next_char(free_intro=self.has_free_intro)
2535

2636
def reset_state(self):
2737
super().reset_state()
28-
self.incarnation = False
38+
self.incarnation = 0
2939
self.has_free_intro = False
30-
self.incarnation_cd = False
31-
32-
def switch_next_char(self, **args):
33-
super().switch_next_char(free_intro=self.has_free_intro, target_low_con=True)
34-
self.has_free_intro = False
35-
40+
self.e2_last = 0
41+
self.last_fly_e_time = 0
42+
3643
def do_get_switch_priority(self, current_char: BaseChar, has_intro=False, target_low_con=False):
37-
if has_intro or self.incarnation or self.incarnation_cd:
44+
if has_intro or self.incarnation > 0 or self.time_elapsed_accounting_for_freeze(self.e2_last) < 4.5:
3845
self.logger.info(
39-
f'switch priority max because has_intro {has_intro} incarnation {self.incarnation} incarnation_cd {self.incarnation_cd}')
46+
f'switch priority max because has_intro {has_intro} incarnation {self.incarnation} e2_cd {self.e2_last}')
4047
return Priority.MAX
4148
else:
42-
return Priority.MIN
43-
44-
def count_base_priority(self):
45-
return -3
46-
49+
return super().do_get_switch_priority(current_char, has_intro)
50+
4751
def count_resonance_priority(self):
52+
if self.time_elapsed_accounting_for_freeze(self.last_fly_e_time) > 12:
53+
return 10
4854
return 0
4955

50-
def count_echo_priority(self):
51-
return 10
52-
5356
def count_liberation_priority(self):
5457
return 0
55-
58+
5659
def handle_incarnation(self):
57-
self.incarnation = False
58-
self.logger.info(f'handle_incarnation click_resonance start')
60+
self.incarnation = 0
61+
self.logger.info('handle_incarnation click_resonance start')
5962
start = time.time()
60-
animation_start = 0
61-
last_op = 'resonance'
62-
self.task.in_liberation = True
63-
while True:
64-
if time.time() - start > 6:
65-
self.logger.info(f'handle incarnation too long')
66-
break
67-
if self.task.in_team()[0]:
68-
if last_op == 'resonance':
69-
self.task.click(interval=0.1)
70-
last_op = 'click'
71-
else:
72-
self.send_resonance_key()
73-
last_op = 'resonance'
74-
if animation_start != 0:
75-
self.logger.info(f'Jinhsi handle_incarnation done')
76-
break
77-
else:
78-
if animation_start == 0:
79-
self.logger.info(f'Jinhsi handle_incarnation start animation')
80-
animation_start = time.time()
81-
self.task.in_liberation = True
63+
while self.time_elapsed_accounting_for_freeze(self.last_fly_e_time) < 10.5:
64+
self.click(interval=0.1)
65+
if time.time() - start > 8:
66+
return
67+
if self.resonance_light():
68+
self.e2_last = time.time()
69+
result = self.resonance_until_not_light()
70+
if result == 1:
71+
self.last_fly_e_time = time.time()
72+
self.incarnation = 1
73+
if result > 0:
74+
return
8275
self.check_combat()
83-
self.task.next_frame()
84-
self.task.in_liberation = False
85-
86-
if not self.click_echo():
87-
self.task.click()
88-
89-
self.add_freeze_duration(animation_start)
90-
# if self.task.debug:
91-
# self.task.screenshot(f'handle_incarnation click_resonance end {time.time() - start}')
92-
self.logger.info(f'handle_incarnation click_resonance end {time.time() - start}')
76+
self.task.next_frame()
9377

9478
def handle_intro(self):
95-
self.logger.info(f'handle_intro start')
79+
self.logger.info('handle_intro start')
9680
start = time.time()
97-
while True:
98-
elapsed = time.time() - start
99-
if self.has_cd('resonance'):
100-
if 0.3 < elapsed < 1.5:
101-
self.incarnation_cd = True
102-
# self.task.screenshot('incarnation_cd')
103-
if not self.click_echo():
104-
self.click()
81+
if self.has_cd('resonance') and self.time_elapsed_accounting_for_freeze(self.last_fly_e_time) < 12:
82+
self.logger.info('e2 has cd')
83+
return
84+
if self.incarnation == 0:
85+
if self.resonance_until_not_light() == 1:
86+
self.last_fly_e_time = time.time()
87+
if not self.click_liberation():
88+
self.dodge()
89+
self.continues_normal_attack(0.1)
90+
self.incarnation = 1
91+
if self.check_outro() in {'char_zhezhi','char_taoqi','char_cantarella','char_brant'}:
92+
self.incarnation = 2
93+
self.handle_incarnation()
94+
return
95+
if self.incarnation == 1:
96+
if self.check_outro() in {'char_zhezhi','char_taoqi','char_cantarella','char_brant'}:
97+
self.incarnation = 2
98+
self.handle_incarnation()
99+
return
100+
while self.time_elapsed_accounting_for_freeze(self.last_fly_e_time) < 11:
101+
if self.resonance_available():
102+
self.click_resonance()
103+
self.incarnation = 2
104+
self.check_animation()
105105
return
106-
elif elapsed > 1.5:
107-
# self.task.screenshot('incarnation_finished')
108-
break
106+
self.task.click(interval=0.1)
107+
self.check_combat()
108+
self.task.next_frame()
109+
self.incarnation = 0
110+
111+
112+
def dodge(self, duration=0.1):
113+
self.check_combat()
114+
self.task.send_key_down(key='w')
115+
self.task.mouse_down(key='right')
116+
self.sleep(duration)
117+
self.task.mouse_up(key='right')
118+
self.task.send_key_up(key='w')
119+
120+
def resonance_light(self):
121+
box = self.task.box_of_screen_scaled(3840, 2160, 3105, 1845, 3285, 2010, name='jinhsi_resonance', hcenter=False)
122+
yellow_percent = self.task.calculate_color_percentage(jinhsi_yellow_color, box)
123+
return yellow_percent > 0.03
124+
125+
def attack_until_resonance(self):
126+
start = time.time()
127+
last = start
128+
while time.time() - start < 7:
129+
self.click(interval=0.1)
130+
if self.resonance_light():
131+
if time.time()-last > 0.1:
132+
return True
109133
else:
110-
self.send_resonance_key(interval=0.1)
134+
last = time.time()
111135
self.task.next_frame()
112136
self.check_combat()
113-
114-
self.last_fly_e_time = start
115-
if self.click_liberation(send_click=True):
116-
self.continues_normal_attack(0.3)
117-
else:
118-
self.continues_normal_attack(1.4)
119-
# self.task.screenshot(f'handle_intro end {time.time() - start}')
120-
self.logger.info(f'handle_intro end {time.time() - start}')
121-
self.incarnation = True
122-
self.incarnation_cd = False
123-
124-
def wait_resonance(self):
125-
while not self.resonance_available(check_ready=True):
126-
self.send_resonance_key(interval=0.1)
137+
return False
138+
139+
140+
def check_team_con(self):
141+
for i, char in enumerate(self.task.chars):
142+
self.logger.debug(f'find char: {char}')
143+
if char == self or char.current_con < 0.8:
144+
continue
145+
return False
146+
return True
147+
148+
149+
def resonance_until_not_light(self):
150+
start = time.time()
151+
b = 0
152+
while not self.resonance_light() or not self.resonance_available():
153+
if time.time() - start > 1:
154+
break
155+
self.check_combat()
156+
self.task.next_frame()
157+
while self.resonance_available() and self.resonance_light():
158+
self.send_resonance_key()
159+
b = 1
160+
if time.time() - start > 2:
161+
return 0
162+
if self.check_animation():
163+
return 2
164+
self.check_combat()
165+
self.task.next_frame()
166+
if self.check_animation():
167+
return 2
168+
return b
169+
170+
def check_animation(self):
171+
if self.task.in_team()[0]:
172+
return False
173+
animation_start = 0
174+
self.task.in_liberation = True
175+
while not self.task.in_team()[0]:
176+
if animation_start == 0:
177+
self.logger.info('Jinhsi handle_incarnation start animation')
178+
animation_start = time.time()
179+
self.check_combat()
180+
self.task.next_frame()
181+
self.task.in_liberation = False
182+
if animation_start == 0:
183+
return False
184+
self.add_freeze_duration(animation_start)
185+
self.incarnation = 0
186+
self.e2_last = 0
187+
if self.time_elapsed_accounting_for_freeze(self.last_free_intro) > 25:
188+
self.has_free_intro = True
189+
self.last_free_intro = time.time()
190+
return True
191+
192+
jinhsi_yellow_color = {
193+
'r': (235, 255), # Red range
194+
'g': (235, 255), # Green range
195+
'b': (200, 230) # Blue range
196+
}

0 commit comments

Comments
 (0)