Skip to content

Commit 52e4c5e

Browse files
authored
Merge pull request #223 from cc004/dev
Dev
2 parents b09593f + 4e4579c commit 52e4c5e

9 files changed

Lines changed: 405 additions & 314 deletions

File tree

autopcr/core/pcrclient.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ async def read_story(self, story_id: int):
609609
await self.story_check(story_id)
610610
return await self.story_view(story_id)
611611

612+
async def read_asb_story(self, sub_story_id: int):
613+
req = SubStoryAsbReadStoryRequest()
614+
req.sub_story_id = sub_story_id
615+
await self.request(req)
616+
612617
async def read_wtm_story(self, sub_story_id: int):
613618
req = SubStoryWtmReadStoryRequest()
614619
req.sub_story_id = sub_story_id

autopcr/db/database.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,14 @@ def hatsune_item(self) -> Dict[int, HatsuneItem]:
11921192
.to_dict(lambda x: x.event_id, lambda x: x)
11931193
)
11941194

1195+
@lazy_property
1196+
def asb_story_data(self) -> Dict[int, AsbStoryDatum]:
1197+
with self.dbmgr.session() as db:
1198+
return (
1199+
AsbStoryDatum.query(db)
1200+
.to_dict(lambda x: x.sub_story_id, lambda x: x)
1201+
)
1202+
11951203
@lazy_property
11961204
def wtm_story_data(self) -> Dict[int, WtmStoryDatum]:
11971205
with self.dbmgr.session() as db:

autopcr/model/handlers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,13 @@ async def update(self, mgr: datamgr, request):
674674
for reward in self.rewards:
675675
mgr.update_inventory(reward)
676676

677+
@handles
678+
class SubStoryAsbReadStoryResponse(responses.SubStoryAsbReadStoryResponse):
679+
async def update(self, mgr: datamgr, request):
680+
if self.reward_info:
681+
for reward in self.reward_info:
682+
mgr.update_inventory(reward)
683+
677684
@handles
678685
class SubStoryWtmReadStoryResponse(responses.SubStoryWtmReadStoryResponse):
679686
async def update(self, mgr: datamgr, request):

autopcr/module/config.py

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -271,26 +271,12 @@ class LimitUnitListConfig(UnitConfigMixin, MultiSearchConfig):
271271
def __init__(self, key: str, desc: str):
272272
super().__init__(key, desc, [], db.limit_unit_condition_candidate)
273273

274-
class ConditionalExecutionMixin:
275-
"""Mixin for conditional execution configs."""
276-
async def check_campaigns(self, campaign_list, client_data):
277-
"""Check if any campaign in the list is active."""
278-
hit = [campaign for campaign in campaign_list if client_data.is_campaign(campaign)]
279-
return hit
280-
281-
class ConditionalExecution1Config(ConditionalExecutionMixin, MultiChoiceConfig):
282-
def __init__(self, key: str, desc: str = "执行条件", default=[], check: bool = True):
283-
super().__init__(key, desc, default, ['无庆典', 'n庆典', 'h庆典', 'vh庆典', '总是执行'])
274+
class ConditionalExecutionWrapper(Config):
275+
def __init__(self, key: str, desc: str, default: Any, candidates: Union[Callable, List], check: bool):
276+
super().__init__(key, desc, default, candidates)
284277
self.check_enabled = check
285-
286-
async def do_check(self, client: pcrclient) -> Tuple[bool, str]:
287-
288-
run_time = self.get_value()
289-
hit = await self.check_campaigns(run_time, client.data)
290-
291-
if hit:
292-
return True, "今日" + ','.join(hit) + ",执行"
293-
return False, "今日不符合执行条件"
278+
279+
async def do_check(self, client: Union[pcrclient, None] = None) -> Tuple[bool, str]: ...
294280

295281
def wrap_init(self, cls: Type, sself: Type):
296282
super().wrap_init(cls, sself)
@@ -309,68 +295,45 @@ async def new_do_check(*args, **kwargs):
309295

310296
cls.do_check = new_do_check
311297

298+
class ConditionalExecutionClient(ConditionalExecutionWrapper):
299+
async def do_check(self, client: pcrclient) -> Tuple[bool, str]:
300+
run_time = self.get_value()
301+
hit = [campaign for campaign in run_time if client.data.is_campaign(campaign)]
302+
if hit:
303+
return True, "今日" + ','.join(hit) + ",执行"
304+
return False, "今日不符合执行条件"
312305

313-
class ConditionalExecution2Config(ConditionalExecutionMixin, MultiChoiceConfig):
314-
def __init__(self, key: str, desc: str = "执行条件", default=[], check: bool = True):
315-
super().__init__(key, desc, default, ['n3以上前夕', 'n3以上首日午前', 'h3以上前夕', '会战前夕', '会战期间', '总是执行'])
316-
self.check_enabled = check
317-
306+
class ConditionalExecutionDB(ConditionalExecutionWrapper, MultiChoiceConfig):
318307
async def do_check(self) -> Tuple[bool, str]:
319-
320308
run_time = self.get_value()
321309
hit = [campaign for campaign in run_time if db.is_campaign(campaign)]
322-
323310
if hit:
324311
return True, "今日" + ','.join(hit) + ",执行"
325312
return False, "今日不符合执行条件"
326-
327-
def wrap_init(self, cls: Type, sself: Type):
328-
super().wrap_init(cls, sself)
329-
if sself.check_enabled and hasattr(cls, 'do_check'):
330-
old_do_check = cls.do_check
331313

332-
async def new_do_check(*args, **kwargs):
333-
ok, msg = await old_do_check(*args, **kwargs)
334-
if not ok:
335-
return False, msg
336-
337-
ok, msg2 = await sself.do_check(*args, **kwargs)
338-
if not ok:
339-
return False, msg + msg2
340-
return True, msg + msg2
341-
342-
cls.do_check = new_do_check
343-
344-
345-
class ConditionalNotExecutionConfig(ConditionalExecutionMixin, MultiChoiceConfig):
346-
def __init__(self, key: str, desc: str = "不执行条件", default=[], check: bool = True):
347-
super().__init__(key, desc, default, ['n2', 'n3', 'n4及以上', 'h2', 'h3及以上', 'vh2', 'vh3及以上'])
348-
self.check_enabled = check
349-
314+
class ConditionalNotExecutionClient(ConditionalExecutionWrapper):
350315
async def do_check(self, client: pcrclient) -> Tuple[bool, str]:
351316
run_time = self.get_value()
352-
hit = await self.check_campaigns(run_time, client.data)
353-
317+
hit = [campaign for campaign in run_time if client.data.is_campaign(campaign)]
354318
if hit:
355319
return False, "今日" + ','.join(hit) + ",不执行"
356320
return True, ""
357-
358-
def wrap_init(self, cls: Type, sself: Type):
359-
super().wrap_init(cls, sself)
360-
if sself.check_enabled and hasattr(cls, 'do_check'):
361-
old_do_check = cls.do_check
362321

363-
async def new_do_check(*args, **kwargs):
364-
ok, msg = await old_do_check(*args, **kwargs)
365-
if not ok:
366-
return False, msg
322+
class ConditionalExecution1Config(ConditionalExecutionClient, MultiChoiceConfig):
323+
def __init__(self, key: str, desc: str = "执行条件", default=[], check: bool = True):
324+
super().__init__(key, desc, default, ['无庆典', 'n庆典', 'h庆典', 'vh庆典', '总是执行'], check)
367325

368-
ok, msg2 = await sself.do_check(*args, **kwargs)
369-
if not ok:
370-
return False, msg + msg2
371-
return True, msg + msg2
326+
class ConditionalExecution2Config(ConditionalExecutionDB, MultiChoiceConfig):
327+
def __init__(self, key: str, desc: str = "执行条件", default=[], check: bool = True):
328+
super().__init__(key, desc, default, ['n3以上前夕', 'n3以上首日午前', 'h3以上前夕', '会战前夕', '会战期间', '总是执行'], check)
372329

373-
cls.do_check = new_do_check
330+
class ConditionalExecution3Config(ConditionalExecutionClient, MultiChoiceConfig):
331+
def __init__(self, key: str, desc: str = "执行条件", default=[], check: bool = True):
332+
super().__init__(key, desc, default, ['n2', 'n3', 'n4及以上', 'h2', 'h3及以上', 'vh2', 'vh3及以上', '总是执行'], check)
333+
334+
class ConditionalNotExecutionConfig(ConditionalNotExecutionClient, MultiChoiceConfig):
335+
def __init__(self, key: str, desc: str = "不执行条件", default=[], check: bool = True):
336+
super().__init__(key, desc, default, ['n2', 'n3', 'n4及以上', 'h2', 'h3及以上', 'vh2', 'vh3及以上'], check)
374337

375338
class TravelQuestConfig(MultiChoiceConfig):
376339
"""Configuration for travel quests."""

autopcr/module/modules/autosweep.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def get_max_times(self, client: pcrclient, quest_id: int) -> int:
215215
return 3
216216

217217
@singlechoice('shiori_sweep_gap_limit', "盈余阈值", 10, [0, 5, 10])
218+
@conditional_not_execution("shiori_sweep_not_run_time", ["n3", 'n4及以上'])
218219
@conditional_execution1("shiori_sweep_run_time", ["无庆典"])
219220
@singlechoice('shiori_sweep_consider_unit_order', "刷取顺序", "缺口少优先", ["缺口少优先", "缺口大优先"])
220221
@description('根据记忆碎片缺口刷外传图,直到盈余超过阈值')
@@ -285,6 +286,8 @@ def get_max_times(self, client: pcrclient, quest_id: int) -> int:
285286
107501, # 水吃
286287
113101, # 水流夏
287288
113301, # 水七七香
289+
117001, # 水娇
290+
117101, # 水姐姐
288291
]
289292
@conditional_execution1("very_hard_sweep_run_time", ["vh庆典"])
290293
@description('储备专二需求的150碎片,包括' + ','.join(db.get_unit_name(unit_id) for unit_id in unique_equip_2_pure_memory_id))

autopcr/module/modules/daily.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ async def check_reward(reward: seasonpass_reward.Reward, full_reward: seasonpass
204204
else:
205205
raise SkipError("没有可领取的女神祭奖励")
206206

207-
@singlechoice("present_receive_stamina_strategy", "体力", "不领取", ["所有", "有限期", "一天到期", "不领取"])
207+
@ConditionalExecution3Config('present_receive_unlimit_stamina_strategy', "无限期体力", [], check = False)
208+
@ConditionalExecution3Config('present_receive_limit_stamina_strategy', "有限期体力", ["n3", "n4及以上"], check = False)
209+
@ConditionalExecution3Config('present_receive_one_day_limit_stamina_strategy', "一天到期体力", ["总是执行"], check = False)
208210
@description('领取非体力的所有东西以及符合条件的体力')
209211
@name('领取礼物箱')
210212
@default(True)
@@ -214,9 +216,16 @@ async def do_task(self, client: pcrclient):
214216
received = False
215217
result = []
216218
stop = False
217-
present_strategy = self.get_config('present_receive_stamina_strategy')
219+
gets = []
220+
for conf in ['present_receive_unlimit_stamina_strategy', 'present_receive_limit_stamina_strategy', 'present_receive_one_day_limit_stamina_strategy']:
221+
config = self.get_config_instance(conf)
222+
get, msg = await config.do_check(client)
223+
gets.append(get)
224+
if get:
225+
self._log(msg + config.desc + "领取")
226+
unlimit_stamina_get, limit_stamina_get, one_day_limit_stamina_get = gets
218227
while not stop:
219-
is_exclude_stamina = False if present_strategy == "所有" else True
228+
is_exclude_stamina = False if unlimit_stamina_get and limit_stamina_get else True
220229
present_index = await client.present_index()
221230
for present in present_index.present_info_list:
222231
if not is_exclude_stamina or not (present.reward_type == eInventoryType.Stamina and present.reward_id == 93001):
@@ -234,15 +243,15 @@ async def do_task(self, client: pcrclient):
234243
else:
235244
stop = True
236245

237-
if present_strategy != "所有" and present_strategy != "不领取":
246+
if unlimit_stamina_get or limit_stamina_get or one_day_limit_stamina_get:
238247
stop = False
239-
limit_stamina = present_strategy == "有限期"
240248
while not stop:
241249
present = await client.present_index()
242250
for present in present.present_info_list:
243251
if present.reward_type == eInventoryType.Stamina and present.reward_id == 93001 \
244-
and present.reward_limit_flag \
245-
and (limit_stamina or present.reward_limit_time <= apiclient.time + 24 * 3600):
252+
and ((not present.reward_limit_flag and unlimit_stamina_get) or
253+
(present.reward_limit_flag and limit_stamina_get) or
254+
(present.reward_limit_flag and one_day_limit_stamina_get and present.reward_limit_time <= apiclient.time + 24 * 3600)):
246255
res = await client.present_receive(present.present_id)
247256
if not res.rewards:
248257
self._warn("体力满了,无法继续领取礼物箱的体力")

autopcr/module/modules/travel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ def get_strategy(event_id: int) -> str:
310310

311311
@inttype("travel_speed_up_paper_threshold", "加速阈值", 12, list(range(13)))
312312
@inttype("travel_target_day", "轮转天数", 7, list(range(1, 31)))
313-
@TravelQuestConfig("travel_target_quest3", "轮转目标3", [11002002, 11002003, 11002005])
314-
@TravelQuestConfig("travel_target_quest2", "轮转目标2", [11002004])
315-
@TravelQuestConfig("travel_target_quest1", "轮转目标1", [11002001])
313+
@TravelQuestConfig("travel_target_quest3", "轮转目标3", [11003002, 11003003])
314+
@TravelQuestConfig("travel_target_quest2", "轮转目标2", [11003004])
315+
@TravelQuestConfig("travel_target_quest1", "轮转目标1", [11003001])
316316
@name('探险轮转')
317317
@description('''
318318
自动根据轮转进行探险,按轮转时间进行目标切换,需保持三支队探险。

0 commit comments

Comments
 (0)