@@ -1040,3 +1040,92 @@ async def do_task(self, client: pcrclient):
10401040 ],
10411041 )
10421042 self ._log (f"{ self .unit_name } 突破成功" )
1043+
1044+ @description (
1045+ "批量角色升星"
1046+ "\n 忽略盈余:默认只有在角色碎片完全盈余的条件下才可以进行升星,开启后可忽略盈余检查"
1047+ "\n 升至最高星级:开启后会升级至填写的目标星级范围内的最大可升级星级"
1048+ )
1049+ @name ("角色升星" )
1050+ @unitlist ("unit_evolution_units" , "角色" )
1051+ @singlechoice ("unit_evolution_to_rarity" , "目标星级" , 5 , range (2 , 6 ))
1052+ @booltype ("unit_evolution_to_max_rarity" , "升至最高星级" , False )
1053+ @booltype ("unit_evolution_ignore_memory" , "忽略盈余" , False )
1054+ @default (False )
1055+ class unit_evolution (UnitController ):
1056+ async def do_task (self , client : pcrclient ):
1057+ self .client = client
1058+ unit_list = self .get_config ("unit_evolution_units" )
1059+ target_rarity = self .get_config ("unit_evolution_to_rarity" )
1060+ to_max_rarity = self .get_config ("unit_evolution_to_max_rarity" )
1061+ ignore_memory = self .get_config ("unit_evolution_ignore_memory" )
1062+
1063+ for unit_id in unit_list :
1064+ self .unit_id = int (unit_id )
1065+ if self .unit_id not in self .client .data .unit :
1066+ self ._warn (f"未解锁角色{ self .unit_name } " )
1067+ continue
1068+
1069+ if self .unit .unit_rarity >= target_rarity :
1070+ self ._warn (f"{ self .unit_name } 已到目标{ target_rarity } 星,无需升星" )
1071+ continue
1072+
1073+ client = self .client
1074+ token = (eInventoryType .Item , self .memory_id )
1075+ required_dict = db .rarity_up_required [unit_id ]
1076+ all_memory_demand = client .data .get_unit_memory_demand (self .unit_id )
1077+ memory_demand = {
1078+ i : sum (
1079+ required_dict [i ][token ]
1080+ for i in range (self .unit .unit_rarity + 1 , i + 1 )
1081+ )
1082+ for i in range (self .unit .unit_rarity + 1 , target_rarity + 1 )
1083+ }
1084+ rarity_memory_demand = memory_demand [target_rarity ]
1085+ memory_inventory = client .data .get_inventory (token )
1086+ all_memory_gap = all_memory_demand - memory_inventory
1087+
1088+ if not ignore_memory and all_memory_gap > 0 :
1089+ self ._warn (
1090+ f"{ self .unit_name } 记忆碎片总需求{ all_memory_demand } ,库存{ memory_inventory } ,不满足升星条件"
1091+ )
1092+ continue
1093+
1094+ if not to_max_rarity and rarity_memory_demand > memory_inventory :
1095+ self ._warn (
1096+ f"{ self .unit_name } 升至{ target_rarity } 星所需记忆碎片{ rarity_memory_demand } ,库存{ memory_inventory } ,不满足升星条件"
1097+ )
1098+ continue
1099+
1100+ min_memory_demand = min (memory_demand .values ())
1101+ if min_memory_demand > memory_inventory :
1102+ self ._warn (
1103+ f"{ self .unit_name } 碎片库存{ memory_inventory } ,升星最低需要记忆碎片{ min_memory_demand } ,不满足升星条件"
1104+ )
1105+ continue
1106+
1107+ to_rarity = min (
1108+ target_rarity ,
1109+ max (k for k , v in memory_demand .items () if memory_inventory >= v ),
1110+ )
1111+ if to_rarity != target_rarity :
1112+ self ._log (
1113+ f"{ self .unit_name } 记忆碎片库存{ memory_inventory } ,升级至{ target_rarity } 星需要{ rarity_memory_demand } 碎片"
1114+ f",最大可升级至{ to_rarity } 星"
1115+ )
1116+
1117+ # 1->2需要2w mana,2->3需要3w mana,以此类推
1118+ mana = sum (
1119+ 10_000 * i for i in range (self .unit .unit_rarity + 1 , to_rarity + 1 )
1120+ )
1121+ if not await self .client .prepare_mana (mana ): # 这点mana都没了吗
1122+ raise AbortError (f"mana不足,升星共需{ mana } " )
1123+
1124+ await client .unit_multi_evolution (
1125+ unit_id = self .unit_id ,
1126+ current_rarity = self .unit .unit_rarity ,
1127+ after_rarity = to_rarity ,
1128+ current_gold_num = self .client .data .get_mana (),
1129+ current_memory_piece_num = memory_inventory ,
1130+ )
1131+ self ._log (f"{ self .unit_name } 升星至{ to_rarity } 星" )
0 commit comments