Inventory structure update

This commit is contained in:
Eriks Karls 2019-10-18 18:18:39 +03:00
parent 94a87091a4
commit c7f084436d

View File

@ -416,13 +416,23 @@ class Citizen(classes.CitizenAPI):
active_items = {} active_items = {}
if j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}): if j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}):
for item in j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}).values(): for item in j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}).values():
active_items.update({item['name']: item['active']['time_left']}) if item.get('token'):
kind = re.sub(r'_q\d\d*', "", item.get('token'))
else:
kind = item.get('type')
if kind not in active_items:
active_items[kind] = []
icon = item['icon'] if item['icon'] else ""
active_items[kind].append(
dict(name=item.get("name"), time_left=item['active']['time_left'], icon=icon, kind=kind,
quality=item.get("quality", 0))
)
final_items = {} final_items = {}
if j.get("inventoryItems", {}).get("finalProducts", {}).get("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') == 'damageBoosters': if item.get('type'):
if item.get('type') in ['damageBoosters', "aircraftDamageBoosters"]:
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:
@ -434,11 +444,13 @@ 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"
elif item['industryId'] == 1: kind = item.get('type')
else:
if item['industryId'] == 1:
amount = item['amount'] amount = item['amount']
q = item['quality'] q = item['quality']
if 1 <= q <= 7: if 1 <= q <= 7:
self.food.update({f"q{q}": item['amount']}) self.food.update({f"q{q}": amount})
else: else:
if q == 10: if q == 10:
self.eb_normal = amount self.eb_normal = amount
@ -448,24 +460,41 @@ 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
kind = re.sub(r'_q\d\d*', "", item.get('token'))
elif item['industryId'] == 3 and item['quality'] == 5: if item.get('token', "") == "house_q100":
self.ot_points = item['amount'] self.ot_points = item['amount']
elif item['industryId'] == 4 and item['quality'] == 100: if kind not in final_items:
self.ot_points = item['amount'] final_items[kind] = []
if item['amount']: icon = item['icon'] if item['icon'] else ""
final_items.update({name: item['amount']}) final_items[kind].append(dict(
kind=kind,
quality=item.get('quality', 0),
amount=item.get('amount', 0),
durability=item.get('durability', 0),
icon=icon,
name=name
))
raw_materials = {} raw_materials = {}
if j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}): if j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}):
for item in j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}).values(): for item in j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}).values():
name = item['name']
if item['isPartial']: if item['isPartial']:
continue continue
if item['amount']: kind = re.sub(r'_q\d\d*', "", item.get('token'))
raw_materials.update({name: item['amount']}) if kind == "magnesium":
kind = "raw_aircraft"
elif kind == "sand":
kind = "raw_house"
if kind not in raw_materials:
raw_materials[kind] = []
icon = item['icon'] if item['icon'].startswith('//www.erepublik.net/') else "//www.erepublik.net/" + item['icon']
raw_materials[kind].append(
dict(name=item.get("name"), amount=item['amount'] + (item.get('underCostruction', 0) / 100),
icon=icon)
)
self.inventory.update({"used": j.get("inventoryStatus").get("usedStorage"), self.inventory.update({"used": j.get("inventoryStatus").get("usedStorage"),
"total": j.get("inventoryStatus").get("totalStorage")}) "total": j.get("inventoryStatus").get("totalStorage")})
@ -1295,12 +1324,11 @@ 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()
if "+100% Ground Damage Booster" in inventory['items']['active']: quality = 0
return 100 for booster in inventory['items']['active'].get('damageBoosters', []):
elif "+50% Ground Damage Booster" in inventory['items']['active']: if booster.get('quality', 0) > quality:
return 50 quality = quality
else: return quality
return 0
def activate_battle_effect(self, battle_id: int, kind: str) -> Response: def activate_battle_effect(self, battle_id: int, kind: str) -> Response:
return self._post_main_activate_battle_effect(battle_id, kind, self.details.citizen_id) return self._post_main_activate_battle_effect(battle_id, kind, self.details.citizen_id)
@ -1800,17 +1828,15 @@ 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()
active = inv["items"]['active'] for active_house in [h for h in inv['items']['active'].get('house', [])]:
for q in range(1, 6): till = utils.good_timedelta(self.now, datetime.timedelta(seconds=active_house['time_left']))
if f"House Q{q}" in active: ret.update({active_house.get('quality'): till})
till = utils.good_timedelta(self.now, datetime.timedelta(seconds=active[f"House Q{q}"]))
ret.update({q: 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]:
inventory = self.update_inventory() inventory = self.update_inventory()
ok_to_activate = False ok_to_activate = False
if not inventory["items"]["final"].get("House Q{}".format(q)): if not [h for h in inventory['items']['final'].get('house', []) if h['quality'] == q]:
offers = [] offers = []
countries = [self.details.citizenship, ] countries = [self.details.citizenship, ]
if self.details.current_country != self.details.citizenship: if self.details.current_country != self.details.citizenship: