206 lines
9.5 KiB
Plaintext
206 lines
9.5 KiB
Plaintext
// Heuristic extraction of integrity granted to objects by school techniques.
|
||
#import "../generation/radar_graphs.typ": school-sources
|
||
#import "../build_config.typ": tier-is-enabled
|
||
#import "class_costs.typ": class-display-names, numeric-cost
|
||
#import "class_balance_families.typ": all-school-balance-techniques
|
||
#import "report_config.typ": class-balance-settings, class-weapon-settings
|
||
|
||
#let integrity-threshold = class-balance-settings.integrity_per_gauge_threshold
|
||
|
||
#let normalized-integrity-text(value) = lower(value).replace("’", "'")
|
||
.replace("à", "a").replace("â", "a").replace("é", "e").replace("è", "e")
|
||
.replace("ê", "e").replace("ô", "o").replace("î", "i").replace("ï", "i")
|
||
.replace("ù", "u").replace("û", "u").replace("ç", "c")
|
||
|
||
#let integrity-number(token) = (
|
||
un: 1, une: 1, deux: 2, trois: 3, quatre: 4, cinq: 5,
|
||
).at(token, default: if token.match(regex("^[0-9]+$")) != none { int(token) } else { none })
|
||
|
||
#let inline-gauge-cost(effect) = {
|
||
let found = lower(effect).match(regex(
|
||
"(?:#spend\\[|dépensez?|dépenser|depensez?|depenser|coût|cout|prix).{0,28}([0-9]+)@jauge",
|
||
))
|
||
if found == none { none } else { int(found.captures.first()) }
|
||
}
|
||
|
||
#let analyzed-integrity(value, gauge) = {
|
||
let ratio = if value == none or gauge == none or gauge == 0 { none } else { value / gauge }
|
||
(
|
||
ratio: ratio,
|
||
flagged: value != none and ((gauge == none or gauge == 0) or ratio > integrity-threshold),
|
||
status: if value == none { "Valeur symbolique" }
|
||
else if gauge == none or gauge == 0 { "À contrôler · sans jauge" }
|
||
else if ratio > integrity-threshold { "Au-dessus du seuil" }
|
||
else { "Dans le seuil" },
|
||
)
|
||
}
|
||
|
||
#let analyze-school-integrities(name, source) = {
|
||
let rows = csv(source, delimiter: "\t")
|
||
let records = ()
|
||
let current-tier = none
|
||
let columns = none
|
||
for row in rows {
|
||
if row.len() == 0 { continue }
|
||
let first = row.first().trim()
|
||
if first.starts-with("Tier") {
|
||
let digits = first.match(regex("\\d+"))
|
||
if digits != none { current-tier = int(digits.text) }
|
||
continue
|
||
}
|
||
if first == "Technique" {
|
||
columns = (
|
||
level: row.position(cell => cell.trim() == "Niv"),
|
||
gauge: row.position(cell => cell.trim() == "Jauge"),
|
||
effect: row.position(cell => cell.trim() == "Effet"),
|
||
)
|
||
continue
|
||
}
|
||
if first == "" or current-tier == none or columns == none or not tier-is-enabled(current-tier) { continue }
|
||
if columns.effect >= row.len() { continue }
|
||
let effect = row.at(columns.effect).trim()
|
||
let text = lower(effect).replace("’", "'")
|
||
let mentions-integrity = (
|
||
text.contains("integrité") or text.contains("integrite")
|
||
or text.contains("@rl_integrity")
|
||
)
|
||
if not mentions-integrity { continue }
|
||
let gauge-cell = if columns.gauge != none and columns.gauge < row.len() {
|
||
numeric-cost(row.at(columns.gauge))
|
||
} else { none }
|
||
let gauge = if gauge-cell != none { gauge-cell } else { inline-gauge-cost(effect) }
|
||
let level = if columns.level != none and columns.level < row.len() { row.at(columns.level).trim() } else { "" }
|
||
|
||
let add(value, raw, kind) = {
|
||
let analysis = analyzed-integrity(value, gauge)
|
||
(
|
||
class: name, display: class-display-names.at(name), tier: current-tier,
|
||
level: level, technique: first, gauge: gauge, value: value, raw: raw,
|
||
kind: kind, effect: effect, ..analysis,
|
||
)
|
||
}
|
||
|
||
for found in text.matches(regex(
|
||
"([0-9]+|un|une|deux|trois|quatre|cinq)\\s+points?.{0,3}int.grit.",
|
||
)) {
|
||
let before = text.slice(calc.max(0, found.start - 52), found.start)
|
||
let destructive = before.find(regex("perd|perte|redui|fait perdre|au moins|reste à|reste a")) != none
|
||
if not destructive {
|
||
let kind = if before.find(regex("gagne|supplementaire|augmente")) != none { "Bonus" } else { "Base" }
|
||
records.push(add(integrity-number(found.captures.first()), found.text, kind))
|
||
}
|
||
}
|
||
for found in text.matches(regex(
|
||
"([0-9]+|un|une|deux|trois|quatre|cinq)\\s+@rl_integrity(?::short)?",
|
||
)) {
|
||
records.push(add(integrity-number(found.captures.first()), found.text, "Base"))
|
||
}
|
||
for found in text.matches(regex(
|
||
"@rl_integrity(?::short)?\\s+([0-9]+|#cr\\.(?:psy|force|vol)|psy|psyche|force|volonte)(?:\\s+@rl_(?:finale|de_base))?",
|
||
)) {
|
||
let token = found.captures.first()
|
||
let value = if token == "psy" or token == "psyche" or token == "#cr.psy" {
|
||
class-weapon-settings.characteristic_values.at("Psy", default: none)
|
||
} else { integrity-number(token) }
|
||
records.push(add(value, found.text, if value == none { "Symbolique" } else { "Base" }))
|
||
}
|
||
for found in text.matches(regex(
|
||
"int.grit. (?:de |égale à |egale a )?([0-9]+|un|une|deux|trois|quatre|cinq)",
|
||
)) {
|
||
records.push(add(integrity-number(found.captures.first()), found.text, "Base"))
|
||
}
|
||
for found in text.matches(regex(
|
||
"(?:gagne(?:nt|z)?|bénéficie(?:nt|z)?).{0,24}([0-9]+|un|une|deux|trois|quatre|cinq) points? de protection et d'int.grit.",
|
||
)) {
|
||
records.push(add(integrity-number(found.captures.first()), found.text, "Bonus"))
|
||
}
|
||
if text.find(regex("int.grit. (?:égale à |egale a |que )?(?:votre )?(?:#cr\\.psy(?:\\s+@rl_(?:finale|de_base))?|psy|psyché|psyche) moins (?:trois|3)")) != none {
|
||
let psy = class-weapon-settings.characteristic_values.at("Psy", default: none)
|
||
records.push(add(if psy == none { none } else { psy - 3 }, "Psy − 3", "Formule"))
|
||
} else if text.find(regex("autant (?:de points )?d'int.grit. que votre (?:#cr\\.psy(?:\\s+@rl_(?:finale|de_base))?|psy|psyché|psyche)")) != none {
|
||
records.push(add(class-weapon-settings.characteristic_values.at("Psy", default: none), "Psy", "Formule"))
|
||
}
|
||
if text.find(regex("ne poss[eèé]de pas d'int.grit.")) != none {
|
||
records.push(add(0, "Aucune intégrité", "Base"))
|
||
}
|
||
}
|
||
let seen = ()
|
||
let distinct = ()
|
||
for item in records {
|
||
let key = item.technique + "/" + item.level + "/" + item.kind + "/" + item.raw
|
||
if key not in seen {
|
||
seen.push(key)
|
||
distinct.push(item)
|
||
}
|
||
}
|
||
distinct
|
||
}
|
||
|
||
#let extract-technique-integrities(item) = {
|
||
let effect = item.effect
|
||
let text = lower(effect).replace("’", "'")
|
||
let gauge-cell = numeric-cost(item.gauge)
|
||
let gauge = if gauge-cell != none { gauge-cell } else { inline-gauge-cost(effect) }
|
||
let records = ()
|
||
let add(value, raw, kind) = {
|
||
let analysis = analyzed-integrity(value, gauge)
|
||
(
|
||
class: item.class, display: item.display, tier: item.tier,
|
||
level: item.level, technique: item.technique, gauge: gauge,
|
||
value: value, raw: raw, kind: kind, effect: effect, ..analysis,
|
||
)
|
||
}
|
||
for found in text.matches(regex(
|
||
"([0-9]+|un|une|deux|trois|quatre|cinq)\\s+points?.{0,3}int.grit.",
|
||
)) {
|
||
let before = text.slice(calc.max(0, found.start - 52), found.start)
|
||
if before.find(regex("perd|perte|rédui|redui|fait perdre|au moins|reste à|reste a")) == none {
|
||
records.push(add(
|
||
integrity-number(found.captures.first()), found.text,
|
||
if before.find(regex("gagne|supplémentaire|supplementaire|augmente")) != none { "Bonus" } else { "Base" },
|
||
))
|
||
}
|
||
}
|
||
for found in text.matches(regex(
|
||
"([0-9]+|un|une|deux|trois|quatre|cinq)\\s+@rl_integrity(?::short)?",
|
||
)) { records.push(add(integrity-number(found.captures.first()), found.text, "Base")) }
|
||
for found in text.matches(regex(
|
||
"@rl_integrity(?::short)?\\s+([0-9]+|#cr\\.(?:psy|force|vol)|psy|psyché|psyche|force|volonté|volonte)(?:\\s+@rl_(?:finale|de_base))?",
|
||
)) {
|
||
let token = found.captures.first()
|
||
let value = if token == "psy" or token == "psyché" or token == "psyche" or token == "#cr.psy" {
|
||
class-weapon-settings.characteristic_values.at("Psy", default: none)
|
||
} else { integrity-number(token) }
|
||
records.push(add(value, found.text, if value == none { "Symbolique" } else { "Base" }))
|
||
}
|
||
for found in text.matches(regex(
|
||
"int.grit. (?:de |égale à |egale a )?([0-9]+|un|une|deux|trois|quatre|cinq)",
|
||
)) { records.push(add(integrity-number(found.captures.first()), found.text, "Base")) }
|
||
for found in text.matches(regex(
|
||
"(?:gagne(?:nt|z)?|bénéficie(?:nt|z)?).{0,24}([0-9]+|un|une|deux|trois|quatre|cinq) points? de protection et d'int.grit.",
|
||
)) { records.push(add(integrity-number(found.captures.first()), found.text, "Bonus")) }
|
||
if text.find(regex("int.grit. (?:égale à |egale a |que )?(?:votre )?(?:#cr\\.psy(?:\\s+@rl_(?:finale|de_base))?|psy|psyché|psyche) moins (?:trois|3)")) != none {
|
||
let psy = class-weapon-settings.characteristic_values.at("Psy", default: none)
|
||
records.push(add(if psy == none { none } else { psy - 3 }, "Psy − 3", "Formule"))
|
||
} else if text.find(regex("autant (?:de points )?d'int.grit. que votre (?:#cr\\.psy(?:\\s+@rl_(?:finale|de_base))?|psy|psyché|psyche)")) != none {
|
||
records.push(add(class-weapon-settings.characteristic_values.at("Psy", default: none), "Psy", "Formule"))
|
||
}
|
||
if text.find(regex("ne poss[eèé]de pas d'int.grit.")) != none {
|
||
records.push(add(0, "Aucune intégrité", "Base"))
|
||
}
|
||
let seen = ()
|
||
let distinct = ()
|
||
for record in records {
|
||
let key = record.kind + "/" + record.raw
|
||
if key not in seen { seen.push(key); distinct.push(record) }
|
||
}
|
||
distinct
|
||
}
|
||
|
||
#let all-school-integrities = all-school-balance-techniques.map(
|
||
extract-technique-integrities,
|
||
).flatten()
|
||
#let numeric-school-integrities = all-school-integrities.filter(item => item.value != none)
|
||
#let flagged-school-integrities = all-school-integrities.filter(item => item.flagged)
|
||
#let symbolic-school-integrities = all-school-integrities.filter(item => item.value == none)
|