55from ...model .common import ChangeRarityUnit , DeckListData , GachaPointInfo , GrandArenaHistoryDetailInfo , GrandArenaHistoryInfo , GrandArenaSearchOpponent , ProfileUserInfo , RankingSearchOpponent , RedeemUnitInfo , RedeemUnitSlotInfo , UnitData , UnitDataLight , VersusResult , VersusResultDetail
66from ...model .responses import GachaIndexResponse , PsyTopResponse
77from ...db .models import GachaExchangeLineup
8- from ...model .custom import ArenaQueryResult , GachaReward , ItemType
8+ from ...model .custom import ArenaQueryResult , GachaReward , ItemType , eRedeemUnitUnlockCondition
99from ..modulebase import *
1010from ..config import *
1111from ...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碎片的最优使用方案,使得剩余碎片的盈余值的最大值最小' )
3939class 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 )
0 commit comments