More inventory structure updates
This commit is contained in:
parent
06d8d1c0b5
commit
e060f67666
@ -411,9 +411,17 @@ class Citizen(classes.CitizenAPI):
|
|||||||
self.my_companies.prepare_holdings(loads(have_holdings.group(1)))
|
self.my_companies.prepare_holdings(loads(have_holdings.group(1)))
|
||||||
self.my_companies.update_holding_companies()
|
self.my_companies.update_holding_companies()
|
||||||
|
|
||||||
def update_inventory(self) -> dict:
|
def update_inventory(self) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
Updates class properties and returns structured inventory.
|
||||||
|
Return structure: {status: {used: int, total: int}, items: {active/final/raw: {item_token:{quality: data}}}
|
||||||
|
If item kind is damageBoosters or aircraftDamageBoosters then kind is renamed to kind+quality and duration is
|
||||||
|
used as quality.
|
||||||
|
:return: dict
|
||||||
|
"""
|
||||||
self.food.update({"q1": 0, "q2": 0, "q3": 0, "q4": 0, "q5": 0, "q6": 0, "q7": 0})
|
self.food.update({"q1": 0, "q2": 0, "q3": 0, "q4": 0, "q5": 0, "q6": 0, "q7": 0})
|
||||||
self.eb_small = 0
|
self.eb_small = self.eb_double = self.eb_normal = 0
|
||||||
|
|
||||||
j = self._get_economy_inventory_items().json()
|
j = self._get_economy_inventory_items().json()
|
||||||
active_items = {}
|
active_items = {}
|
||||||
if j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}):
|
if j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}):
|
||||||
@ -423,22 +431,28 @@ class Citizen(classes.CitizenAPI):
|
|||||||
else:
|
else:
|
||||||
kind = item.get('type')
|
kind = item.get('type')
|
||||||
if kind not in active_items:
|
if kind not in active_items:
|
||||||
active_items[kind] = []
|
active_items[kind] = {}
|
||||||
icon = item['icon'] if item['icon'] else ""
|
icon = item['icon'] if item['icon'] else "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||||
active_items[kind].append(
|
item_data = dict(name=item.get("name"), time_left=item['active']['time_left'], icon=icon, kind=kind,
|
||||||
dict(name=item.get("name"), time_left=item['active']['time_left'], icon=icon, kind=kind,
|
quality=item.get("quality", 0))
|
||||||
quality=item.get("quality", 0))
|
|
||||||
)
|
if item.get('isPackBooster'):
|
||||||
|
active_items[kind].update({0: item_data})
|
||||||
|
else:
|
||||||
|
active_items[kind].update({item.get("quality"): item_data})
|
||||||
|
|
||||||
final_items = {}
|
final_items = {}
|
||||||
for item in j.get("inventoryItems", {}).get("finalProducts", {}).get("items", {}).values():
|
for item in j.get("inventoryItems", {}).get("finalProducts", {}).get("items", {}).values():
|
||||||
name = item['name']
|
name = item['name']
|
||||||
|
|
||||||
if item.get('type'):
|
if item.get('type'):
|
||||||
if item.get('type') in ['damageBoosters', "aircraftDamageBoosters"]:
|
if item.get('type') in ['damageBoosters', "aircraftDamageBoosters"]:
|
||||||
|
kind = "{}{}".format(item['type'], item['quality'])
|
||||||
if item['quality'] == 5:
|
if item['quality'] == 5:
|
||||||
self.boosters[50].update({item['duration']: item['amount']})
|
self.boosters[50].update({item['duration']: item['amount']})
|
||||||
elif item['quality'] == 10:
|
elif item['quality'] == 10:
|
||||||
self.boosters[100].update({item['duration']: item['amount']})
|
self.boosters[100].update({item['duration']: item['amount']})
|
||||||
|
|
||||||
delta = item['duration']
|
delta = item['duration']
|
||||||
if delta // 3600:
|
if delta // 3600:
|
||||||
name += f" {delta // 3600}h"
|
name += f" {delta // 3600}h"
|
||||||
@ -446,7 +460,8 @@ class Citizen(classes.CitizenAPI):
|
|||||||
name += f" {delta // 60 % 60}m"
|
name += f" {delta // 60 % 60}m"
|
||||||
if delta % 60:
|
if delta % 60:
|
||||||
name += f" {delta % 60}s"
|
name += f" {delta % 60}s"
|
||||||
kind = item.get('type')
|
else:
|
||||||
|
kind = item.get('type')
|
||||||
else:
|
else:
|
||||||
if item['industryId'] == 1:
|
if item['industryId'] == 1:
|
||||||
amount = item['amount']
|
amount = item['amount']
|
||||||
@ -462,23 +477,24 @@ class Citizen(classes.CitizenAPI):
|
|||||||
self.eb_small += amount
|
self.eb_small += amount
|
||||||
elif q == 14:
|
elif q == 14:
|
||||||
self.eb_small += amount
|
self.eb_small += amount
|
||||||
|
elif q == 15:
|
||||||
|
self.eb_small += amount
|
||||||
kind = re.sub(r'_q\d\d*', "", item.get('token'))
|
kind = re.sub(r'_q\d\d*', "", item.get('token'))
|
||||||
|
|
||||||
if item.get('token', "") == "house_q100":
|
if item.get('token', "") == "house_q100":
|
||||||
self.ot_points = item['amount']
|
self.ot_points = item['amount']
|
||||||
|
|
||||||
if kind not in final_items:
|
if kind not in final_items:
|
||||||
final_items[kind] = []
|
final_items[kind] = {}
|
||||||
|
|
||||||
icon = item['icon'] if item['icon'] else ""
|
icon = item['icon'] if item['icon'] else "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||||
final_items[kind].append(dict(
|
data = dict(kind=kind, quality=item.get('quality', 0), amount=item.get('amount', 0),
|
||||||
kind=kind,
|
durability=item.get('duration', 0), icon=icon, name=name)
|
||||||
quality=item.get('quality', 0),
|
if item.get('type') in ('damageBoosters', "aircraftDamageBoosters"):
|
||||||
amount=item.get('amount', 0),
|
data = {data['durability']: data}
|
||||||
durability=item.get('durability', 0),
|
else:
|
||||||
icon=icon,
|
data = {data['quality']: data}
|
||||||
name=name
|
final_items[kind].update(data)
|
||||||
))
|
|
||||||
|
|
||||||
raw_materials = {}
|
raw_materials = {}
|
||||||
if j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}):
|
if j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}):
|
||||||
@ -492,7 +508,8 @@ class Citizen(classes.CitizenAPI):
|
|||||||
kind = "raw_house"
|
kind = "raw_house"
|
||||||
if kind not in raw_materials:
|
if kind not in raw_materials:
|
||||||
raw_materials[kind] = []
|
raw_materials[kind] = []
|
||||||
icon = item['icon'] if item['icon'].startswith('//www.erepublik.net/') else "//www.erepublik.net/" + item['icon']
|
icon = (item['icon'] if item['icon'].startswith('//www.erepublik.net/') else "//www.erepublik."
|
||||||
|
"net/" + item['icon'])
|
||||||
raw_materials[kind].append(
|
raw_materials[kind].append(
|
||||||
dict(name=item.get("name"), amount=item['amount'] + (item.get('underCostruction', 0) / 100),
|
dict(name=item.get("name"), amount=item['amount'] + (item.get('underCostruction', 0) / 100),
|
||||||
icon=icon)
|
icon=icon)
|
||||||
@ -1327,9 +1344,10 @@ class Citizen(classes.CitizenAPI):
|
|||||||
def get_active_ground_damage_booster(self):
|
def get_active_ground_damage_booster(self):
|
||||||
inventory = self.update_inventory()
|
inventory = self.update_inventory()
|
||||||
quality = 0
|
quality = 0
|
||||||
for booster in inventory['items']['active'].get('damageBoosters', []):
|
if inventory['items']['active'].get('damageBoosters', {}).get(10):
|
||||||
if booster.get('quality', 0) > quality:
|
quality = 100
|
||||||
quality = quality
|
elif inventory['items']['active'].get('damageBoosters', {}).get(5):
|
||||||
|
quality = 50
|
||||||
return quality
|
return quality
|
||||||
|
|
||||||
def activate_battle_effect(self, battle_id: int, kind: str) -> Response:
|
def activate_battle_effect(self, battle_id: int, kind: str) -> Response:
|
||||||
@ -1832,9 +1850,9 @@ class Citizen(classes.CitizenAPI):
|
|||||||
def check_house_durability(self) -> Dict[int, datetime.datetime]:
|
def check_house_durability(self) -> Dict[int, datetime.datetime]:
|
||||||
ret = {}
|
ret = {}
|
||||||
inv = self.update_inventory()
|
inv = self.update_inventory()
|
||||||
for active_house in [h for h in inv['items']['active'].get('house', [])]:
|
for house_quality, active_house in inv['items']['active'].get('house', {}).items():
|
||||||
till = utils.good_timedelta(self.now, datetime.timedelta(seconds=active_house['time_left']))
|
till = utils.good_timedelta(self.now, datetime.timedelta(seconds=active_house['time_left']))
|
||||||
ret.update({active_house.get('quality'): till})
|
ret.update({house_quality: till})
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def buy_and_activate_house(self, q: int) -> Dict[int, datetime.datetime]:
|
def buy_and_activate_house(self, q: int) -> Dict[int, datetime.datetime]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user