fix: weapon combat stats extraction + spell_contains SQL bug

Bug 1: Weapon stats (max_damage, attack_bonus, variance, damage_type,
weapon_time, weapon_skill) were read from top-level MyWorldObject fields
which are -1 by default. Now extracted from IntValues/DoubleValues keys
where the plugin actually stores them (218103842, 167772170, etc.).

Bug 2: spell_contains and has_spell filters used direct sp.spell_id
reference which fails in the count query CTE (sp table not available
in outer SELECT). Changed to EXISTS subqueries matching the pattern
already used by legendary_cantrips filter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-08 17:24:48 +02:00
parent 5b26a19666
commit 1e9dffb65b

View file

@ -1359,10 +1359,16 @@ def extract_item_properties(item_data: Dict[str, Any]) -> Dict[str, Any]:
"remaining_lifespan": int_values.get("268", int_values.get(268, -1)),
},
"combat": {
"max_damage": item_data.get("MaxDamage", -1),
"armor_level": item_data.get("ArmorLevel", -1),
"damage_bonus": item_data.get("DamageBonus", -1.0),
"attack_bonus": item_data.get("AttackBonus", -1.0),
# Extract weapon stats from IntValues/DoubleValues (plugin stores them there)
# Fall back to top-level fields for backward compatibility
"max_damage": int_values.get("218103842", int_values.get(218103842, item_data.get("MaxDamage", -1))),
"armor_level": item_data.get("ArmorLevel", int_values.get("28", int_values.get(28, -1))),
"damage_bonus": double_values.get("167772174", double_values.get(167772174, item_data.get("DamageBonus", -1.0))),
"attack_bonus": double_values.get("167772170", double_values.get(167772170, item_data.get("AttackBonus", -1.0))),
"variance": double_values.get("167772171", double_values.get(167772171, -1.0)),
"damage_type": int_values.get("218103832", int_values.get(218103832, -1)),
"weapon_time": int_values.get("218103835", int_values.get(218103835, -1)),
"weapon_skill": int_values.get("218103840", int_values.get(218103840, -1)),
# Defense bonuses from raw values
"melee_defense_bonus": double_values.get("29", double_values.get(29, -1.0)),
"magic_defense_bonus": double_values.get(
@ -3272,7 +3278,9 @@ async def search_items(
break
if spell_id:
spell_conditions.append("sp.spell_id = :has_spell_id")
spell_conditions.append(
"EXISTS (SELECT 1 FROM item_spells sp3 WHERE sp3.item_id = db_item_id AND sp3.spell_id = :has_spell_id)"
)
params["has_spell_id"] = spell_id
else:
# If spell not found by exact name, no results
@ -3290,7 +3298,7 @@ async def search_items(
if matching_spell_ids:
spell_conditions.append(
f"sp.spell_id IN ({','.join(map(str, matching_spell_ids))})"
f"EXISTS (SELECT 1 FROM item_spells sp4 WHERE sp4.item_id = db_item_id AND sp4.spell_id IN ({','.join(map(str, matching_spell_ids))}))"
)
else:
# If no spells found containing the text, no results