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": def from_api(cls, data: Dict[str, Any]) -> "NexusArmorSet":
"""Create from API response.""" """Create from API response."""
props = data.get('Properties', {}) props = data.get('Properties', {})
pieces = data.get('Pieces', []) or []
# Calculate total protection from pieces # Get pieces from 'Armors' field (array of arrays)
protection = ProtectionProfile() armors_data = data.get('Armors', []) or []
for piece_data in pieces: pieces = []
prot = piece_data.get('Protection', {}) for armor_group in armors_data:
protection.impact += safe_decimal(prot.get('Impact')) if isinstance(armor_group, list):
protection.cut += safe_decimal(prot.get('Cut')) for armor in armor_group:
protection.stab += safe_decimal(prot.get('Stab')) pieces.append(armor.get('Name', ''))
protection.burn += safe_decimal(prot.get('Burn')) elif isinstance(armor_group, dict):
protection.cold += safe_decimal(prot.get('Cold')) pieces.append(armor_group.get('Name', ''))
protection.acid += safe_decimal(prot.get('Acid'))
protection.electric += safe_decimal(prot.get('Electric')) # 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( return cls(
id=data.get('Id', 0), id=data.get('Id', 0),
name=data.get('Name', 'Unknown'), name=data.get('Name', 'Unknown'),
item_id=str(data.get('Id', 0)), item_id=str(data.get('Id', 0)),
category='armorset', category='armorset',
pieces=[p.get('Name', '') for p in pieces], pieces=pieces,
total_protection=protection, total_protection=protection,
set_bonus=props.get('SetBonus'), set_bonus=set_bonus,
) )