Skip to content

Commit ee6f34a

Browse files
authored
Merge pull request #271 from cc004/dev
2 parents e4d5580 + 68fd2da commit ee6f34a

7 files changed

Lines changed: 83 additions & 11 deletions

File tree

autopcr/core/pcrclient.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,15 @@ async def tpr_register_success(self, panel_id: int, correct_type: int, parts_id_
739739
req.parts_id_list = parts_id_list
740740
return await self.request(req)
741741

742+
async def read_lss_story(self, sub_story_id: int):
743+
req = SubStoryLssReadStoryRequest()
744+
req.sub_story_id = sub_story_id
745+
req.skip_info = StorySkipInfo(
746+
skip_type = eStorySkipType.MENU_SKIP,
747+
scroll_coordinate = ""
748+
)
749+
return await self.request(req)
750+
742751
async def read_tpr_story(self, sub_story_id: int):
743752
req = SubStoryTprReadStoryRequest()
744753
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
@@ -1263,6 +1263,14 @@ def hatsune_item(self) -> Dict[int, HatsuneItem]:
12631263
.to_dict(lambda x: x.event_id, lambda x: x)
12641264
)
12651265

1266+
@lazy_property
1267+
def lss_story_data(self) -> Dict[int, LssStoryDatum]:
1268+
with self.dbmgr.session() as db:
1269+
return (
1270+
LssStoryDatum.query(db)
1271+
.to_dict(lambda x: x.sub_story_id, lambda x: x)
1272+
)
1273+
12661274
@lazy_property
12671275
def tpr_story_data(self) -> Dict[int, TprStoryDatum]:
12681276
with self.dbmgr.session() as db:

autopcr/model/custom.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ class ArenaQueryResponse(BaseModel):
239239
data: Optional[ArenaQueryData]
240240
version: str
241241

242+
class eRedeemUnitUnlockCondition(IntEnum):
243+
NONE = 0
244+
UNLOCK_UNIT = 1
245+
VIEWED_STORY = 2
246+
GOLD = 3
247+
CURRENCY = 4
248+
MEMORY_PIECE = 5
249+
SUPER_MEMORY_PIECE = 6
250+
JEWEL = 7
251+
EQUIP = 8
252+
EQUIP_MATERIAL = 9
253+
242254
class TalentQuestData(BaseModel):
243255
talent_id: int = None
244256
clear_count: int = None

autopcr/model/handlers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,17 @@ async def update(self, mgr: datamgr, request):
784784
mgr.update_inventory(reward)
785785

786786
@handles
787+
class SubStoryLssReadStoryResponse(responses.SubStoryLssReadStoryResponse):
788+
async def update(self, mgr: datamgr, request):
789+
if self.reward_info:
790+
for reward in self.reward_info:
791+
mgr.update_inventory(reward)
792+
if self.special_reward_list:
793+
for reward in self.special_reward_list:
794+
mgr.update_inventory(reward)
795+
if self.user_jewel:
796+
mgr.jewel = self.user_jewel
797+
@handles
787798
class SubStoryNydReadStoryResponse(responses.SubStoryNydReadStoryResponse):
788799
async def update(self, mgr: datamgr, request):
789800
if self.reward_info:

autopcr/module/modules/story.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async def do_task(self, client: pcrclient):
199199

200200
if any(sub_story.status == eEventSubStoryStatus.ADDED for sub_story in sub_storys.sub_story_info_list):
201201
await reader.confirm()
202-
for sub_story in sub_storys.sub_story_info_list:
202+
for sub_story in await reader.sort_by_time(sub_storys.sub_story_info_list):
203203
if sub_story.status == eEventSubStoryStatus.UNREAD and reader.is_readable(sub_story.sub_story_id):
204204
await reader.read(sub_story.sub_story_id)
205205
self._log(f"阅读了{reader.title(sub_story.sub_story_id)}")

autopcr/module/modules/tools.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ...model.common import ChangeRarityUnit, DeckListData, GachaPointInfo, GrandArenaHistoryDetailInfo, GrandArenaHistoryInfo, GrandArenaSearchOpponent, ProfileUserInfo, RankingSearchOpponent, RedeemUnitInfo, RedeemUnitSlotInfo, UnitData, UnitDataLight, VersusResult, VersusResultDetail
66
from ...model.responses import GachaIndexResponse, PsyTopResponse
77
from ...db.models import GachaExchangeLineup
8-
from ...model.custom import ArenaQueryResult, GachaReward, ItemType
8+
from ...model.custom import ArenaQueryResult, GachaReward, ItemType, eRedeemUnitUnlockCondition
99
from ..modulebase import *
1010
from ..config import *
1111
from ...core.pcrclient import pcrclient
@@ -37,6 +37,7 @@ async def do_task(self, client: pcrclient):
3737
@booltype('redeem_unit_swap_do', '开换', False)
3838
@description('计算兑换对应角色所需的3000碎片的最优使用方案,使得剩余碎片的盈余值的最大值最小')
3939
class redeem_unit_swap(Module):
40+
4041
async def do_task(self, client: pcrclient):
4142
do = self.get_config('redeem_unit_swap_do')
4243

@@ -57,17 +58,27 @@ async def do_task(self, client: pcrclient):
5758

5859
for slot_info in info.slot_info:
5960
db_info = db.get_redeem_unit_slot_info(unit_id,slot_info.slot_id)
60-
if slot_info.slot_id == 1:
61-
self._log(f"已使用{slot_info.register_num}碎片")
62-
use_piece = int(db_info.consume_num) - slot_info.register_num
63-
elif slot_info.slot_id == 2:
64-
self._log(f"已使用{slot_info.register_num}玛那")
65-
elif slot_info.slot_id == 3:
61+
if db_info.condition_category == eRedeemUnitUnlockCondition.UNLOCK_UNIT:
6662
if db_info.condition_id not in client.data.unit:
6763
raise AbortError(f"未解锁{db.get_unit_name(db_info.condition_id)},无法兑换{db.get_unit_name(unit_id)}")
68-
elif slot_info.slot_id == 4:
64+
elif db_info.condition_category == eRedeemUnitUnlockCondition.VIEWED_STORY:
6965
if db_info.condition_id not in client.data.read_story_ids:
7066
raise AbortError(f"未阅读{db_info.condition_id},无法兑换{db.get_unit_name(unit_id)}")
67+
elif db_info.condition_category == eRedeemUnitUnlockCondition.GOLD:
68+
self._log(f"已使用{slot_info.register_num}玛那")
69+
elif db_info.condition_category == eRedeemUnitUnlockCondition.CURRENCY:
70+
self._log(f"已使用{slot_info.register_num}??")
71+
elif db_info.condition_category == eRedeemUnitUnlockCondition.MEMORY_PIECE:
72+
self._log(f"已使用{slot_info.register_num}碎片")
73+
use_piece = int(db_info.consume_num) - slot_info.register_num
74+
elif db_info.condition_category == eRedeemUnitUnlockCondition.SUPER_MEMORY_PIECE:
75+
self._log(f"已使用{slot_info.register_num}纯净碎片")
76+
elif db_info.condition_category == eRedeemUnitUnlockCondition.JEWEL:
77+
self._log(f"已使用{slot_info.register_num}宝石")
78+
elif db_info.condition_category == eRedeemUnitUnlockCondition.EQUIP:
79+
self._log(f"已使用{slot_info.register_num}装备")
80+
elif db_info.condition_category == eRedeemUnitUnlockCondition.EQUIP_MATERIAL:
81+
self._log(f"已使用{slot_info.register_num}装备碎片")
7182
else:
7283
raise ValueError(f"未知的兑换条件{slot_info.slot_id}")
7384

@@ -90,13 +101,14 @@ async def do_task(self, client: pcrclient):
90101

91102
if do:
92103
for slot_info in info.slot_info:
93-
if slot_info.slot_id == 1:
104+
db_info = db.get_redeem_unit_slot_info(unit_id,slot_info.slot_id)
105+
if db_info.condition_category == eRedeemUnitUnlockCondition.MEMORY_PIECE:
94106
memory_use = Counter({item[i]: res[i] for i in id if res[i] > 0})
95107
if memory_use:
96108
self._log(f"使用了角色碎片")
97109
ret = await client.unit_register_item(unit_id, slot_info.slot_id, memory_use, slot_info.register_num)
98110
slot_info.register_num = ret.register_num
99-
elif slot_info.slot_id == 2:
111+
elif db_info.condition_category == eRedeemUnitUnlockCondition.GOLD:
100112
info = db.get_redeem_unit_slot_info(unit_id,slot_info.slot_id)
101113
total_mana = int(info.consume_num) - slot_info.register_num
102114
if not (await client.prepare_mana(total_mana)):
@@ -107,6 +119,11 @@ async def do_task(self, client: pcrclient):
107119
ret = await client.unit_register_item(unit_id, slot_info.slot_id, Counter({(eInventoryType.Gold, info.condition_id): mana}), slot_info.register_num)
108120
slot_info.register_num = ret.register_num
109121
total_mana -= mana
122+
else:
123+
if db_info.condition_category in [eRedeemUnitUnlockCondition.UNLOCK_UNIT,
124+
eRedeemUnitUnlockCondition.VIEWED_STORY]:
125+
continue
126+
raise AbortError(f"未实现的兑换条件{db_info.condition_category}")
110127

111128
self._log(f"兑换{db.get_unit_name(unit_id)}")
112129
await client.unit_unlock_redeem_unit(unit_id)

autopcr/util/substory.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ async def special_read(self, sub_storys: List[EventSubStory], _log: Callable): .
3636
async def confirm(self): ...
3737
async def prepare(self):
3838
pass
39+
async def sort_by_time(self, sub_story_ids: List[EventSubStory]) -> List[EventSubStory]:
40+
return sub_story_ids
3941

4042
def __init__(self, client: pcrclient):
4143
self.client = client
@@ -45,6 +47,16 @@ def GetSubStoryReader(sub_story_data: EventSubStory, client: pcrclient) -> Union
4547
return constructor[sub_story_data.event_id](client)
4648
return None
4749

50+
@EventId(10150)
51+
class lss_substory(SubStoryReader):
52+
53+
def title(self, sub_story_id: int) -> str:
54+
return db.lss_story_data[sub_story_id].title
55+
56+
async def read(self, sub_story_id: int):
57+
await self.client.story_check(sub_story_id)
58+
await self.client.read_lss_story(sub_story_id)
59+
4860
@EventId(10148)
4961
class tpr_substory(SubStoryReader):
5062
special = True
@@ -98,6 +110,9 @@ async def prepare(self):
98110
async def read(self, sub_story_id: int):
99111
await self.client.read_apg_story(sub_story_id)
100112

113+
async def sort_by_time(self, sub_story_ids: List[EventSubStory]) -> List[EventSubStory]:
114+
return sorted(sub_story_ids, key=lambda s: db.parse_time(db.apg_story_data[s.sub_story_id].condition_time))
115+
101116
@EventId(10140)
102117
class fpc_substory(SubStoryReader):
103118
special = True

0 commit comments

Comments
 (0)