Skip to content

Commit

Permalink
feat(farmer): imp socf_thread
Browse files Browse the repository at this point in the history
  • Loading branch information
hldh214 committed Mar 30, 2022
1 parent e67ee73 commit b1af2c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lokbot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def field_march_info(self, data):
wait=tenacity.wait_fixed(1),
retry=tenacity.retry_if_exception_type(ratelimit.RateLimitException),
)
@ratelimit.limits(calls=1, period=6)
@ratelimit.limits(calls=1, period=4)
def field_march_start(self, data):
return self.post('field/march/start', data)

Expand Down
7 changes: 2 additions & 5 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self, access_token, captcha_solver_config):
# [food, lumber, stone, gold]
self.resources = self.kingdom_enter.get('kingdom').get('resources')
self.buff_item_use_lock = threading.RLock()
self.march_start_lock = threading.RLock()
self.has_additional_building_queue = self.kingdom_enter.get('kingdom').get('vip', {}).get('level') >= 5
self.troop_queue = []
self.march_limit = 2
Expand Down Expand Up @@ -291,7 +290,7 @@ def _get_land_array():
return numpy.arange(100000, 165536).reshape(256, 256)

@functools.lru_cache()
def _get_nearest_land(self, x, y, radius=16):
def _get_nearest_land(self, x, y, radius=32):
land_array = self._get_land_array()
# current_land_id = land_array[y // 8, x // 8]
nearby_land_ids = neighbors(land_array, radius, y // 8 + 1, x // 8 + 1)
Expand Down Expand Up @@ -327,6 +326,7 @@ def _get_top_leveled_land(self, limit=1024):

return lands

@functools.lru_cache()
def _get_zone_id_by_land_id(self, land_id):
land_array = blockshaped(self._get_land_array(), 4, 4)

Expand All @@ -348,9 +348,6 @@ def _calc_distance(from_loc, to_loc):
return math.ceil(math.sqrt(math.pow(from_loc[1] - to_loc[1], 2) + math.pow(from_loc[2] - to_loc[2], 2)))

def _start_march(self, to_loc, march_troops, march_type=MARCH_TYPE_GATHER):
if not self.march_start_lock.acquire(blocking=False):
return

res = self.api.field_march_start({
'fromId': self.kingdom_enter.get('kingdom').get('fieldObjectId'),
'marchType': march_type,
Expand Down

0 comments on commit b1af2c1

Please sign in to comment.