1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-24 21:49:03 +08:00

Refactor: Shop module

This commit is contained in:
LmeSzinc
2021-09-23 22:04:03 +08:00
parent 69682aad46
commit 60f7a64066
12 changed files with 212 additions and 17 deletions

View File

@@ -2,10 +2,10 @@ from module.base.button import ButtonGrid
from module.base.decorator import cached_property
from module.combat.assets import GET_ITEMS_1, GET_SHIP
from module.logger import logger
from module.reward.tactical_class import Book
from module.shop.assets import *
from module.shop.base_globals import *
from module.statistics.item import ItemGrid
from module.tactical.tactical_class import Book
from module.ui.assets import BACK_ARROW
from module.ui.ui import UI
@@ -218,6 +218,7 @@ class ShopBase(UI):
Returns:
int:
"""
logger.hr(f'{shop_type} shop buy', level=2)
count = 0
for _ in range(12):
item = self.shop_get_item_to_buy(shop_type, selection)

View File

@@ -45,7 +45,7 @@ class GeneralShop(ShopBase):
return False
return True
if self.config.ENABLE_SHOP_GENERAL_GEMS:
if self.config.GeneralShop_UseGems:
if item.cost == 'Gems':
if item.price > self._shop_gems:
return False

View File

@@ -172,13 +172,13 @@ class GuildShop(ShopBase):
additional = '' if item.additional is None else f'_{item.additional}'
try:
limit = globals()[f'SELECT_{category.upper()}_LIMIT']
choice = getattr(self.config, f'SHOP_GUILD_{category.upper()}{additional.upper()}')
choice = getattr(self.config, f'GuildShop_{category.upper()}{additional.upper()}')
except KeyError:
logger.warning(f'shop_buy_select_execute --> Missing SELECT_{category.upper()}_LIMIT')
self.device.click(SHOP_CLICK_SAFE_AREA) # Close secondary prompt
return False
except AttributeError:
logger.warning(f'shop_buy_select_execute --> Missing Config SHOP_GUILD_{category.upper()}')
logger.warning(f'shop_buy_select_execute --> Missing Config GuildShop_{category.upper()}{additional.upper()}')
self.device.click(SHOP_CLICK_SAFE_AREA) # Close secondary prompt
return False

View File

@@ -28,9 +28,9 @@ class RewardShop(GachaUI, ShopUI, GeneralShop, GuildShop, MedalShop, MeritShop):
bool: If worth visiting, empty selection means should not visit
"""
try:
selection = getattr(self.config, f'SHOP_{shop_type.upper()}_SELECTION')
selection = getattr(self.config, f'{shop_type.capitalize()}Shop_Filter')
except AttributeError:
logger.warning(f'_shop_visit --> Missing Config SHOP_{shop_type.upper()}_SELECTION')
logger.warning(f'_shop_visit --> Missing Config {shop_type.capitalize()}Shop_Filter')
return False
if not selection.strip():
@@ -75,8 +75,8 @@ class RewardShop(GachaUI, ShopUI, GeneralShop, GuildShop, MedalShop, MeritShop):
Common helper func for general, guild, and merit shops
"""
try:
selection = getattr(self.config, f'SHOP_{shop_type.upper()}_SELECTION')
refresh = getattr(self.config, f'ENABLE_SHOP_{shop_type.upper()}_REFRESH')
selection = getattr(self.config, f'{shop_type.capitalize()}Shop_Filter')
refresh = getattr(self.config, f'{shop_type.capitalize()}Shop_Refresh')
except AttributeError:
logger.warning(f'_shop_repeat --> Missing necessary Configs')
return
@@ -134,7 +134,7 @@ class RewardShop(GachaUI, ShopUI, GeneralShop, GuildShop, MedalShop, MeritShop):
for _ in range(1, 3):
if self.gacha_bottom_navbar_ensure(left=_, is_build=False):
self.shop_buy(shop_type='medal',
selection=self.config.SHOP_MEDAL_SELECTION)
selection=self.config.MedalShop_Filter)
else:
logger.warning('Failed to arrive at expected '
'build interface for medal exchanges, '
@@ -156,3 +156,39 @@ class RewardShop(GachaUI, ShopUI, GeneralShop, GuildShop, MedalShop, MeritShop):
self.ui_goto_main()
return True
def run(self):
self.ui_goto_shop()
if self._shop_visit('general'):
logger.hr('General shop', level=1)
if self.shop_bottom_navbar_ensure(left=5):
self._shop_repeat(shop_type='general')
if self.config.Scheduler_NextRun.hour == 0:
if self._shop_visit('merit'):
logger.hr('Merit shop', level=1)
if self.shop_bottom_navbar_ensure(left=4):
self._shop_repeat(shop_type='merit')
if self._shop_visit('guild'):
logger.hr('Guild shop', level=1)
if self.shop_bottom_navbar_ensure(left=1):
self._shop_repeat(shop_type='guild')
if self._shop_visit('medal'):
logger.hr('Medal shop', level=1)
self.ui_goto_gacha()
if self.gacha_side_navbar_ensure(bottom=2):
for _ in [1, 2]:
if self.gacha_bottom_navbar_ensure(left=_, is_build=False):
self.shop_buy(shop_type='medal',
selection=self.config.MedalShop_Filter)
else:
logger.warning('Failed to arrive at expected '
'build interface for medal exchanges, '
f'left={_}, try again next time')
else:
logger.info(f'Next run {self.config.Scheduler_NextRun} is not at 00:00, skip merit, guild and medal shops')
self.config.task_delay(server_update=True)

View File

@@ -152,11 +152,11 @@ class ShopUI(UI):
self.appear(SHOP_GENERAL_SWIPE_END, offset=(15, 5)):
return True
backup = self.config.cover(DEVICE_CONTROL_METHOD='minitouch')
# backup = self.config.cover(DEVICE_CONTROL_METHOD='minitouch')
p1, p2 = random_rectangle_vector(
(480, 0), box=detection_area, random_range=(-50, -50, 50, 50), padding=20)
self.device.drag(p1, p2, segments=2, shake=(0, 25), point_random=(0, 0, 0, 0), shake_random=(0, -5, 0, 5))
backup.recover()
# backup.recover()
self.device.sleep(0.3)
return False