Update traveling to incorporate travel cooldown (1travel / 15sec)
This commit is contained in:
parent
8da376b852
commit
76edd6bb7d
@ -695,6 +695,17 @@ class CitizenTravel(BaseCitizen):
|
|||||||
self.details.current_region = region_id
|
self.details.current_region = region_id
|
||||||
self.details.current_country = country
|
self.details.current_country = country
|
||||||
|
|
||||||
|
def _travel(self, country: constants.Country, region_id: int = 0) -> bool:
|
||||||
|
r_json = super()._travel(country, region_id).json()
|
||||||
|
if not bool(r_json.get('error')):
|
||||||
|
self._update_citizen_location(country, region_id)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
if "Travelling too fast." in r_json.get('message'):
|
||||||
|
self.sleep(1)
|
||||||
|
return self._travel(country, region_id)
|
||||||
|
return False
|
||||||
|
|
||||||
def get_country_travel_region(self, country: constants.Country) -> int:
|
def get_country_travel_region(self, country: constants.Country) -> int:
|
||||||
regions = self.get_travel_regions(country=country)
|
regions = self.get_travel_regions(country=country)
|
||||||
regs = []
|
regs = []
|
||||||
@ -711,11 +722,11 @@ class CitizenTravel(BaseCitizen):
|
|||||||
self.update_citizen_info()
|
self.update_citizen_info()
|
||||||
res_r = self.details.residence_region
|
res_r = self.details.residence_region
|
||||||
if self.details.residence_country and res_r and not res_r == self.details.current_region:
|
if self.details.residence_country and res_r and not res_r == self.details.current_region:
|
||||||
r_json = self._travel(self.details.residence_country, self.details.residence_region).json()
|
if self._travel(self.details.residence_country, self.details.residence_region):
|
||||||
if r_json.get('message', '') == 'success':
|
self._report_action("TRAVEL", "Traveled to residence")
|
||||||
self._update_citizen_location(self.details.residence_country, self.details.current_region)
|
|
||||||
self._report_action("TRAVEL", "Traveled to residence", response=r_json)
|
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
|
self._report_action("TRAVEL", "Unable to travel to residence!")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -725,11 +736,13 @@ class CitizenTravel(BaseCitizen):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
country = constants.COUNTRIES[data.get('preselectCountryId')]
|
country = constants.COUNTRIES[data.get('preselectCountryId')]
|
||||||
r_json = self._travel(country, region_id).json()
|
|
||||||
if r_json.get('message', '') == 'success':
|
if self._travel(country, region_id):
|
||||||
self._update_citizen_location(country, region_id)
|
self._report_action("TRAVEL", "Traveled to region")
|
||||||
self._report_action("TRAVEL", "Traveled to region", response=r_json)
|
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
|
self._report_action("TRAVEL", "Unable to travel to region!")
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def travel_to_country(self, country: constants.Country) -> bool:
|
def travel_to_country(self, country: constants.Country) -> bool:
|
||||||
@ -742,11 +755,13 @@ class CitizenTravel(BaseCitizen):
|
|||||||
regs.append((region['id'], region['distanceInKm']))
|
regs.append((region['id'], region['distanceInKm']))
|
||||||
if regs:
|
if regs:
|
||||||
region_id = min(regs, key=lambda _: int(_[1]))[0]
|
region_id = min(regs, key=lambda _: int(_[1]))[0]
|
||||||
r_json = self._travel(country, region_id).json()
|
|
||||||
if r_json.get('message', '') == 'success':
|
if self._travel(country, region_id):
|
||||||
self._update_citizen_location(country, region_id)
|
self._report_action("TRAVEL", f"Traveled to {country.name}")
|
||||||
self._report_action("TRAVEL", f"Traveled to {country.name}", response=r_json)
|
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
|
self._report_action("TRAVEL", f"Unable to travel to {country.name}!")
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def travel_to_holding(self, holding: classes.Holding) -> bool:
|
def travel_to_holding(self, holding: classes.Holding) -> bool:
|
||||||
@ -756,14 +771,35 @@ class CitizenTravel(BaseCitizen):
|
|||||||
else:
|
else:
|
||||||
country = constants.COUNTRIES[data.get('preselectCountryId')]
|
country = constants.COUNTRIES[data.get('preselectCountryId')]
|
||||||
region_id = data.get('preselectRegionId')
|
region_id = data.get('preselectRegionId')
|
||||||
r_json = self._travel(country, region_id).json()
|
|
||||||
if r_json.get('message', '') == 'success':
|
if self._travel(country, region_id):
|
||||||
self._update_citizen_location(country, region_id)
|
self._report_action("TRAVEL", f"Traveled to {holding}")
|
||||||
self._report_action("TRAVEL", f"Traveled to holding {holding}", response=r_json)
|
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
|
self._report_action("TRAVEL", f"Unable to travel to {holding}!")
|
||||||
|
|
||||||
|
def travel_to_battle(self, battle: classes.Battle, allowed_countries: List[constants.Country]) -> bool:
|
||||||
|
data = self.get_travel_regions(battle=battle)
|
||||||
|
|
||||||
|
regs = []
|
||||||
|
countries: Dict[int, constants.Country] = {c.id: c for c in allowed_countries}
|
||||||
|
if data:
|
||||||
|
for region in data.values():
|
||||||
|
if region['countryId'] in countries: # Is not occupied by other country
|
||||||
|
regs.append((region['distanceInKm'], region['id'], countries[region['countryId']]))
|
||||||
|
if regs:
|
||||||
|
reg = min(regs, key=lambda _: int(_[0]))
|
||||||
|
region_id = reg[1]
|
||||||
|
country = reg[2]
|
||||||
|
if self._travel(country, region_id):
|
||||||
|
self._report_action("TRAVEL", f"Traveled to {battle}")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self._report_action("TRAVEL", f"Unable to travel to {battle}!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_travel_regions(self, holding: classes.Holding = None, battle: classes.Battle = None, country: constants.Country = None
|
def get_travel_regions(
|
||||||
|
self, holding: classes.Holding = None, battle: classes.Battle = None, country: constants.Country = None
|
||||||
) -> Union[List[Any], Dict[str, Dict[str, Any]]]:
|
) -> Union[List[Any], Dict[str, Dict[str, Any]]]:
|
||||||
return self._post_main_travel_data(
|
return self._post_main_travel_data(
|
||||||
holdingId=holding.id if holding else 0,
|
holdingId=holding.id if holding else 0,
|
||||||
@ -1894,25 +1930,6 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
self._post_wars_attack_region(war_id, region_id, region_name)
|
self._post_wars_attack_region(war_id, region_id, region_name)
|
||||||
self._report_action("MILITARY_QUEUE_ATTACK", f"Battle for *{region_name}* queued")
|
self._report_action("MILITARY_QUEUE_ATTACK", f"Battle for *{region_name}* queued")
|
||||||
|
|
||||||
def travel_to_battle(self, battle: classes.Battle, allowed_countries: List[constants.Country]) -> bool:
|
|
||||||
data = self.get_travel_regions(battle=battle)
|
|
||||||
|
|
||||||
regs = []
|
|
||||||
countries: Dict[int, constants.Country] = {c.id: c for c in allowed_countries}
|
|
||||||
if data:
|
|
||||||
for region in data.values():
|
|
||||||
if region['countryId'] in countries: # Is not occupied by other country
|
|
||||||
regs.append((region['distanceInKm'], region['id'], countries[region['countryId']]))
|
|
||||||
if regs:
|
|
||||||
reg = min(regs, key=lambda _: int(_[0]))
|
|
||||||
region_id = reg[1]
|
|
||||||
country = reg[2]
|
|
||||||
r = self._travel(country, region_id).json()
|
|
||||||
if r.get('message', '') == 'success':
|
|
||||||
self._update_citizen_location(country, region_id)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_country_mus(self, country: constants.Country) -> Dict[int, str]:
|
def get_country_mus(self, country: constants.Country) -> Dict[int, str]:
|
||||||
ret = {}
|
ret = {}
|
||||||
r = self._get_main_leaderboards_damage_rankings(country.id)
|
r = self._get_main_leaderboards_damage_rankings(country.id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user