Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
feat(farmer): cache kingdom_tasks
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Jun 26, 2023
1 parent 8a3f1bf commit 4aeee99
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(self, token, captcha_solver_config):
self.building_queue_available = threading.Event()
self.research_queue_available = threading.Event()
self.train_queue_available = threading.Event()
self.kingdom_tasks = []

@staticmethod
def calc_time_diff_in_seconds(expected_ended):
Expand All @@ -133,8 +134,7 @@ def _is_building_upgradeable(self, building, buildings):
return False

if building.get('code') == BUILDING_CODE_MAP['barrack']:
current_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])
for t in current_tasks:
for t in self.kingdom_tasks:
if t.get('code') == TASK_CODE_CAMP:
return False

Expand Down Expand Up @@ -936,10 +936,10 @@ def building_farmer_thread(self, speedup=False):
:param speedup:
:return:
"""
kingdom_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])
self.kingdom_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])

silver_in_use = [t for t in kingdom_tasks if t.get('code') == TASK_CODE_SILVER_HAMMER]
gold_in_use = [t for t in kingdom_tasks if t.get('code') == TASK_CODE_GOLD_HAMMER]
silver_in_use = [t for t in self.kingdom_tasks if t.get('code') == TASK_CODE_SILVER_HAMMER]
gold_in_use = [t for t in self.kingdom_tasks if t.get('code') == TASK_CODE_GOLD_HAMMER]

if not silver_in_use or (self.has_additional_building_queue and not gold_in_use):
if not self._building_farmer_worker(speedup):
Expand All @@ -958,9 +958,9 @@ def academy_farmer_thread(self, to_max_level=False, speedup=False):
:param speedup:
:return:
"""
current_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])
self.kingdom_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])

worker_used = [t for t in current_tasks if t.get('code') == TASK_CODE_ACADEMY]
worker_used = [t for t in self.kingdom_tasks if t.get('code') == TASK_CODE_ACADEMY]

if worker_used:
if worker_used[0].get('status') != STATUS_CLAIMED:
Expand Down Expand Up @@ -1047,9 +1047,9 @@ def train_troop_thread(self, troop_code, speedup=False):
:param speedup:
:return:
"""
current_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])
self.kingdom_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])

worker_used = [t for t in current_tasks if t.get('code') == TASK_CODE_CAMP]
worker_used = [t for t in self.kingdom_tasks if t.get('code') == TASK_CODE_CAMP]

troop_training_capacity = self._troop_training_capacity()

Expand Down

0 comments on commit 4aeee99

Please sign in to comment.