|
|
|
@ -264,6 +264,8 @@ class BaseCitizen(access_points.CitizenAPI):
|
|
|
|
|
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
|
|
|
|
else:
|
|
|
|
|
kind = item_data.get('type')
|
|
|
|
|
if constants.INDUSTRIES[kind]:
|
|
|
|
|
kind = constants.INDUSTRIES[constants.INDUSTRIES[kind]]
|
|
|
|
|
if kind not in active_items:
|
|
|
|
|
active_items[kind] = {}
|
|
|
|
|
icon = item_data['icon'] if item_data[
|
|
|
|
@ -316,11 +318,15 @@ class BaseCitizen(access_points.CitizenAPI):
|
|
|
|
|
self.eb_small += amount
|
|
|
|
|
elif q == 15:
|
|
|
|
|
self.eb_small += amount
|
|
|
|
|
item_data.update(token='energy_bar')
|
|
|
|
|
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
|
|
|
|
|
|
|
|
|
if item_data.get('token', "") == "house_q100":
|
|
|
|
|
self.ot_points = item_data['amount']
|
|
|
|
|
|
|
|
|
|
if constants.INDUSTRIES[kind]:
|
|
|
|
|
kind = constants.INDUSTRIES[constants.INDUSTRIES[kind]]
|
|
|
|
|
|
|
|
|
|
if kind not in final_items:
|
|
|
|
|
final_items[kind] = {}
|
|
|
|
|
|
|
|
|
@ -339,10 +345,10 @@ class BaseCitizen(access_points.CitizenAPI):
|
|
|
|
|
icon = "/images/modules/pvp/ghost_boosters/icon_booster_30_60.png"
|
|
|
|
|
else:
|
|
|
|
|
icon = "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
|
|
|
|
item_data = dict(kind=kind, quality=item_data.get('quality', 0), amount=item_data.get('amount', 0),
|
|
|
|
|
durability=item_data.get('duration', 0), icon=icon, name=name)
|
|
|
|
|
_item_data = dict(kind=kind, quality=item_data.get('quality', 0), amount=item_data.get('amount', 0),
|
|
|
|
|
durability=item_data.get('duration', 0), icon=icon, name=name)
|
|
|
|
|
if item_data.get('type') in ('damageBoosters', "aircraftDamageBoosters"):
|
|
|
|
|
item_data = {item_data['durability']: item_data}
|
|
|
|
|
_item_data = {_item_data['durability']: _item_data}
|
|
|
|
|
else:
|
|
|
|
|
if item_data.get('type') == 'bomb':
|
|
|
|
|
firepower = 0
|
|
|
|
@ -351,9 +357,9 @@ class BaseCitizen(access_points.CitizenAPI):
|
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
|
|
|
|
finally:
|
|
|
|
|
item_data.update(fire_power=firepower)
|
|
|
|
|
item_data = {item_data['quality']: item_data}
|
|
|
|
|
final_items[kind].update(item_data)
|
|
|
|
|
_item_data.update(fire_power=firepower)
|
|
|
|
|
_item_data = {_item_data['quality']: _item_data}
|
|
|
|
|
final_items[kind].update(_item_data)
|
|
|
|
|
|
|
|
|
|
raw_materials: Dict[str, Dict[int, Dict[str, Union[str, int]]]] = {}
|
|
|
|
|
if data.get("rawMaterials", {}).get("items", {}):
|
|
|
|
@ -908,6 +914,7 @@ class CitizenCompanies(BaseCitizen):
|
|
|
|
|
|
|
|
|
|
if int(free_inventory * 0.75) < self.my_companies.get_needed_inventory_usage(wam_list):
|
|
|
|
|
self.update_inventory()
|
|
|
|
|
free_inventory = self.inventory_status["total"] - self.inventory_status["used"]
|
|
|
|
|
|
|
|
|
|
while wam_list and free_inventory < self.my_companies.get_needed_inventory_usage(wam_list):
|
|
|
|
|
wam_list.pop(-1)
|
|
|
|
@ -976,7 +983,7 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
def check_house_durability(self) -> Dict[int, datetime]:
|
|
|
|
|
ret = {}
|
|
|
|
|
inv = self.get_inventory()
|
|
|
|
|
for house_quality, active_house in inv['active'].get('house', {}).items():
|
|
|
|
|
for house_quality, active_house in inv['active'].get('House', {}).items():
|
|
|
|
|
till = utils.good_timedelta(self.now, timedelta(seconds=active_house['time_left']))
|
|
|
|
|
ret.update({house_quality: till})
|
|
|
|
|
return ret
|
|
|
|
@ -985,14 +992,14 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
original_region = self.details.current_country, self.details.current_region
|
|
|
|
|
ok_to_activate = False
|
|
|
|
|
inv = self.get_inventory()
|
|
|
|
|
if not inv['final'].get('house', {}).get(q, {}):
|
|
|
|
|
if not inv['final'].get('House', {}).get(q, {}):
|
|
|
|
|
countries = [self.details.citizenship, ]
|
|
|
|
|
if self.details.current_country != self.details.citizenship:
|
|
|
|
|
countries.append(self.details.current_country)
|
|
|
|
|
offers = [self.get_market_offers("house", q, country)[f"q{q}"] for country in countries]
|
|
|
|
|
offers = [self.get_market_offers("House", q, country)[f"q{q}"] for country in countries]
|
|
|
|
|
local_cheapest = sorted(offers, key=lambda o: o.price)[0]
|
|
|
|
|
|
|
|
|
|
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 self.travel_to_country(global_cheapest.country):
|
|
|
|
|
buy = self.buy_from_market(global_cheapest.offer_id, 1)
|
|
|
|
@ -1029,7 +1036,7 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
r: Dict[str, Any] = self._post_economy_activate_house(quality).json()
|
|
|
|
|
self._update_inventory_data(r)
|
|
|
|
|
if r.get("status") and not r.get("error"):
|
|
|
|
|
house: Dict[str, Union[int, str]] = self.get_inventory()['active']['house'][quality]
|
|
|
|
|
house: Dict[str, Union[int, str]] = self.get_inventory()['active']['House'][quality]
|
|
|
|
|
time_left = timedelta(seconds=house["time_left"])
|
|
|
|
|
active_until = utils.good_timedelta(self.now, time_left)
|
|
|
|
|
self._report_action(
|
|
|
|
@ -1085,7 +1092,7 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
offers = self.get_my_market_offers()
|
|
|
|
|
for offer in offers:
|
|
|
|
|
if offer['id'] == offer_id:
|
|
|
|
|
industry = constants.INDUSTRIES[offer['industry']]
|
|
|
|
|
industry = constants.INDUSTRIES[offer['industryId']]
|
|
|
|
|
amount = offer['amount']
|
|
|
|
|
q = offer['quality']
|
|
|
|
|
price = offer['price']
|
|
|
|
@ -1097,7 +1104,7 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
self._report_action("ECONOMY_DELETE_OFFER",
|
|
|
|
|
f"Removed offer for {amount} x {industry} q{q} for {price}cc/each",
|
|
|
|
|
kwargs=offer)
|
|
|
|
|
return ret.get('error')
|
|
|
|
|
return not ret.get('error')
|
|
|
|
|
else:
|
|
|
|
|
self._report_action("ECONOMY_DELETE_OFFER", f"Unable to find offer id{offer_id}", kwargs={'offers': offers})
|
|
|
|
|
return False
|
|
|
|
@ -1128,18 +1135,16 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
message = (f"Posted market offer for {amount}q{quality} "
|
|
|
|
|
f"{constants.INDUSTRIES[industry]} for price {price}cc")
|
|
|
|
|
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret)
|
|
|
|
|
return bool(ret.get('error', True))
|
|
|
|
|
return not bool(ret.get('error', True))
|
|
|
|
|
|
|
|
|
|
def buy_from_market(self, offer: int, amount: int) -> dict:
|
|
|
|
|
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
|
|
|
|
|
json_ret = ret.json()
|
|
|
|
|
if json_ret.get('error'):
|
|
|
|
|
return json_ret
|
|
|
|
|
else:
|
|
|
|
|
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", "", kwargs=json_ret)
|
|
|
|
|
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
|
|
|
|
|
return json_ret
|
|
|
|
|
|
|
|
|
|
def get_market_offers(
|
|
|
|
@ -1160,7 +1165,7 @@ class CitizenEconomy(CitizenTravel):
|
|
|
|
|
if quality:
|
|
|
|
|
offers[f"q{quality}"] = classes.OfferItem()
|
|
|
|
|
else:
|
|
|
|
|
max_quality = 1 if product_name in q1_industries else 5 if product_name == 'house' else 7
|
|
|
|
|
max_quality = 1 if product_name in q1_industries else 5 if product_name.lower() == 'house' else 7
|
|
|
|
|
for q in range(max_quality):
|
|
|
|
|
offers[f"q{q + 1}"] = classes.OfferItem()
|
|
|
|
|
|
|
|
|
@ -2564,6 +2569,10 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|
|
|
|
raw_kind = raw_kind.group(1)
|
|
|
|
|
result = response.get("result", {})
|
|
|
|
|
amount_needed = round(result.get("consume", 0) - result.get("stock", 0) + 0.49)
|
|
|
|
|
self._report_action(
|
|
|
|
|
'WORK_AS_MANAGER', f"Unable to wam! Missing {amount_needed} {raw_kind}, will try to buy.",
|
|
|
|
|
kwargs=response
|
|
|
|
|
)
|
|
|
|
|
start_place = (self.details.current_country, self.details.current_region)
|
|
|
|
|
while amount_needed > 0:
|
|
|
|
|
amount = amount_needed
|
|
|
|
@ -2572,20 +2581,31 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|
|
|
|
|
|
|
|
|
if not best_offer.country == self.details.current_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")
|
|
|
|
|
rj = self.buy_from_market(amount=amount, offer=best_offer.offer_id)
|
|
|
|
|
if not rj.get('error'):
|
|
|
|
|
amount_needed -= amount
|
|
|
|
|
else:
|
|
|
|
|
self.write_log(rj.get('message', ""))
|
|
|
|
|
self._report_action(
|
|
|
|
|
"ECONOMY_BUY", f"Unable to buy products! Reason: {rj.get('message')}", kwargs=rj
|
|
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
if not start_place == (self.details.current_country, self.details.current_region):
|
|
|
|
|
self.travel_to_holding(holding)
|
|
|
|
|
self._wam(holding)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if not start_place == (self.details.current_country, self.details.current_region):
|
|
|
|
|
self.travel_to_residence()
|
|
|
|
|
return
|
|
|
|
|
elif response.get("message") == "not_enough_health_food":
|
|
|
|
|
self.buy_food()
|
|
|
|
|
self._wam(holding)
|
|
|
|
|
elif response.get("message") == "tax_money":
|
|
|
|
|
self._report_action("WORK_AS_MANAGER", "Not enough money to work as manager!", kwargs=response)
|
|
|
|
|
self.write_log("Not enough money to work as manager!")
|
|
|
|
|
else:
|
|
|
|
|
msg = "I was not able to wam and or employ because:\n{}".format(response)
|
|
|
|
|
self._report_action("WORK_AS_MANAGER", f"Worked as manager failed: {msg}", kwargs=response)
|
|
|
|
|