Skip to content

Commit

Permalink
Merge pull request #291 from EightyDollars/dev_shawn
Browse files Browse the repository at this point in the history
 增加森空岛签到功能,修改公招筛选干员逻辑
  • Loading branch information
ZhaoZuohong authored Sep 18, 2023
2 parents 34204e8 + 73bec55 commit a9cdafd
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 196 deletions.
25 changes: 25 additions & 0 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ def set_maa_options(base_scheduler):

logger.debug(f"更新Maa设置:{base_scheduler.maa_config}")

def set_recruit_options(base_scheduler):
conf = update_conf()
global recruit_config
recruit_config['recruit_enable'] = conf['recruit_enable']
recruit_config['recruit_only_4'] = conf['recruit_only_4']
recruit_config['recruit_robot'] = conf['recruit_robot']
recruit_config['recruitment_time'] = conf['recruitment_time']
base_scheduler.recruit_config = recruit_config

logger.debug(f"更新公招设置:{base_scheduler.recruit_config}")

def set_skland_options(base_scheduler):
conf = update_conf()
global skland_config
skland_config['skland_enable'] = conf['skland_enable']
skland_config['skland_info'] = conf['skland_info']
base_scheduler.skland_config = skland_config

logger.debug(f"更新森空岛设置:{base_scheduler.skland_config}")

def initialize(tasks, scheduler=None):
from arknights_mower.solvers.base_schedule import BaseSchedulerSolver
Expand Down Expand Up @@ -148,6 +167,8 @@ def initialize(tasks, scheduler=None):
}

set_maa_options(base_scheduler)
set_recruit_options(base_scheduler)
set_skland_options(base_scheduler)

base_scheduler.ADB_CONNECT = config.ADB_CONNECT[0]
base_scheduler.error = False
Expand Down Expand Up @@ -217,6 +238,8 @@ def simulate():
remaining_time = (base_scheduler.tasks[0].time - datetime.now()).total_seconds()

set_maa_options(base_scheduler)
set_recruit_options(base_scheduler)
set_skland_options(base_scheduler)

if sleep_time > 540 and base_scheduler.maa_config['maa_enable'] == 1:
subject = f"下次任务在{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}"
Expand Down Expand Up @@ -292,6 +315,8 @@ def load_state(file='state.json'):

agent_base_config = {}
maa_config = {}
recruit_config = {}
skland_config = {}


def __init_params__():
Expand Down
6 changes: 3 additions & 3 deletions arknights_mower/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def shop(args: list[str] = [], device: Device = None):
ShopSolver(device).run(args)


def recruit(args: list[str] = [], email_config={}, maa_config={}, device: Device = None):
def recruit(args: list[str] = [], email_config={}, recruit_config={}, device: Device = None):
"""
recruit [agents ...]
自动进行公共招募
Expand All @@ -93,9 +93,9 @@ def recruit(args: list[str] = [], email_config={}, maa_config={}, device: Device
choose = {}
result = {}
if len(args) == 0:
choose, result = RecruitSolver(device).run(config.RECRUIT_PRIORITY, email_config, maa_config)
choose, result = RecruitSolver(device).run(config.RECRUIT_PRIORITY, email_config, recruit_config)
else:
choose, result = RecruitSolver(device).run(args, email_config)
choose, result = RecruitSolver(device).run(args, email_config,recruit_config)

return choose, result

Expand Down
11 changes: 7 additions & 4 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
self.credit_fight = None
self.exit_game_when_idle = False
self.refresh_connecting = False
self.recruit_config = {}
self.skland_config = {}

def run(self) -> None:
"""
Expand Down Expand Up @@ -2195,12 +2197,13 @@ def maa_plan_solver(self, tasks='All', one_time=False):
logger.info("间隔未超过设定时间,不启动maa")
else:
"""森空岛签到"""
# skland = SKLand()
# skland.attendance()
if self.skland_config['skland_enable']:
skland = SKLand(self.skland_config['skland_info'])
skland.attendance()

"""测试公招用"""
if 'Recruit' in tasks or tasks == 'All':
recruit([], self.email_config, self.maa_config)
if self.recruit_config['recruit_enable']:
recruit([], self.email_config, self.recruit_config)

self.send_email('启动MAA')
self.back_to_index()
Expand Down
102 changes: 61 additions & 41 deletions arknights_mower/solvers/recruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:

self.recruit_pos = -1

def run(self, priority: list[str] = None, email_config={}, maa_config={}):
def run(self, priority: list[str] = None, email_config={}, recruit_config={}):
"""
:param priority: list[str], 优先考虑的公招干员,默认为高稀有度优先
"""
Expand All @@ -59,7 +59,7 @@ def run(self, priority: list[str] = None, email_config={}, maa_config={}):
self.email_config = email_config

# 调整公招参数
self.add_recruit_param(maa_config)
self.add_recruit_param(recruit_config)

logger.info('Start: 公招')
# 清空
Expand Down Expand Up @@ -89,21 +89,22 @@ def run(self, priority: list[str] = None, email_config={}, maa_config={}):

return self.agent_choose, self.result_agent

def add_recruit_param(self, maa_config):
if not maa_config:
def add_recruit_param(self, recruit_config):
if not recruit_config:
raise Exception("招募设置为空")

if maa_config['recruitment_time']:
if recruit_config['recruitment_time']:
recruitment_time = 460
else:
recruitment_time = 540

self.recruit_config = {
"recruit_only_4": maa_config['recruit_only_4'],
"recruit_only_4": recruit_config['recruit_only_4'],
"recruitment_time": {
"3": recruitment_time,
"4": 540
}
},
"recruit_robot": recruit_config['recruit_robot']
}

def transition(self) -> bool:
Expand Down Expand Up @@ -183,7 +184,7 @@ def recruit_tags(self) -> bool:
logger.info(f'第{self.recruit_pos + 1}个位置上的公招标签:{tags}')

# 计算招募标签组合结果
best, need_choose = self.recruit_cal(tags, self.priority)
best, need_choose = self.recruit_cal(tags)

# 刷新标签
if need_choose is False:
Expand Down Expand Up @@ -360,10 +361,11 @@ def merge_agent_list(self, tags: [str], list_1: list[dict], list_2={}, list_3={}

return merge_list, level, isRarity, isRobot

def recruit_cal(self, tags: list[str], auto_robot=False, need_Robot=True) -> (dict, bool):
def recruit_cal(self, tags: list[str]) -> (dict, bool):
possible_list = {}
has_rarity = False
has_robot = False
recruit_robot =self.recruit_config["recruit_robot"]

for item in combinations(tags, 1):
# 防止出现类似情况 ['重', '装', '干', '员']
Expand Down Expand Up @@ -414,47 +416,65 @@ def recruit_cal(self, tags: list[str], auto_robot=False, need_Robot=True) -> (di

logger.debug(f"公招可能性:{self.recruit_str(possible_list)}")

rarity_list = {
"level": -1,
"possible": {}
}
normal_list = {
"level": -1,
"possible": {}
}
robot_list = {}
for key in list(possible_list.keys()):
# 五星六星选择优先级大于支援机械
if has_rarity:
if possible_list[key]['isRarity'] is False:
del possible_list[key]
continue
elif possible_list[key]['level'] < 6 and "高级资深干员" in tags:
del possible_list[key]
if possible_list[key]["isRarity"]:
if possible_list[key]["level"] > rarity_list["level"]:
rarity_list["level"] = possible_list[key]["level"]
rarity_list["possible"][key] = possible_list[key]
elif possible_list[key]["isRobot"]:
robot_list[key] = possible_list[key]
else:
if possible_list[key]["level"] > normal_list["level"]:
normal_list["level"] = possible_list[key]["level"]
normal_list["possible"][key] = possible_list[key]

# 筛选稀有tag
if rarity_list["possible"]:
for key in list(rarity_list["possible"].keys()):
if rarity_list["possible"][key]["level"] < rarity_list["level"]:
del rarity_list["possible"][key]
continue
# 不要支援机械
elif need_Robot is False and possible_list[key]['isRobot'] is True:
del possible_list[key]
continue
# 支援机械手动选择
elif has_robot and need_Robot is True and possible_list[key]['isRobot'] is False:
del possible_list[key]
continue
for i in range(len(rarity_list["possible"][key]["agent"]) - 1, -1, -1):
if rarity_list["possible"][key]["agent"][i]['level'] != rarity_list["possible"][key]["level"]:
rarity_list["possible"][key]["agent"].remove(rarity_list["possible"][key]["agent"][i])
logger.debug(f"rarity_list:{rarity_list}")
return rarity_list, False

if robot_list and self.recruit_config["recruit_robot"]:
logger.debug(f"robot_list:{robot_list.popitem()}")
return robot_list, False

'''只保留大概率能出的tag'''
for i in range(len(possible_list[key]["agent"]) - 1, -1, -1):
if possible_list[key]["agent"][i]['level'] != possible_list[key]["level"]:
possible_list[key]["agent"].remove(possible_list[key]["agent"][i])
# 筛选非稀有tag

# 六星 五星 支援机械手动选择返回全部结果
logger.debug(normal_list["level"])
if normal_list["level"] < 4:
return {}, True

# 有支援机械 不需要自动点支援机械 并且需要支援机械的情况下,邮件提醒
notice_robot = (has_robot and auto_robot == False and need_Robot)
need_choose = True
if notice_robot or has_rarity:
need_choose = False
logger.info(f"稀有tag:{self.recruit_str(possible_list)}")
return possible_list, need_choose
for key in list(normal_list["possible"].keys()):
if normal_list["possible"][key]["level"] < normal_list["level"]:
del normal_list["possible"][key]
continue
for i in range(len(normal_list["possible"][key]["agent"]) - 1, -1, -1):
if normal_list["possible"][key]["agent"][i]['level'] != normal_list["possible"][key]["level"]:
normal_list["possible"][key]["agent"].remove(normal_list["possible"][key]["agent"][i])

best = {}
# 4星=需要选择tag返回选择的tag,3星不选
for key in possible_list:
if possible_list[key]['level'] >= 4:
best[key] = possible_list[key]
break

return best, need_choose
for key in normal_list["possible"]:
best[key] = normal_list["possible"][key]
break
logger.debug(f"normal_list:{normal_list}")
return best, True

def recruit_str(self, recruit_result: dict):
if not recruit_result:
Expand Down
Loading

0 comments on commit a9cdafd

Please sign in to comment.