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

Commit

Permalink
feat(farmer): imp on_field_objects(): add march_started logging
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Aug 24, 2023
1 parent 1558e3a commit f18d4fd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,31 +594,33 @@ def _get_available_dragos(self):

def _on_field_objects_gather(self, each_obj):
if each_obj.get('occupied'):
return
return False

if each_obj.get('code') == OBJECT_CODE_CRYSTAL_MINE and self.level < 11:
return
return False

to_loc = each_obj.get('loc')
march_troops = self._prepare_march_troops(each_obj, MARCH_TYPE_GATHER)

if not march_troops:
return
return False

if each_obj.get('code') == OBJECT_CODE_DRAGON_SOUL_CAVERN:
self._start_march(to_loc, march_troops, MARCH_TYPE_GATHER, self.available_dragos[0]['_id'])
return
return True

self._start_march(to_loc, march_troops, MARCH_TYPE_GATHER)
return True

def _on_field_objects_monster(self, each_obj):
to_loc = each_obj.get('loc')
march_troops = self._prepare_march_troops(each_obj, MARCH_TYPE_MONSTER)

if not march_troops:
return
return False

self._start_march(to_loc, march_troops, MARCH_TYPE_MONSTER)
return True

@tenacity.retry(
stop=tenacity.stop_after_attempt(4),
Expand Down Expand Up @@ -790,12 +792,13 @@ def on_field_objects(data):
logger.info(f'level not in whitelist, ignore: {each_obj}')
continue

res = False
try:
if code in set(OBJECT_MINE_CODE_LIST).intersection(target_code_set):
self._on_field_objects_gather(each_obj)
res = self._on_field_objects_gather(each_obj)

if code in set(OBJECT_MONSTER_CODE_LIST).intersection(target_code_set):
self._on_field_objects_monster(each_obj)
res = self._on_field_objects_monster(each_obj)
except OtherException as error_code:
if str(error_code) in (
'full_task', 'not_enough_troop', 'insufficient_actionpoint', 'not_open_gate',
Expand All @@ -807,7 +810,8 @@ def on_field_objects(data):
return
raise
else:
logger.info(f'march_started {code}({level}): {each_obj}')
if res is True:
logger.info(f'march_started {code}({level}): {each_obj}')

self.field_object_processed = True

Expand Down

0 comments on commit f18d4fd

Please sign in to comment.