From 6d6f686e0f59cff197672a658c6b6d0702f57d33 Mon Sep 17 00:00:00 2001 From: LmeSzinc Date: Tue, 26 May 2020 23:35:51 +0800 Subject: [PATCH 1/3] Fix: Misuse emergency_repair after retirement --- module/combat/combat.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module/combat/combat.py b/module/combat/combat.py index 5609e3909..654f6ab6c 100644 --- a/module/combat/combat.py +++ b/module/combat/combat.py @@ -96,7 +96,6 @@ class Combat(HPBalancer, EnemySearchingHandler, Retirement, SubmarineCall, Comba self.emotion.wait(fleet=fleet_index) if balance_hp: self.hp_balance() - # logger.info('start combat') while 1: self.device.screenshot() @@ -105,7 +104,12 @@ class Combat(HPBalancer, EnemySearchingHandler, Retirement, SubmarineCall, Comba if self.handle_combat_automation_set(auto=auto): continue if self.handle_retirement(): - continue + if self.config.ENABLE_HP_BALANCE: + self.wait_until_appear(BATTLE_PREPARATION) + # When re-entering battle_preparation page, the emergency icon is active by default, even if + # nothing to use. After a short animation, everything shows as usual. + self.device.sleep(0.5) # Wait animation. + continue if self.handle_combat_low_emotion(): continue if self.handle_emergency_repair_use(): @@ -157,6 +161,8 @@ class Combat(HPBalancer, EnemySearchingHandler, Retirement, SubmarineCall, Comba return False def handle_emergency_repair_use(self): + if not self.config.ENABLE_HP_BALANCE: + return False if self.appear_then_click(EMERGENCY_REPAIR_CONFIRM, offset=True): self.device.sleep(0.5) # Animation: hp increase and emergency_repair amount decrease. return True From 83674b7a371f564209290b6db4f7a1ac3b3bda58 Mon Sep 17 00:00:00 2001 From: LmeSzinc Date: Tue, 26 May 2020 23:47:08 +0800 Subject: [PATCH 2/3] Optimize: Redundant campaign_hard file --- module/campaign/campaign_hard.py | 92 -------------------------------- module/hard/hard.py | 2 +- 2 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 module/campaign/campaign_hard.py diff --git a/module/campaign/campaign_hard.py b/module/campaign/campaign_hard.py deleted file mode 100644 index 5b54be7c2..000000000 --- a/module/campaign/campaign_hard.py +++ /dev/null @@ -1,92 +0,0 @@ -from module.base.timer import Timer -from module.campaign.campaign_base import CampaignBase -from module.hard.equipment import HardEquipment -from module.logger import logger -from module.map.assets import MAP_PREPARATION, FLEET_PREPARATION -from module.exception import CampaignEnd -from module.ui.ui import CAMPAIGN_CHECK - - -class Config: - MAP_HAS_AMBUSH = False - EMOTION_REDUCE = False - -class Campaign(CampaignBase, HardEquipment): - def run(self): - logger.hr(self.ENTRANCE, level=2) - self.enter_map(self.ENTRANCE, mode='hard') - self.map = self.MAP - self.map.reset() - - if self.config.FLEET_HARD == 1: - self.ensure_edge_insight(reverse=True) - self.full_scan_find_boss() - else: - self.fleet_switch_click() - self.ensure_no_info_bar() - self.ensure_edge_insight() - self.full_scan_find_boss() - - try: - self.clear_boss() - except CampaignEnd: - logger.hr('Campaign end') - - def fleet_preparation(self): - self.equipment_take_on() - - @property - def _expected_combat_end(self): - return 'in_stage' - - def clear_boss(self): - grids = self.map.select(is_boss=True) - grids = grids.add(self.map.select(may_boss=True, is_enemy=True)) - logger.info('May boss: %s' % self.map.select(may_boss=True)) - logger.info('May boss and is enemy: %s' % self.map.select(may_boss=True, is_enemy=True)) - logger.info('Is boss: %s' % self.map.select(is_boss=True)) - # logger.info('Grids: %s' % grids) - if grids: - logger.hr('Clear BOSS') - grids = grids.sort(cost=True, weight=True) - logger.info('Grids: %s' % str(grids)) - self._goto(grids[0]) - raise CampaignEnd('BOSS Clear.') - - return False - - def equipment_take_off_when_finished(self): - logger.info('equipment_take_off_when_finished') - campaign_timer = Timer(2) - map_timer = Timer(1) - fleet_timer = Timer(1) - - while 1: - self.device.screenshot() - - # Enter campaign - if campaign_timer.reached() and self.appear_then_click(self.ENTRANCE): - campaign_timer.reset() - continue - - # Map preparation - if map_timer.reached() and self.appear(MAP_PREPARATION): - self.device.click(MAP_PREPARATION) - map_timer.reset() - campaign_timer.reset() - continue - - # Fleet preparation - if fleet_timer.reached() and self.appear(FLEET_PREPARATION): - self.equipment_take_off() - self.ui_back(check_button=CAMPAIGN_CHECK, appear_button=FLEET_PREPARATION) - break - - # Retire - if self.handle_retirement(): - continue - - # Emotion - pass - - return True diff --git a/module/hard/hard.py b/module/hard/hard.py index de97551ff..4bea42edc 100644 --- a/module/hard/hard.py +++ b/module/hard/hard.py @@ -1,7 +1,7 @@ import importlib from module.base.ocr import Digit -from module.campaign.campaign_hard import Campaign +from campaign.campaign_hard.campaign_hard import Campaign from module.campaign.run import CampaignRun from module.hard.assets import * from module.logger import logger From 56992b1d7fc5cb8f93680ec809a440442c1b09b6 Mon Sep 17 00:00:00 2001 From: LmeSzinc Date: Wed, 27 May 2020 02:42:25 +0800 Subject: [PATCH 3/3] Fix: dev_tools import error - Use `python -m dev_tools.button_extract` to run --- dev_tools/button_extract.py | 6 ++---- dev_tools/emulator_test.py | 5 ++++- doc/development.md | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dev_tools/button_extract.py b/dev_tools/button_extract.py index 7d2ac6244..fc9848b41 100644 --- a/dev_tools/button_extract.py +++ b/dev_tools/button_extract.py @@ -3,8 +3,6 @@ import os import numpy as np from PIL import Image -os.chdir('../') - from module.base.button import get_color from module.config.config import AzurLaneConfig from module.logger import logger @@ -179,5 +177,5 @@ class AssetExtractor: me = ModuleExtractor(name=module, config=config) me.write() - -ae = AssetExtractor(AzurLaneConfig()) +if __name__ == '__main__': + ae = AssetExtractor(AzurLaneConfig('template')) diff --git a/dev_tools/emulator_test.py b/dev_tools/emulator_test.py index 591109622..62bba5ac3 100644 --- a/dev_tools/emulator_test.py +++ b/dev_tools/emulator_test.py @@ -1,6 +1,9 @@ import time import numpy as np +import module.config.server as server + +server.server = 'cn' # Don't need to edit, it's used to avoid error. from module.config.config import AzurLaneConfig from module.device.device import Device @@ -33,5 +36,5 @@ class Config: USE_ADB_SCREENSHOT = False -az = EmulatorChecker(AzurLaneConfig().merge(Config())) +az = EmulatorChecker(AzurLaneConfig('template').merge(Config())) az.stress_test() diff --git a/doc/development.md b/doc/development.md index 9cce14dd5..86a3bc822 100644 --- a/doc/development.md +++ b/doc/development.md @@ -78,6 +78,10 @@ BATTLE_PREPARATION = Button(area=(1043, 607, 1241, 667), color=(234, 179, 97), b button_extract.py会自动提取按钮的属性, 免去了人工输入的烦恼 + ``` + python -m dev_tools.button_extract + ``` + 8. **使用按钮** 继承 module.base.base 下的 ModuleBase 类, 可以调用以下方法: