Skip to content

Commit

Permalink
Merge pull request cc004#151 from cc004/dev
Browse files Browse the repository at this point in the history
Travel
  • Loading branch information
Lanly109 authored Nov 4, 2024
2 parents c5164a2 + c3369e2 commit 77cff8f
Show file tree
Hide file tree
Showing 18 changed files with 1,071 additions and 47 deletions.
45 changes: 43 additions & 2 deletions autopcr/core/datamgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ class datamgr(Component[apiclient]):
dispatch_units: List[UnitDataForClanMember] = None
event_sub_story: Dict[int, EventSubStory] = None
user_gold_bank_info: UserBankGoldInfo = None
ex_equips: Dict[int, ExtraEquipInfo] = None

def __init__(self):
self.finishedQuest = set()
self.hatsune_quest_dict = {}
self._inventory = {}
self.deck_list = {}
self.ex_equips = {}
self.campaign_list = []

lck = Lock()
Expand Down Expand Up @@ -253,8 +255,17 @@ def get_library_import_data(self) -> str:
def _weight_mapper(cnt: int) -> float:
return max(0, cnt) + max(0, cnt + 300) * .1 + max(0, cnt + 600) * .01 + max(0, cnt + 900) * .001

def get_quest_weght(self, require_equip: typing.Counter[ItemType]) -> Dict[int, float]: # weight demand

def get_ex_quest_weght(self, require_equip: typing.Counter[ItemType]) -> Dict[int, float]:
return (
flow(db.travel_quest_data.items())
.to_dict(lambda x: x[0], lambda x:
flow(x[1].get_rewards())
.select(lambda y: require_equip.get(y.reward_item, 0))
.sum()
)
)

def get_quest_weght(self, require_equip: typing.Counter[ItemType]) -> Dict[int, float]:
return (
flow(db.normal_quest_rewards.items())
.to_dict(lambda x: x[0], lambda x:
Expand Down Expand Up @@ -322,6 +333,27 @@ def get_pure_memory_demand_gap(self) -> typing.Counter[ItemType]: # need -- >0
gap = self.get_demand_gap(demand, lambda x: db.is_unit_pure_memory(x))
return gap

def get_clan_ex_equip_demand(self, start_rank: Union[None, int] = None, like_unit_only: bool = False) -> typing.Counter[ItemType]:
ex_type: typing.Counter[int] = Counter()
for unit_id in self.unit:
if like_unit_only and not self.unit[unit_id].favorite_flag:
continue
if start_rank and self.unit[unit_id].promotion_level < start_rank:
continue
ex_type[db.unit_ex_equipment_slot[unit_id].slot_category_1] += 1
ex_type[db.unit_ex_equipment_slot[unit_id].slot_category_2] += 1
ex_type[db.unit_ex_equipment_slot[unit_id].slot_category_3] += 1
result: typing.Counter[ItemType] = Counter({
(eInventoryType.ExtraEquip, db.ex_equipment_type_to_clan_battle_ex[ex]): cnt
for ex, cnt in ex_type.items()
})
return result

def get_clan_ex_equip_gap(self, start_rank: Union[None, int] = None, like_unit_only: bool = False) -> typing.Counter[ItemType]:
demand = self.get_clan_ex_equip_demand(start_rank, like_unit_only)
gap = self.get_demand_gap(demand, lambda x: db.is_clan_ex_equip(x))
return gap

def get_suixin_demand(self) -> Tuple[List[Tuple[ItemType, int]], int]:
cnt = 0
result: List[Tuple[ItemType, int]] = []
Expand Down Expand Up @@ -388,6 +420,8 @@ def update_inventory(self, item: InventoryInfo):
self.unit_love_data[unit_id].chara_id = unit_id
self.unit_love_data[unit_id].chara_love = 0
self.unit_love_data[unit_id].love_level = 0
elif item.type == eInventoryType.ExtraEquip:
self.ex_equips[item.id] = item.ex_equip
else:
self._inventory[token] = item.stock

Expand Down Expand Up @@ -452,6 +486,13 @@ def get_not_enough_item(self, demand: typing.Counter[ItemType]) -> List[Tuple[It
bad = [(item, cnt - self.get_inventory(item)) for item, cnt in demand.items() if cnt > self.get_inventory(item)]
return bad

def get_unit_power(self, unit_id: int) -> int:
power = db.calc_unit_power(self.unit[unit_id], set(self.read_story_ids))
return int(power + 0.5)

def is_quest_cleared(self, quest: int) -> bool:
return quest in self.quest_dict and self.quest_dict[quest].result_type == eMissionStatusType.AlreadyReceive

async def request(self, request: Request[TResponse], next: RequestHandler) -> TResponse:
resp = await next.request(request)
if resp: await resp.update(self, request)
Expand Down
74 changes: 69 additions & 5 deletions autopcr/core/pcrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .misc import errorhandler
from .datamgr import datamgr
from ..db.database import db
from typing import Tuple, Union
from typing import Callable, Tuple, Union
import typing, math

class pcrclient(apiclient):
Expand Down Expand Up @@ -50,6 +50,66 @@ async def season_ticket_new_accept(self, season_id: int, mission_id: int):
req.mission_id = mission_id
return await self.request(req)

async def travel_top(self, travel_area_id: int, get_ex_equip_album_flag: int):
if not self.data.is_quest_cleared(11018001):
raise SkipError("探险未解锁")
req = TravelTopRequest()
req.travel_area_id = travel_area_id
req.get_ex_equip_album_flag = get_ex_equip_album_flag
return await self.request(req)

async def travel_start(self, start_travel_quest_list: List[TravelStartInfo], add_lap_travel_quest_list: List[TravelQuestAddLap], start_secret_travel_quest_list: List[SecretTravelStartInfo], action_type: eTravelStartType):
req = TravelStartRequest()
req.start_travel_quest_list = start_travel_quest_list
req.add_lap_travel_quest_list = add_lap_travel_quest_list
req.start_secret_travel_quest_list = start_secret_travel_quest_list
req.action_type = action_type
req.current_currency_num = TravelCurrentCurrencyNum(jewel = self.data.jewel.free_jewel + self.data.jewel.jewel, item = self.data.get_inventory(db.travel_speed_up_paper))
return await self.request(req)

async def travel_receive_top_event_reward(self, top_event_appear_id: int, choice_number: int):
req = TravelReceiveTopEventRewardRequest()
req.top_event_appear_id = top_event_appear_id
req.choice_number = choice_number
return await self.request(req)

async def travel_receive_all(self, ex_auto_recycle_option: Union[TravelExtraEquipAutoRecycleOptionData, None] = None):
if ex_auto_recycle_option is None:
ex_auto_recycle_option = TravelExtraEquipAutoRecycleOptionData(rarity=[], frame=[], category=[])
req = TravelReceiveAllRequest()
req.ex_auto_recycle_option = ex_auto_recycle_option
return await self.request(req)

async def travel_decrease_time(self, travel_quest_id: int, travel_id: int, decrease_time_item: TravelDecreaseItem):
req = TravelDecreaseTimeRequest()
req.travel_quest_id = travel_quest_id
req.travel_id = travel_id
req.decrease_time_item = decrease_time_item
req.current_currency_num = TravelCurrentCurrencyNum(jewel = self.data.jewel.free_jewel + self.data.jewel.jewel, item = self.data.get_inventory(db.travel_speed_up_paper))
return await self.request(req)

async def travel_receive(self, travel_id: int, ex_auto_recycle_option: Union[TravelExtraEquipAutoRecycleOptionData, None] = None):
if ex_auto_recycle_option is None:
ex_auto_recycle_option = TravelExtraEquipAutoRecycleOptionData(rarity=[], frame=[], category=[])
req = TravelReceiveRequest()
req.travel_quest_id = travel_id
req.ex_auto_recycle_option = ex_auto_recycle_option
return await self.request(req)

async def travel_retire(self, travel_quest_id: int, travel_id: int, ex_auto_recycle_option: Union[TravelExtraEquipAutoRecycleOptionData, None] = None):
if ex_auto_recycle_option is None:
ex_auto_recycle_option = TravelExtraEquipAutoRecycleOptionData(rarity=[], frame=[], category=[])
req = TravelRetireRequest()
req.travel_quest_id = travel_quest_id
req.travel_id = travel_id
req.ex_auto_recycle_option = ex_auto_recycle_option
return await self.request(req)

async def travel_update_priority_unit_list(self, unit_id_list: List[int]):
req = TravelUpdatePriorityUnitListRequest()
req.unit_id_list = unit_id_list
return await self.request(req)

async def deck_update(self, deck_number: int, units: List[int]):
req = DeckUpdateRequest()
req.deck_number = deck_number
Expand Down Expand Up @@ -695,10 +755,14 @@ async def get_grand_arena_history_detail(self, log_id: int):
return await self.request(req)

async def get_arena_info(self):
if not self.data.is_quest_cleared(11004006):
raise SkipError("未解锁竞技场")
req = ArenaInfoRequest()
return await self.request(req)

async def get_grand_arena_info(self):
if not self.data.is_quest_cleared(11008015):
raise SkipError("未解锁公主竞技场")
req = GrandArenaInfoRequest()
return await self.request(req)

Expand Down Expand Up @@ -746,18 +810,18 @@ async def serlize_gacha_reward(self, gacha: GachaReward, gacha_id: int = 0):

return res

async def serlize_reward(self, reward_list: List[InventoryInfo], target: Union[ItemType, None] = None):
result = []
async def serlize_reward(self, reward_list: List[InventoryInfo], target: Union[ItemType, None] = None, filter: Union[None, Callable[[ItemType],bool]] = None):
rewards = {}
for reward in reward_list:
if target is None or (reward.type == target[0] and reward.id == target[1]):
if target and (reward.type == target[0] and reward.id == target[1]) or filter and filter((reward.type, reward.id)) or not target and not filter:
if (reward.id, reward.type) not in rewards:
rewards[(reward.id, reward.type)] = [reward.count, reward.stock, reward]
else:
rewards[(reward.id, reward.type)][0] += reward.count
rewards[(reward.id, reward.type)][1] = max(reward.stock, rewards[(reward.id, reward.type)][1])
reward_item = list(rewards.values())
reward_item = sorted(reward_item, key = lambda x: x[0], reverse = True)
result = []
for value in reward_item:
try:
result.append(f"{db.get_inventory_name(value[2])}x{value[0]}({value[1]})")
Expand Down Expand Up @@ -849,7 +913,7 @@ def set_stamina_recover_cnt(self, value: int):
self.keys['stamina_recover_times'] = value

async def quest_skip_aware(self, quest: int, times: int, recover: bool = False, is_total: bool = False):
name = db.quest_name[quest] if quest in db.quest_name else f"未知关卡{quest}"
name = db.get_quest_name(quest)
if db.is_hatsune_quest(quest):
event = db.quest_to_event[quest].event_id
if not quest in self.data.hatsune_quest_dict[event]:
Expand Down
Loading

0 comments on commit 77cff8f

Please sign in to comment.