From b554a3935147a65b2b1f64c6419b57d8b5109462 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sat, 6 Nov 2021 20:30:36 +0800 Subject: [PATCH] Refactor: Fleet switching and fleet reverse - Revert swipe limit of ensure_edge_insight --- assets/cn/map/FLEET_NUM.png | Bin 3563 -> 0 bytes assets/en/map/FLEET_NUM.png | Bin 3385 -> 0 bytes assets/jp/map/FLEET_NUM.png | Bin 3563 -> 0 bytes assets/tw/map/FLEET_NUM.png | Bin 3563 -> 0 bytes module/campaign/campaign_base.py | 2 +- module/combat/auto_search_combat.py | 86 +++++++++++++----------- module/combat/combat.py | 9 ++- module/combat/emotion.py | 29 ++++---- module/combat/hp_balancer.py | 1 + module/handler/ambush.py | 6 +- module/map/assets.py | 1 - module/map/camera.py | 2 +- module/map/fleet.py | 20 +++--- module/map/map_operation.py | 98 ++++++++++++++++++++++------ 14 files changed, 159 insertions(+), 95 deletions(-) delete mode 100644 assets/cn/map/FLEET_NUM.png delete mode 100644 assets/en/map/FLEET_NUM.png delete mode 100644 assets/jp/map/FLEET_NUM.png delete mode 100644 assets/tw/map/FLEET_NUM.png diff --git a/assets/cn/map/FLEET_NUM.png b/assets/cn/map/FLEET_NUM.png deleted file mode 100644 index 42eb0f99c8b798b6b0ba2a73756f743fe0dd6c3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3563 zcmeAS@N?(olHy`uVBq!ia0y~yU({G1vII_)5S5QBJSPu1@mOaoWH!NzcqtrzuA8h*HPVMzJO_M%|W}olBQ4eY!1rmgM)n zbLI0Me6W~t^nCmBSu<;Y>0AGP#{;x=6hK4ZkNl+jhwA6--~jS(tqI($KLgGzv{HP2!RJ{UfoX>hJFbzf=nlN)|@{e);~b z!Jo?5nE9shGVMc1&geaBee$++CpqKpT9z zZ)~h&(9bu~E`Psfhv>9J(_cT+WdtUp10|iZ)?5#|+l$VX9#fEu^gGuXfzEOSJ)*C1$8S?wf0{Sf1^FY5eN@w~xR1qPPC( z$7D#r-rSL_e&+Mz^`A8F)!VJI6B7q&aF`t$yv=Oxgf(Bf0DqGioyY7DfSMTQa$Alr)nPzRX_?`8BP1ydQF}#<~-hDRtzYin|!dBnxOpm|I z^I663ncAK|HnX5k@Bs;n>f7H}%~#uxEDVZti-&Jk@7-LoG<D%-Fo;oN*4u<9 z9o_ouX86x1wl!7aeZRL_?pXIv8XDPQY#+SVNABN0tGoSG=LJZZ&ICF9L8t&II`?p; zGMq2J{Pu6XX}-N`u{VRZa(GVC7fzc2c4S~@R i7!8489|G&oojKzl<$u~dq$B(<$hV%ZelF{r5}E*kYQ&%b diff --git a/assets/en/map/FLEET_NUM.png b/assets/en/map/FLEET_NUM.png deleted file mode 100644 index 3eb4d2aa57d1d1a937308b4c7b37aae4ad1aad09..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3385 zcmeAS@N?(olHy`uVBq!ia0y~yU({G#lXOG&eO#)q$2L^-Hlly(G15Q?&(UH$k=T= zL5VptW<$ZjLyacfVF#UpJU0kf3vzR6<`rsh{46G(xAJaS)4s-~>mMk;ICt*k9NYA( z-Y!q>?7V+`KgaBum;c{5nZggWaTEYU;79B%>F)QsIoICgZ~MFY;pCc+7C_Mz!C~8e z{xwiNq_n5&+n>Zk2QXMjC+%i*a4uv z5Ixr1eTog&FG|0&<@Ued@_hDP`}}K?duo?5urV+^uvaX7b7RZwuV1To#E9qrzP|k1 z;pvGFldj6>J~nm!l~=c;tX8fcXnuoLs;PC_haADY`EBm&Z|@KO%f~2ljKMCVKQwpqhcENLT|IvHi|jO8CfnV29QRkq01djL$^GE>^ZVZS6C)Y=Z{LxIIHLFK z?t7w46|dJRHa{)|stQYX_ZpPTQks~5f2{P~gSh1ad(tDkK+owqXv;_@lBXZCC@c)g`wute~H_-lqZ zv2ea_h)cWrWUt%5s@W)X0BEO=%f*eEOcKB_(bTju^96;zfvW5AWt<5>$z@Ak+%RF} zVPH5gMMQSCS_3euW=vX?e3``nC>b17l5^`SQw20c-!6Icbe+I~Vvur&w`E!1iXf&+ za+}@nXWp@6M?Az~TfVyH*+I;la#z}1`~c7>pHqIn_=LeMZ|u%FyQ|=jicQVTw?90M zZ`&yB-3$rVl`n40kAs+d Z_u4#-kAwqET7yA8_H^}gS?83{1OOB2R)_!q diff --git a/assets/jp/map/FLEET_NUM.png b/assets/jp/map/FLEET_NUM.png deleted file mode 100644 index 42eb0f99c8b798b6b0ba2a73756f743fe0dd6c3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3563 zcmeAS@N?(olHy`uVBq!ia0y~yU({G1vII_)5S5QBJSPu1@mOaoWH!NzcqtrzuA8h*HPVMzJO_M%|W}olBQ4eY!1rmgM)n zbLI0Me6W~t^nCmBSu<;Y>0AGP#{;x=6hK4ZkNl+jhwA6--~jS(tqI($KLgGzv{HP2!RJ{UfoX>hJFbzf=nlN)|@{e);~b z!Jo?5nE9shGVMc1&geaBee$++CpqKpT9z zZ)~h&(9bu~E`Psfhv>9J(_cT+WdtUp10|iZ)?5#|+l$VX9#fEu^gGuXfzEOSJ)*C1$8S?wf0{Sf1^FY5eN@w~xR1qPPC( z$7D#r-rSL_e&+Mz^`A8F)!VJI6B7q&aF`t$yv=Oxgf(Bf0DqGioyY7DfSMTQa$Alr)nPzRX_?`8BP1ydQF}#<~-hDRtzYin|!dBnxOpm|I z^I663ncAK|HnX5k@Bs;n>f7H}%~#uxEDVZti-&Jk@7-LoG<D%-Fo;oN*4u<9 z9o_ouX86x1wl!7aeZRL_?pXIv8XDPQY#+SVNABN0tGoSG=LJZZ&ICF9L8t&II`?p; zGMq2J{Pu6XX}-N`u{VRZa(GVC7fzc2c4S~@R i7!8489|G&oojKzl<$u~dq$B(<$hV%ZelF{r5}E*kYQ&%b diff --git a/assets/tw/map/FLEET_NUM.png b/assets/tw/map/FLEET_NUM.png deleted file mode 100644 index 42eb0f99c8b798b6b0ba2a73756f743fe0dd6c3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3563 zcmeAS@N?(olHy`uVBq!ia0y~yU({G1vII_)5S5QBJSPu1@mOaoWH!NzcqtrzuA8h*HPVMzJO_M%|W}olBQ4eY!1rmgM)n zbLI0Me6W~t^nCmBSu<;Y>0AGP#{;x=6hK4ZkNl+jhwA6--~jS(tqI($KLgGzv{HP2!RJ{UfoX>hJFbzf=nlN)|@{e);~b z!Jo?5nE9shGVMc1&geaBee$++CpqKpT9z zZ)~h&(9bu~E`Psfhv>9J(_cT+WdtUp10|iZ)?5#|+l$VX9#fEu^gGuXfzEOSJ)*C1$8S?wf0{Sf1^FY5eN@w~xR1qPPC( z$7D#r-rSL_e&+Mz^`A8F)!VJI6B7q&aF`t$yv=Oxgf(Bf0DqGioyY7DfSMTQa$Alr)nPzRX_?`8BP1ydQF}#<~-hDRtzYin|!dBnxOpm|I z^I663ncAK|HnX5k@Bs;n>f7H}%~#uxEDVZti-&Jk@7-LoG<D%-Fo;oN*4u<9 z9o_ouX86x1wl!7aeZRL_?pXIv8XDPQY#+SVNABN0tGoSG=LJZZ&ICF9L8t&II`?p; zGMq2J{Pu6XX}-N`u{VRZa(GVC7fzc2c4S~@R i7!8489|G&oojKzl<$u~dq$B(<$hV%ZelF{r5}E*kYQ&%b diff --git a/module/campaign/campaign_base.py b/module/campaign/campaign_base.py index 60c7d1331..f9dd30b7b 100644 --- a/module/campaign/campaign_base.py +++ b/module/campaign/campaign_base.py @@ -172,5 +172,5 @@ class CampaignBase(CampaignUI, Map, AutoSearchCombat): def auto_search_execute_a_battle(self): logger.hr(f'{self.FUNCTION_NAME_BASE}{self.battle_count}', level=2) self.auto_search_moving() - self.auto_search_combat(fleet_index=self.fleet_current_index) + self.auto_search_combat(fleet_index=self.fleet_show_index) self.battle_count += 1 diff --git a/module/combat/auto_search_combat.py b/module/combat/auto_search_combat.py index af452f569..1ab8ef886 100644 --- a/module/combat/auto_search_combat.py +++ b/module/combat/auto_search_combat.py @@ -4,7 +4,6 @@ from module.combat.assets import * from module.combat.combat import Combat from module.exception import CampaignEnd from module.logger import logger -from module.map.assets import * from module.map.map_operation import MapOperation from module.ocr.ocr import Digit @@ -16,22 +15,6 @@ class AutoSearchCombat(MapOperation, Combat): _auto_search_confirm_low_emotion = False auto_search_oil_limit_triggered = False - def get_fleet_current_index(self): - """ - Returns: - int: 1 or 2 - - Pages: - in: map - """ - if self.appear(FLEET_NUM_1, offset=(20, 20)): - return 1 - elif self.appear(FLEET_NUM_2, offset=(20, 20)): - return 2 - else: - logger.warning('Unknown fleet current index, use 1 by default') - return 1 - def _handle_auto_search_menu_missing(self): """ Sometimes game is bugged, auto search menu is not shown. @@ -50,6 +33,51 @@ class AutoSearchCombat(MapOperation, Combat): return False + def auto_search_watch_fleet(self, checked=False): + """ + Watch fleet index and ship level. + + Args: + checked (bool): Watchers are only executed or logged once during fleet moving. + Set True to skip executing again. + + Returns: + bool: If executed. + """ + prev = self.fleet_current_index + self.get_fleet_show_index() + self.get_fleet_current_index() + if self.fleet_current_index == prev: + # Same as current, only print once + if not checked: + logger.info(f'Fleet: {self.fleet_show_index}, fleet_current_index: {self.fleet_current_index}') + checked = True + self.lv_get(after_battle=True) + else: + # Fleet changed + logger.info(f'Fleet: {self.fleet_show_index}, fleet_current_index: {self.fleet_current_index}') + checked = True + self.lv_get(after_battle=False) + + return checked + + def auto_search_watch_oil(self, checked=False): + """ + Watch oil. + This will set auto_search_oil_limit_triggered. + """ + if not checked: + oil = OCR_OIL.ocr(self.device.image) + if oil == 0: + logger.warning('Oil not found') + else: + if oil < self.config.StopCondition_OilLimit: + logger.info('Reach oil limit') + self.auto_search_oil_limit_triggered = True + checked = True + + return checked + def auto_search_moving(self, skip_first_screenshot=True): """ Pages: @@ -58,8 +86,8 @@ class AutoSearchCombat(MapOperation, Combat): """ logger.info('Auto search moving') self.device.stuck_record_clear() - fleet_log = False - check_oil = False + checked_fleet = False + checked_oil = False while 1: if skip_first_screenshot: skip_first_screenshot = False @@ -67,24 +95,8 @@ class AutoSearchCombat(MapOperation, Combat): self.device.screenshot() if self.is_auto_search_running(): - index = self.get_fleet_current_index() - fleet_current_index = 3 - index if self.fleets_reversed else index - if not fleet_log: - logger.info(f'Fleet: {index}, fleet_current_index: {fleet_current_index}') - fleet_log = True - self.lv_get(True) - elif fleet_current_index != self.fleet_current_index: - logger.info(f'Fleet: {index}, fleet_current_index: {fleet_current_index}') - self.fleet_current_index = fleet_current_index - if not check_oil: - oil = OCR_OIL.ocr(self.device.image) - if oil == 0: - logger.warning('Oil not found') - else: - if oil < self.config.StopCondition_OilLimit: - logger.info('Reach oil limit') - self.auto_search_oil_limit_triggered = True - check_oil = True + checked_fleet = self.auto_search_watch_fleet(checked_fleet) + checked_oil = self.auto_search_watch_oil(checked_oil) if self.handle_retirement(): continue if self.handle_auto_search_map_option(): diff --git a/module/combat/combat.py b/module/combat/combat.py index ffd734348..94627c370 100644 --- a/module/combat/combat.py +++ b/module/combat/combat.py @@ -1,5 +1,6 @@ import numpy as np +from module.base.decorator import cached_property from module.base.timer import Timer from module.combat.assets import * from module.combat.combat_auto import CombatAuto @@ -19,14 +20,12 @@ from module.ui.assets import BACK_ARROW class Combat(Level, HPBalancer, Retirement, SubmarineCall, CombatAuto, CombatManual, AutoSearchHandler): _automation_set_timer = Timer(1) - _emotion: Emotion battle_status_click_interval = 0 + emotion: Emotion - @property + @cached_property def emotion(self): - if not hasattr(self, '_emotion'): - self._emotion = Emotion(config=self.config) - return self._emotion + return Emotion(config=self.config) def combat_appear(self): """ diff --git a/module/combat/emotion.py b/module/combat/emotion.py index 2c6ea703c..482027eb2 100644 --- a/module/combat/emotion.py +++ b/module/combat/emotion.py @@ -187,24 +187,19 @@ class Emotion: """ if self.config.Campaign_UseAutoSearch: method = self.config.Fleet_AutoSearchFleetOrder - if method == 'fleet1_mob_fleet2_boss': - battle = (battle - 1, 1) - elif method == 'fleet1_boss_fleet2_mob': - battle = (1, battle - 1) - elif method == 'fleet1_all_fleet2_standby': - battle = (battle, 0) - elif method == 'fleet1_standby_fleet2_all': - battle = (0, battle) - else: - raise ScriptError(f'Unknown AutoSearchFleetOrder: {method}') else: - boss = self.config.FLEET_BOSS - if boss == 1: - battle = (battle, 0) - elif boss == 2: - battle = (battle - 1, 1) - else: - raise ScriptError(f'Unknown FLEET_BOSS: {boss}') + method = self.config.Fleet_FleetOrder + + if method == 'fleet1_mob_fleet2_boss': + battle = (battle - 1, 1) + elif method == 'fleet1_boss_fleet2_mob': + battle = (1, battle - 1) + elif method == 'fleet1_all_fleet2_standby': + battle = (battle, 0) + elif method == 'fleet1_standby_fleet2_all': + battle = (0, battle) + else: + raise ScriptError(f'Unknown fleet order: {method}') battle = tuple(np.array(battle) * self.reduce_per_battle) logger.info(f'Expect emotion reduce: {battle}') diff --git a/module/combat/hp_balancer.py b/module/combat/hp_balancer.py index 71789e6df..711266f2f 100644 --- a/module/combat/hp_balancer.py +++ b/module/combat/hp_balancer.py @@ -16,6 +16,7 @@ SCOUT_POSITION = [ class HPBalancer(ModuleBase): fleet_current_index = 1 + fleet_show_index = 1 _hp = {} _hp_has_ship = {} diff --git a/module/handler/ambush.py b/module/handler/ambush.py index 994f222df..0bddc613b 100644 --- a/module/handler/ambush.py +++ b/module/handler/ambush.py @@ -62,12 +62,12 @@ class AmbushHandler(Combat): logger.attr('Ambush_evade', 'success') elif TEMPLATE_AMBUSH_EVADE_FAILED.match(image): logger.attr('Ambush_evade', 'failed') - self.combat(expected_end='no_searching') + self.combat(expected_end='no_searching', fleet_index=self.fleet_show_index) else: logger.warning('Unrecognised info when ambush evade.') self.ensure_no_info_bar() if self.combat_appear(): - self.combat() + self.combat(fleet_index=self.fleet_show_index) def _handle_ambush_attack(self): logger.info('Map ambushed') @@ -88,7 +88,7 @@ class AmbushHandler(Combat): self.device.screenshot() logger.attr('Ambush_evade', 'attack') - self.combat(expected_end='no_searching') + self.combat(expected_end='no_searching', fleet_index=self.fleet_show_index) def _handle_ambush(self): if self.config.Campaign_AmbushEvade: diff --git a/module/map/assets.py b/module/map/assets.py index bed5de861..92f826dfb 100644 --- a/module/map/assets.py +++ b/module/map/assets.py @@ -12,7 +12,6 @@ FLEET_2_BAR = Button(area={'cn': (1015, 377, 1186, 622), 'en': (998, 380, 1169, FLEET_2_CHOOSE = Button(area={'cn': (1026, 300, 1088, 357), 'en': (1008, 303, 1071, 360), 'jp': (1024, 298, 1090, 359), 'tw': (1009, 303, 1071, 360)}, color={'cn': (208, 164, 103), 'en': (197, 148, 83), 'jp': (198, 158, 103), 'tw': (210, 167, 106)}, button={'cn': (1026, 300, 1088, 357), 'en': (1008, 303, 1071, 360), 'jp': (1024, 298, 1090, 359), 'tw': (1009, 303, 1071, 360)}, file={'cn': './assets/cn/map/FLEET_2_CHOOSE.png', 'en': './assets/en/map/FLEET_2_CHOOSE.png', 'jp': './assets/jp/map/FLEET_2_CHOOSE.png', 'tw': './assets/tw/map/FLEET_2_CHOOSE.png'}) FLEET_2_CLEAR = Button(area={'cn': (1108, 300, 1170, 357), 'en': (1090, 303, 1153, 360), 'jp': (1108, 298, 1169, 359), 'tw': (1091, 303, 1153, 360)}, color={'cn': (153, 153, 154), 'en': (138, 139, 142), 'jp': (150, 151, 153), 'tw': (155, 155, 157)}, button={'cn': (1108, 300, 1170, 357), 'en': (1090, 303, 1153, 360), 'jp': (1108, 298, 1169, 359), 'tw': (1091, 303, 1153, 360)}, file={'cn': './assets/cn/map/FLEET_2_CLEAR.png', 'en': './assets/en/map/FLEET_2_CLEAR.png', 'jp': './assets/jp/map/FLEET_2_CLEAR.png', 'tw': './assets/tw/map/FLEET_2_CLEAR.png'}) FLEET_2_IN_USE = Button(area={'cn': (389, 351, 472, 385), 'en': (389, 351, 472, 385), 'jp': (389, 351, 472, 385), 'tw': (389, 351, 472, 385)}, color={'cn': (125, 130, 124), 'en': (125, 130, 124), 'jp': (125, 130, 124), 'tw': (125, 130, 124)}, button={'cn': (389, 351, 472, 385), 'en': (389, 351, 472, 385), 'jp': (389, 351, 472, 385), 'tw': (389, 351, 472, 385)}, file={'cn': './assets/cn/map/FLEET_2_IN_USE.png', 'en': './assets/en/map/FLEET_2_IN_USE.png', 'jp': './assets/jp/map/FLEET_2_IN_USE.png', 'tw': './assets/tw/map/FLEET_2_IN_USE.png'}) -FLEET_NUM = Button(area={'cn': (208, 72, 230, 104), 'en': (205, 71, 229, 104), 'jp': (208, 72, 230, 104), 'tw': (208, 72, 230, 104)}, color={'cn': (42, 93, 125), 'en': (45, 78, 115), 'jp': (42, 93, 125), 'tw': (42, 93, 125)}, button={'cn': (208, 72, 230, 104), 'en': (205, 71, 229, 104), 'jp': (208, 72, 230, 104), 'tw': (208, 72, 230, 104)}, file={'cn': './assets/cn/map/FLEET_NUM.png', 'en': './assets/en/map/FLEET_NUM.png', 'jp': './assets/jp/map/FLEET_NUM.png', 'tw': './assets/tw/map/FLEET_NUM.png'}) FLEET_NUM_1 = Button(area={'cn': (213, 76, 224, 101), 'en': (213, 76, 224, 101), 'jp': (213, 76, 224, 101), 'tw': (213, 76, 224, 101)}, color={'cn': (51, 143, 186), 'en': (51, 143, 186), 'jp': (51, 143, 186), 'tw': (51, 143, 186)}, button={'cn': (213, 76, 224, 101), 'en': (213, 76, 224, 101), 'jp': (213, 76, 224, 101), 'tw': (213, 76, 224, 101)}, file={'cn': './assets/cn/map/FLEET_NUM_1.png', 'en': './assets/en/map/FLEET_NUM_1.png', 'jp': './assets/jp/map/FLEET_NUM_1.png', 'tw': './assets/tw/map/FLEET_NUM_1.png'}) FLEET_NUM_2 = Button(area={'cn': (212, 75, 226, 101), 'en': (212, 75, 226, 101), 'jp': (212, 75, 226, 101), 'tw': (212, 75, 226, 101)}, color={'cn': (52, 150, 194), 'en': (52, 150, 194), 'jp': (52, 150, 194), 'tw': (52, 150, 194)}, button={'cn': (212, 75, 226, 101), 'en': (212, 75, 226, 101), 'jp': (212, 75, 226, 101), 'tw': (212, 75, 226, 101)}, file={'cn': './assets/cn/map/FLEET_NUM_2.png', 'en': './assets/en/map/FLEET_NUM_2.png', 'jp': './assets/jp/map/FLEET_NUM_2.png', 'tw': './assets/tw/map/FLEET_NUM_2.png'}) FLEET_PREPARATION = Button(area={'cn': (965, 578, 1162, 637), 'en': (969, 576, 1160, 637), 'jp': (983, 583, 1140, 632), 'tw': (964, 577, 1163, 638)}, color={'cn': (236, 186, 116), 'en': (233, 175, 90), 'jp': (232, 181, 102), 'tw': (235, 186, 114)}, button={'cn': (965, 578, 1162, 637), 'en': (969, 576, 1160, 637), 'jp': (983, 583, 1140, 632), 'tw': (964, 577, 1163, 638)}, file={'cn': './assets/cn/map/FLEET_PREPARATION.png', 'en': './assets/en/map/FLEET_PREPARATION.png', 'jp': './assets/jp/map/FLEET_PREPARATION.png', 'tw': './assets/tw/map/FLEET_PREPARATION.png'}) diff --git a/module/map/camera.py b/module/map/camera.py index cf27d9da5..537dce896 100644 --- a/module/map/camera.py +++ b/module/map/camera.py @@ -172,7 +172,7 @@ class Camera(MapOperation): def show_camera(self): logger.attr_align('Camera', location2node(self.camera)) - def ensure_edge_insight(self, reverse=False, preset=None, swipe_limit=(4, 3)): + def ensure_edge_insight(self, reverse=False, preset=None, swipe_limit=(3, 2)): """ Swipe to bottom left until two edges insight. Edges are used to locate camera. diff --git a/module/map/fleet.py b/module/map/fleet.py index c98933ebe..5f9557e04 100644 --- a/module/map/fleet.py +++ b/module/map/fleet.py @@ -13,7 +13,6 @@ from module.map.utils import match_movable class Fleet(Camera, AmbushHandler): fleet_1_location = () fleet_2_location = () - fleet_current_index = 1 battle_count = 0 mystery_count = 0 siren_count = 0 @@ -23,7 +22,7 @@ class Fleet(Camera, AmbushHandler): @property def fleet_1(self): if self.fleet_current_index != 1: - self.fleet_switch() + self.fleet_switch_to(index=1) return self @fleet_1.setter @@ -34,7 +33,7 @@ class Fleet(Camera, AmbushHandler): def fleet_2(self): if self.config.FLEET_2 and self.config.FLEET_BOSS == 2: if self.fleet_current_index != 2: - self.fleet_switch() + self.fleet_switch_to(index=2) return self @fleet_2.setter @@ -78,9 +77,8 @@ class Fleet(Camera, AmbushHandler): else: return self.config.Fleet_Fleet1Step - def fleet_switch(self): - self.fleet_switch_click() - self.fleet_current_index = 1 if self.fleet_current_index == 2 else 2 + def fleet_switch_to(self, index): + self.fleet_set(index=index) self.camera = self.fleet_current self.update() self.find_path_initial() @@ -288,7 +286,7 @@ class Fleet(Camera, AmbushHandler): if self.handle_combat_low_emotion(): walk_timeout.reset() if self.combat_appear(): - self.combat(expected_end=self._expected_combat_end(expected), fleet_index=self.fleet_current_index) + self.combat(expected_end=self._expected_combat_end(expected), fleet_index=self.fleet_show_index) self.hp_get() self.lv_get(after_battle=True) arrived = True if not self.config.MAP_HAS_MOVABLE_ENEMY else False @@ -668,7 +666,6 @@ class Fleet(Camera, AmbushHandler): logger.warning('Too many fleets: %s.' % str(fleets)) self.find_all_fleets() - self.fleet_current_index = 1 self.show_fleet() return self.fleet_current @@ -720,15 +717,16 @@ class Fleet(Camera, AmbushHandler): Preparation before operations. Such as select strategy, calculate hp and level, init camera position, do first map scan. """ - self.handle_strategy(index=1 if not self.fleets_reversed else 2) self.update() - if self.handle_fleet_reverse(): - self.handle_strategy(index=1) + if not self.handle_fleet_reverse(): + self.fleet_set(index=1) + self.handle_strategy(index=self.fleet_show_index) self.hp_reset() self.hp_get() self.lv_reset() self.lv_get() self.ensure_edge_insight(preset=self.map.in_map_swipe_preset_data) + self.handle_info_bar() # The info_bar which shows "Changed to fleet 2", will block the ammo icon self.full_scan(must_scan=self.map.camera_data_spawn_point) self.find_current_fleet() self.find_path_initial() diff --git a/module/map/map_operation.py b/module/map/map_operation.py index bbd008413..39400ecf4 100644 --- a/module/map/map_operation.py +++ b/module/map/map_operation.py @@ -16,24 +16,77 @@ class MapOperation(MysteryHandler, FleetPreparation, Retirement, FastForwardHand map_cat_attack_timer = Timer(2) map_clear_percentage_prev = -1 map_clear_percentage_timer = Timer(0.3, count=1) - _emotion_expected_reduce: tuple - def fleet_switch_click(self): - """ - Switch fleet. - """ - logger.info('Switch over') - self.wait_until_appear(SWITCH_OVER, skip_first_screenshot=True) + # Fleet that shows on screen. + fleet_show_index = 1 + # Note that this is different from get_fleet_current_index() + # In fleet_current_index, 1 means mob fleet, 2 means boss fleet. + fleet_current_index = 1 - FLEET_NUM.load_color(self.device.image) - FLEET_NUM._match_init = True + def get_fleet_show_index(self): + """ + Get the fleet that shows on screen. + + Returns: + int: 1 or 2 + + Pages: + in: in_map + """ + if self.appear(FLEET_NUM_1, offset=(20, 20)): + self.fleet_show_index = 1 + return 1 + elif self.appear(FLEET_NUM_2, offset=(20, 20)): + self.fleet_show_index = 2 + return 2 + else: + logger.warning('Unknown fleet current index, use 1 by default') + self.fleet_show_index = 1 + return 1 + + def get_fleet_current_index(self): + """ + Returns: + int: 1 or 2 + """ + if self.fleets_reversed: + self.fleet_current_index = 3 - self.fleet_show_index + return self.fleet_current_index + else: + self.fleet_current_index = self.fleet_show_index + return self.fleet_current_index + + def fleet_set(self, index=None, skip_first_screenshot=True): + """ + Args: + index (int): Target fleet_current_index + skip_first_screenshot (bool): + + Returns: + bool: If switched. + """ + logger.info(f'Fleet set to {index}') + count = 0 while 1: - self.device.click(SWITCH_OVER) - self.device.sleep((1, 1.5)) - self.device.screenshot() - if not FLEET_NUM.match(self.device.image, offset=(0, 0), threshold=0.9): + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + self.get_fleet_show_index() + self.get_fleet_current_index() + logger.info(f'Fleet: {self.fleet_show_index}, fleet_current_index: {self.fleet_current_index}') + if self.fleet_current_index == index: break - logger.warning('Fleet switch failed. Retrying.') + elif self.appear_then_click(SWITCH_OVER): + count += 1 + self.device.sleep((1, 1.5)) + continue + else: + logger.warning('SWITCH_OVER not found') + continue + + return count > 0 def enter_map(self, button, mode='normal', skip_first_screenshot=True): """Enter a campaign. @@ -226,12 +279,14 @@ class MapOperation(MysteryHandler, FleetPreparation, Retirement, FastForwardHand @property def fleets_reversed(self): + if not self.config.FLEET_2: + return False + if self.map_is_auto_search: return self.config.Fleet_AutoSearchFleetOrder in ['fleet1_boss_fleet2_mob', 'fleet1_standby_fleet2_all'] else: # return (self.config.FLEET_2 != 0) and (self.config.FLEET_2 < self.config.FLEET_1) - return self.map_is_hard_mode \ - and self.config.Fleet_FleetOrder in ['fleet1_boss_fleet2_mob', 'fleet1_standby_fleet2_all'] + return self.config.Fleet_FleetOrder in ['fleet1_boss_fleet2_mob', 'fleet1_standby_fleet2_all'] def handle_fleet_reverse(self): """ @@ -243,9 +298,14 @@ class MapOperation(MysteryHandler, FleetPreparation, Retirement, FastForwardHand Returns: bool: Fleet changed """ + if not self.map_is_hard_mode \ + and self.config.Fleet_FleetOrder in ['fleet1_boss_fleet2_mob', 'fleet1_standby_fleet2_all']: + logger.warning(f"You shouldn't use a reversed fleet order ({self.config.Fleet_FleetOrder}) in normal mode.") + logger.warning('Please reverse your Fleet 1 and Fleet 2, ' + 'use "fleet1_mob_fleet2_boss" or "fleet1_all_fleet2_standby"') + # raise RequestHumanTakeover + if not self.fleets_reversed: return False - self.fleet_switch_click() - self.ensure_no_info_bar() # The info_bar which shows "Changed to fleet 2", will block the ammo icon - return True + return self.fleet_set(index=2)