355 lines
11 KiB
TypeScript
355 lines
11 KiB
TypeScript
import type { Database } from '@tursodatabase/database';
|
|
import { attachWeaponCategoryBonuses } from '$lib/weapons/category-bonuses';
|
|
import { hydrateSkillChipProfileRows } from '$lib/skill-chips/profiles';
|
|
import { loadBuildMechanicRuntimes } from './build-mechanic-runtime';
|
|
|
|
export async function loadSharedBuildSummaryCatalog(database: Database) {
|
|
const [
|
|
attributes,
|
|
gear,
|
|
gearAugments,
|
|
brands,
|
|
brandEffects,
|
|
weapons,
|
|
weaponBonuses,
|
|
talents,
|
|
talentTiers,
|
|
talentEffects,
|
|
talentTemplates,
|
|
chipSets,
|
|
abilitySkillChipLinks,
|
|
chipTwoPiece,
|
|
chipPrimaryOptions,
|
|
chipPrimaryQualityValues,
|
|
chipSecondaryOptions,
|
|
chipSecondaryQualityValues,
|
|
chipTalents,
|
|
chipTalentEffects,
|
|
protocols,
|
|
protocolPrimary,
|
|
protocolProfiles,
|
|
protocolSecondary,
|
|
protocolTalents,
|
|
protocolTalentEffects,
|
|
specializations,
|
|
specializationFocuses,
|
|
specializationAbilities,
|
|
focusAbilities,
|
|
specializationNodes,
|
|
specializationRanks,
|
|
specializationRankEffects,
|
|
specializationRankCombatEffects,
|
|
] = await Promise.all([
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM stat_attributes ORDER BY name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM gear ORDER BY slot,name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM gear_tactical_augments ORDER BY gear_slot,augment_slot',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM brand_sets ORDER BY name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM brand_set_effects ORDER BY pieces_required',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM weapons ORDER BY category,name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM weapon_category_attribute_bonuses ORDER BY weapon_category,sort_order',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM talents ORDER BY name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(await database.prepare('SELECT * FROM talent_tiers ORDER BY tier')).all(),
|
|
(await database.prepare('SELECT * FROM talent_tier_effects')).all(),
|
|
(
|
|
await database.prepare('SELECT * FROM talent_description_templates')
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM skill_chip_sets ORDER BY name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
`SELECT link.ability_id,link.compatible_ability_id
|
|
FROM specialization_ability_skill_chip_links link
|
|
JOIN specialization_abilities ability ON ability.id=link.ability_id AND ability.active=1
|
|
JOIN specialization_abilities compatible ON compatible.id=link.compatible_ability_id AND compatible.active=1`,
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare('SELECT * FROM skill_chip_two_piece_bonuses')
|
|
).all(),
|
|
(await database.prepare('SELECT * FROM skill_chip_primary_options')).all(),
|
|
(
|
|
await database.prepare('SELECT * FROM skill_chip_primary_quality_values')
|
|
).all(),
|
|
(
|
|
await database.prepare('SELECT * FROM skill_chip_secondary_options')
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM skill_chip_secondary_quality_values',
|
|
)
|
|
).all(),
|
|
(await database.prepare('SELECT * FROM skill_chip_talents')).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM skill_chip_talent_effects ORDER BY sort_order',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM os_protocols ORDER BY name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(await database.prepare('SELECT * FROM os_protocol_primary_effects')).all(),
|
|
(
|
|
await database.prepare('SELECT * FROM os_protocol_secondary_profiles')
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM os_protocol_secondary_effects ORDER BY effect_role',
|
|
)
|
|
).all(),
|
|
(await database.prepare('SELECT * FROM os_protocol_talents')).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM os_protocol_talent_effects ORDER BY sort_order',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specializations ORDER BY name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specialization_focuses ORDER BY specialization_id,display_order,name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specialization_abilities ORDER BY specialization_id,name COLLATE NOCASE',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specialization_focus_abilities ORDER BY focus_id,ability_slot',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specialization_tree_nodes ORDER BY focus_id,row_number,column_number',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specialization_tree_node_ranks ORDER BY node_id,rank',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(
|
|
'SELECT * FROM specialization_tree_rank_effects ORDER BY node_id,rank,effect_order',
|
|
)
|
|
).all(),
|
|
(
|
|
await database.prepare(`SELECT attachment.*,effect.name AS definition_name
|
|
FROM specialization_tree_rank_combat_effects attachment
|
|
JOIN specialization_tree_node_ranks rank
|
|
ON rank.node_id=attachment.node_id AND rank.rank=attachment.rank
|
|
JOIN specialization_tree_nodes node ON node.id=attachment.node_id AND node.active=1
|
|
JOIN specialization_focuses focus ON focus.id=node.focus_id AND focus.active=1
|
|
JOIN specializations specialization
|
|
ON specialization.id=focus.specialization_id AND specialization.active=1
|
|
JOIN specialization_combat_effects effect
|
|
ON effect.id=attachment.combat_effect_id
|
|
AND effect.specialization_id=focus.specialization_id
|
|
AND effect.active=1
|
|
ORDER BY specialization.id,focus.display_order,focus.name COLLATE NOCASE,
|
|
node.row_number,node.column_number,attachment.rank,
|
|
attachment.effect_order,attachment.id`)
|
|
).all(),
|
|
]);
|
|
const mechanics = await loadBuildMechanicRuntimes(database, {
|
|
talentIds: talents.map((talent) => String(talent.id)),
|
|
protocolTalentIds: protocolTalents.map((talent) => String(talent.id)),
|
|
skillChipTalentIds: chipTalents.map((talent) => String(talent.id)),
|
|
specializationAttachmentIds: specializationRankCombatEffects.map((effect) =>
|
|
String(effect.id),
|
|
),
|
|
});
|
|
|
|
return {
|
|
mechanics,
|
|
attributes,
|
|
gear,
|
|
gearAugments,
|
|
brands: brands.map((brand) => ({
|
|
...brand,
|
|
effects: brandEffects.filter(
|
|
(effect) => effect.brand_set_id === brand.id,
|
|
),
|
|
})),
|
|
weapons: attachWeaponCategoryBonuses(weapons, weaponBonuses),
|
|
talents: talents.map((talent) => ({
|
|
...talent,
|
|
runtime: mechanics.talents[String(talent.id)] ?? null,
|
|
template:
|
|
talentTemplates.find((item) => item.talent_id === talent.id)
|
|
?.template ?? '',
|
|
tiers: talentTiers
|
|
.filter((tier) => tier.talent_id === talent.id)
|
|
.map((tier) => ({
|
|
...tier,
|
|
effects: talentEffects.filter(
|
|
(effect) => effect.talent_tier_id === tier.id,
|
|
),
|
|
})),
|
|
})),
|
|
skillChipProfile: {
|
|
primaryOptions: hydrateSkillChipProfileRows(
|
|
chipPrimaryOptions,
|
|
chipPrimaryQualityValues,
|
|
),
|
|
secondaryOptions: hydrateSkillChipProfileRows(
|
|
chipSecondaryOptions,
|
|
chipSecondaryQualityValues,
|
|
),
|
|
},
|
|
chipSets: chipSets.map((set) => {
|
|
const talent = chipTalents.find(
|
|
(item) => item.skill_chip_set_id === set.id,
|
|
);
|
|
return {
|
|
...set,
|
|
compatibleAbilityIds: [
|
|
String(set.specialization_ability_id),
|
|
...abilitySkillChipLinks.flatMap((link) =>
|
|
link.ability_id === set.specialization_ability_id
|
|
? [String(link.compatible_ability_id)]
|
|
: link.compatible_ability_id === set.specialization_ability_id
|
|
? [String(link.ability_id)]
|
|
: [],
|
|
),
|
|
],
|
|
twoPiece:
|
|
chipTwoPiece.find((item) => item.skill_chip_set_id === set.id) ??
|
|
null,
|
|
talent: talent
|
|
? {
|
|
...talent,
|
|
runtime: mechanics.skillChipTalents[String(talent.id)] ?? null,
|
|
effects: chipTalentEffects.filter(
|
|
(effect) => effect.talent_id === talent.id,
|
|
),
|
|
}
|
|
: null,
|
|
};
|
|
}),
|
|
protocols: protocols.map((protocol) => {
|
|
const profile = protocolProfiles.find(
|
|
(item) =>
|
|
item.quality === protocol.quality &&
|
|
item.primary_attribute_type === protocol.primary_attribute_type,
|
|
);
|
|
const talent = protocolTalents.find(
|
|
(item) => item.protocol_id === protocol.id,
|
|
);
|
|
return {
|
|
...protocol,
|
|
primaryEffect:
|
|
protocolPrimary.find((item) => item.protocol_id === protocol.id) ??
|
|
null,
|
|
secondaryEffects: profile
|
|
? protocolSecondary.filter(
|
|
(effect) => effect.profile_id === profile.id,
|
|
)
|
|
: [],
|
|
talent: talent
|
|
? {
|
|
...talent,
|
|
runtime: mechanics.protocolTalents[String(talent.id)] ?? null,
|
|
effects: protocolTalentEffects.filter(
|
|
(effect) => effect.talent_id === talent.id,
|
|
),
|
|
}
|
|
: null,
|
|
};
|
|
}),
|
|
specializations: specializations.map((specialization) => ({
|
|
...specialization,
|
|
focuses: specializationFocuses
|
|
.filter((focus) => focus.specialization_id === specialization.id)
|
|
.map((focus) => ({
|
|
...focus,
|
|
abilities: focusAbilities
|
|
.filter((link) => link.focus_id === focus.id)
|
|
.sort(
|
|
(left, right) =>
|
|
Number(left.ability_slot) - Number(right.ability_slot),
|
|
)
|
|
.map((link) =>
|
|
specializationAbilities.find(
|
|
(ability) => ability.id === link.ability_id,
|
|
),
|
|
)
|
|
.filter(Boolean),
|
|
nodes: specializationNodes
|
|
.filter((node) => node.focus_id === focus.id)
|
|
.map((node) => ({
|
|
...node,
|
|
ranks: specializationRanks
|
|
.filter((rank) => rank.node_id === node.id)
|
|
.map((rank) => ({
|
|
...rank,
|
|
effects: specializationRankEffects.filter(
|
|
(effect) =>
|
|
effect.node_id === node.id &&
|
|
Number(effect.rank) === Number(rank.rank),
|
|
),
|
|
combatEffects: specializationRankCombatEffects
|
|
.filter(
|
|
(effect) =>
|
|
effect.node_id === node.id &&
|
|
Number(effect.rank) === Number(rank.rank),
|
|
)
|
|
.map((effect) => ({
|
|
...effect,
|
|
definition: {
|
|
id: String(effect.combat_effect_id),
|
|
name: String(effect.definition_name),
|
|
},
|
|
runtime:
|
|
mechanics.specializationAttachments[
|
|
String(effect.id)
|
|
] ?? null,
|
|
})),
|
|
})),
|
|
})),
|
|
})),
|
|
})),
|
|
};
|
|
}
|