diff --git a/config/template.json b/config/template.json index 01bb92be5..1a9c42c6f 100644 --- a/config/template.json +++ b/config/template.json @@ -23,6 +23,10 @@ "Optimization": { "ScreenshotInterval": 0.3, "CombatScreenshotInterval": 1.0, + "ClickMaxRecord": 15, + "SingleButtonMaxCount": 12, + "MultiButtonMaxCount1": 6, + "MultiButtonMaxCount2": 6, "TaskHoardingDuration": 0, "WhenTaskQueueEmpty": "goto_main" }, diff --git a/deploy/Windows/config.py b/deploy/Windows/config.py index 5c10ab0a8..90ca2ae6c 100644 --- a/deploy/Windows/config.py +++ b/deploy/Windows/config.py @@ -56,7 +56,7 @@ class ConfigModel: # Webui WebuiHost: str = "0.0.0.0" - WebuiPort: int = 22367 + WebuiPort: int = 22267 Language: str = "en-US" Theme: str = "default" DpiScaling: bool = True diff --git a/module/config/argument/args.json b/module/config/argument/args.json index e07dbc2a2..8f0be1fda 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -198,6 +198,22 @@ "type": "input", "value": 1.0 }, + "ClickMaxRecord": { + "type": "input", + "value": 15 + }, + "SingleButtonMaxCount": { + "type": "input", + "value": 12 + }, + "MultiButtonMaxCount1": { + "type": "input", + "value": 6 + }, + "MultiButtonMaxCount2": { + "type": "input", + "value": 6 + }, "TaskHoardingDuration": { "type": "input", "value": 0 diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 94bc1a7ca..f28172d3e 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -91,6 +91,10 @@ Error: Optimization: ScreenshotInterval: 0.3 CombatScreenshotInterval: 1.0 + ClickMaxRecord: 15 + SingleButtonMaxCount: 12 + MultiButtonMaxCount1: 6 + MultiButtonMaxCount2: 6 TaskHoardingDuration: 0 WhenTaskQueueEmpty: value: goto_main diff --git a/module/config/config_generated.py b/module/config/config_generated.py index 09ac57934..469a97063 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -40,6 +40,10 @@ class GeneratedConfig: # Group `Optimization` Optimization_ScreenshotInterval = 0.3 Optimization_CombatScreenshotInterval = 1.0 + Optimization_ClickMaxRecord = 15 + Optimization_SingleButtonMaxCount = 12 + Optimization_MultiButtonMaxCount1 = 6 + Optimization_MultiButtonMaxCount2 = 6 Optimization_TaskHoardingDuration = 0 Optimization_WhenTaskQueueEmpty = 'goto_main' # stay_there, goto_main, close_game diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 7ee70430e..7848721db 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -505,6 +505,22 @@ "name": "Take Screenshots Every X Second(s) In Combat", "help": "Minimum interval between 2 screenshots, limited in 0.1 ~ 1.0, can help reduce CPU during battle" }, + "ClickMaxRecord": { + "name": "Optimization.ClickMaxRecord.name", + "help": "Optimization.ClickMaxRecord.help" + }, + "SingleButtonMaxCount": { + "name": "Optimization.SingleButtonMaxCount.name", + "help": "Optimization.SingleButtonMaxCount.help" + }, + "MultiButtonMaxCount1": { + "name": "Optimization.MultiButtonMaxCount1.name", + "help": "Optimization.MultiButtonMaxCount1.help" + }, + "MultiButtonMaxCount2": { + "name": "Optimization.MultiButtonMaxCount2.name", + "help": "Optimization.MultiButtonMaxCount2.help" + }, "TaskHoardingDuration": { "name": "Hoard Tasks For X Minute(s)", "help": "By purposely not adding ready tasks to pending, allows for larger subsets to be built and run en masse at a later time\nCan reduce the frequency of operating AL" diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 89c80e76b..d3c3af122 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -505,6 +505,22 @@ "name": "Optimization.CombatScreenshotInterval.name", "help": "Optimization.CombatScreenshotInterval.help" }, + "ClickMaxRecord": { + "name": "Optimization.ClickMaxRecord.name", + "help": "Optimization.ClickMaxRecord.help" + }, + "SingleButtonMaxCount": { + "name": "Optimization.SingleButtonMaxCount.name", + "help": "Optimization.SingleButtonMaxCount.help" + }, + "MultiButtonMaxCount1": { + "name": "Optimization.MultiButtonMaxCount1.name", + "help": "Optimization.MultiButtonMaxCount1.help" + }, + "MultiButtonMaxCount2": { + "name": "Optimization.MultiButtonMaxCount2.name", + "help": "Optimization.MultiButtonMaxCount2.help" + }, "TaskHoardingDuration": { "name": "Optimization.TaskHoardingDuration.name", "help": "Optimization.TaskHoardingDuration.help" diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 2a5201fb8..5e27e9e4d 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -499,11 +499,27 @@ }, "ScreenshotInterval": { "name": "放慢截图速度至 X 秒一张", - "help": "执行两次截图之间的最小间隔,限制在 0.1 ~ 2.0,根据需要自行调整\n建议调整为较短的间隔,比如0.1s\n我也不知道为什么,但这似乎对于减少Alas的部分报错有一定的帮助 : )" + "help": "" }, "CombatScreenshotInterval": { "name": "战斗中放慢截图速度至 X 秒一张", - "help": "执行两次截图之间的最小间隔,限制在 0.1 ~ 5.0,根据需要自行调整\n建议调整为较短的间隔,比如0.5s\n我也不知道为什么,但这似乎对于减少Alas的部分报错有一定的帮助 : )" + "help": "" + }, + "ClickMaxRecord": { + "name": "最大点击记录量", + "help": "默认为15" + }, + "SingleButtonMaxCount": { + "name": "单Button最大计数", + "help": "该数值单项不得超过最大点击记录量,默认为12" + }, + "MultiButtonMaxCount1": { + "name": "多Button最大计数(Button1)", + "help": "该数值与下一项设置之和不得大于最大点击记录量,默认为6" + }, + "MultiButtonMaxCount2": { + "name": "多Button最大计数(Button2)", + "help": "该数值与上一项设置之和不得大于最大点击记录量,默认为6" }, "TaskHoardingDuration": { "name": "囤积任务 X 分钟", diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index 60152eccb..3894ea770 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -505,6 +505,22 @@ "name": "戰鬥中放慢截圖速度至 X 秒一張", "help": "執行兩次截圖之間的最小間隔,限制在 0.1 ~ 1.0,能降低戰鬥時的 CPU 佔用" }, + "ClickMaxRecord": { + "name": "Optimization.ClickMaxRecord.name", + "help": "Optimization.ClickMaxRecord.help" + }, + "SingleButtonMaxCount": { + "name": "Optimization.SingleButtonMaxCount.name", + "help": "Optimization.SingleButtonMaxCount.help" + }, + "MultiButtonMaxCount1": { + "name": "Optimization.MultiButtonMaxCount1.name", + "help": "Optimization.MultiButtonMaxCount1.help" + }, + "MultiButtonMaxCount2": { + "name": "Optimization.MultiButtonMaxCount2.name", + "help": "Optimization.MultiButtonMaxCount2.help" + }, "TaskHoardingDuration": { "name": "囤積任務 X 分鐘", "help": "能在收穫期間降低操作遊戲的頻率\n任務觸發後,等待 X 分鐘後,一次性執行佇列中的任務" diff --git a/module/device/device.py b/module/device/device.py index e745b55c9..e5b25a9c9 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -72,6 +72,10 @@ class Device(Screenshot, Control, AppControl): stuck_long_wait_list = ['BATTLE_STATUS_S', 'PAUSE', 'LOGIN_CHECK'] def __init__(self, *args, **kwargs): + record_maxlen = self.config.Optimization_ClickMaxRecord + if record_maxlen != self.click_record.maxlen: + self.click_record = collections.deque(maxlen=record_maxlen) + for _ in range(2): try: super().__init__(*args, **kwargs) @@ -263,19 +267,29 @@ class Device(Screenshot, Control, AppControl): return removed + def check_and_ensure_record_setting(self): + record_maxlen = self.config.Optimization_ClickMaxRecord + if self.config.Optimization_SingleButtonMaxCount > record_maxlen: + self.config.Optimization_SingleButtonMaxCount = int(0.8 * record_maxlen) + if self.config.Optimization_MultiButtonMaxCount1 + self.config.Optimization_MultiButtonMaxCount2 > record_maxlen: + self.config.Optimization_MultiButtonMaxCount1 = int(0.4 * record_maxlen) + self.config.Optimization_MultiButtonMaxCount2 = int(0.4 * record_maxlen) + def click_record_check(self): """ Raises: GameTooManyClickError: """ + self.check_and_ensure_record_setting() + count = collections.Counter(self.click_record).most_common(2) - if count[0][1] >= 12: + if count[0][1] >= self.config.Optimization_SingleButtonMaxCount: show_function_call() logger.warning(f'Too many click for a button: {count[0][0]}') logger.warning(f'History click: {[str(prev) for prev in self.click_record]}') self.click_record_clear() raise GameTooManyClickError(f'Too many click for a button: {count[0][0]}') - if len(count) >= 2 and count[0][1] >= 6 and count[1][1] >= 6: + if len(count) >= 2 and count[0][1] >= self.config.Optimization_MultiButtonMaxCount1 and count[1][1] >= self.config.Optimization_MultiButtonMaxCount2: show_function_call() logger.warning(f'Too many click between 2 buttons: {count[0][0]}, {count[1][0]}') logger.warning(f'History click: {[str(prev) for prev in self.click_record]}') diff --git a/module/device/screenshot.py b/module/device/screenshot.py index 6032dfa63..0c68b66f1 100644 --- a/module/device/screenshot.py +++ b/module/device/screenshot.py @@ -155,31 +155,12 @@ class Screenshot(Adb, WSA, DroidCast, AScreenCap, Scrcpy, NemuIpc): Minimum interval between 2 screenshots in seconds. Or None for Optimization_ScreenshotInterval, 'combat' for Optimization_CombatScreenshotInterval """ - if interval is None: - origin = self.config.Optimization_ScreenshotInterval - interval = limit_in(origin, 0.1, 2.0) - if interval != origin: - logger.warning(f'Optimization.ScreenshotInterval {origin} is revised to {interval}') - self.config.Optimization_ScreenshotInterval = interval - # Allow nemu_ipc to have a lower default - if self.config.Emulator_ScreenshotMethod == 'nemu_ipc': - interval = limit_in(origin, 0.1, 0.2) - elif interval == 'combat': - origin = self.config.Optimization_CombatScreenshotInterval - interval = limit_in(origin, 0.3, 5.0) - if interval != origin: - logger.warning(f'Optimization.CombatScreenshotInterval {origin} is revised to {interval}') - self.config.Optimization_CombatScreenshotInterval = interval - elif isinstance(interval, (int, float)): + if isinstance(interval, (int, float)): # No limitation for manual set in code pass else: logger.warning(f'Unknown screenshot interval: {interval}') raise ScriptError(f'Unknown screenshot interval: {interval}') - # Screenshot interval in scrcpy is meaningless, - # video stream is received continuously no matter you use it or not. - if self.config.Emulator_ScreenshotMethod == 'scrcpy': - interval = 0.1 if interval != self._screenshot_interval.limit: logger.info(f'Screenshot interval set to {interval}s')