mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:27:33 +08:00
Add: Coalition task
This commit is contained in:
parent
7147fd1646
commit
7ecf3ac502
4
alas.py
4
alas.py
@ -357,6 +357,10 @@ class AzurLaneAutoScript:
|
||||
from module.raid.run import RaidRun
|
||||
RaidRun(config=self.config, device=self.device).run()
|
||||
|
||||
def coalition(self):
|
||||
from module.coalition.coalition import Coalition
|
||||
Coalition(config=self.config, device=self.device).run()
|
||||
|
||||
def c72_mystery_farming(self):
|
||||
from module.campaign.run import CampaignRun
|
||||
CampaignRun(config=self.config, device=self.device).run(
|
||||
|
BIN
assets/cn/coalition/FROSTFALL_OCR_PT.png
Normal file
BIN
assets/cn/coalition/FROSTFALL_OCR_PT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
assets/en/coalition/FROSTFALL_OCR_PT.png
Normal file
BIN
assets/en/coalition/FROSTFALL_OCR_PT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
assets/jp/coalition/FROSTFALL_OCR_PT.png
Normal file
BIN
assets/jp/coalition/FROSTFALL_OCR_PT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
assets/tw/coalition/FROSTFALL_OCR_PT.png
Normal file
BIN
assets/tw/coalition/FROSTFALL_OCR_PT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
@ -2,6 +2,7 @@ import re
|
||||
from datetime import datetime
|
||||
|
||||
from module.campaign.campaign_status import CampaignStatus
|
||||
from module.config.config_updater import EVENTS, RAIDS, COALITIONS, GEMS_FARMINGS, MARITIME_ESCORTS
|
||||
from module.config.utils import DEFAULT_TIME
|
||||
from module.logger import logger
|
||||
from module.ui.assets import CAMPAIGN_MENU_NO_EVENT
|
||||
@ -44,18 +45,7 @@ class CampaignEvent(CampaignStatus):
|
||||
limit = int(
|
||||
re.sub(r'[,.\'",。]', '', str(self.config.EventGeneral_PtLimit))
|
||||
)
|
||||
tasks = [
|
||||
'Event',
|
||||
'Event2',
|
||||
'EventA',
|
||||
'EventB',
|
||||
'EventC',
|
||||
'EventD',
|
||||
'EventSp',
|
||||
'Raid',
|
||||
'RaidDaily',
|
||||
'GemsFarming',
|
||||
]
|
||||
tasks = EVENTS + RAIDS + COALITIONS + GEMS_FARMINGS
|
||||
command = self.config.Scheduler_Command
|
||||
if limit <= 0 or command not in tasks:
|
||||
return False
|
||||
@ -80,19 +70,7 @@ class CampaignEvent(CampaignStatus):
|
||||
in: page_event or page_sp
|
||||
"""
|
||||
limit = self.config.EventGeneral_TimeLimit
|
||||
tasks = [
|
||||
'Event',
|
||||
'Event2',
|
||||
'EventA',
|
||||
'EventB',
|
||||
'EventC',
|
||||
'EventD',
|
||||
'EventSp',
|
||||
'GemsFarming',
|
||||
'Raid',
|
||||
'RaidDaily',
|
||||
'MaritimeEscort',
|
||||
]
|
||||
tasks = EVENTS + RAIDS + COALITIONS + MARITIME_ESCORTS
|
||||
command = self.config.Scheduler_Command
|
||||
if command not in tasks or limit == DEFAULT_TIME:
|
||||
return False
|
||||
@ -149,16 +127,7 @@ class CampaignEvent(CampaignStatus):
|
||||
# Check event availability
|
||||
if self.appear(CAMPAIGN_MENU_NO_EVENT, offset=(20, 20)):
|
||||
logger.info('Event unavailable, disable task')
|
||||
tasks = [
|
||||
'Event',
|
||||
'Event2',
|
||||
'EventA',
|
||||
'EventB',
|
||||
'EventC',
|
||||
'EventD',
|
||||
'EventSp',
|
||||
'GemsFarming',
|
||||
]
|
||||
tasks = EVENTS + GEMS_FARMINGS
|
||||
self._disable_tasks(tasks)
|
||||
self.config.task_stop()
|
||||
else:
|
||||
@ -176,16 +145,7 @@ class CampaignEvent(CampaignStatus):
|
||||
# Check event availability
|
||||
if self.appear(CAMPAIGN_MENU_NO_EVENT, offset=(20, 20)):
|
||||
logger.info('Event unavailable, disable task')
|
||||
tasks = [
|
||||
'Event',
|
||||
'Event2',
|
||||
'EventA',
|
||||
'EventB',
|
||||
'EventC',
|
||||
'EventD',
|
||||
'EventSp',
|
||||
'GemsFarming',
|
||||
]
|
||||
tasks = EVENTS + GEMS_FARMINGS
|
||||
self._disable_tasks(tasks)
|
||||
self.config.task_stop()
|
||||
else:
|
||||
|
@ -10,6 +10,7 @@ FLEET_PREPARATION = Button(area={'cn': (1057, 527, 1155, 548), 'en': (1057, 527,
|
||||
FLEET_SWITCH_MULTI = Button(area={'cn': (1106, 449, 1237, 478), 'en': (1106, 449, 1237, 478), 'jp': (1106, 449, 1237, 478), 'tw': (1106, 449, 1237, 478)}, color={'cn': (232, 175, 58), 'en': (232, 175, 58), 'jp': (232, 175, 58), 'tw': (232, 175, 58)}, button={'cn': (1106, 449, 1237, 478), 'en': (1106, 449, 1237, 478), 'jp': (1106, 449, 1237, 478), 'tw': (1106, 449, 1237, 478)}, file={'cn': './assets/cn/coalition/FLEET_SWITCH_MULTI.png', 'en': './assets/cn/coalition/FLEET_SWITCH_MULTI.png', 'jp': './assets/cn/coalition/FLEET_SWITCH_MULTI.png', 'tw': './assets/cn/coalition/FLEET_SWITCH_MULTI.png'})
|
||||
FLEET_SWITCH_SINGLE = Button(area={'cn': (968, 449, 1098, 478), 'en': (968, 449, 1098, 478), 'jp': (968, 449, 1098, 478), 'tw': (968, 449, 1098, 478)}, color={'cn': (230, 173, 57), 'en': (230, 173, 57), 'jp': (230, 173, 57), 'tw': (230, 173, 57)}, button={'cn': (968, 449, 1098, 478), 'en': (968, 449, 1098, 478), 'jp': (968, 449, 1098, 478), 'tw': (968, 449, 1098, 478)}, file={'cn': './assets/cn/coalition/FLEET_SWITCH_SINGLE.png', 'en': './assets/cn/coalition/FLEET_SWITCH_SINGLE.png', 'jp': './assets/cn/coalition/FLEET_SWITCH_SINGLE.png', 'tw': './assets/cn/coalition/FLEET_SWITCH_SINGLE.png'})
|
||||
FROSTFALL_EX = Button(area={'cn': (622, 372, 649, 384), 'en': (622, 372, 649, 384), 'jp': (622, 372, 649, 384), 'tw': (622, 372, 649, 384)}, color={'cn': (198, 152, 252), 'en': (198, 152, 252), 'jp': (198, 152, 252), 'tw': (198, 152, 252)}, button={'cn': (622, 372, 649, 384), 'en': (622, 372, 649, 384), 'jp': (622, 372, 649, 384), 'tw': (622, 372, 649, 384)}, file={'cn': './assets/cn/coalition/FROSTFALL_EX.png', 'en': './assets/en/coalition/FROSTFALL_EX.png', 'jp': './assets/jp/coalition/FROSTFALL_EX.png', 'tw': './assets/tw/coalition/FROSTFALL_EX.png'})
|
||||
FROSTFALL_OCR_PT = Button(area={'cn': (1181, 641, 1254, 663), 'en': (1181, 641, 1254, 663), 'jp': (1181, 641, 1254, 663), 'tw': (1181, 641, 1254, 663)}, color={'cn': (93, 100, 106), 'en': (93, 100, 106), 'jp': (93, 100, 106), 'tw': (93, 100, 106)}, button={'cn': (1181, 641, 1254, 663), 'en': (1181, 641, 1254, 663), 'jp': (1181, 641, 1254, 663), 'tw': (1181, 641, 1254, 663)}, file={'cn': './assets/cn/coalition/FROSTFALL_OCR_PT.png', 'en': './assets/en/coalition/FROSTFALL_OCR_PT.png', 'jp': './assets/jp/coalition/FROSTFALL_OCR_PT.png', 'tw': './assets/tw/coalition/FROSTFALL_OCR_PT.png'})
|
||||
FROSTFALL_SP = Button(area={'cn': (631, 160, 658, 173), 'en': (631, 160, 658, 173), 'jp': (631, 160, 658, 173), 'tw': (631, 160, 658, 173)}, color={'cn': (194, 145, 252), 'en': (194, 145, 252), 'jp': (194, 145, 252), 'tw': (194, 145, 252)}, button={'cn': (631, 160, 658, 173), 'en': (631, 160, 658, 173), 'jp': (631, 160, 658, 173), 'tw': (631, 160, 658, 173)}, file={'cn': './assets/cn/coalition/FROSTFALL_SP.png', 'en': './assets/en/coalition/FROSTFALL_SP.png', 'jp': './assets/jp/coalition/FROSTFALL_SP.png', 'tw': './assets/tw/coalition/FROSTFALL_SP.png'})
|
||||
FROSTFALL_TC1 = Button(area={'cn': (304, 320, 330, 332), 'en': (304, 320, 330, 332), 'jp': (304, 320, 330, 332), 'tw': (304, 320, 330, 332)}, color={'cn': (204, 162, 254), 'en': (204, 162, 254), 'jp': (204, 162, 254), 'tw': (204, 162, 254)}, button={'cn': (304, 320, 330, 332), 'en': (304, 320, 330, 332), 'jp': (304, 320, 330, 332), 'tw': (304, 320, 330, 332)}, file={'cn': './assets/cn/coalition/FROSTFALL_TC1.png', 'en': './assets/en/coalition/FROSTFALL_TC1.png', 'jp': './assets/jp/coalition/FROSTFALL_TC1.png', 'tw': './assets/tw/coalition/FROSTFALL_TC1.png'})
|
||||
FROSTFALL_TC2 = Button(area={'cn': (810, 362, 835, 373), 'en': (810, 362, 835, 373), 'jp': (810, 362, 835, 373), 'tw': (810, 362, 835, 373)}, color={'cn': (214, 178, 254), 'en': (214, 178, 254), 'jp': (214, 178, 254), 'tw': (214, 178, 254)}, button={'cn': (810, 362, 835, 373), 'en': (810, 362, 835, 373), 'jp': (810, 362, 835, 373), 'tw': (810, 362, 835, 373)}, file={'cn': './assets/cn/coalition/FROSTFALL_TC2.png', 'en': './assets/en/coalition/FROSTFALL_TC2.png', 'jp': './assets/jp/coalition/FROSTFALL_TC2.png', 'tw': './assets/tw/coalition/FROSTFALL_TC2.png'})
|
||||
|
128
module/coalition/coalition.py
Normal file
128
module/coalition/coalition.py
Normal file
@ -0,0 +1,128 @@
|
||||
import re
|
||||
|
||||
from module.campaign.campaign_event import CampaignEvent
|
||||
from module.coalition.assets import *
|
||||
from module.coalition.combat import CoalitionCombat
|
||||
from module.exception import ScriptError
|
||||
from module.logger import logger
|
||||
from module.ocr.ocr import Digit
|
||||
from module.ui.page import page_raid
|
||||
|
||||
OCR_PT = Digit(FROSTFALL_OCR_PT, name='OCR_PT', letter=(198, 158, 82), threshold=128)
|
||||
|
||||
|
||||
class Coalition(CoalitionCombat, CampaignEvent):
|
||||
run_count: int
|
||||
run_limit: int
|
||||
|
||||
def get_event_pt(self):
|
||||
"""
|
||||
Returns:
|
||||
int: PT amount, or 0 if unable to parse
|
||||
"""
|
||||
pt = OCR_PT.ocr(self.device.image)
|
||||
return pt
|
||||
|
||||
def triggered_stop_condition(self):
|
||||
"""
|
||||
Returns:
|
||||
bool: If triggered a stop condition.
|
||||
"""
|
||||
# Run count limit
|
||||
if self.run_limit and self.config.StopCondition_RunCount <= 0:
|
||||
logger.hr('Triggered stop condition: Run count')
|
||||
self.config.StopCondition_RunCount = 0
|
||||
self.config.Scheduler_Enable = False
|
||||
return True
|
||||
# Oil limit
|
||||
if self.get_oil() < max(500, self.config.StopCondition_OilLimit):
|
||||
logger.hr('Triggered stop condition: Oil limit')
|
||||
self.config.task_delay(minute=(120, 240))
|
||||
return True
|
||||
# Event limit
|
||||
if self.event_pt_limit_triggered():
|
||||
logger.hr('Triggered stop condition: Event PT limit')
|
||||
return True
|
||||
# TaskBalancer
|
||||
if self.run_count >= 1:
|
||||
if self.config.TaskBalancer_Enable and self.triggered_task_balancer():
|
||||
logger.hr('Triggered stop condition: Coin limit')
|
||||
self.handle_task_balancer()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def coalition_execute_once(self, event, stage, fleet):
|
||||
"""
|
||||
Args:
|
||||
event:
|
||||
stage:
|
||||
fleet:
|
||||
|
||||
Pages:
|
||||
in: in_coalition
|
||||
out: in_coalition
|
||||
"""
|
||||
self.config.override(
|
||||
Campaign_Name=f'{event}_{stage}',
|
||||
Campaign_UseAutoSearch=False,
|
||||
Fleet_FleetOrder='fleet1_all_fleet2_standby'
|
||||
)
|
||||
self.emotion.check_reduce(battle=self.coalition_get_battles(stage))
|
||||
|
||||
self.enter_map(stage=stage, fleet=fleet)
|
||||
self.coalition_combat()
|
||||
|
||||
@staticmethod
|
||||
def handle_stage_name(event, stage):
|
||||
stage = re.sub('[ \t\n]', '', str(stage)).lower()
|
||||
if event == 'coalition_20230323':
|
||||
stage = stage.replace('-', '')
|
||||
|
||||
return event, stage
|
||||
|
||||
def run(self, name='', stage='', fleet='', total=0):
|
||||
name = name if name else self.config.Campaign_Event
|
||||
stage = stage if stage else self.config.Campaign_Name
|
||||
fleet = fleet if fleet else self.config.Coalition_Fleet
|
||||
if not name or not stage or not fleet:
|
||||
raise ScriptError(f'RaidRun arguments unfilled. name={name}, stage={stage}, fleet={fleet}')
|
||||
|
||||
name, stage = self.handle_stage_name(name, stage)
|
||||
self.run_count = 0
|
||||
self.run_limit = self.config.StopCondition_RunCount
|
||||
while 1:
|
||||
# End
|
||||
if total and self.run_count == total:
|
||||
break
|
||||
if self.event_time_limit_triggered():
|
||||
self.config.task_stop()
|
||||
|
||||
# Log
|
||||
logger.hr(f'{name}_{stage}', level=2)
|
||||
if self.config.StopCondition_RunCount > 0:
|
||||
logger.info(f'Count remain: {self.config.StopCondition_RunCount}')
|
||||
else:
|
||||
logger.info(f'Count: {self.run_count}')
|
||||
|
||||
# UI switches
|
||||
self.ui_ensure(page_raid)
|
||||
self.coalition_ensure_mode('battle')
|
||||
|
||||
# End
|
||||
if self.triggered_stop_condition():
|
||||
break
|
||||
|
||||
# Run
|
||||
self.coalition_execute_once(event=name, stage=stage, fleet=fleet)
|
||||
|
||||
# After run
|
||||
self.run_count += 1
|
||||
if self.config.StopCondition_RunCount:
|
||||
self.config.StopCondition_RunCount -= 1
|
||||
# End
|
||||
if self.triggered_stop_condition():
|
||||
break
|
||||
# Scheduler
|
||||
if self.config.task_switched():
|
||||
self.config.task_stop()
|
@ -23,7 +23,7 @@ class CoalitionCombat(CoalitionUI, CampaignBase):
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
if self.is_combat_executing():
|
||||
if self.is_combat_loading():
|
||||
break
|
||||
if self.in_coalition():
|
||||
raise CampaignEnd
|
||||
|
@ -17,6 +17,7 @@ FLEET_SWITCH.add_status('multi', FLEET_SWITCH_MULTI)
|
||||
|
||||
class CoalitionUI(Combat):
|
||||
def in_coalition(self):
|
||||
# The same as raid
|
||||
return self.appear(COALITION_CHECK, offset=(20, 20))
|
||||
|
||||
def coalition_ensure_mode(self, mode):
|
||||
@ -72,6 +73,24 @@ class CoalitionUI(Combat):
|
||||
|
||||
raise CampaignNameError
|
||||
|
||||
@staticmethod
|
||||
def coalition_get_battles(stage):
|
||||
"""
|
||||
Args:
|
||||
stage (str): Stage name.
|
||||
|
||||
Returns:
|
||||
int: Number of battles
|
||||
"""
|
||||
if stage == 'tc1':
|
||||
return 1
|
||||
if stage == 'tc2':
|
||||
return 2
|
||||
if stage == 'tc3':
|
||||
return 3
|
||||
|
||||
return 1
|
||||
|
||||
def handle_fleet_preparation(self, stage, fleet):
|
||||
stage = stage.lower()
|
||||
|
||||
|
@ -139,6 +139,7 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig, ConfigWatcher
|
||||
if (
|
||||
func.startswith("Event")
|
||||
or func.startswith("Raid")
|
||||
or func.startswith("Coalition")
|
||||
or func in ["MaritimeEscort", "GemsFarming"]
|
||||
):
|
||||
func_set.add("EventGeneral")
|
||||
|
@ -21,8 +21,9 @@ class ManualConfig:
|
||||
> OpsiDaily > OpsiShop > OpsiVoucher
|
||||
> OpsiAbyssal > OpsiStronghold > OpsiObscure > OpsiArchive
|
||||
> Daily > Hard > OpsiAshBeacon > OpsiAshAssist > OpsiMonthBoss
|
||||
> Sos > EventSp > EventA > EventB > EventC > EventD > RaidDaily > WarArchives > MaritimeEscort
|
||||
> Event > Event2 > Raid > Main > Main2 > Main3
|
||||
> Sos > EventSp > EventA > EventB > EventC > EventD
|
||||
> RaidDaily > CoalitionSp > WarArchives > MaritimeEscort
|
||||
> Event > Event2 > Raid > Coalition > Main > Main2 > Main3
|
||||
> OpsiMeowfficerFarming
|
||||
> GemsFarming
|
||||
> OpsiHazard1Leveling
|
||||
|
@ -33,6 +33,7 @@ GEMS_FARMINGS = ['GemsFarming']
|
||||
RAIDS = ['Raid', 'RaidDaily']
|
||||
WAR_ARCHIVES = ['WarArchives']
|
||||
COALITIONS = ['Coalition', 'CoalitionSp']
|
||||
MARITIME_ESCORTS = ['MaritimeEscort']
|
||||
|
||||
|
||||
class Event:
|
||||
|
Loading…
Reference in New Issue
Block a user