555 lines
15 KiB
Plaintext
555 lines
15 KiB
Plaintext
// Data-driven, player-facing craft recipes.
|
|
//
|
|
// Ingredient names intentionally match the first column of the craft CSVs.
|
|
// This keeps cookbook recipes readable while leaving the source tables as the
|
|
// single source of truth for costs, difficulty, toxicity, and effects.
|
|
#import "core/macros.typ" as macros
|
|
#import "theme/variables.typ": theme
|
|
#import "/chapters/craft/forge-data.typ": equipments
|
|
#let ddlvl = macros.ddlvl
|
|
|
|
#let restoration-main = csv("/data/src/craft/restoration_main.csv")
|
|
#let restoration-sides = csv("/data/src/craft/restoration_sides.csv")
|
|
#let restoration-seasonings = csv("/data/src/craft/restoration_seasoning.csv")
|
|
#let alchemy-solvents = csv("/data/src/craft/alchemy_solvants.csv")
|
|
#let alchemy-reagents = csv("/data/src/craft/alchemy_reagents.csv")
|
|
#let alchemy-transmutations = csv("/data/src/craft/alchemy_transmutations.csv")
|
|
#let forge-materials = csv("/data/src/craft/forge_materials.csv")
|
|
#let forge-finishings = csv("/data/src/craft/forge_finishing.csv")
|
|
#let recipe-catalog = yaml("/data/config/recipes.yaml")
|
|
#let forge-modifiers = yaml("/data/config/forge_modifiers.yaml")
|
|
|
|
#let number(value) = if type(value) == int or type(value) == float {
|
|
value
|
|
} else {
|
|
// Craft CSVs store values as renderable calls such as `#ddlvl(-2)`.
|
|
// Re-evaluate those calls with numeric stand-ins so recipes can total them.
|
|
eval(
|
|
value.replace("#", ""),
|
|
mode: "code",
|
|
scope: (
|
|
ddlvl: (n, ..args) => n,
|
|
toxlvl: (n, ..args) => n,
|
|
winelvl: (n, ..args) => n,
|
|
timelvl: (n, ..args) => n,
|
|
),
|
|
)
|
|
}
|
|
|
|
#let markup(value) = if type(value) != str {
|
|
value
|
|
} else if value == "" {
|
|
[]
|
|
} else {
|
|
eval(value, mode: "markup", scope: macros.bigscope)
|
|
}
|
|
|
|
#let find-ingredient(data, ingredient, stage) = {
|
|
let matches = data.slice(1).filter(row => row.first() == ingredient)
|
|
if matches.len() == 0 {
|
|
panic("Unknown " + stage + " ingredient: " + ingredient)
|
|
}
|
|
matches.first()
|
|
}
|
|
|
|
#let component(
|
|
name,
|
|
stage,
|
|
tier,
|
|
cost,
|
|
difficulty,
|
|
toxicity,
|
|
effect,
|
|
satiety: 0,
|
|
finishing: 0,
|
|
detail: none,
|
|
stat-modifiers: (:),
|
|
) = (
|
|
name: name,
|
|
stage: stage,
|
|
tier: number(tier),
|
|
cost: number(cost),
|
|
difficulty: number(difficulty),
|
|
toxicity: number(toxicity),
|
|
satiety: number(satiety),
|
|
finishing: number(finishing),
|
|
effect: markup(effect),
|
|
detail: detail,
|
|
stat-modifiers: stat-modifiers,
|
|
)
|
|
|
|
#let restoration-component(name, stage) = {
|
|
if stage == "Principal" {
|
|
let row = find-ingredient(restoration-main, name, stage)
|
|
component(
|
|
row.at(0), stage, row.at(2), row.at(3), row.at(4), row.at(5), row.at(7),
|
|
satiety: row.at(6),
|
|
detail: row.at(1),
|
|
)
|
|
} else if stage == "Accompagnement" {
|
|
let row = find-ingredient(restoration-sides, name, stage)
|
|
component(
|
|
row.at(0), stage, row.at(1), row.at(2), row.at(3), row.at(4), row.at(6),
|
|
satiety: row.at(5),
|
|
)
|
|
} else {
|
|
let row = find-ingredient(restoration-seasonings, name, stage)
|
|
component(
|
|
row.at(0), stage, row.at(1), row.at(3), 0, row.at(4), row.at(5),
|
|
finishing: row.at(2),
|
|
)
|
|
}
|
|
}
|
|
|
|
#let alchemy-component(name, stage) = {
|
|
if stage == "Solvant" {
|
|
let row = find-ingredient(alchemy-solvents, name, stage)
|
|
component(row.at(0), stage, row.at(1), row.at(2), row.at(3), row.at(4), row.at(5))
|
|
} else if stage == "Réagent" {
|
|
let row = find-ingredient(alchemy-reagents, name, stage)
|
|
component(
|
|
row.at(0), stage, row.at(2), row.at(3), row.at(4), row.at(5), row.at(7),
|
|
detail: [#row.at(1) — #row.at(6)],
|
|
)
|
|
} else {
|
|
let row = find-ingredient(alchemy-transmutations, name, stage)
|
|
component(
|
|
row.at(0), stage, row.at(1), row.at(3), 0, 0, row.at(5),
|
|
finishing: row.at(2),
|
|
detail: [Production : #row.at(4)],
|
|
)
|
|
}
|
|
}
|
|
|
|
#let find-equipment(shape, nature) = {
|
|
let matches = equipments.filter(item => (
|
|
item.shape_name == shape
|
|
and (item.nature_name == nature or item.nature_category == nature)
|
|
))
|
|
if matches.len() == 0 {
|
|
panic("Unknown forge equipment: " + shape + " + " + nature)
|
|
}
|
|
matches.first()
|
|
}
|
|
|
|
#let forge-display-name(item) = {
|
|
let feminine = item.shape_name in ("Épée", "Hache", "Arbalète", "Armure")
|
|
let plural = item.shape_name == "Griffes"
|
|
let adjective = if feminine or plural {
|
|
(
|
|
Light: "légère",
|
|
Medium: "moyenne",
|
|
Heavy: "lourde",
|
|
SuperHeavy: "super-lourde",
|
|
).at(item.nature_category) + if plural { "s" } else { "" }
|
|
} else {
|
|
(
|
|
Light: "léger",
|
|
Medium: "moyen",
|
|
Heavy: "lourd",
|
|
SuperHeavy: "super-lourd",
|
|
).at(item.nature_category)
|
|
}
|
|
item.shape_name + " " + adjective
|
|
}
|
|
|
|
#let forge-base-component(item) = component(
|
|
forge-display-name(item),
|
|
"Base",
|
|
item.tier,
|
|
item.cost,
|
|
item.difficulty,
|
|
0,
|
|
[Dégâts #item.damage, dégâts par réussite #item.p_damage, réussites max #item.rmax, brise-armure #item.armor_break, protection #item.protection, intégrité #item.integrity.],
|
|
)
|
|
|
|
#let forge-material-component(name, target) = {
|
|
let row = find-ingredient(forge-materials, name, "Matériau")
|
|
let effect-index = if target == "Weapons" { 4 } else { 5 }
|
|
let target-name = if target == "Weapons" { "weapon" } else { "armor" }
|
|
let modifiers = forge-modifiers.materials.at(name, default: (:)).at(
|
|
target-name,
|
|
default: (:),
|
|
)
|
|
component(
|
|
row.at(0),
|
|
"Matériau",
|
|
row.at(1),
|
|
row.at(2),
|
|
row.at(3),
|
|
0,
|
|
row.at(effect-index),
|
|
stat-modifiers: modifiers,
|
|
)
|
|
}
|
|
|
|
#let forge-finishing-component(name, stage) = {
|
|
let row = find-ingredient(forge-finishings, name, stage)
|
|
let modifiers = forge-modifiers.finishings.at(name, default: (:))
|
|
component(
|
|
row.at(0),
|
|
stage,
|
|
row.at(2),
|
|
row.at(4),
|
|
0,
|
|
0,
|
|
row.at(5),
|
|
finishing: row.at(3),
|
|
stat-modifiers: modifiers,
|
|
)
|
|
}
|
|
|
|
#let assemble(craft, stages) = {
|
|
let components = stages.map(stage => stage.ingredients.map(
|
|
name => (stage.load)(name, stage.name),
|
|
)).flatten()
|
|
if components.len() == 0 { panic("A recipe needs at least one ingredient") }
|
|
|
|
let tier = 0
|
|
let cost = 0
|
|
let difficulty = 0
|
|
let toxicity = 0
|
|
let satiety = 0
|
|
let finishing = 0
|
|
for item in components {
|
|
tier = calc.max(tier, item.tier)
|
|
cost += item.cost
|
|
difficulty += item.difficulty
|
|
toxicity += item.toxicity
|
|
satiety += item.satiety
|
|
finishing += item.finishing
|
|
}
|
|
|
|
(
|
|
craft: craft,
|
|
stages: stages,
|
|
components: components,
|
|
tier: tier,
|
|
cost: cost,
|
|
difficulty: difficulty,
|
|
toxicity: toxicity,
|
|
satiety: satiety,
|
|
finishing: finishing,
|
|
)
|
|
}
|
|
|
|
// Build the calculated restoration data without rendering it.
|
|
#let restoration(main: (), sides: (), seasonings: ()) = assemble(
|
|
"Restauration",
|
|
(
|
|
(name: "Principal", ingredients: main, load: restoration-component),
|
|
(name: "Accompagnement", ingredients: sides, load: restoration-component),
|
|
(name: "Assaisonnement", ingredients: seasonings, load: restoration-component),
|
|
),
|
|
)
|
|
|
|
// Build the calculated alchemy data without rendering it.
|
|
#let alchemy(solvents: (), reagents: (), transmutations: ()) = assemble(
|
|
"Alchimie",
|
|
(
|
|
(name: "Solvant", ingredients: solvents, load: alchemy-component),
|
|
(name: "Réagent", ingredients: reagents, load: alchemy-component),
|
|
(name: "Transmutation", ingredients: transmutations, load: alchemy-component),
|
|
),
|
|
)
|
|
|
|
#let forge-stat-fields = (
|
|
"damage", "p_damage", "rmax", "armor_break", "armor_pierce",
|
|
"antimaterial", "protection", "integrity", "dodge", "parry", "speed",
|
|
"stealth", "precision", "agility_bonus", "range", "action_cost",
|
|
"torque_two_handed", "torque_one_handed", "reload_cost",
|
|
)
|
|
|
|
// Forge bases come from weapons.db; materials and finishings remain CSV-backed.
|
|
#let forge(shape, nature, materials: (), finishings: ()) = {
|
|
let equipment = find-equipment(shape, nature)
|
|
let result = assemble(
|
|
"Forge",
|
|
(
|
|
(
|
|
name: "Base",
|
|
ingredients: (forge-display-name(equipment),),
|
|
load: (..args) => forge-base-component(equipment),
|
|
),
|
|
(
|
|
name: "Matériau",
|
|
ingredients: materials,
|
|
load: (name, ..args) => forge-material-component(name, equipment.apply_category),
|
|
),
|
|
(
|
|
name: "Finition",
|
|
ingredients: finishings,
|
|
load: forge-finishing-component,
|
|
),
|
|
),
|
|
)
|
|
let stats = (:)
|
|
for field in forge-stat-fields {
|
|
stats.insert(field, equipment.at(field, default: none))
|
|
}
|
|
for item in result.components {
|
|
for (field, delta) in item.stat-modifiers {
|
|
let current = stats.at(field, default: none)
|
|
if current != none and current != "null" {
|
|
stats.insert(field, current + delta)
|
|
}
|
|
}
|
|
}
|
|
// Fer improves each material effect which already increases weapon damage.
|
|
if equipment.apply_category == "Weapons" and "Fer" in materials {
|
|
let boosted-materials = result.components.filter(item => (
|
|
item.stage == "Matériau"
|
|
and item.stat-modifiers.at("damage", default: 0) > 0
|
|
)).len()
|
|
stats.insert("damage", stats.damage + boosted-materials)
|
|
}
|
|
result.insert("equipment", equipment)
|
|
result.insert("stats", stats)
|
|
result
|
|
}
|
|
|
|
#let metric(label, value) = block(
|
|
width: 100%,
|
|
inset: (x: 3.5pt, y: 3pt),
|
|
fill: theme.parchment-light,
|
|
stroke: 0.4pt + theme.border,
|
|
radius: 2pt,
|
|
)[
|
|
#text(size: 6.2pt, fill: theme.muted)[#label]\
|
|
#text(size: 7.8pt, weight: "bold")[#value]
|
|
]
|
|
|
|
#let forge-stat-labels = (
|
|
("damage", "Dég."),
|
|
("p_damage", "+/réuss."),
|
|
("rmax", "R. max"),
|
|
("armor_break", "Brise"),
|
|
("armor_pierce", "Perce"),
|
|
("antimaterial", "Anti-mat."),
|
|
("protection", "Prot."),
|
|
("integrity", "Int."),
|
|
("dodge", "Esq."),
|
|
("parry", "Par."),
|
|
("speed", "Vit."),
|
|
("stealth", "Disc."),
|
|
("precision", "Préc."),
|
|
("agility_bonus", "Agi."),
|
|
("range", "Portée"),
|
|
("action_cost", "Actions"),
|
|
("torque_two_handed", "Torque 2M"),
|
|
("torque_one_handed", "Torque 1M"),
|
|
("reload_cost", "Recharge"),
|
|
)
|
|
|
|
#let shown-stat(value) = if value == none or value == "null" { [—] } else { value }
|
|
|
|
#let forge-stat-line(stats) = block(
|
|
width: 100%,
|
|
inset: (x: 4pt, y: 3.5pt),
|
|
fill: theme.parchment-dark,
|
|
stroke: 0.45pt + theme.border,
|
|
radius: 3pt,
|
|
)[
|
|
#for pair in forge-stat-labels {
|
|
let value = stats.at(pair.at(0), default: none)
|
|
box(
|
|
inset: (x: 4pt, y: 2pt),
|
|
fill: theme.parchment-light,
|
|
stroke: 0.35pt + theme.border,
|
|
radius: 8pt,
|
|
)[
|
|
#text(size: 5.8pt, fill: theme.muted)[#pair.at(1)]
|
|
#h(0.25em)
|
|
#text(size: 7pt, weight: "bold")[#shown-stat(value)]
|
|
]
|
|
h(2.5pt)
|
|
}
|
|
]
|
|
|
|
#let ingredient-name(item) = text(
|
|
size: 6.6pt,
|
|
weight: "semibold",
|
|
fill: theme.heading.transparentize(20%),
|
|
)[
|
|
#item.name
|
|
]
|
|
|
|
#let ingredient-effect(item) = text(size: 6.4pt)[
|
|
#if item.detail != none {
|
|
text(size: 5.7pt, fill: theme.muted.transparentize(15%))[(#item.detail)]
|
|
h(0.35em)
|
|
}
|
|
#item.effect
|
|
]
|
|
|
|
#let step-pill(step) = box(
|
|
inset: (x: 3pt, y: 1pt),
|
|
fill: theme.parchment-light.transparentize(28%),
|
|
stroke: 0.25pt + theme.border.transparentize(60%),
|
|
radius: 7pt,
|
|
)[
|
|
#text(size: 5.5pt, fill: theme.muted)[#step]
|
|
]
|
|
|
|
// Render any calculated craft data as a complete cookbook card.
|
|
#let render-recipe(name, ingredients, flavor: none) = {
|
|
let craft = ingredients.craft
|
|
let metrics = if craft == "Forge" {
|
|
(
|
|
([Maîtrise], ingredients.tier),
|
|
([Coût], ddlvl(ingredients.cost)),
|
|
([Difficulté], ddlvl(ingredients.difficulty)),
|
|
([Finition], if ingredients.finishing == 0 { [—] } else { ddlvl(ingredients.finishing) }),
|
|
)
|
|
} else {
|
|
(
|
|
([Maîtrise], ingredients.tier),
|
|
([Coût], ddlvl(ingredients.cost)),
|
|
([Difficulté], ddlvl(ingredients.difficulty)),
|
|
([Toxicité], ddlvl(ingredients.toxicity)),
|
|
([Satiété], if ingredients.satiety == 0 { [—] } else { ddlvl(ingredients.satiety) }),
|
|
([Finition], if ingredients.finishing == 0 { [—] } else { ddlvl(ingredients.finishing) }),
|
|
)
|
|
}
|
|
block(
|
|
width: 100%,
|
|
breakable: false,
|
|
above: 6pt,
|
|
below: 6pt,
|
|
fill: theme.parchment,
|
|
stroke: 0.75pt + theme.gold,
|
|
inset: 8.5pt,
|
|
radius: 4pt,
|
|
)[
|
|
#text(size: 6.2pt, weight: "bold", tracking: 0.08em, fill: theme.dark-gold)[#craft]
|
|
#h(0.65em)
|
|
#text(size: 12.5pt, weight: "bold", fill: theme.heading)[#name]
|
|
#if flavor != none {
|
|
linebreak()
|
|
v(2.5pt)
|
|
text(size: 7.6pt, style: "italic", fill: theme.muted)[#flavor]
|
|
}
|
|
#v(5pt)
|
|
#grid(
|
|
columns: metrics.len(),
|
|
gutter: 3pt,
|
|
..metrics.map(pair => metric(pair.at(0), pair.at(1))),
|
|
)
|
|
#if craft == "Forge" {
|
|
v(4pt)
|
|
forge-stat-line(ingredients.stats)
|
|
}
|
|
#v(5pt)
|
|
#text(size: 6.6pt, weight: "bold", fill: theme.dark-gold)[Ingrédients et effets]
|
|
#v(-1pt)
|
|
#pad(left: 6pt)[
|
|
#table(
|
|
columns: (auto, auto, 1fr),
|
|
align: (left + horizon, left + horizon, left + horizon),
|
|
column-gutter: 3pt,
|
|
stroke: none,
|
|
inset: (x: 1pt, y: 1.5pt),
|
|
..ingredients.components.map(item => (
|
|
ingredient-name(item),
|
|
step-pill(item.stage),
|
|
ingredient-effect(item),
|
|
)).flatten(),
|
|
)
|
|
]
|
|
]
|
|
}
|
|
|
|
#let restoration-recipe(
|
|
name,
|
|
flavor: none,
|
|
main: (),
|
|
sides: (),
|
|
seasonings: (),
|
|
) = render-recipe(
|
|
name,
|
|
restoration(
|
|
main: main,
|
|
sides: sides,
|
|
seasonings: seasonings,
|
|
),
|
|
flavor: flavor,
|
|
)
|
|
|
|
#let alchemy-recipe(
|
|
name,
|
|
flavor: none,
|
|
solvents: (),
|
|
reagents: (),
|
|
transmutations: (),
|
|
) = render-recipe(
|
|
name,
|
|
alchemy(
|
|
solvents: solvents,
|
|
reagents: reagents,
|
|
transmutations: transmutations,
|
|
),
|
|
flavor: flavor,
|
|
)
|
|
|
|
#let forge-recipe(
|
|
name,
|
|
shape,
|
|
nature,
|
|
flavor: none,
|
|
materials: (),
|
|
finishings: (),
|
|
) = render-recipe(
|
|
name,
|
|
forge(
|
|
shape,
|
|
nature,
|
|
materials: materials,
|
|
finishings: finishings,
|
|
),
|
|
flavor: flavor,
|
|
)
|
|
|
|
// Render a catalog entry from data/config/recipes.yaml. This is the public
|
|
// authoring API used by books and chapters: `#recipe("restoration", "name")`.
|
|
#let recipe(module, recipe-name) = {
|
|
if module not in recipe-catalog {
|
|
panic("Unknown recipe module: " + module)
|
|
}
|
|
let recipes = recipe-catalog.at(module)
|
|
if recipe-name not in recipes {
|
|
panic("Unknown recipe in " + module + ": " + recipe-name)
|
|
}
|
|
let entry = recipes.at(recipe-name)
|
|
let flavor = entry.at("flavor", default: none)
|
|
|
|
if module == "restoration" {
|
|
restoration-recipe(
|
|
entry.name,
|
|
flavor: flavor,
|
|
main: entry.at("main", default: ()),
|
|
sides: entry.at("sides", default: ()),
|
|
seasonings: entry.at("seasonings", default: ()),
|
|
)
|
|
} else if module == "alchemy" {
|
|
alchemy-recipe(
|
|
entry.name,
|
|
flavor: flavor,
|
|
solvents: entry.at("solvents", default: ()),
|
|
reagents: entry.at("reagents", default: ()),
|
|
transmutations: entry.at("transmutations", default: ()),
|
|
)
|
|
} else if module == "forge" {
|
|
let base = entry.at("base")
|
|
forge-recipe(
|
|
entry.name,
|
|
base.shape,
|
|
base.nature,
|
|
flavor: flavor,
|
|
materials: entry.at("materials", default: ()),
|
|
finishings: entry.at("finishings", default: ()),
|
|
)
|
|
} else {
|
|
panic("Recipe module has no constructor: " + module)
|
|
}
|
|
}
|