Compare commits
47 Commits
Author | SHA1 | Date | |
---|---|---|---|
32546505b9 | |||
00ceabf8e3 | |||
19113da8e6 | |||
3ad7172925 | |||
179f1a0892 | |||
65adf707e2 | |||
29f9ce5ccc | |||
fa3881bf10 | |||
c1e8e94cba | |||
8133461fd7 | |||
c87333411a | |||
d679006b34 | |||
fa308db074 | |||
a080163af9 | |||
8aa159edf7 | |||
1211a98227 | |||
734a5ef2b6 | |||
5c3b405ca8 | |||
75de8fce96 | |||
01e5e44350 | |||
500409f74a | |||
9d79bb713c | |||
684b2a6ba4 | |||
447aee8134 | |||
64249fc3d9 | |||
95a78b6e7e | |||
b338ea598a | |||
b88e7973e8 | |||
c671425531 | |||
08937d06e4 | |||
cec4510831 | |||
cfb9501647 | |||
d419211955 | |||
0ea144db17 | |||
1418f580cd | |||
49575bddf5 | |||
c874247335 | |||
6e9def4394 | |||
d6fbaa7945 | |||
eb740c60c7 | |||
240c409739 | |||
f348a315c5 | |||
7a09eea2b4 | |||
81b1069cf0 | |||
429d43df15 | |||
c81986d65e | |||
7bb988f716 |
24
HISTORY.rst
24
HISTORY.rst
@ -2,6 +2,30 @@
|
|||||||
History
|
History
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
0.23.2 (2020-12-01)
|
||||||
|
-------------------
|
||||||
|
* Added concurrency checks to guard against simultaneous fighting/wam'ing/traveling
|
||||||
|
* For concurrency checking use `utils.wait_for_lock` decorator
|
||||||
|
|
||||||
|
0.23.1 (2020-12-01)
|
||||||
|
-------------------
|
||||||
|
* Separated battle finding logic from CitizenMilitary.find_battle_and_fight method
|
||||||
|
* Base dmg calculations
|
||||||
|
* Get max hit value for divisions on current side
|
||||||
|
* Added method to get division stats
|
||||||
|
* Wheel of fortune updates
|
||||||
|
|
||||||
|
0.23.0 (2020-11-26)
|
||||||
|
-------------------
|
||||||
|
* ***0.23 - last supported version for Python 3.7.***
|
||||||
|
* Added `Config.maverick` switch, to allow/deny automated fighting in non native divisions if the player has MaverickPack
|
||||||
|
* Added `CitizenMedia.get_article(article_id:int)` method to get article data
|
||||||
|
* Added `CitizenMedia.delete_article(article_id:int)` method to delete article
|
||||||
|
* Fixed `CitizenTravel.travel_to_region(region_id:int)` method
|
||||||
|
* Added `CitizenAnniversary.collect_map_quest_node(node_id:int, extra:bool=False)` to collect also extra rewards
|
||||||
|
* Fixed `CitizenTasks.work()` when employer out of money - resign and find a new job
|
||||||
|
* Fixed `CitizenEconomy.post_market_offer()`
|
||||||
|
|
||||||
0.22.3 (2020-11-16)
|
0.22.3 (2020-11-16)
|
||||||
-------------------
|
-------------------
|
||||||
* Fixed round to even bug when doing wam and not enough raw.
|
* Fixed round to even bug when doing wam and not enough raw.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
__author__ = """Eriks Karls"""
|
__author__ = """Eriks Karls"""
|
||||||
__email__ = 'eriks@72.lv'
|
__email__ = 'eriks@72.lv'
|
||||||
__version__ = '0.22.3'
|
__version__ = '0.23.2.7'
|
||||||
|
|
||||||
from erepublik import classes, utils, constants
|
from erepublik import classes, utils, constants
|
||||||
from erepublik.citizen import Citizen
|
from erepublik.citizen import Citizen
|
||||||
|
@ -29,14 +29,10 @@ class SlowRequests(Session):
|
|||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0',
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0',
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0',
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0',
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
|
|
||||||
'Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0',
|
'Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0',
|
'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0',
|
'Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
|
'Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0',
|
|
||||||
'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
|
|
||||||
]
|
]
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
|
|
||||||
@ -87,9 +83,9 @@ class SlowRequests(Session):
|
|||||||
|
|
||||||
body = "[{dt}]\tURL: '{url}'\tMETHOD: {met}\tARGS: {args}\n".format(dt=utils.now().strftime("%F %T"),
|
body = "[{dt}]\tURL: '{url}'\tMETHOD: {met}\tARGS: {args}\n".format(dt=utils.now().strftime("%F %T"),
|
||||||
url=url, met=method, args=args)
|
url=url, met=method, args=args)
|
||||||
utils.get_file(self.request_log_name)
|
|
||||||
with open(self.request_log_name, 'ab') as file:
|
with open(self.request_log_name, 'ab') as file:
|
||||||
file.write(body.encode("UTF-8"))
|
file.write(body.encode("UTF-8"))
|
||||||
|
pass
|
||||||
|
|
||||||
def _log_response(self, url, resp, redirect: bool = False):
|
def _log_response(self, url, resp, redirect: bool = False):
|
||||||
from erepublik import Citizen
|
from erepublik import Citizen
|
||||||
@ -113,8 +109,8 @@ class SlowRequests(Session):
|
|||||||
file_data.update({"ext": "html"})
|
file_data.update({"ext": "html"})
|
||||||
|
|
||||||
filename = 'debug/requests/{time}_{name}{extra}.{ext}'.format(**file_data)
|
filename = 'debug/requests/{time}_{name}{extra}.{ext}'.format(**file_data)
|
||||||
with open(utils.get_file(filename), 'wb') as f:
|
utils.write_file(filename, resp.text)
|
||||||
f.write(resp.text.encode('utf-8'))
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CitizenBaseAPI:
|
class CitizenBaseAPI:
|
||||||
@ -161,8 +157,10 @@ class ErepublikAnniversaryAPI(CitizenBaseAPI):
|
|||||||
data = {'nodeId': node_id, '_token': self.token, "currencyCost": currency_amount}
|
data = {'nodeId': node_id, '_token': self.token, "currencyCost": currency_amount}
|
||||||
return self.post(f"{self.url}/main/map-rewards-speedup", data=data)
|
return self.post(f"{self.url}/main/map-rewards-speedup", data=data)
|
||||||
|
|
||||||
def _post_map_rewards_claim(self, node_id: int) -> Response:
|
def _post_map_rewards_claim(self, node_id: int, extra: bool = False) -> Response:
|
||||||
data = {'nodeId': node_id, '_token': self.token}
|
data = {'nodeId': node_id, '_token': self.token}
|
||||||
|
if extra:
|
||||||
|
data['claimExtra'] = 1
|
||||||
return self.post(f"{self.url}/main/map-rewards-claim", data=data)
|
return self.post(f"{self.url}/main/map-rewards-claim", data=data)
|
||||||
|
|
||||||
def _post_main_wheel_of_fortune_spin(self, cost) -> Response:
|
def _post_main_wheel_of_fortune_spin(self, cost) -> Response:
|
||||||
@ -176,6 +174,9 @@ class ErepublikArticleAPI(CitizenBaseAPI):
|
|||||||
def _get_main_article_json(self, article_id: int) -> Response:
|
def _get_main_article_json(self, article_id: int) -> Response:
|
||||||
return self.get(f"{self.url}/main/articleJson/{article_id}")
|
return self.get(f"{self.url}/main/articleJson/{article_id}")
|
||||||
|
|
||||||
|
def _get_main_delete_article(self, article_id: int) -> Response:
|
||||||
|
return self.get(f"{self.url}/main/delete-article/{article_id}/1")
|
||||||
|
|
||||||
def _post_main_article_comments(self, article_id: int, page: int = 1) -> Response:
|
def _post_main_article_comments(self, article_id: int, page: int = 1) -> Response:
|
||||||
data = dict(_token=self.token, articleId=article_id, page=page)
|
data = dict(_token=self.token, articleId=article_id, page=page)
|
||||||
if page:
|
if page:
|
||||||
@ -383,6 +384,9 @@ class ErepublikLocationAPI(CitizenBaseAPI):
|
|||||||
|
|
||||||
|
|
||||||
class ErepublikMilitaryAPI(CitizenBaseAPI):
|
class ErepublikMilitaryAPI(CitizenBaseAPI):
|
||||||
|
def _get_military_battle_stats(self, battle_id: int, division: int, division_id: int):
|
||||||
|
return self.get(f"{self.url}/military/battle-stats/{battle_id}/{division}/{division_id}")
|
||||||
|
|
||||||
def _get_military_battlefield_choose_side(self, battle_id: int, side_id: int) -> Response:
|
def _get_military_battlefield_choose_side(self, battle_id: int, side_id: int) -> Response:
|
||||||
return self.get(f"{self.url}/military/battlefield-choose-side/{battle_id}/{side_id}")
|
return self.get(f"{self.url}/military/battlefield-choose-side/{battle_id}/{side_id}")
|
||||||
|
|
||||||
|
@ -33,13 +33,16 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
maverick: bool = False
|
maverick: bool = False
|
||||||
|
|
||||||
eday: int = 0
|
eday: int = 0
|
||||||
|
wheel_of_fortune: bool
|
||||||
|
|
||||||
|
debug: bool = False
|
||||||
config: classes.Config = None
|
config: classes.Config = None
|
||||||
energy: classes.Energy = None
|
energy: classes.Energy = None
|
||||||
details: classes.Details = None
|
details: classes.Details = None
|
||||||
politics: classes.Politics = None
|
politics: classes.Politics = None
|
||||||
reporter: classes.Reporter = None
|
reporter: classes.Reporter = None
|
||||||
stop_threads: Event = None
|
stop_threads: Event = None
|
||||||
|
concurrency_available: Event = None
|
||||||
telegram: classes.TelegramBot = None
|
telegram: classes.TelegramBot = None
|
||||||
|
|
||||||
r: Response = None
|
r: Response = None
|
||||||
@ -56,12 +59,15 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
self.my_companies = classes.MyCompanies(self)
|
self.my_companies = classes.MyCompanies(self)
|
||||||
self.reporter = classes.Reporter(self)
|
self.reporter = classes.Reporter(self)
|
||||||
self.stop_threads = Event()
|
self.stop_threads = Event()
|
||||||
|
self.concurrency_available = Event()
|
||||||
|
self.concurrency_available.set()
|
||||||
self.telegram = classes.TelegramBot(stop_event=self.stop_threads)
|
self.telegram = classes.TelegramBot(stop_event=self.stop_threads)
|
||||||
|
|
||||||
self.config.email = email
|
self.config.email = email
|
||||||
self.config.password = password
|
self.config.password = password
|
||||||
self.inventory = {}
|
self.inventory = {}
|
||||||
self.inventory_status = dict(used=0, total=0)
|
self.inventory_status = dict(used=0, total=0)
|
||||||
|
self.wheel_of_fortune = False
|
||||||
|
|
||||||
def get_csrf_token(self):
|
def get_csrf_token(self):
|
||||||
"""
|
"""
|
||||||
@ -230,6 +236,9 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
self.politics.is_party_president = bool(party.get('is_party_president'))
|
self.politics.is_party_president = bool(party.get('is_party_president'))
|
||||||
self.politics.party_slug = f"{party.get('stripped_title')}-{party.get('party_id')}"
|
self.politics.party_slug = f"{party.get('stripped_title')}-{party.get('party_id')}"
|
||||||
|
|
||||||
|
self.wheel_of_fortune = bool(
|
||||||
|
re.search(r'<a id="launch_wof" class="powerspin_sidebar( show_free)?" href="javascript:">', html))
|
||||||
|
|
||||||
def update_inventory(self):
|
def update_inventory(self):
|
||||||
"""
|
"""
|
||||||
Updates class properties and returns structured inventory.
|
Updates class properties and returns structured inventory.
|
||||||
@ -416,6 +425,10 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
else:
|
else:
|
||||||
sleep(seconds)
|
sleep(seconds)
|
||||||
|
|
||||||
|
def set_debug(self, debug: bool):
|
||||||
|
self.debug = bool(debug)
|
||||||
|
self._req.debug = bool(debug)
|
||||||
|
|
||||||
def to_json(self, indent: bool = False) -> str:
|
def to_json(self, indent: bool = False) -> str:
|
||||||
return utils.json.dumps(self, cls=classes.MyJSONEncoder, indent=4 if indent else None)
|
return utils.json.dumps(self, cls=classes.MyJSONEncoder, indent=4 if indent else None)
|
||||||
|
|
||||||
@ -731,31 +744,41 @@ class CitizenAnniversary(BaseCitizen):
|
|||||||
def start_unlocking_map_quest_node(self, node_id: int):
|
def start_unlocking_map_quest_node(self, node_id: int):
|
||||||
return self._post_map_rewards_unlock(node_id)
|
return self._post_map_rewards_unlock(node_id)
|
||||||
|
|
||||||
def collect_map_quest_node(self, node_id: int):
|
def collect_map_quest_node(self, node_id: int, extra: bool = False):
|
||||||
return self._post_map_rewards_claim(node_id)
|
return self._post_map_rewards_claim(node_id, extra)
|
||||||
|
|
||||||
def speedup_map_quest_node(self, node_id: int):
|
def speedup_map_quest_node(self, node_id: int):
|
||||||
node = self.get_anniversary_quest_data().get('cities', {}).get(str(node_id), {})
|
node = self.get_anniversary_quest_data().get('cities', {}).get(str(node_id), {})
|
||||||
return self._post_map_rewards_speedup(node_id, node.get("skipCost", 0))
|
return self._post_map_rewards_speedup(node_id, node.get("skipCost", 0))
|
||||||
|
|
||||||
def spin_wheel_of_fortune(self, max_cost=0, spin_count=0):
|
def spin_wheel_of_fortune(self, max_cost=0, spin_count=0):
|
||||||
def _write_spin_data(cost, cc, prize):
|
if not self.config.spin_wheel_of_fortune:
|
||||||
self._report_action("WHEEL_SPIN", f"Cost: {cost:4d} | Currency left: {cc:,} | Prize: {prize}")
|
self.write_log("Unable to spin wheel of fortune because 'config.spin_wheel_of_fortune' is False")
|
||||||
|
return
|
||||||
|
|
||||||
|
def _write_spin_data(cost: int, prize: str):
|
||||||
|
self._report_action("WHEEL_SPIN", f"Cost: {cost:4d} | Currency left: {self.details.cc:,} | Prize: {prize}")
|
||||||
|
|
||||||
|
if not self.wheel_of_fortune:
|
||||||
|
self.update_citizen_info()
|
||||||
base = self._post_main_wheel_of_fortune_build().json()
|
base = self._post_main_wheel_of_fortune_build().json()
|
||||||
current_cost = 0 if base.get('progress').get('free_spin') else base.get('cost')
|
current_cost = 0 if base.get('progress').get('free_spin') else base.get('cost')
|
||||||
current_count = base.get('progress').get('spins')
|
current_count = base.get('progress').get('spins')
|
||||||
|
prizes = base.get('prizes')
|
||||||
if not max_cost and not spin_count:
|
if not max_cost and not spin_count:
|
||||||
r = self._post_main_wheel_of_fortune_spin(current_cost).json()
|
r = self._post_main_wheel_of_fortune_spin(current_cost).json()
|
||||||
_write_spin_data(current_cost, r.get('account'),
|
_write_spin_data(current_cost, prizes.get('prizes').get(str(r.get('result'))).get('tooltip'))
|
||||||
base.get('prizes').get('prizes').get(str(r.get('result'))).get('tooltip'))
|
|
||||||
else:
|
else:
|
||||||
while max_cost >= current_cost if max_cost else spin_count >= current_count if spin_count else False:
|
while max_cost >= current_cost if max_cost else spin_count >= current_count if spin_count else False:
|
||||||
r = self._spin_wheel_of_loosing(current_cost)
|
r = self._spin_wheel_of_loosing(current_cost)
|
||||||
current_count += 1
|
current_count += 1
|
||||||
|
prize_name = prizes.get('prizes').get(str(r.get('result'))).get('tooltip')
|
||||||
|
if r.get('result') == 7:
|
||||||
|
prize_name += f" - {prizes.get('jackpot').get(str(r.get('jackpot'))).get('tooltip')}"
|
||||||
|
_write_spin_data(current_cost, prize_name)
|
||||||
current_cost = r.get('cost')
|
current_cost = r.get('cost')
|
||||||
_write_spin_data(current_cost, r.get('account'),
|
if r.get('jackpot', 0) == 3:
|
||||||
base.get('prizes').get('prizes').get(str(r.get('result'))).get('tooltip'))
|
return
|
||||||
|
|
||||||
def _spin_wheel_of_loosing(self, current_cost: int) -> Dict[str, Any]:
|
def _spin_wheel_of_loosing(self, current_cost: int) -> Dict[str, Any]:
|
||||||
r = self._post_main_wheel_of_fortune_spin(current_cost).json()
|
r = self._post_main_wheel_of_fortune_spin(current_cost).json()
|
||||||
@ -808,7 +831,14 @@ class CitizenTravel(BaseCitizen):
|
|||||||
if data.get('alreadyInRegion'):
|
if data.get('alreadyInRegion'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
country = constants.COUNTRIES[data.get('preselectCountryId')]
|
country = None
|
||||||
|
for country_data in data.get('countries').values():
|
||||||
|
if region_id in country_data.get('regions'):
|
||||||
|
country = constants.COUNTRIES[country_data.get('id')]
|
||||||
|
break
|
||||||
|
|
||||||
|
if country is None:
|
||||||
|
raise classes.ErepublikException('Region not found!')
|
||||||
|
|
||||||
if self._travel(country, region_id):
|
if self._travel(country, region_id):
|
||||||
self._report_action("TRAVEL", "Traveled to region")
|
self._report_action("TRAVEL", "Traveled to region")
|
||||||
@ -906,6 +936,7 @@ class CitizenCompanies(BaseCitizen):
|
|||||||
def work_as_manager_in_holding(self, holding: classes.Holding) -> Optional[Dict[str, Any]]:
|
def work_as_manager_in_holding(self, holding: classes.Holding) -> Optional[Dict[str, Any]]:
|
||||||
return self._work_as_manager(holding)
|
return self._work_as_manager(holding)
|
||||||
|
|
||||||
|
@utils.wait_for_lock
|
||||||
def _work_as_manager(self, wam_holding: classes.Holding) -> Optional[Dict[str, Any]]:
|
def _work_as_manager(self, wam_holding: classes.Holding) -> Optional[Dict[str, Any]]:
|
||||||
if self.restricted_ip:
|
if self.restricted_ip:
|
||||||
return None
|
return None
|
||||||
@ -995,7 +1026,7 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
ret.update({house_quality: till})
|
ret.update({house_quality: till})
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def buy_and_activate_house(self, q: int) -> Dict[int, datetime]:
|
def buy_and_activate_house(self, q: int) -> Optional[Dict[int, datetime]]:
|
||||||
original_region = self.details.current_country, self.details.current_region
|
original_region = self.details.current_country, self.details.current_region
|
||||||
ok_to_activate = False
|
ok_to_activate = False
|
||||||
inv = self.get_inventory()
|
inv = self.get_inventory()
|
||||||
@ -1009,12 +1040,14 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
global_cheapest = self.get_market_offers("House", q)[f"q{q}"]
|
global_cheapest = self.get_market_offers("House", q)[f"q{q}"]
|
||||||
if global_cheapest.price + 200 < local_cheapest.price:
|
if global_cheapest.price + 200 < local_cheapest.price:
|
||||||
if self.travel_to_country(global_cheapest.country):
|
if self.travel_to_country(global_cheapest.country):
|
||||||
buy = self.buy_from_market(global_cheapest.offer_id, 1)
|
buy = self.buy_market_offer(global_cheapest, 1)
|
||||||
else:
|
else:
|
||||||
buy = {'error': True, 'message': 'Unable to travel!'}
|
buy = {'error': True, 'message': 'Unable to travel!'}
|
||||||
else:
|
else:
|
||||||
buy = self.buy_from_market(local_cheapest.offer_id, 1)
|
buy = self.buy_market_offer(local_cheapest, 1)
|
||||||
if buy["error"]:
|
if buy is None:
|
||||||
|
pass
|
||||||
|
elif buy["error"]:
|
||||||
msg = f"Unable to buy q{q} house! \n{buy['message']}"
|
msg = f"Unable to buy q{q} house! \n{buy['message']}"
|
||||||
self.write_log(msg)
|
self.write_log(msg)
|
||||||
else:
|
else:
|
||||||
@ -1036,7 +1069,9 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
house_durability = self.check_house_durability()
|
house_durability = self.check_house_durability()
|
||||||
for q, active_till in house_durability.items():
|
for q, active_till in house_durability.items():
|
||||||
if utils.good_timedelta(active_till, - timedelta(hours=48)) <= self.now or forced:
|
if utils.good_timedelta(active_till, - timedelta(hours=48)) <= self.now or forced:
|
||||||
house_durability = self.buy_and_activate_house(q)
|
durability = self.buy_and_activate_house(q)
|
||||||
|
if durability:
|
||||||
|
house_durability = durability
|
||||||
return house_durability
|
return house_durability
|
||||||
|
|
||||||
def activate_house(self, quality: int) -> bool:
|
def activate_house(self, quality: int) -> bool:
|
||||||
@ -1117,17 +1152,21 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def post_market_offer(self, industry: int, quality: int, amount: int, price: float) -> bool:
|
def post_market_offer(self, industry: int, quality: int, amount: int, price: float) -> bool:
|
||||||
|
if isinstance(industry, str):
|
||||||
|
industry = constants.INDUSTRIES[industry]
|
||||||
if not constants.INDUSTRIES[industry]:
|
if not constants.INDUSTRIES[industry]:
|
||||||
self.write_log(f"Trying to sell unsupported industry {industry}")
|
self.write_log(f"Trying to sell unsupported industry {industry}")
|
||||||
|
|
||||||
final = industry in [1, 2, 4, 23]
|
_inv_qlt = quality if industry in [1, 2, 3, 4, 23] else 0
|
||||||
items = self.inventory['final' if final else 'raw'][constants.INDUSTRIES[industry]]
|
_kind = 'final' if industry in [1, 2, 4, 23] else 'raw'
|
||||||
if items[quality if final else 0]['amount'] < amount:
|
inventory = self.get_inventory()
|
||||||
self.update_inventory()
|
items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}})
|
||||||
items = self.inventory['final' if final else 'raw'][constants.INDUSTRIES[industry]]
|
if items[_inv_qlt]['amount'] < amount:
|
||||||
if items[quality if final else 0]['amount'] < amount:
|
inventory = self.get_inventory(True)
|
||||||
|
items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}})
|
||||||
|
if items[_inv_qlt]['amount'] < amount:
|
||||||
self._report_action("ECONOMY_SELL_PRODUCTS", "Unable to sell! Not enough items in storage!",
|
self._report_action("ECONOMY_SELL_PRODUCTS", "Unable to sell! Not enough items in storage!",
|
||||||
kwargs=dict(inventory=items[quality if final else 0], amount=amount))
|
kwargs=dict(inventory=items[_inv_qlt], amount=amount))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
@ -1144,7 +1183,7 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret)
|
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret)
|
||||||
return not bool(ret.get('error', True))
|
return not bool(ret.get('error', True))
|
||||||
|
|
||||||
def buy_from_market(self, offer: int, amount: int) -> dict:
|
def buy_from_market(self, offer: int, amount: int) -> Dict[str, Any]:
|
||||||
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
|
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
|
||||||
json_ret = ret.json()
|
json_ret = ret.json()
|
||||||
if not json_ret.get('error', True):
|
if not json_ret.get('error', True):
|
||||||
@ -1154,20 +1193,15 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
|
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
|
||||||
return json_ret
|
return json_ret
|
||||||
|
|
||||||
def buy_market_offer(self, offer: OfferItem, amount: int = None) -> dict:
|
@utils.wait_for_lock
|
||||||
|
def buy_market_offer(self, offer: OfferItem, amount: int = None) -> Optional[Dict[str, Any]]:
|
||||||
if amount is None or amount > offer.amount:
|
if amount is None or amount > offer.amount:
|
||||||
amount = offer.amount
|
amount = offer.amount
|
||||||
traveled = False
|
traveled = False
|
||||||
if not self.details.current_country == offer.country:
|
if not self.details.current_country == offer.country:
|
||||||
traveled = True
|
traveled = True
|
||||||
self.travel_to_country(offer.country)
|
self.travel_to_country(offer.country)
|
||||||
ret = self._post_economy_marketplace_actions('buy', offer=offer.offer_id, amount=amount)
|
json_ret = self.buy_from_market(offer.offer_id, amount)
|
||||||
json_ret = ret.json()
|
|
||||||
if not json_ret.get('error', True):
|
|
||||||
self.details.cc = ret.json()['currency']
|
|
||||||
self.details.gold = ret.json()['gold']
|
|
||||||
json_ret.pop("offerUpdate", None)
|
|
||||||
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
|
|
||||||
if traveled:
|
if traveled:
|
||||||
self.travel_to_residence()
|
self.travel_to_residence()
|
||||||
return json_ret
|
return json_ret
|
||||||
@ -1435,6 +1469,19 @@ class CitizenMedia(BaseCitizen):
|
|||||||
"\n".join(["{}: {}".format(k, v) for k, v in kinds.items()]), kind
|
"\n".join(["{}: {}".format(k, v) for k, v in kinds.items()]), kind
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def get_article(self, article_id: int) -> Dict[str, Any]:
|
||||||
|
return self._get_main_article_json(article_id).json()
|
||||||
|
|
||||||
|
def delete_article(self, article_id: int) -> NoReturn:
|
||||||
|
article_data = self.get_article(article_id)
|
||||||
|
if article_data and article_data['articleData']['canDelete']:
|
||||||
|
self._report_action("ARTICLE_DELETE",
|
||||||
|
f"Attempting to delete article '{article_data['article']['title']}' (#{article_id})",
|
||||||
|
kwargs=article_data)
|
||||||
|
self._get_main_delete_article(article_id)
|
||||||
|
else:
|
||||||
|
self.write_log(f"Unable to delete article (#{article_id})!")
|
||||||
|
|
||||||
|
|
||||||
class CitizenMilitary(CitizenTravel):
|
class CitizenMilitary(CitizenTravel):
|
||||||
all_battles: Dict[int, classes.Battle] = None
|
all_battles: Dict[int, classes.Battle] = None
|
||||||
@ -1606,6 +1653,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
def get_cheap_tp_divisions(self) -> Dict[str, List[Tuple[int, classes.BattleDivision]]]:
|
def get_cheap_tp_divisions(self) -> Dict[str, List[Tuple[int, classes.BattleDivision]]]:
|
||||||
air_divs: List[Tuple[int, classes.BattleDivision]] = []
|
air_divs: List[Tuple[int, classes.BattleDivision]] = []
|
||||||
ground_divs: List[Tuple[int, classes.BattleDivision]] = []
|
ground_divs: List[Tuple[int, classes.BattleDivision]] = []
|
||||||
|
check_maverick = self.maverick and self.config.maverick
|
||||||
for battle in reversed(self.sorted_battles(True, True)):
|
for battle in reversed(self.sorted_battles(True, True)):
|
||||||
for division in battle.div.values():
|
for division in battle.div.values():
|
||||||
is_start_ok = utils.good_timedelta(division.battle.start, timedelta(minutes=-1)) < self.now
|
is_start_ok = utils.good_timedelta(division.battle.start, timedelta(minutes=-1)) < self.now
|
||||||
@ -1618,7 +1666,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
else:
|
else:
|
||||||
air_divs.append((medal.get('1').get('raw_value'), division))
|
air_divs.append((medal.get('1').get('raw_value'), division))
|
||||||
elif not division.is_air and self.config.ground:
|
elif not division.is_air and self.config.ground:
|
||||||
if not division.div == self.division and not self.maverick:
|
if not division.div == self.division and not check_maverick:
|
||||||
continue
|
continue
|
||||||
division_medals = self.get_battle_round_data(division)
|
division_medals = self.get_battle_round_data(division)
|
||||||
medal = division_medals[self.details.citizenship == division.battle.defender.country]
|
medal = division_medals[self.details.citizenship == division.battle.defender.country]
|
||||||
@ -1635,9 +1683,10 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
def has_battle_contribution(self):
|
def has_battle_contribution(self):
|
||||||
return bool(self.__last_war_update_data.get("citizen_contribution", []))
|
return bool(self.__last_war_update_data.get("citizen_contribution", []))
|
||||||
|
|
||||||
def find_battle_and_fight(self):
|
def find_battle_to_fight(self, silent: bool = False) -> Tuple[
|
||||||
if self.should_fight()[0]:
|
classes.Battle, classes.BattleDivision, classes.BattleSide
|
||||||
self.write_log("Checking for battles to fight in...")
|
]:
|
||||||
|
self.update_war_info()
|
||||||
for battle in self.sorted_battles(self.config.sort_battles_time):
|
for battle in self.sorted_battles(self.config.sort_battles_time):
|
||||||
if not isinstance(battle, classes.Battle):
|
if not isinstance(battle, classes.Battle):
|
||||||
continue
|
continue
|
||||||
@ -1646,10 +1695,11 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
if div.terrain == 0:
|
if div.terrain == 0:
|
||||||
if div.div_end:
|
if div.div_end:
|
||||||
continue
|
continue
|
||||||
|
maverick_ok = self.maverick and self.config.maverick
|
||||||
if self.config.air and div.is_air:
|
if self.config.air and div.is_air:
|
||||||
battle_zone = div
|
battle_zone = div
|
||||||
break
|
break
|
||||||
elif self.config.ground and not div.is_air and (div.div == self.division or self.maverick):
|
elif self.config.ground and not div.is_air and (div.div == self.division or maverick_ok):
|
||||||
battle_zone = div
|
battle_zone = div
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -1667,6 +1717,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
defender_side = self.details.current_country in battle.defender.allies + [battle.defender.country, ]
|
defender_side = self.details.current_country in battle.defender.allies + [battle.defender.country, ]
|
||||||
side = battle.defender if defender_side else battle.invader
|
side = battle.defender if defender_side else battle.invader
|
||||||
|
|
||||||
|
if not silent:
|
||||||
self.write_log(battle)
|
self.write_log(battle)
|
||||||
|
|
||||||
travel = (self.config.travel_to_fight and self.should_travel_to_fight() or self.config.force_travel) \
|
travel = (self.config.travel_to_fight and self.should_travel_to_fight() or self.config.force_travel) \
|
||||||
@ -1674,6 +1725,17 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
|
|
||||||
if not travel:
|
if not travel:
|
||||||
continue
|
continue
|
||||||
|
yield battle, battle_zone, side
|
||||||
|
|
||||||
|
def find_battle_and_fight(self):
|
||||||
|
if self.should_fight()[0]:
|
||||||
|
self.write_log("Checking for battles to fight in...")
|
||||||
|
for battle, division, side in self.find_battle_to_fight():
|
||||||
|
|
||||||
|
allies = battle.invader.deployed + battle.defender.deployed + [battle.invader.country,
|
||||||
|
battle.defender.country]
|
||||||
|
|
||||||
|
travel_needed = self.details.current_country not in allies
|
||||||
|
|
||||||
if battle.start > self.now:
|
if battle.start > self.now:
|
||||||
self.sleep(utils.get_sleep_seconds(battle.start))
|
self.sleep(utils.get_sleep_seconds(battle.start))
|
||||||
@ -1690,14 +1752,16 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
|
|
||||||
if not self.travel_to_battle(battle, countries_to_travel):
|
if not self.travel_to_battle(battle, countries_to_travel):
|
||||||
break
|
break
|
||||||
if self.change_division(battle, battle_zone):
|
|
||||||
self.set_default_weapon(battle, battle_zone)
|
if self.change_division(battle, division):
|
||||||
self.fight(battle, battle_zone, side)
|
self.set_default_weapon(battle, division)
|
||||||
|
self.fight(battle, division, side)
|
||||||
self.travel_to_residence()
|
self.travel_to_residence()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@utils.wait_for_lock
|
||||||
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None,
|
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None,
|
||||||
count: int = None) -> int:
|
count: int = None) -> Optional[int]:
|
||||||
"""Fight in a battle.
|
"""Fight in a battle.
|
||||||
|
|
||||||
Will auto activate booster and travel if allowed to do it.
|
Will auto activate booster and travel if allowed to do it.
|
||||||
@ -1798,7 +1862,8 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
|
|
||||||
return hits, err, damage
|
return hits, err, damage
|
||||||
|
|
||||||
def deploy_bomb(self, battle: classes.Battle, bomb_id: int, inv_side: bool = None, count: int = 1) -> int:
|
@utils.wait_for_lock
|
||||||
|
def deploy_bomb(self, battle: classes.Battle, bomb_id: int, inv_side: bool = None, count: int = 1) -> Optional[int]:
|
||||||
"""Deploy bombs in a battle for given side.
|
"""Deploy bombs in a battle for given side.
|
||||||
|
|
||||||
:param battle: Battle
|
:param battle: Battle
|
||||||
@ -1809,6 +1874,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
:return: Deployed count
|
:return: Deployed count
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(count, int) or count < 1:
|
if not isinstance(count, int) or count < 1:
|
||||||
count = 1
|
count = 1
|
||||||
has_traveled = False
|
has_traveled = False
|
||||||
@ -1972,13 +2038,8 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
count = self.energy.food_fights
|
count = self.energy.food_fights
|
||||||
msg = "Fighting all-in. Doing %i hits" % count
|
msg = "Fighting all-in. Doing %i hits" % count
|
||||||
|
|
||||||
# All-in for AIR battles
|
|
||||||
elif all([self.config.air, self.config.all_in, self.energy.available >= self.energy.limit]):
|
|
||||||
count = self.energy.food_fights
|
|
||||||
msg = "Fighting all-in in AIR. Doing %i hits" % count
|
|
||||||
|
|
||||||
# Get to next Energy +1
|
# Get to next Energy +1
|
||||||
elif self.next_reachable_energy and self.config.next_energy:
|
elif self.config.next_energy and self.next_reachable_energy:
|
||||||
count = self.next_reachable_energy
|
count = self.next_reachable_energy
|
||||||
msg = "Fighting for +1 energy. Doing %i hits" % count
|
msg = "Fighting for +1 energy. Doing %i hits" % count
|
||||||
|
|
||||||
@ -2000,6 +2061,21 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
return (r_json.get(str(battle.invader.id)).get("fighterData"),
|
return (r_json.get(str(battle.invader.id)).get("fighterData"),
|
||||||
r_json.get(str(battle.defender.id)).get("fighterData"))
|
r_json.get(str(battle.defender.id)).get("fighterData"))
|
||||||
|
|
||||||
|
def get_battle_division_stats(self, division: classes.BattleDivision) -> Dict[str, Any]:
|
||||||
|
battle = division.battle
|
||||||
|
r = self._get_military_battle_stats(battle.id, division.div, division.id)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def get_division_max_hit(self, division: classes.BattleDivision) -> int:
|
||||||
|
""" Returns max hit in division for current side (if not on either side returns 0)
|
||||||
|
|
||||||
|
:param division: BattleDivision for which to get max hit value
|
||||||
|
:type division: classes.BattleDivision
|
||||||
|
:return: max hit value
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
return self.get_battle_division_stats(division).get('maxHit', -1)
|
||||||
|
|
||||||
def schedule_attack(self, war_id: int, region_id: int, region_name: str, at_time: datetime):
|
def schedule_attack(self, war_id: int, region_id: int, region_name: str, at_time: datetime):
|
||||||
if at_time:
|
if at_time:
|
||||||
self.sleep(utils.get_sleep_seconds(at_time))
|
self.sleep(utils.get_sleep_seconds(at_time))
|
||||||
@ -2219,7 +2295,8 @@ class CitizenTasks(BaseCitizen):
|
|||||||
js = response.json()
|
js = response.json()
|
||||||
good_msg = ["already_worked", "captcha"]
|
good_msg = ["already_worked", "captcha"]
|
||||||
if not js.get("status") and not js.get("message") in good_msg:
|
if not js.get("status") and not js.get("message") in good_msg:
|
||||||
if js.get('message') == 'employee':
|
if js.get('message') in ['employee', 'money']:
|
||||||
|
self.resign_from_employer()
|
||||||
self.find_new_job()
|
self.find_new_job()
|
||||||
self.update_citizen_info()
|
self.update_citizen_info()
|
||||||
self.work()
|
self.work()
|
||||||
@ -2333,8 +2410,6 @@ class CitizenTasks(BaseCitizen):
|
|||||||
|
|
||||||
class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeaderBoard,
|
class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeaderBoard,
|
||||||
CitizenMedia, CitizenMilitary, CitizenPolitics, CitizenSocial, CitizenTasks):
|
CitizenMedia, CitizenMilitary, CitizenPolitics, CitizenSocial, CitizenTasks):
|
||||||
debug: bool = False
|
|
||||||
|
|
||||||
def __init__(self, email: str = "", password: str = "", auto_login: bool = False):
|
def __init__(self, email: str = "", password: str = "", auto_login: bool = False):
|
||||||
super().__init__(email, password)
|
super().__init__(email, password)
|
||||||
self._last_full_update = constants.min_datetime
|
self._last_full_update = constants.min_datetime
|
||||||
@ -2363,10 +2438,8 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
self.update_citizen_info()
|
self.update_citizen_info()
|
||||||
self.reporter.do_init()
|
self.reporter.do_init()
|
||||||
if self.config.telegram:
|
if self.config.telegram:
|
||||||
# noinspection SpellCheckingInspection
|
if self.config.telegram_chat_id and self.config.telegram_token:
|
||||||
self.telegram.do_init(self.config.telegram_chat_id or 620981703,
|
self.telegram.do_init(self.config.telegram_chat_id, self.config.telegram_token, self.name)
|
||||||
self.config.telegram_token or "864251270:AAFzZZdjspI-kIgJVk4gF3TViGFoHnf8H4o",
|
|
||||||
"" if self.config.telegram_chat_id or self.config.telegram_token else self.name)
|
|
||||||
self.telegram.send_message(f"*Started* {utils.now():%F %T}")
|
self.telegram.send_message(f"*Started* {utils.now():%F %T}")
|
||||||
|
|
||||||
self.update_all(True)
|
self.update_all(True)
|
||||||
@ -2387,7 +2460,6 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
if self.details.gold >= 54:
|
if self.details.gold >= 54:
|
||||||
self.buy_tg_contract()
|
self.buy_tg_contract()
|
||||||
else:
|
else:
|
||||||
|
|
||||||
self.write_log(f"Training ground contract active but "
|
self.write_log(f"Training ground contract active but "
|
||||||
f"don't have enough gold ({self.details.gold}g {self.details.cc}cc)")
|
f"don't have enough gold ({self.details.gold}g {self.details.cc}cc)")
|
||||||
if self.energy.is_energy_full and self.config.telegram:
|
if self.energy.is_energy_full and self.config.telegram:
|
||||||
@ -2434,10 +2506,6 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
for info in data.values():
|
for info in data.values():
|
||||||
self.reporter.report_action("NEW_MEDAL", info)
|
self.reporter.report_action("NEW_MEDAL", info)
|
||||||
|
|
||||||
def set_debug(self, debug: bool):
|
|
||||||
self.debug = bool(debug)
|
|
||||||
self._req.debug = bool(debug)
|
|
||||||
|
|
||||||
def set_pin(self, pin: str):
|
def set_pin(self, pin: str):
|
||||||
self.details.pin = str(pin[:4])
|
self.details.pin = str(pin[:4])
|
||||||
|
|
||||||
@ -2514,7 +2582,7 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
start_time = utils.good_timedelta(start_time, timedelta(minutes=30))
|
start_time = utils.good_timedelta(start_time, timedelta(minutes=30))
|
||||||
self.send_state_update()
|
self.send_state_update()
|
||||||
self.send_inventory_update()
|
self.send_inventory_update()
|
||||||
self.reporter.report_action('COMPANIES', json_val=self.my_companies.as_dict)
|
self.send_my_companies_update()
|
||||||
sleep_seconds = (start_time - self.now).total_seconds()
|
sleep_seconds = (start_time - self.now).total_seconds()
|
||||||
self.stop_threads.wait(sleep_seconds if sleep_seconds > 0 else 0)
|
self.stop_threads.wait(sleep_seconds if sleep_seconds > 0 else 0)
|
||||||
except: # noqa
|
except: # noqa
|
||||||
@ -2530,6 +2598,9 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
def send_inventory_update(self):
|
def send_inventory_update(self):
|
||||||
self.reporter.report_action("INVENTORY", json_val=self.get_inventory(True))
|
self.reporter.report_action("INVENTORY", json_val=self.get_inventory(True))
|
||||||
|
|
||||||
|
def send_my_companies_update(self):
|
||||||
|
self.reporter.report_action('COMPANIES', json_val=self.my_companies.as_dict)
|
||||||
|
|
||||||
def eat(self):
|
def eat(self):
|
||||||
"""
|
"""
|
||||||
Try to eat food
|
Try to eat food
|
||||||
@ -2607,7 +2678,8 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
|
|
||||||
if not best_offer.country == self.details.current_country:
|
if not best_offer.country == self.details.current_country:
|
||||||
self.travel_to_country(best_offer.country)
|
self.travel_to_country(best_offer.country)
|
||||||
self._report_action("ECONOMY_BUY", f"Attempting to buy {amount} {raw_kind} for {best_offer.price*amount}cc")
|
self._report_action("ECONOMY_BUY",
|
||||||
|
f"Attempting to buy {amount} {raw_kind} for {best_offer.price * amount}cc")
|
||||||
rj = self.buy_from_market(amount=amount, offer=best_offer.offer_id)
|
rj = self.buy_from_market(amount=amount, offer=best_offer.offer_id)
|
||||||
if not rj.get('error'):
|
if not rj.get('error'):
|
||||||
amount_needed -= amount
|
amount_needed -= amount
|
||||||
|
@ -357,6 +357,8 @@ class Config:
|
|||||||
telegram = True
|
telegram = True
|
||||||
telegram_chat_id = 0
|
telegram_chat_id = 0
|
||||||
telegram_token = ""
|
telegram_token = ""
|
||||||
|
maverick = False
|
||||||
|
spin_wheel_of_fortune = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.auto_sell = []
|
self.auto_sell = []
|
||||||
@ -389,6 +391,8 @@ class Config:
|
|||||||
self.telegram = True
|
self.telegram = True
|
||||||
self.telegram_chat_id = 0
|
self.telegram_chat_id = 0
|
||||||
self.telegram_token = ""
|
self.telegram_token = ""
|
||||||
|
self.maverick = False
|
||||||
|
self.spin_wheel_of_fortune = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
@ -397,10 +401,11 @@ class Config:
|
|||||||
fight=self.fight, air=self.air, ground=self.ground, all_in=self.all_in,
|
fight=self.fight, air=self.air, ground=self.ground, all_in=self.all_in,
|
||||||
next_energy=self.next_energy, boosters=self.boosters, travel_to_fight=self.travel_to_fight,
|
next_energy=self.next_energy, boosters=self.boosters, travel_to_fight=self.travel_to_fight,
|
||||||
always_travel=self.always_travel, epic_hunt=self.epic_hunt, epic_hunt_ebs=self.epic_hunt_ebs,
|
always_travel=self.always_travel, epic_hunt=self.epic_hunt, epic_hunt_ebs=self.epic_hunt_ebs,
|
||||||
rw_def_side=self.rw_def_side, interactive=self.interactive,
|
rw_def_side=self.rw_def_side, interactive=self.interactive, maverick=self.maverick,
|
||||||
continuous_fighting=self.continuous_fighting, auto_buy_raw=self.auto_buy_raw,
|
continuous_fighting=self.continuous_fighting, auto_buy_raw=self.auto_buy_raw,
|
||||||
force_wam=self.force_wam, sort_battles_time=self.sort_battles_time, force_travel=self.force_travel,
|
force_wam=self.force_wam, sort_battles_time=self.sort_battles_time, force_travel=self.force_travel,
|
||||||
telegram=self.telegram, telegram_chat_id=self.telegram_chat_id, telegram_token=self.telegram_token)
|
telegram=self.telegram, telegram_chat_id=self.telegram_chat_id, telegram_token=self.telegram_token,
|
||||||
|
spin_wheel_of_fortune=self.spin_wheel_of_fortune)
|
||||||
|
|
||||||
|
|
||||||
class Energy:
|
class Energy:
|
||||||
@ -714,11 +719,11 @@ class BattleSide:
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
side_text = "Defender" if self.is_defender else "Invader "
|
side_text = "Defender" if self.is_defender else "Invader "
|
||||||
return f"<BattleSide: {side_text} {self.country.name}|{self.points:02d}p>"
|
return f"<BattleSide: {side_text} {self.country.name}|{self.points:>2d}p>"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
side_text = "Defender" if self.is_defender else "Invader "
|
side_text = "Defender" if self.is_defender else "Invader "
|
||||||
return f"{side_text} {self.country.name} - {self.points:02d} points"
|
return f"{side_text} {self.country.name} - {self.points:>2d} points"
|
||||||
|
|
||||||
def __format__(self, format_spec):
|
def __format__(self, format_spec):
|
||||||
return self.country.iso
|
return self.country.iso
|
||||||
@ -784,7 +789,7 @@ class BattleDivision:
|
|||||||
return constants.TERRAINS[self.terrain]
|
return constants.TERRAINS[self.terrain]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
base_name = f"Div #{self.id} d{self.div}"
|
base_name = f"D{self.div} #{self.id}"
|
||||||
if self.terrain:
|
if self.terrain:
|
||||||
base_name += f" ({self.terrain_display})"
|
base_name += f" ({self.terrain_display})"
|
||||||
if self.div_end:
|
if self.div_end:
|
||||||
@ -894,8 +899,8 @@ class Battle:
|
|||||||
else:
|
else:
|
||||||
time_part = "-{}".format(self.start - time_now)
|
time_part = "-{}".format(self.start - time_now)
|
||||||
|
|
||||||
return (f"Battle {self.id} for {self.region_name[:16]} | "
|
return (f"Battle {self.id} for {self.region_name[:16]:16} | "
|
||||||
f"{self.invader} : {self.defender} | Round time {time_part}")
|
f"{self.invader} : {self.defender} | Round time {time_part} | {'R'+str(self.zone_id):>3}")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Battle #{self.id} {self.invader}:{self.defender} R{self.zone_id}>"
|
return f"<Battle #{self.id} {self.invader}:{self.defender} R{self.zone_id}>"
|
||||||
@ -1011,7 +1016,7 @@ class TelegramBot:
|
|||||||
|
|
||||||
|
|
||||||
class OfferItem(NamedTuple):
|
class OfferItem(NamedTuple):
|
||||||
price: float = 99_999.
|
price: float = 999_999_999.
|
||||||
country: constants.Country = constants.Country(0, "", "", "")
|
country: constants.Country = constants.Country(0, "", "", "")
|
||||||
amount: int = 0
|
amount: int = 0
|
||||||
offer_id: int = 0
|
offer_id: int = 0
|
||||||
|
@ -25,7 +25,7 @@ __all__ = ['VERSION', 'calculate_hit', 'caught_error', 'date_from_eday', 'eday_f
|
|||||||
'get_air_hit_dmg_value', 'get_file', 'get_ground_hit_dmg_value', 'get_sleep_seconds', 'good_timedelta',
|
'get_air_hit_dmg_value', 'get_file', 'get_ground_hit_dmg_value', 'get_sleep_seconds', 'good_timedelta',
|
||||||
'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now',
|
'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now',
|
||||||
'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file',
|
'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file',
|
||||||
'write_interactive_log', 'write_silent_log']
|
'write_interactive_log', 'write_silent_log', 'get_final_hit_dmg', 'wait_for_lock']
|
||||||
|
|
||||||
if not sys.version_info >= (3, 6):
|
if not sys.version_info >= (3, 6):
|
||||||
raise AssertionError('This script requires Python version 3.6 and higher\n'
|
raise AssertionError('This script requires Python version 3.6 and higher\n'
|
||||||
@ -152,7 +152,8 @@ def get_file(filepath: str) -> str:
|
|||||||
def write_file(filename: str, content: str) -> int:
|
def write_file(filename: str, content: str) -> int:
|
||||||
filename = get_file(filename)
|
filename = get_file(filename)
|
||||||
with open(filename, 'ab') as f:
|
with open(filename, 'ab') as f:
|
||||||
return f.write(content.encode("utf-8"))
|
ret = f.write(content.encode("utf-8"))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def write_request(response: requests.Response, is_error: bool = False):
|
def write_request(response: requests.Response, is_error: bool = False):
|
||||||
@ -338,17 +339,8 @@ def calculate_hit(strength: float, rang: int, tp: bool, elite: bool, ne: bool, b
|
|||||||
base_wpn = (1 + Decimal(str(weapon / 100)))
|
base_wpn = (1 + Decimal(str(weapon / 100)))
|
||||||
dmg = 10 * base_str * base_rnk * base_wpn
|
dmg = 10 * base_str * base_rnk * base_wpn
|
||||||
|
|
||||||
if elite:
|
dmg = get_final_hit_dmg(dmg, rang, tp=tp, elite=elite, ne=ne, booster=booster)
|
||||||
dmg = dmg * 11 / 10
|
return Decimal(round(dmg, dec))
|
||||||
|
|
||||||
if tp and rang >= 70:
|
|
||||||
dmg = dmg * (1 + Decimal((rang - 69) / 10))
|
|
||||||
|
|
||||||
dmg = dmg * (100 + booster) / 100
|
|
||||||
|
|
||||||
if ne:
|
|
||||||
dmg = dmg * 11 / 10
|
|
||||||
return round(dmg, dec)
|
|
||||||
|
|
||||||
|
|
||||||
def get_ground_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False,
|
def get_ground_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False,
|
||||||
@ -371,6 +363,19 @@ def get_air_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_pat
|
|||||||
return calculate_hit(0, rang, true_patriot, elite, natural_enemy, booster, weapon_power)
|
return calculate_hit(0, rang, true_patriot, elite, natural_enemy, booster, weapon_power)
|
||||||
|
|
||||||
|
|
||||||
|
def get_final_hit_dmg(base_dmg: Union[Decimal, float, str], rang: int,
|
||||||
|
tp: bool = False, elite: bool = False, ne: bool = False, booster: int = 0) -> Decimal:
|
||||||
|
dmg = Decimal(str(base_dmg))
|
||||||
|
|
||||||
|
if elite:
|
||||||
|
dmg = dmg * 11 / 10
|
||||||
|
if tp and rang >= 70:
|
||||||
|
dmg = dmg * (1 + Decimal((rang - 69) / 10))
|
||||||
|
dmg = dmg * (100 + booster) / 100
|
||||||
|
if ne:
|
||||||
|
dmg = dmg * 11 / 10
|
||||||
|
return Decimal(dmg)
|
||||||
|
|
||||||
# def _clear_up_battle_memory(battle):
|
# def _clear_up_battle_memory(battle):
|
||||||
# del battle.invader._battle, battle.defender._battle
|
# del battle.invader._battle, battle.defender._battle
|
||||||
# for div_id, division in battle.div.items():
|
# for div_id, division in battle.div.items():
|
||||||
@ -379,3 +384,19 @@ def get_air_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_pat
|
|||||||
|
|
||||||
def deprecation(message):
|
def deprecation(message):
|
||||||
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_lock(function):
|
||||||
|
def wrapper(instance, *args, **kwargs):
|
||||||
|
if not instance.concurrency_available.wait(600):
|
||||||
|
e = 'Concurrency not freed in 10min!'
|
||||||
|
instance.write_log(e)
|
||||||
|
if instance.debug:
|
||||||
|
instance.report_error(e)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
instance.concurrency_available.clear()
|
||||||
|
ret = function(instance, *args, **kwargs)
|
||||||
|
instance.concurrency_available.set()
|
||||||
|
return ret
|
||||||
|
return wrapper
|
||||||
|
@ -4,16 +4,16 @@ edx-sphinx-theme==1.5.0
|
|||||||
flake8==3.8.4
|
flake8==3.8.4
|
||||||
ipython>=7.19.0
|
ipython>=7.19.0
|
||||||
isort==5.6.4
|
isort==5.6.4
|
||||||
pip==20.2.4
|
pip==20.3
|
||||||
PyInstaller==4.0
|
PyInstaller==4.1
|
||||||
pytz==2020.4
|
pytz==2020.4
|
||||||
pytest==6.1.2
|
pytest==6.1.2
|
||||||
responses==0.12.0
|
responses==0.12.1
|
||||||
setuptools==50.3.2
|
setuptools==50.3.2
|
||||||
Sphinx==3.3.0
|
Sphinx==3.3.1
|
||||||
requests==2.24.0
|
requests==2.25.0
|
||||||
PySocks==1.7.1
|
PySocks==1.7.1
|
||||||
tox==3.20.1
|
tox==3.20.1
|
||||||
twine==3.2.0
|
twine==3.2.0
|
||||||
watchdog==0.10.3
|
watchdog==0.10.4
|
||||||
wheel==0.35.1
|
wheel==0.35.1
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.22.3
|
current_version = 0.23.2.7
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?
|
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?
|
||||||
|
6
setup.py
6
setup.py
@ -13,7 +13,7 @@ with open('HISTORY.rst') as history_file:
|
|||||||
|
|
||||||
requirements = [
|
requirements = [
|
||||||
'pytz==2020.4',
|
'pytz==2020.4',
|
||||||
'requests==2.24.0',
|
'requests==2.25.0',
|
||||||
'PySocks==1.7.1'
|
'PySocks==1.7.1'
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ setup_requirements = []
|
|||||||
|
|
||||||
test_requirements = [
|
test_requirements = [
|
||||||
"pytest==6.1.2",
|
"pytest==6.1.2",
|
||||||
"responses==0.12.0"
|
"responses==0.12.1"
|
||||||
]
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
@ -50,6 +50,6 @@ setup(
|
|||||||
test_suite='tests',
|
test_suite='tests',
|
||||||
tests_require=test_requirements,
|
tests_require=test_requirements,
|
||||||
url='https://github.com/eeriks/erepublik/',
|
url='https://github.com/eeriks/erepublik/',
|
||||||
version='0.22.3',
|
version='0.23.2.7',
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user