mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:07:36 +08:00
Refactor: Shop module
This commit is contained in:
parent
69682aad46
commit
60f7a64066
8
alas.py
8
alas.py
@ -24,6 +24,7 @@ from module.logger import logger, log_file
|
||||
from module.meowfficer.meowfficer import RewardMeowfficer
|
||||
from module.research.research import RewardResearch
|
||||
from module.reward.reward import Reward
|
||||
from module.shop.shop_reward import RewardShop
|
||||
from module.tactical.tactical_class import RewardTacticalClass
|
||||
|
||||
|
||||
@ -117,14 +118,17 @@ class AzurLaneAutoScript:
|
||||
def dorm(self):
|
||||
RewardDorm(config=self.config, device=self.device).run()
|
||||
|
||||
def meowfficer(self):
|
||||
RewardMeowfficer(config=self.config, device=self.device).run()
|
||||
|
||||
def guild(self):
|
||||
RewardGuild(config=self.config, device=self.device).run()
|
||||
|
||||
def reward(self):
|
||||
Reward(config=self.config, device=self.device).run()
|
||||
|
||||
def meowfficer(self):
|
||||
RewardMeowfficer(config=self.config, device=self.device).run()
|
||||
def shop(self):
|
||||
RewardShop(config=self.config, device=self.device).run()
|
||||
|
||||
def daily(self):
|
||||
Daily(config=self.config, device=self.device).run()
|
||||
|
@ -284,6 +284,46 @@ Reward:
|
||||
CollectOil: true
|
||||
CollectCoin: true
|
||||
CollectMission: true
|
||||
Shop:
|
||||
Scheduler:
|
||||
Enable: false
|
||||
NextRun: 2020-01-01 00:00:00
|
||||
Command: Shop
|
||||
SuccessInterval: 40-60
|
||||
FailureInterval: 40-60
|
||||
ServerUpdate: 00:00, 12:00, 18:00
|
||||
GeneralShop:
|
||||
UseGems: false
|
||||
Refresh: false
|
||||
Filter: |-
|
||||
BookRedT3 > BookYellowT3 > BookBlueT3 > BookRedT2
|
||||
> Cube
|
||||
> FoodT6 > FoodT5
|
||||
GuildShop:
|
||||
Refresh: true
|
||||
Filter: PlateT4 > BookT3 > PRBP > CatT3 > Chips > Retrofit > FoodT6 > FoodT5 >
|
||||
CatT2 > BoxT4
|
||||
BOX_T3: ironblood
|
||||
BOX_T4: ironblood
|
||||
BOOK_T2: red
|
||||
BOOK_T3: red
|
||||
RETROFIT_T2: cl
|
||||
RETROFIT_T3: cl
|
||||
PLATE_T2: general
|
||||
PLATE_T3: general
|
||||
PLATE_T4: gun
|
||||
PR1: neptune
|
||||
PR2: seattle
|
||||
PR3: champagne
|
||||
MedalShop:
|
||||
Filter: |-
|
||||
DR > PRY
|
||||
> BookRedT3 > BookYellowT3 > BookBlueT3 > BookRedT2 > BookYellowT2 > BookBlueT2
|
||||
> BulinT2 > RetrofitT3 > PlateGeneralT3
|
||||
> FoodT6 > FoodT5
|
||||
MeritShop:
|
||||
Refresh: false
|
||||
Filter: Cube > BulinT2
|
||||
Daily:
|
||||
Scheduler:
|
||||
Enable: false
|
||||
|
@ -396,6 +396,73 @@ Reward:
|
||||
CollectOil: true
|
||||
CollectCoin: true
|
||||
CollectMission: true
|
||||
Shop:
|
||||
_info:
|
||||
Menu: Reward
|
||||
Scheduler:
|
||||
Enable: false
|
||||
NextRun: 2020-01-01 00:00:00
|
||||
Command: Shop
|
||||
SuccessInterval: 40-60
|
||||
FailureInterval: 40-60
|
||||
ServerUpdate: 00:00, 12:00, 18:00
|
||||
GeneralShop:
|
||||
UseGems: false
|
||||
Refresh: false
|
||||
Filter: |-
|
||||
BookRedT3 > BookYellowT3 > BookBlueT3 > BookRedT2
|
||||
> Cube
|
||||
> FoodT6 > FoodT5
|
||||
GuildShop:
|
||||
Refresh: true
|
||||
Filter: |-
|
||||
PlateT4 > BookT3 > PRBP > CatT3 > Chips > BookT2 > Retrofit > FoodT6 > FoodT5 > CatT2 > BoxT4
|
||||
BOX_T3:
|
||||
value: ironblood
|
||||
option: [eagle, royal, sakura, ironblood]
|
||||
BOX_T4:
|
||||
value: ironblood
|
||||
option: [eagle, royal, sakura, ironblood]
|
||||
BOOK_T2:
|
||||
value: red
|
||||
option: [red, blue, yellow]
|
||||
BOOK_T3:
|
||||
value: red
|
||||
option: [red, blue, yellow]
|
||||
RETROFIT_T2:
|
||||
value: cl
|
||||
option: [dd, cl, bb, cv]
|
||||
RETROFIT_T3:
|
||||
value: cl
|
||||
option: [dd, cl, bb, cv]
|
||||
PLATE_T2:
|
||||
value: general
|
||||
option: [general, gun, torpedo, antiair, plane]
|
||||
PLATE_T3:
|
||||
value: general
|
||||
option: [general, gun, torpedo, antiair, plane]
|
||||
PLATE_T4:
|
||||
value: gun
|
||||
option: [general, gun, torpedo, antiair, plane]
|
||||
PR1:
|
||||
value: neptune
|
||||
option: [neptune, monarch, ibuki, izumo, roon, saintlouis]
|
||||
PR2:
|
||||
value: seattle
|
||||
option: [seattle, georgia, kitakaze, gascogne]
|
||||
PR3:
|
||||
value: champagne
|
||||
option: [champagne, anchorage, august, marcopolo]
|
||||
MedalShop:
|
||||
Filter: |-
|
||||
DR > PRY
|
||||
> BookRedT3 > BookYellowT3 > BookBlueT3 > BookRedT2 > BookYellowT2 > BookBlueT2
|
||||
> BulinT2 > RetrofitT3 > PlateGeneralT3
|
||||
> FoodT6 > FoodT5
|
||||
MeritShop:
|
||||
Refresh: false
|
||||
Filter: |-
|
||||
Cube > BulinT2
|
||||
Daily:
|
||||
_info:
|
||||
Menu: Daily
|
||||
|
@ -340,3 +340,7 @@ class AzurLaneConfig(ManualConfig, GeneratedConfig):
|
||||
@FLEET_BOSS.setter
|
||||
def FLEET_BOSS(self, value):
|
||||
self._fleet_boss = value
|
||||
|
||||
@property
|
||||
def GuildShop_PR(self):
|
||||
return [self.GuildShop_PR1, self.GuildShop_PR2, self.GuildShop_PR3]
|
||||
|
@ -138,6 +138,28 @@ class GeneratedConfig:
|
||||
Reward_CollectCoin = True
|
||||
Reward_CollectMission = True
|
||||
|
||||
# Func `Shop`
|
||||
GeneralShop_UseGems = False
|
||||
GeneralShop_Refresh = False
|
||||
GeneralShop_Filter = 'BookRedT3 > BookYellowT3 > BookBlueT3 > BookRedT2\n> Cube\n> FoodT6 > FoodT5'
|
||||
GuildShop_Refresh = True
|
||||
GuildShop_Filter = 'PlateT4 > BookT3 > PRBP > CatT3 > Chips > Retrofit > FoodT6 > FoodT5 > CatT2 > BoxT4'
|
||||
GuildShop_BOX_T3 = 'ironblood' # eagle, royal, sakura, ironblood
|
||||
GuildShop_BOX_T4 = 'ironblood' # eagle, royal, sakura, ironblood
|
||||
GuildShop_BOOK_T2 = 'red' # red, blue, yellow
|
||||
GuildShop_BOOK_T3 = 'red' # red, blue, yellow
|
||||
GuildShop_RETROFIT_T2 = 'cl' # dd, cl, bb, cv
|
||||
GuildShop_RETROFIT_T3 = 'cl' # dd, cl, bb, cv
|
||||
GuildShop_PLATE_T2 = 'general' # general, gun, torpedo, antiair, plane
|
||||
GuildShop_PLATE_T3 = 'general' # general, gun, torpedo, antiair, plane
|
||||
GuildShop_PLATE_T4 = 'gun' # general, gun, torpedo, antiair, plane
|
||||
GuildShop_PR1 = 'neptune' # neptune, monarch, ibuki, izumo, roon, saintlouis
|
||||
GuildShop_PR2 = 'seattle' # seattle, georgia, kitakaze, gascogne
|
||||
GuildShop_PR3 = 'champagne' # champagne, anchorage, august, marcopolo
|
||||
MedalShop_Filter = 'DR > PRY\n> BookRedT3 > BookYellowT3 > BookBlueT3 > BookRedT2 > BookYellowT2 > BookBlueT2\n> BulinT2 > RetrofitT3 > PlateGeneralT3\n> FoodT6 > FoodT5'
|
||||
MeritShop_Refresh = False
|
||||
MeritShop_Filter = 'Cube > BulinT2'
|
||||
|
||||
# Func `Daily`
|
||||
Daily_UseDailySkip = True
|
||||
Daily_EscortMission = 'first' # no, first, second, third
|
||||
|
@ -344,6 +344,29 @@ def get_server_next_update(daily_trigger):
|
||||
return update
|
||||
|
||||
|
||||
def get_server_last_update(daily_trigger):
|
||||
"""
|
||||
Args:
|
||||
daily_trigger (list[str], str): [ "00:00", "12:00", "18:00",]
|
||||
|
||||
Returns:
|
||||
datetime.datetime
|
||||
"""
|
||||
if isinstance(daily_trigger, str):
|
||||
daily_trigger = daily_trigger.replace(' ', '').split(',')
|
||||
d = datetime.now(timezone.utc).astimezone()
|
||||
diff = d.utcoffset() // timedelta(seconds=1) // 3600 - server_timezone()
|
||||
trigger = []
|
||||
for t in daily_trigger:
|
||||
h, m = [int(x) for x in t.split(':')]
|
||||
h = (h + diff) % 24
|
||||
past = datetime.now().replace(hour=h, minute=m, second=0, microsecond=0)
|
||||
past = past - timedelta(days=1) if past > datetime.now() else past
|
||||
trigger.append(past)
|
||||
update = sorted(trigger, reverse=True)[0]
|
||||
return update
|
||||
|
||||
|
||||
def nearest_future(future, interval=120):
|
||||
"""
|
||||
Get the neatest future time.
|
||||
|
@ -1,6 +1,4 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from module.config.utils import get_server_next_update
|
||||
from module.config.utils import get_server_last_update
|
||||
from module.exercise.assets import *
|
||||
from module.exercise.combat import ExerciseCombat
|
||||
from module.logger import logger
|
||||
@ -98,7 +96,7 @@ class Exercise(ExerciseCombat):
|
||||
int:
|
||||
"""
|
||||
record = self.config.OpponentRefresh_Record
|
||||
update = get_server_next_update('00:00') - timedelta(days=1)
|
||||
update = get_server_last_update('00:00')
|
||||
if record.date() == update.date():
|
||||
# Same Day
|
||||
return self.config.OpponentRefresh_Count
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user