fix(api): correct NexusArmorSet parser for actual API structure

- Fixed field name: API uses 'Armors' not 'Pieces'
- Fixed protection location: API uses 'Defense' not per-piece protection
- Armors is array of arrays, now properly flattened
- Added set bonus parsing from EffectsOnSetEquip
This commit is contained in:
LemonNexus 2026-02-09 18:55:38 +00:00
parent f2d1162d27
commit 4375a00f0f
1 changed files with 31 additions and 15 deletions

View File

@ -265,28 +265,44 @@ class NexusArmorSet(NexusItem):
def from_api(cls, data: Dict[str, Any]) -> "NexusArmorSet":
"""Create from API response."""
props = data.get('Properties', {})
pieces = data.get('Pieces', []) or []
# Calculate total protection from pieces
protection = ProtectionProfile()
for piece_data in pieces:
prot = piece_data.get('Protection', {})
protection.impact += safe_decimal(prot.get('Impact'))
protection.cut += safe_decimal(prot.get('Cut'))
protection.stab += safe_decimal(prot.get('Stab'))
protection.burn += safe_decimal(prot.get('Burn'))
protection.cold += safe_decimal(prot.get('Cold'))
protection.acid += safe_decimal(prot.get('Acid'))
protection.electric += safe_decimal(prot.get('Electric'))
# Get pieces from 'Armors' field (array of arrays)
armors_data = data.get('Armors', []) or []
pieces = []
for armor_group in armors_data:
if isinstance(armor_group, list):
for armor in armor_group:
pieces.append(armor.get('Name', ''))
elif isinstance(armor_group, dict):
pieces.append(armor_group.get('Name', ''))
# Get total protection from 'Defense' field
defense = props.get('Defense', {})
protection = ProtectionProfile(
impact=safe_decimal(defense.get('Impact')),
cut=safe_decimal(defense.get('Cut')),
stab=safe_decimal(defense.get('Stab')),
burn=safe_decimal(defense.get('Burn')),
cold=safe_decimal(defense.get('Cold')),
acid=safe_decimal(defense.get('Acid')),
electric=safe_decimal(defense.get('Electric')),
)
# Get set bonus from EffectsOnSetEquip
set_bonus = None
effects = data.get('EffectsOnSetEquip', [])
if effects:
# Join all effects into a string
set_bonus = "; ".join([str(e) for e in effects])
return cls(
id=data.get('Id', 0),
name=data.get('Name', 'Unknown'),
item_id=str(data.get('Id', 0)),
category='armorset',
pieces=[p.get('Name', '') for p in pieces],
pieces=pieces,
total_protection=protection,
set_bonus=props.get('SetBonus'),
set_bonus=set_bonus,
)