Skip to content

Commit

Permalink
Opt: reduce config write frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
Air111 committed Jul 15, 2024
1 parent 870dff6 commit e39390f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 86 deletions.
113 changes: 57 additions & 56 deletions module/campaign/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,67 +72,68 @@ def triggered_stop_condition(self, oil_check=True):
Returns:
bool: If triggered a stop condition.
"""
# Run count limit
if self.run_limit and self.config.StopCondition_RunCount <= 0:
logger.hr('Triggered stop condition: Run count')
self.config.StopCondition_RunCount = 0
self.config.Scheduler_Enable = False
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config.config_name}> campaign finished",
content=f"<{self.config.config_name}> {self.name} reached run count limit"
)
return True
# Lv120 limit
if self.config.StopCondition_ReachLevel and self.campaign.config.LV_TRIGGERED:
logger.hr(f'Triggered stop condition: Reach level {self.config.StopCondition_ReachLevel}')
self.config.Scheduler_Enable = False
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config.config_name}> campaign finished",
content=f"<{self.config.config_name}> {self.name} reached level limit"
)
return True
# Oil limit
if oil_check:
self.status_get_gems()
self.get_coin()
if self.get_oil() < max(500, self.config.StopCondition_OilLimit):
logger.hr('Triggered stop condition: Oil limit')
with self.config.multi_set():
# Run count limit
if self.run_limit and self.config.StopCondition_RunCount <= 0:
logger.hr('Triggered stop condition: Run count')
self.config.StopCondition_RunCount = 0
self.config.Scheduler_Enable = False
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config.config_name}> campaign finished",
content=f"<{self.config.config_name}> {self.name} reached run count limit"
)
return True
# Lv120 limit
if self.config.StopCondition_ReachLevel and self.campaign.config.LV_TRIGGERED:
logger.hr(f'Triggered stop condition: Reach level {self.config.StopCondition_ReachLevel}')
self.config.Scheduler_Enable = False
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config.config_name}> campaign finished",
content=f"<{self.config.config_name}> {self.name} reached level limit"
)
return True
# Oil limit
if oil_check:
self.status_get_gems()
self.get_coin()
if self.get_oil() < max(500, self.config.StopCondition_OilLimit):
logger.hr('Triggered stop condition: Oil limit')
self.config.task_delay(minute=(120, 240))
return True
# Auto search oil limit
if self.campaign.auto_search_oil_limit_triggered:
logger.hr('Triggered stop condition: Auto search oil limit')
self.config.task_delay(minute=(120, 240))
return True
# Auto search oil limit
if self.campaign.auto_search_oil_limit_triggered:
logger.hr('Triggered stop condition: Auto search oil limit')
self.config.task_delay(minute=(120, 240))
return True
# If Get a New Ship
if self.config.StopCondition_GetNewShip and self.campaign.config.GET_SHIP_TRIGGERED:
logger.hr('Triggered stop condition: Get new ship')
self.config.Scheduler_Enable = False
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config.config_name}> campaign finished",
content=f"<{self.config.config_name}> {self.name} got new ship"
)
return True
# Event limit
if oil_check and self.campaign.event_pt_limit_triggered():
logger.hr('Triggered stop condition: Event PT limit')
return True
# Auto search TaskBalancer
if self.config.TaskBalancer_Enable and self.campaign.auto_search_coin_limit_triggered:
logger.hr('Triggered stop condition: Auto search coin limit')
self.handle_task_balancer()
return True
# TaskBalancer
if oil_check and self.run_count >= 1:
if self.config.TaskBalancer_Enable and self.triggered_task_balancer():
logger.hr('Triggered stop condition: Coin limit')
# If Get a New Ship
if self.config.StopCondition_GetNewShip and self.campaign.config.GET_SHIP_TRIGGERED:
logger.hr('Triggered stop condition: Get new ship')
self.config.Scheduler_Enable = False
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config.config_name}> campaign finished",
content=f"<{self.config.config_name}> {self.name} got new ship"
)
return True
# Event limit
if oil_check and self.campaign.event_pt_limit_triggered():
logger.hr('Triggered stop condition: Event PT limit')
return True
# Auto search TaskBalancer
if self.config.TaskBalancer_Enable and self.campaign.auto_search_coin_limit_triggered:
logger.hr('Triggered stop condition: Auto search coin limit')
self.handle_task_balancer()
return True
# TaskBalancer
if oil_check and self.run_count >= 1:
if self.config.TaskBalancer_Enable and self.triggered_task_balancer():
logger.hr('Triggered stop condition: Coin limit')
self.handle_task_balancer()
return True

return False
return False

def _triggered_app_restart(self):
"""
Expand Down
49 changes: 25 additions & 24 deletions module/coalition/coalition.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,32 @@ def triggered_stop_condition(self, oil_check=False, pt_check=False):
Returns:
bool: If triggered a stop condition.
"""
# Run count limit
if self.run_limit and self.config.StopCondition_RunCount <= 0:
logger.hr('Triggered stop condition: Run count')
self.config.StopCondition_RunCount = 0
self.config.Scheduler_Enable = False
return True
# Oil limit
if oil_check:
if self.get_oil() < max(500, self.config.StopCondition_OilLimit):
logger.hr('Triggered stop condition: Oil limit')
self.config.task_delay(minute=(120, 240))
with self.config.multi_set():
# Run count limit
if self.run_limit and self.config.StopCondition_RunCount <= 0:
logger.hr('Triggered stop condition: Run count')
self.config.StopCondition_RunCount = 0
self.config.Scheduler_Enable = False
return True
# Event limit
if pt_check:
if self.event_pt_limit_triggered():
logger.hr('Triggered stop condition: Event PT limit')
return True
# TaskBalancer
if self.run_count >= 1:
if self.config.TaskBalancer_Enable and self.triggered_task_balancer():
logger.hr('Triggered stop condition: Coin limit')
self.handle_task_balancer()
return True

return False
# Oil limit
if oil_check:
if self.get_oil() < max(500, self.config.StopCondition_OilLimit):
logger.hr('Triggered stop condition: Oil limit')
self.config.task_delay(minute=(120, 240))
return True
# Event limit
if pt_check:
if self.event_pt_limit_triggered():
logger.hr('Triggered stop condition: Event PT limit')
return True
# TaskBalancer
if self.run_count >= 1:
if self.config.TaskBalancer_Enable and self.triggered_task_balancer():
logger.hr('Triggered stop condition: Coin limit')
self.handle_task_balancer()
return True

return False

def coalition_execute_once(self, event, stage, fleet):
"""
Expand Down
5 changes: 3 additions & 2 deletions module/combat/auto_search_combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ def auto_search_moving(self, skip_first_screenshot=True):
if self.is_auto_search_running():
checked_fleet = self.auto_search_watch_fleet(checked_fleet)
if not checked_oil or not checked_coin:
checked_oil = self.auto_search_watch_oil(checked_oil)
checked_coin = self.auto_search_watch_coin(checked_coin)
with self.config.multi_set():
checked_oil = self.auto_search_watch_oil(checked_oil)
checked_coin = self.auto_search_watch_coin(checked_coin)
if self.handle_retirement():
self.map_offensive_auto_search()
continue
Expand Down
5 changes: 3 additions & 2 deletions module/os_handler/action_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ def action_point_update(self):
oil = box[0]

logger.info(f'Action points: {current}({total}), oil: {oil}')
self.config.stored.Oil.value = oil
self.config.stored.ActionPoint.set(current, total)
with self.config.multi_set():
self.config.stored.Oil.value = oil
self.config.stored.ActionPoint.set(current, total)
self._action_point_current = current
self._action_point_box = box
self._action_point_total = total
Expand Down
5 changes: 3 additions & 2 deletions module/raid/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ def check_coin():
if self.appear(BATTLE_PREPARATION, offset=(30, 20)):
if self.handle_combat_automation_set(auto=auto == 'combat_auto'):
continue
check_oil()
check_coin()
with self.config.multi_set():
check_oil()
check_coin()
if self.handle_raid_ticket_use():
continue
if self.handle_retirement():
Expand Down

0 comments on commit e39390f

Please sign in to comment.