Compare commits

...

12 Commits

5 changed files with 30 additions and 25 deletions

View File

@ -4,7 +4,7 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.23.2.5'
__version__ = '0.23.2.9'
from erepublik import classes, utils, constants
from erepublik.citizen import Citizen

View File

@ -1026,7 +1026,6 @@ class CitizenEconomy(CitizenTravel):
ret.update({house_quality: till})
return ret
@utils.wait_for_lock
def buy_and_activate_house(self, q: int) -> Optional[Dict[int, datetime]]:
original_region = self.details.current_country, self.details.current_region
ok_to_activate = False
@ -1040,14 +1039,22 @@ class CitizenEconomy(CitizenTravel):
global_cheapest = self.get_market_offers("House", q)[f"q{q}"]
if global_cheapest.price + 200 < local_cheapest.price:
if self.travel_to_country(global_cheapest.country):
buy = self.buy_from_market(global_cheapest.offer_id, 1)
if global_cheapest.price + 2000 < self.details.cc:
if self.travel_to_country(global_cheapest.country):
buy = self.buy_market_offer(global_cheapest, 1)
else:
buy = dict(error=True, message='Unable to travel!')
else:
buy = {'error': True, 'message': 'Unable to travel!'}
buy = dict(error=True, message='Not enough money to buy house!')
else:
buy = self.buy_from_market(local_cheapest.offer_id, 1)
if buy["error"]:
msg = f"Unable to buy q{q} house! \n{buy['message']}"
if local_cheapest.price < self.details.cc:
buy = self.buy_market_offer(local_cheapest, 1)
else:
buy = dict(error=True, message='Not enough money to buy house!')
if buy is None:
pass
elif buy["error"]:
msg = f'Unable to buy q{q} house! \n{buy["message"]}'
self.write_log(msg)
else:
ok_to_activate = True
@ -1151,11 +1158,13 @@ class CitizenEconomy(CitizenTravel):
return False
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]:
self.write_log(f"Trying to sell unsupported industry {industry}")
_inv_qlt = quality if industry in [1, 2, 3, 4, 23] else 0
_kind = 'final' if industry in [1, 2, 4, 4, 23] else 'raw'
_kind = 'final' if industry in [1, 2, 4, 23] else 'raw'
inventory = self.get_inventory()
items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}})
if items[_inv_qlt]['amount'] < amount:
@ -1180,7 +1189,7 @@ class CitizenEconomy(CitizenTravel):
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret)
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)
json_ret = ret.json()
if not json_ret.get('error', True):
@ -1198,13 +1207,7 @@ class CitizenEconomy(CitizenTravel):
if not self.details.current_country == offer.country:
traveled = True
self.travel_to_country(offer.country)
ret = self._post_economy_marketplace_actions('buy', offer=offer.offer_id, amount=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)
json_ret = self.buy_from_market(offer.offer_id, amount)
if traveled:
self.travel_to_residence()
return json_ret
@ -1693,6 +1696,8 @@ class CitizenMilitary(CitizenTravel):
for battle in self.sorted_battles(self.config.sort_battles_time):
if not isinstance(battle, classes.Battle):
continue
if battle.is_dict_lib:
continue
battle_zone: Optional[classes.BattleDivision] = None
for div in battle.div.values():
if div.terrain == 0:
@ -1844,6 +1849,9 @@ class CitizenMilitary(CitizenTravel):
elif r_json.get("message") == "ZONE_INACTIVE":
self.write_log("Wrong division!!")
return 0, 10, 0
elif r_json.get("message") == "NON_BELLIGERENT":
self.write_log("Dictatorship/Liberation wars are not supported!")
return 0, 10, 0
elif r_json.get("message") in ["FIGHT_DISABLED", "DEPLOYMENT_MODE"]:
self._post_main_profile_update('options',
params='{"optionName":"enable_web_deploy","optionValue":"off"}')
@ -2441,10 +2449,8 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
self.update_citizen_info()
self.reporter.do_init()
if self.config.telegram:
# noinspection SpellCheckingInspection
self.telegram.do_init(self.config.telegram_chat_id or 620981703,
self.config.telegram_token or "864251270:AAFzZZdjspI-kIgJVk4gF3TViGFoHnf8H4o",
"" if self.config.telegram_chat_id or self.config.telegram_token else self.name)
if self.config.telegram_chat_id and self.config.telegram_token:
self.telegram.do_init(self.config.telegram_chat_id, self.config.telegram_token, self.name)
self.telegram.send_message(f"*Started* {utils.now():%F %T}")
self.update_all(True)
@ -2465,7 +2471,6 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
if self.details.gold >= 54:
self.buy_tg_contract()
else:
self.write_log(f"Training ground contract active but "
f"don't have enough gold ({self.details.gold}g {self.details.cc}cc)")
if self.energy.is_energy_full and self.config.telegram:

View File

@ -1016,7 +1016,7 @@ class TelegramBot:
class OfferItem(NamedTuple):
price: float = 99_999.
price: float = 999_999_999.
country: constants.Country = constants.Country(0, "", "", "")
amount: int = 0
offer_id: int = 0

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.23.2.5
current_version = 0.23.2.9
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?

View File

@ -50,6 +50,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik/',
version='0.23.2.5',
version='0.23.2.9',
zip_safe=False,
)