From 411b1584876d52b1f2acbef7cff9338e0e16a05e Mon Sep 17 00:00:00 2001 From: Eriks Karls Date: Mon, 26 Aug 2019 09:32:12 +0300 Subject: [PATCH] Citizen.buy_food() now buys 48h worth of food When doing WAM and fialing because not enough food - buy food Integrated new RW side chooser --- erepublik/citizen.py | 7 ++++--- erepublik/classes.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/erepublik/citizen.py b/erepublik/citizen.py index f5dc433..18cb6fa 100644 --- a/erepublik/citizen.py +++ b/erepublik/citizen.py @@ -978,7 +978,8 @@ class Citizen(classes.CitizenAPI): break else: return self._do_wam_and_employee_work(wam_holding_id, employee_companies) - + elif response.get("message") == "not_enough_health_food": + self.buy_food() else: self.write_log("I was not able to wam and or employ because:\n{}".format(response)) wam_count = self.my_companies.get_total_wam_count() @@ -1210,7 +1211,7 @@ class Citizen(classes.CitizenAPI): def buy_food(self) -> None: self.update_money() hp_per_quality = {"q1": 2, "q2": 4, "q3": 6, "q4": 8, "q5": 10, "q6": 12, "q7": 20} - hp_needed = 24 * self.energy.interval * 10 - self.food["total"] + hp_needed = 48 * self.energy.interval * 10 - self.food["total"] local_offers = self.get_market_offers(country_id=self.details.current_country, product="food") cheapest_q, cheapest = sorted(local_offers.items(), key=lambda v: v[1]["price"] / hp_per_quality[v[0]])[0] @@ -1307,7 +1308,7 @@ class Citizen(classes.CitizenAPI): return count def _rw_choose_side(self, battle_id: int, side_id: int) -> Response: - return self._get_battlefield_choose_side(battle_id, side_id) + return self._post_battlefield_travel(side_id, battle_id) def should_travel_to_fight(self) -> bool: ret = False diff --git a/erepublik/classes.py b/erepublik/classes.py index 7ba8af5..287ff79 100644 --- a/erepublik/classes.py +++ b/erepublik/classes.py @@ -523,6 +523,10 @@ Class for unifying eRepublik known endpoints and their required/optional paramet def _get_military_campaigns(self) -> Response: return self.get("{}/military/campaigns-new/".format(self.url)) + def _get_military_show_weapons(self, battle_id: int) -> Response: + params = {"_token": self.token, "battleId": battle_id} + return self.get("{}/military/show-weapons".format(self.url), params=params) + def _get_military_unit_data(self, unit_id: int, **kwargs) -> Response: params = {"groupId": unit_id, "panel": "members", **kwargs} return self.get("{}/military/military-unit-data/".format(self.url), params=params) @@ -584,6 +588,10 @@ Class for unifying eRepublik known endpoints and their required/optional paramet return self.post("{}/military/battle-console".format(self.url), data=data) + def _post_battlefield_travel(self, side_id: int, battle_id: int) -> Response: + data = dict(_token=self.token, sideCountryId=side_id, battleId=battle_id) + return self.post("{}/main/battlefieldTravel".format(self.url), data=data) + def _post_buy_gold_items(self, currency: str, item: str, amount: int) -> Response: data = dict(itemId=item, currency=currency, amount=amount, _token=self.token) return self.post("{}/main/buyGoldItems".format(self.url), data=data) @@ -773,6 +781,11 @@ Class for unifying eRepublik known endpoints and their required/optional paramet data.update(page=page) return self.post("{}/military/battle-console".format(self.url), data=data) + def _post_military_change_weapon(self, battle_id: int, battle_zone_id: int, customization_level: int) -> Response: + data = dict(_token=self.token, battleZoneId=battle_zone_id, battleId=battle_id, + customizationLevel=customization_level) + return self.post("{}/military/change-weapon".format(self.url), data=data) + def _post_military_deploy_bomb(self, battle_id: int, bomb_id: int) -> Response: data = dict(battleId=battle_id, bombId=bomb_id, _token=self.token) return self.post("{}/military/deploy-bomb".format(self.url), data=data)