Skip to content

Commit

Permalink
fix: campaign error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanly109 committed Sep 1, 2024
1 parent 233c5e2 commit a497f66
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
32 changes: 24 additions & 8 deletions autopcr/core/datamgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,42 @@ def get_campaign_times(self, condition_func) -> int:
times = [db.get_campaign_times(campaign_id) for campaign_id in self.campaign_list if condition_func(campaign_id)]
if not times:
return 0
assert(len(times) == 1)
return int(times[0] // 1000)
times = max(times)
return int(times)

def get_heart_piece_campaign_times(self) -> int:
return self.get_campaign_times(db.is_heart_piece_campaign)
return self.get_campaign_times(db.is_heart_piece_campaign) // 1000

def get_star_cup_campaign_times(self) -> int:
return self.get_campaign_times(db.is_star_cup_campaign)
return self.get_campaign_times(db.is_star_cup_campaign) // 1000

def get_normal_quest_campaign_times(self) -> int:
return self.get_campaign_times(db.is_normal_quest_campaign)
return self.get_campaign_times(db.is_normal_quest_campaign) // 1000

def get_hard_quest_campaign_times(self) -> int:
return self.get_campaign_times(db.is_hard_quest_campaign)
return self.get_campaign_times(db.is_hard_quest_campaign) // 1000

def get_very_hard_quest_campaign_times(self) -> int:
return self.get_campaign_times(db.is_very_hard_quest_campaign)
return self.get_campaign_times(db.is_very_hard_quest_campaign) // 1000

def get_dungeon_mana_campaign_times(self) -> int:
return self.get_campaign_times(db.is_dungeon_mana_campaign)
return self.get_campaign_times(db.is_dungeon_mana_campaign) // 1000

def get_quest_stamina_half_campaign_times(self, quest: int) -> int:
func = lambda campaign_id: \
(
db.is_normal_quest(quest) and db.is_normal_quest_stamina_half_campaign(campaign_id)
or db.is_hard_quest(quest) and db.is_hard_quest_stamina_half_campaign(campaign_id)
or db.is_very_hard_quest(quest) and db.is_very_hard_quest_stamina_half_campaign(campaign_id)
or db.is_heart_piece_quest(quest) and db.is_heart_piece_stamina_half_campaign(campaign_id)
or db.is_star_cup_quest(quest) and db.is_star_cup_stamina_half_campaign(campaign_id)
or db.is_hatsune_normal_quest(quest) and db.is_hatsune_normal_quest_stamina_half_campaign(campaign_id)
or db.is_hatsune_hard_quest(quest) and db.is_hatsune_hard_quest_stamina_half_campaign(campaign_id)
or db.is_shiori_normal_quest(quest) and db.is_shiori_normal_quest_stamina_half_campaign(campaign_id)
or db.is_shiori_hard_quest(quest) and db.is_shiori_hard_quest_stamina_half_campaign(campaign_id)
) \
and db.is_effective_scope_in_campaign(quest, campaign_id)
return self.get_campaign_times(func)

def clear_inventory(self):
self._inventory.clear()
Expand Down
54 changes: 53 additions & 1 deletion autopcr/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ def update(self, dbmgr: dbmgr):
HatsuneSchedule.query(db)
.to_dict(lambda x: x.event_id, lambda x: x)
)


self.campaign_beginner_data: Dict[int, CampaignBeginnerDatum] = (
CampaignBeginnerDatum.query(db)
.to_dict(lambda x: x.beginner_id, lambda x: x)
)

self.campaign_schedule: Dict[int, CampaignSchedule] = (
CampaignSchedule.query(db)
.to_dict(lambda x: x.id, lambda x: x)
Expand Down Expand Up @@ -700,9 +705,18 @@ def is_star_cup_quest(self, quest_id: int) -> bool:
def is_hatsune_quest(self, quest_id: int) -> bool:
return quest_id // 1000000 == 10

def is_hatsune_normal_quest(self, quest_id: int) -> bool:
return self.is_hatsune_quest(quest_id) and (quest_id // 100) % 10 == 1

def is_hatsune_hard_quest(self, quest_id: int) -> bool:
return self.is_hatsune_quest(quest_id) and (quest_id // 100) % 10 == 2

def is_shiori_quest(self, quest_id: int) -> bool:
return quest_id // 1000000 == 20

def is_shiori_normal_quest(self, quest_id: int) -> bool:
return self.is_shiori_quest(quest_id) and (quest_id // 100) % 10 == 1

def is_shiori_hard_quest(self, quest_id: int) -> bool:
return self.is_shiori_quest(quest_id) and (quest_id // 100) % 10 == 2

Expand All @@ -721,6 +735,37 @@ def is_hard_quest_campaign(self, campaign_id: int) -> bool:
def is_very_hard_quest_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.ITEM_DROP_AMOUNT_VERY_HARD

def is_normal_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_NORMAL \
or self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_BOTH

def is_hard_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_HARD \
or self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_BOTH

def is_very_hard_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_VERY_HARD

def is_heart_piece_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_UNIQUE_EQUIP

def is_star_cup_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_HIGH_RARITY_EQUIP

def is_hatsune_normal_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_HATSUNE_NORMAL \
or self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_HATSUNE_BOTH

def is_hatsune_hard_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_HATSUNE_HARD \
or self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_HATSUNE_BOTH

def is_shiori_normal_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_SHIORI_NORMAL

def is_shiori_hard_quest_stamina_half_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.HALF_STAMINA_SHIORI_HARD

def is_dungeon_mana_campaign(self, campaign_id: int) -> bool:
return self.campaign_schedule[campaign_id].campaign_category == eCampaignCategory.GOLD_DROP_AMOUNT_DUNGEON

Expand Down Expand Up @@ -810,6 +855,13 @@ def is_campaign(self, campaign: str, now: Union[None, datetime.datetime] = None)
raise ValueError(f"不支持的庆典查询:{campaign}")
return campaign_list[campaign]()

def is_effective_scope_in_campaign(self, quest_id: int, campaign_id: int) -> bool:
beginner_id = self.campaign_schedule[campaign_id].beginner_id
if beginner_id == 0: return True
id_from = self.campaign_beginner_data[beginner_id].id_from
id_to = self.campaign_beginner_data[beginner_id].id_to
return id_from <= quest_id and quest_id <= id_to

def is_clan_battle_time(self, now: Union[None, datetime.datetime] = None) -> bool:
schedule = [(db.parse_time(schedule.start_time), db.parse_time(schedule.end_time))
for schedule in self.clan_battle_period.values()]
Expand Down

0 comments on commit a497f66

Please sign in to comment.