|
2 | 2 | from src.tasks.BaseCombatTask import BaseCombatTask, NotInCombatException, CharDeadException |
3 | 3 |
|
4 | 4 | from pynput import mouse |
| 5 | + |
5 | 6 | logger = Logger.get_logger(__name__) |
6 | 7 |
|
| 8 | + |
7 | 9 | class AutoCombatTask(BaseCombatTask, TriggerTask): |
8 | 10 |
|
9 | 11 | def __init__(self, *args, **kwargs): |
10 | 12 | super().__init__(*args, **kwargs) |
11 | 13 | self.name = "自动战斗" |
12 | 14 | self.description = "需使用鼠标侧键主动激活" |
13 | 15 | self.default_config.update({ |
14 | | - '激活键': 'x2', |
| 16 | + "激活键": "x2", |
| 17 | + "技能": "普攻", |
| 18 | + "释放间隔": 0.1, |
15 | 19 | }) |
16 | | - self.config_type['激活键'] = {'type': 'drop_down', 'options': ['x1', 'x2']} |
| 20 | + self.config_type["激活键"] = {"type": "drop_down", "options": ["x1", "x2"]} |
| 21 | + self.config_type["技能"] = {"type": "drop_down", "options": ["普攻", "战技", "终结技"]} |
17 | 22 | self.config_description.update({ |
18 | | - '激活键': '鼠标侧键', |
| 23 | + "激活键": "鼠标侧键", |
19 | 24 | }) |
20 | 25 | self.connected = False |
21 | | - |
| 26 | + |
22 | 27 | def run(self): |
23 | 28 | if not self.connected: |
24 | 29 | self.connected = True |
25 | 30 | og.my_app.clicked.connect(self.on_global_click) |
26 | 31 |
|
27 | 32 | ret = False |
28 | | - |
29 | 33 | while self.in_combat(): |
| 34 | + if not ret: |
| 35 | + n = self.config.get("释放间隔", 0.1) |
| 36 | + interval = 0.1 if n < 0.1 else n |
| 37 | + char = self.get_current_char() |
30 | 38 | ret = True |
31 | 39 | try: |
32 | | - self.get_current_char().perform() |
| 40 | + skill = self.config.get("技能", "普攻") |
| 41 | + if skill == "战技": |
| 42 | + char.send_combat_key() |
| 43 | + elif skill == "终结技": |
| 44 | + char.send_ultimate_key() |
| 45 | + else: |
| 46 | + char.click() |
| 47 | + self.sleep(interval) |
33 | 48 | except CharDeadException: |
34 | | - self.log_error(f'Characters dead', notify=True) |
| 49 | + self.log_error(f"Characters dead", notify=True) |
35 | 50 | break |
36 | 51 | except NotInCombatException as e: |
37 | | - logger.info(f'auto_combat_task_out_of_combat {e}') |
| 52 | + logger.info(f"auto_combat_task_out_of_combat {e}") |
38 | 53 | break |
39 | | - |
| 54 | + |
40 | 55 | if ret: |
41 | 56 | self.combat_end() |
42 | 57 | return ret |
43 | | - |
| 58 | + |
44 | 59 | def on_global_click(self, x, y, button, pressed): |
45 | 60 | if self._executor.paused: |
46 | 61 | return |
47 | | - if self.config.get('激活键', 'x2') == 'x1': |
| 62 | + if self.config.get("激活键", "x2") == "x1": |
48 | 63 | btn = mouse.Button.x1 |
49 | 64 | else: |
50 | 65 | btn = mouse.Button.x2 |
|
0 commit comments