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

Commit

Permalink
fix(farmer): _prepare_march_troops && march_size issue
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Jun 19, 2023
1 parent 7eb8868 commit 95308e5
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,24 +490,11 @@ def _prepare_march_troops(self, each_obj, march_type=MARCH_TYPE_GATHER):
return []

troop_count = sum([each_troop.get('amount') for each_troop in troops])

# we don't care about insufficient troops when gathering
if (march_type == MARCH_TYPE_MONSTER) and (need_troop_count > troop_count):
logger.info(f'Insufficient troops: {troop_count} < {need_troop_count}: {each_obj}')
return []

if troop_count > self.march_size:
logger.info(f'Troop count exceeded: {troop_count} > {self.march_size}: {each_obj}')
return []

delay = random.randint(2, 4)
logger.info('Add dummy delay: {} seconds'.format(delay))
time.sleep(delay) # add dummy delay

# distance = self._calc_distance(from_loc, to_loc)
distance = march_info.get('distance')
logger.info(f'distance: {distance}, object: {each_obj}')

march_troops = []
for troop in troops:
code = troop.get('code')
Expand Down Expand Up @@ -542,6 +529,14 @@ def _prepare_march_troops(self, each_obj, march_type=MARCH_TYPE_GATHER):
'seq': 0
})

march_troop_count = sum([each_troop.get('amount') for each_troop in march_troops])
if march_troop_count > self.march_size:
logger.info(f'Troop count exceeded: {march_troop_count} > {self.march_size}: {each_obj}')
return []

distance = march_info.get('distance')
logger.info(f'distance: {distance}, object: {each_obj}')

march_troops.sort(key=lambda x: x.get('code')) # sort by code asc

return march_troops
Expand Down

0 comments on commit 95308e5

Please sign in to comment.