def create_weapon_stat(db_session, record, item): if not "weaponStats" in record: return db_session.query(ModelWeaponStat).filter_by(item_id=item.uuid).delete() weapon_stat = ModelWeaponStat( item_id=item.uuid, ap_cost=record["weaponStats"]["apCost"], uses_per_turn=record["weaponStats"]["usesPerTurn"], min_range=record["weaponStats"]["minRange"], max_range=record["weaponStats"]["maxRange"], ) if record["weaponStats"]["baseCritChance"] > 0: weapon_stat.base_crit_chance = (record["weaponStats"]["baseCritChance"],) weapon_stat.crit_bonus_damage = (record["weaponStats"]["critBonusDamage"],) db_session.add(weapon_stat) db_session.flush() for effect in record["weaponStats"]["weapon_effects"]: weapon_effects = ModelWeaponEffect( weapon_stat_id=weapon_stat.uuid, effect_type=to_effect_enum[effect["stat"]], min_damage=effect["minStat"], max_damage=effect["maxStat"], ) db_session.add(weapon_effects)
item.stats.append(item_stat) i = i + 1 # If this item belongs in a set, query the set and add the relationship to the record if record["setID"]: set = record["setID"] set_record = (db.session.query(ModelSet).filter( ModelSet.dofus_db_id == set).first()) set_record.items.append(item) db.session.merge(set_record) except KeyError as err: print("KeyError occurred:", err) weapon_stat = ModelWeaponStat( ap_cost=record["weaponStats"]["apCost"], uses_per_turn=record["weaponStats"]["usesPerTurn"], min_range=record["weaponStats"]["minRange"], max_range=record["weaponStats"]["maxRange"], ) if record["weaponStats"]["baseCritChance"] > 0: weapon_stat.base_crit_chance = ( record["weaponStats"]["baseCritChance"], ) weapon_stat.crit_bonus_damage = ( record["weaponStats"]["critBonusDamage"], ) for effect in record["weaponStats"]["weapon_effects"]: weapon_effects = ModelWeaponEffect( effect_type=to_effect_enum[effect["stat"]], min_damage=effect["minStat"], max_damage=effect["maxStat"], )