Compare commits
82 Commits
complexity
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
342b2105c6 | |
|
|
8238a4bf2f | |
|
|
26b4b31684 | |
|
|
dd9999b347 | |
|
|
4dc5a5f03e | |
|
|
61206c7a88 | |
|
|
a9dc404da0 | |
|
|
2bfccc4175 | |
|
|
395c03621f | |
|
|
b5f4b8daf0 | |
|
|
ba8e6c09f3 | |
|
|
d7914c6eaa | |
|
|
f34d581522 | |
|
|
c008e16556 | |
|
|
daf65e8a27 | |
|
|
cec31c6689 | |
|
|
9408152f98 | |
|
|
29a1c93f3f | |
|
|
8ff115e593 | |
|
|
55960bffbd | |
|
|
d58ddc9349 | |
|
|
05092c354f | |
|
|
a449407ab4 | |
|
|
70cde5aa52 | |
|
|
c5481210d8 | |
|
|
44db2ca294 | |
|
|
7be200c749 | |
|
|
9ae9471ccd | |
|
|
7f5c09ae36 | |
|
|
a3b0f4a744 | |
|
|
9ca9e49a8e | |
|
|
c91ca2f26f | |
|
|
41fead32a4 | |
|
|
264fadfdc8 | |
|
|
886f139bbb | |
|
|
a0f05fb638 | |
|
|
3b9bd39a5a | |
|
|
854020118b | |
|
|
f5e63b9b89 | |
|
|
f659bebc9a | |
|
|
3d211b711a | |
|
|
54688cb74f | |
|
|
d50a22d3f8 | |
|
|
483dc1003f | |
|
|
2235357925 | |
|
|
c74de46f8b | |
|
|
59a78f4236 | |
|
|
4ff3d2c992 | |
|
|
4ac2146b13 | |
|
|
7ec926432e | |
|
|
1c216df46d | |
|
|
c06ca05151 | |
|
|
bcf01e2004 | |
|
|
161a7d2ab4 | |
|
|
536ef42d70 | |
|
|
6da458a236 | |
|
|
55f5fe10d2 | |
|
|
eb63fb0806 | |
|
|
885a1caaf6 | |
|
|
08a1697345 | |
|
|
27debbf153 | |
|
|
789b925400 | |
|
|
f1337b1678 | |
|
|
5600804ab4 | |
|
|
8a655d2a69 | |
|
|
c3c0309948 | |
|
|
1caff57923 | |
|
|
62e459e5bd | |
|
|
2e12f9708d | |
|
|
e0be27ae6f | |
|
|
abe9db7c0b | |
|
|
d01ce27d5b | |
|
|
7e021d644a | |
|
|
209c24aab2 | |
|
|
572ad159a2 | |
|
|
08a66bf2b8 | |
|
|
f86199d497 | |
|
|
006ebe9a0b | |
|
|
37a6531ae4 | |
|
|
46b8e35254 | |
|
|
1e0c6dfb53 | |
|
|
529f90b93e |
|
|
@ -16,12 +16,11 @@ Cargo.lock
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
*.html
|
||||||
.cargo/
|
.cargo/
|
||||||
.tracey/
|
.tracey/
|
||||||
*.json.gz
|
*.json.gz
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
[submodule "ravenous_databases"]
|
[submodule "ravenous_databases"]
|
||||||
path = ravenous_databases
|
path = ravenous_databases
|
||||||
url = git@git.dandaedre.com:Ravenous/ravenous_databases.git
|
url = git@git.dandaedre.com:Ravenous/ravenous_databases.git
|
||||||
|
# url = https://proxy.dandaedre.com/gitea/Ravenous/ravenous_databases.git
|
||||||
|
|
|
||||||
20
Cargo.toml
20
Cargo.toml
|
|
@ -6,7 +6,7 @@ resolver = "3"
|
||||||
# edition = "2024"
|
# edition = "2024"
|
||||||
# license = "MIT OR Apache-2.0"
|
# license = "MIT OR Apache-2.0"
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.3.0"
|
version = "0.3.34"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
@ -30,6 +30,16 @@ codegen-units = 256
|
||||||
incremental = true
|
incremental = true
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
|
# [profile.dev-analysis]
|
||||||
|
# inherits = "dev"
|
||||||
|
# opt-level = 0
|
||||||
|
# debug = 0
|
||||||
|
# strip = "none"
|
||||||
|
# lto = false
|
||||||
|
# # codegen-units = 256
|
||||||
|
# incremental = true
|
||||||
|
# # codegen-backend = "cranelift"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
config = {path = "./crates/config"}
|
config = {path = "./crates/config"}
|
||||||
tablegen = {path = "./crates/tablegen"}
|
tablegen = {path = "./crates/tablegen"}
|
||||||
|
|
@ -41,6 +51,7 @@ fast_class = {path = "./crates/fast_class"}
|
||||||
formatter = {path = "./crates/formatter"}
|
formatter = {path = "./crates/formatter"}
|
||||||
weaponry = {path = "./crates/weaponry"}
|
weaponry = {path = "./crates/weaponry"}
|
||||||
more_fields = {path = "./crates/more_fields"}
|
more_fields = {path = "./crates/more_fields"}
|
||||||
|
monsters = {path = "./crates/monsters"}
|
||||||
|
|
||||||
anyhow = "1.0.103"
|
anyhow = "1.0.103"
|
||||||
toml = "1.1.3"
|
toml = "1.1.3"
|
||||||
|
|
@ -49,9 +60,16 @@ phf = { version = "0.14.0", features = ["macros"] }
|
||||||
regex = "1.13.0"
|
regex = "1.13.0"
|
||||||
regex_static = "0.1.1"
|
regex_static = "0.1.1"
|
||||||
serde = { version = "1.0.228", features = ["derive", "alloc"] }
|
serde = { version = "1.0.228", features = ["derive", "alloc"] }
|
||||||
|
serde_json = { version = "1.0.150", features = ["alloc"] }
|
||||||
csv = "1.4.0"
|
csv = "1.4.0"
|
||||||
ron = "0.12.2"
|
ron = "0.12.2"
|
||||||
glob = "0.3.3"
|
glob = "0.3.3"
|
||||||
tokio = { version = "1.52.3", features = ["full"] }
|
tokio = { version = "1.52.3", features = ["full"] }
|
||||||
dynfmt = { version = "0.1.5", features = ["curly"] }
|
dynfmt = { version = "0.1.5", features = ["curly"] }
|
||||||
pretty_assertions = "^1.4"
|
pretty_assertions = "^1.4"
|
||||||
|
indexmap = {version= "2.14.0", features= ["serde"]}
|
||||||
|
rusqlite = { version = "0.40.1" } # , features = ["bundled"]
|
||||||
|
serde_rusqlite = "0.43.0"
|
||||||
|
handlebars = "6.4.3"
|
||||||
|
strum = { version = "0.28.0", features = ["derive"] }
|
||||||
|
probability = "0.20.3"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cli_parser"
|
name = "cli_parser"
|
||||||
version = "0.1.7"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@
|
||||||
|
|
||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
use config::{
|
use config::{
|
||||||
analysis::AnalysisConfig,
|
analysis::{AnalysisConfig, WeaponConfig},
|
||||||
fast_tables::FastTableConfig,
|
fast_tables::FastTableConfig,
|
||||||
formatter::FormatterConfig,
|
formatter::FormatterConfig,
|
||||||
graph::GraphConfig,
|
graph::GraphConfig,
|
||||||
make::{MakeTargets, VerboseLevel, HELP_BLOCK_SELECTION},
|
make::{HELP_BLOCK_SELECTION, MakeTargets, VerboseLevel},
|
||||||
|
monsters::{MonsterConfig, MonsterMarkup, WeaponExport},
|
||||||
statsolver::StatConfig,
|
statsolver::StatConfig,
|
||||||
tablegen::{Craft, TableArgs},
|
tablegen::{Craft, TableArgs},
|
||||||
};
|
};
|
||||||
|
|
@ -46,8 +47,12 @@ pub enum Commands {
|
||||||
Format(FormatterConfig),
|
Format(FormatterConfig),
|
||||||
/// Generate analysis data
|
/// Generate analysis data
|
||||||
Analysis(AnalysisConfig),
|
Analysis(AnalysisConfig),
|
||||||
|
/// Export all weapon data
|
||||||
|
Weapons(WeaponConfig),
|
||||||
/// Better Generation
|
/// Better Generation
|
||||||
BetterGen(FastTableConfig),
|
BetterGen(FastTableConfig),
|
||||||
|
/// Monster database handling
|
||||||
|
Monsters(MonsterConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
|
|
@ -74,6 +79,10 @@ pub struct Config {
|
||||||
pub classes: Classes,
|
pub classes: Classes,
|
||||||
/// Config for all the tables
|
/// Config for all the tables
|
||||||
pub craft: Craft,
|
pub craft: Craft,
|
||||||
|
/// Config for monster exporting
|
||||||
|
pub monster: MonsterMarkup,
|
||||||
|
/// The config for weapon exporting
|
||||||
|
pub weapons: WeaponExport,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "config"
|
name = "config"
|
||||||
version = "0.1.1"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = {workspace = true}
|
clap = {workspace = true}
|
||||||
serde = {workspace = true}
|
serde = {workspace = true}
|
||||||
phf = {workspace = true}
|
phf = {workspace = true}
|
||||||
|
indexmap = {workspace = true}
|
||||||
|
anyhow = {workspace = true}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,21 @@ pub struct AnalysisConfig {
|
||||||
// - average per category
|
// - average per category
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
/// Basic weapon generation
|
||||||
|
pub struct WeaponConfig {
|
||||||
|
#[arg(help = format!("The target to perform an analysis on [{:?}]", AnalysisTarget::value_variants()))]
|
||||||
|
/// The analysis target
|
||||||
|
pub target: ExportTarget,
|
||||||
|
|
||||||
|
/// The path to export to
|
||||||
|
#[arg(short, long, default_value = "./Craft/")]
|
||||||
|
pub export: String,
|
||||||
|
|
||||||
|
#[arg(long, default_value_t = String::from("safe"))]
|
||||||
|
/// What function to sort by
|
||||||
|
pub sort: String,
|
||||||
|
}
|
||||||
#[derive(ValueEnum, Clone, Debug)]
|
#[derive(ValueEnum, Clone, Debug)]
|
||||||
/// The type of analysis to perform
|
/// The type of analysis to perform
|
||||||
pub enum AnalysisTarget {
|
pub enum AnalysisTarget {
|
||||||
|
|
@ -52,3 +67,10 @@ pub enum AnalysisTarget {
|
||||||
/// Analysis over shields
|
/// Analysis over shields
|
||||||
Shields,
|
Shields,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(ValueEnum, Clone, Debug)]
|
||||||
|
/// The type of generation to perform
|
||||||
|
pub enum ExportTarget {
|
||||||
|
/// Generate all
|
||||||
|
All,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,6 @@ pub mod fast_tables;
|
||||||
pub mod formatter;
|
pub mod formatter;
|
||||||
pub mod graph;
|
pub mod graph;
|
||||||
pub mod make;
|
pub mod make;
|
||||||
|
pub mod monsters;
|
||||||
pub mod statsolver;
|
pub mod statsolver;
|
||||||
pub mod tablegen;
|
pub mod tablegen;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ pub enum VerboseLevel {
|
||||||
Error,
|
Error,
|
||||||
/// Uncatchable errors
|
/// Uncatchable errors
|
||||||
Critical,
|
Critical,
|
||||||
|
/// Interactive prompt context, only useful in interactive mode
|
||||||
|
InteractiveContext,
|
||||||
/// Literrally uncatchable things
|
/// Literrally uncatchable things
|
||||||
Uncatchable,
|
Uncatchable,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,178 @@
|
||||||
|
// Workspace: config
|
||||||
|
// File: config/src/monsters.rs
|
||||||
|
//! The inner config for monster module
|
||||||
|
//!
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use clap::Args;
|
||||||
|
use clap::Parser;
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
|
/// The top‑level configuration – only a subcommand is needed here.
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(
|
||||||
|
name = "monster",
|
||||||
|
author,
|
||||||
|
version,
|
||||||
|
about = "Export or balance monster data"
|
||||||
|
)]
|
||||||
|
pub struct MonsterConfig {
|
||||||
|
/// Which action to perform
|
||||||
|
#[command(subcommand)]
|
||||||
|
pub target: MonsterTarget,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The two actions the binary can take.
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub enum MonsterTarget {
|
||||||
|
/// Generate a tex file(s) with monster lists
|
||||||
|
Export(ExportArgs),
|
||||||
|
|
||||||
|
/// Produce balancing diagnostics
|
||||||
|
Balance(BalanceArgs),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Common arguments
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
pub struct CommonDb {
|
||||||
|
#[arg(
|
||||||
|
short = 'd',
|
||||||
|
long = "database",
|
||||||
|
default_value = "./ravenous_databases/monsters.db",
|
||||||
|
help = "Path to the SQLite monster database"
|
||||||
|
)]
|
||||||
|
/// Database to load from – shared by *both* commands.
|
||||||
|
pub database: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
/// Filter data
|
||||||
|
pub struct CommonFilter {
|
||||||
|
#[arg(
|
||||||
|
long = "filter",
|
||||||
|
default_value = "show_to_master = 1",
|
||||||
|
help = "SQL‑like filter applied when querying monsters"
|
||||||
|
)]
|
||||||
|
/// Optional data filter – also shared by both commands.
|
||||||
|
pub filter: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
/// Export only arguments
|
||||||
|
pub struct ExportArgs {
|
||||||
|
/// Flatten the shared database flag into this command.
|
||||||
|
#[clap(flatten)]
|
||||||
|
pub db: CommonDb,
|
||||||
|
|
||||||
|
/// Flatten the shared filter flag into this command.
|
||||||
|
#[clap(flatten)]
|
||||||
|
pub filter: CommonFilter,
|
||||||
|
|
||||||
|
/// Path where the tex files will be written
|
||||||
|
#[arg(long, default_value = "./Bestiaire/")]
|
||||||
|
pub destination: String,
|
||||||
|
|
||||||
|
/// Export *all* monsters (full_bestiaire.tex)
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub master: bool,
|
||||||
|
|
||||||
|
/// Export only player‑usable monsters
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub player: bool,
|
||||||
|
|
||||||
|
/// Export both `master` and `player`
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub all: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
/// Balance only arguments
|
||||||
|
pub struct BalanceArgs {
|
||||||
|
/// Flatten the shared database flag into this command.
|
||||||
|
#[clap(flatten)]
|
||||||
|
pub db: CommonDb,
|
||||||
|
|
||||||
|
/// Flatten the shared filter flag into this command.
|
||||||
|
#[clap(flatten)]
|
||||||
|
pub filter: CommonFilter,
|
||||||
|
|
||||||
|
/// Show the raw balancing numbers
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub show_extra: bool,
|
||||||
|
|
||||||
|
/// Show even the balanced numbers
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub show_balanced: bool,
|
||||||
|
|
||||||
|
/// Show detailed profiles for each monster
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub show_profiles: bool,
|
||||||
|
}
|
||||||
|
/// Configuration data for generating a monster sheet.
|
||||||
|
///
|
||||||
|
/// The values are plain LaTeX fragments stored in the `[monster]` section of a `.toml`
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct MonsterMarkup {
|
||||||
|
/// Color map
|
||||||
|
#[serde(deserialize_with = "parse_monster_color")]
|
||||||
|
pub color_table: MonsterColor,
|
||||||
|
|
||||||
|
/// Default color
|
||||||
|
pub default_color: String,
|
||||||
|
|
||||||
|
/// Common part of monsters
|
||||||
|
pub common_part: String,
|
||||||
|
|
||||||
|
/// Master part of monsters
|
||||||
|
pub master_part: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
/// The configuration for the weapon exporting
|
||||||
|
pub struct WeaponExport {
|
||||||
|
/// The template to use
|
||||||
|
pub template: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ghetto color import
|
||||||
|
pub struct MonsterColor {
|
||||||
|
/// Inner color
|
||||||
|
pub inner: IndexMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for MonsterColor {
|
||||||
|
type Target = IndexMap<String, String>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the monster colors from a toml
|
||||||
|
fn parse_monster_color<'de, D>(deserializer: D) -> Result<MonsterColor, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let color = String::deserialize(deserializer)?;
|
||||||
|
Ok(MonsterColor {
|
||||||
|
inner: color
|
||||||
|
.lines()
|
||||||
|
.filter_map(|line| {
|
||||||
|
let line = line.trim();
|
||||||
|
if line.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split at the first ':' only.
|
||||||
|
let mut parts = line.splitn(2, ':');
|
||||||
|
let key = parts.next()?.trim().to_string();
|
||||||
|
let value = parts.next().map(|v| v.trim()).ok_or(()).ok()?;
|
||||||
|
|
||||||
|
Some((key, value.to_owned()))
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ pub struct TableArgs {
|
||||||
pub filenames: Vec<String>,
|
pub filenames: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This config is can contain unconstructed code for compatibility purposes
|
// This config can contain unconstructed code for compatibility purposes
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
/// The Craft configs
|
/// The Craft configs
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "fast_class"
|
name = "fast_class"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "formatter"
|
name = "formatter"
|
||||||
version = "0.1.1"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "graphs"
|
name = "graphs"
|
||||||
version = "0.1.4"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ fn init_graph_config(_args: &GraphConfig) -> Result<()> {
|
||||||
/// Load the config if given of the default config if none
|
/// Load the config if given of the default config if none
|
||||||
fn load_graph_config(args: &GraphConfig) -> Result<MiniTheme> {
|
fn load_graph_config(args: &GraphConfig) -> Result<MiniTheme> {
|
||||||
if let Some(c) = &args.config {
|
if let Some(c) = &args.config {
|
||||||
println!("[INFO] Reading config {}", &c);
|
println!("[INFO] Reading config {}", c);
|
||||||
let mut f = File::open(c).context("Opening config")?;
|
let mut f = File::open(c).context("Opening config")?;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
f.read_to_string(&mut buf).context("Reading the config")?;
|
f.read_to_string(&mut buf).context("Reading the config")?;
|
||||||
|
|
@ -104,8 +104,8 @@ fn gen_graph(args: &GraphConfig) -> Result<()> {
|
||||||
let cfg = load_graph_config(args)?;
|
let cfg = load_graph_config(args)?;
|
||||||
|
|
||||||
for graph in csv.values {
|
for graph in csv.values {
|
||||||
let path_svg = format!("{}/{}.svg", args.destination, &graph.name);
|
let path_svg = format!("{}/{}.svg", args.destination, graph.name);
|
||||||
let path_png = format!("{}/{}.png", args.destination, &graph.name);
|
let path_png = format!("{}/{}.png", args.destination, graph.name);
|
||||||
println!("[INFO] Processing {}", path_svg);
|
println!("[INFO] Processing {}", path_svg);
|
||||||
|
|
||||||
let mut f = File::create(&path_svg)?;
|
let mut f = File::create(&path_svg)?;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "make"
|
name = "make"
|
||||||
version = "0.1.2"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -12,8 +12,8 @@ serde = {workspace = true}
|
||||||
toml = {workspace = true}
|
toml = {workspace = true}
|
||||||
tokio = {workspace = true}
|
tokio = {workspace = true}
|
||||||
dynfmt = {workspace = true}
|
dynfmt = {workspace = true}
|
||||||
|
indexmap = {workspace = true}
|
||||||
|
|
||||||
indicatif = { version = "0.18.6", features = ["rayon"] }
|
indicatif = { version = "0.18.6", features = ["rayon"] }
|
||||||
logos = "0.16.1"
|
logos = "0.16.1"
|
||||||
indexmap = "2.14.0"
|
|
||||||
console = "0.16.4"
|
console = "0.16.4"
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,16 @@ use tokio::{
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Context, Result, anyhow};
|
||||||
|
|
||||||
use crate::makepdf_functions::{
|
|
||||||
BuilderParseResult, make_clean, make_file, make_glossaries, make_list,
|
|
||||||
};
|
|
||||||
use crate::makepdf_structs::{
|
use crate::makepdf_structs::{
|
||||||
BuildInfo, COL_INFO, COL_NORMAL, LineType, Status, TXT_BOXX, TXT_CNTX, TXT_CRIT, TXT_ERRR,
|
BuildInfo, COL_INFO, COL_NORMAL, LineType, Status, TXT_BOXX, TXT_CNTX, TXT_CRIT, TXT_ERRR,
|
||||||
TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN,
|
TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN,
|
||||||
};
|
};
|
||||||
|
use crate::{
|
||||||
|
makepdf_functions::{BuilderParseResult, make_clean, make_file, make_glossaries, make_list},
|
||||||
|
makepdf_structs::TXT_ICTX,
|
||||||
|
};
|
||||||
|
|
||||||
/// Make a pdf spawning a subprocess
|
/// Make a pdf spawning a subprocess
|
||||||
pub fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> {
|
pub fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> {
|
||||||
|
|
@ -61,7 +62,7 @@ pub fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> {
|
||||||
Some(MakeTargets::Clean) => make_clean(args),
|
Some(MakeTargets::Clean) => make_clean(args),
|
||||||
None => {
|
None => {
|
||||||
let file = make_file(args);
|
let file = make_file(args);
|
||||||
launch_subprocess(args, file).unwrap();
|
launch_subprocess(args, file).context("Launching PdfLatex")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -102,7 +103,7 @@ async fn launch_subprocess(
|
||||||
// Specify that we want the command's standard output piped back to us.
|
// Specify that we want the command's standard output piped back to us.
|
||||||
cmd.stdout(Stdio::piped());
|
cmd.stdout(Stdio::piped());
|
||||||
|
|
||||||
let mut child = cmd.spawn().expect("Failed to spawn command");
|
let mut child = cmd.spawn().context("Failed to spawn command")?;
|
||||||
|
|
||||||
let stdout = child
|
let stdout = child
|
||||||
.stdout
|
.stdout
|
||||||
|
|
@ -267,6 +268,10 @@ fn checkline(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if final_line.vlvl() >= VerboseLevel::Error {
|
||||||
|
let v = final_line.clone();
|
||||||
|
let _ = status.first_error.set(v);
|
||||||
|
}
|
||||||
match &final_line.vlvl() {
|
match &final_line.vlvl() {
|
||||||
VerboseLevel::None => (),
|
VerboseLevel::None => (),
|
||||||
VerboseLevel::Misc => pb.println(format!(
|
VerboseLevel::Misc => pb.println(format!(
|
||||||
|
|
@ -284,6 +289,15 @@ fn checkline(
|
||||||
*TXT_CNTX,
|
*TXT_CNTX,
|
||||||
COL_NORMAL.apply_to(final_line)
|
COL_NORMAL.apply_to(final_line)
|
||||||
)), // Context tends to be shit ))?
|
)), // Context tends to be shit ))?
|
||||||
|
VerboseLevel::InteractiveContext => {
|
||||||
|
if !args.non_interactive {
|
||||||
|
pb.println(format!(
|
||||||
|
"{} {:?}",
|
||||||
|
*TXT_ICTX,
|
||||||
|
COL_NORMAL.apply_to(final_line)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
VerboseLevel::Info => {
|
VerboseLevel::Info => {
|
||||||
status.info += 1;
|
status.info += 1;
|
||||||
pb.println(format!(
|
pb.println(format!(
|
||||||
|
|
@ -317,7 +331,7 @@ fn checkline(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
VerboseLevel::Uncatchable => {
|
VerboseLevel::Uncatchable => {
|
||||||
// status.errors += 1;
|
status.errors += 1;
|
||||||
pb.println(format!(
|
pb.println(format!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
*TXT_UKNW,
|
*TXT_UKNW,
|
||||||
|
|
@ -325,5 +339,6 @@ fn checkline(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ pub(super) fn make_file(args: &MakeConfig) -> BuilderParseResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
BuilderParseResult {
|
BuilderParseResult {
|
||||||
new_name: format!("{:?}", &path),
|
new_name: format!("{:?}", path),
|
||||||
chapt_list: chapters,
|
chapt_list: chapters,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -301,9 +301,9 @@ pub(super) fn make_clean(args: &MakeConfig) {
|
||||||
for s in list_suff {
|
for s in list_suff {
|
||||||
// The most ghetto *** I've done so far
|
// The most ghetto *** I've done so far
|
||||||
// cmd.arg(format!("{}{}", &target, s));
|
// cmd.arg(format!("{}{}", &target, s));
|
||||||
cmd.arg(format!("{}_build{}", &target, s));
|
cmd.arg(format!("{}_build{}", target, s));
|
||||||
}
|
}
|
||||||
cmd.arg(format!("{}_build{}", &target, ".tex"));
|
cmd.arg(format!("{}_build{}", target, ".tex"));
|
||||||
// println!("{:?}", cmd);
|
// println!("{:?}", cmd);
|
||||||
if let Err(e) = cmd.output() {
|
if let Err(e) = cmd.output() {
|
||||||
println!(
|
println!(
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use config::make::VerboseLevel;
|
||||||
use logos::Logos;
|
use logos::Logos;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
|
cell::OnceCell,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
|
|
@ -46,6 +47,9 @@ pub(super) static TXT_BOXX: LazyLock<String> =
|
||||||
/// Filler box for the [CNTX] text box
|
/// Filler box for the [CNTX] text box
|
||||||
pub(super) static TXT_CNTX: LazyLock<String> =
|
pub(super) static TXT_CNTX: LazyLock<String> =
|
||||||
LazyLock::new(|| format!("{}", COL_CONTEXT.apply_to(&"[CNTX]")));
|
LazyLock::new(|| format!("{}", COL_CONTEXT.apply_to(&"[CNTX]")));
|
||||||
|
/// Filler box for the [CNTX] text box
|
||||||
|
pub(super) static TXT_ICTX: LazyLock<String> =
|
||||||
|
LazyLock::new(|| format!("{}", COL_CONTEXT.apply_to(&"[ICTX]")));
|
||||||
/// Filler box for the [INFO] text box
|
/// Filler box for the [INFO] text box
|
||||||
pub(super) static TXT_INFO: LazyLock<String> =
|
pub(super) static TXT_INFO: LazyLock<String> =
|
||||||
LazyLock::new(|| format!("{}", COL_INFO.apply_to(&"[INFO]")));
|
LazyLock::new(|| format!("{}", COL_INFO.apply_to(&"[INFO]")));
|
||||||
|
|
@ -138,7 +142,7 @@ impl BuildInfo {
|
||||||
|
|
||||||
/// The line encountered
|
/// The line encountered
|
||||||
// #[allow(unused)]
|
// #[allow(unused)]
|
||||||
#[derive(Debug, Logos, PartialEq)]
|
#[derive(Debug, Logos, PartialEq, Clone)]
|
||||||
#[logos(skip r"[) ]+")]
|
#[logos(skip r"[) ]+")]
|
||||||
pub(super) enum LineType {
|
pub(super) enum LineType {
|
||||||
/// The tex building mode : entering extended mode
|
/// The tex building mode : entering extended mode
|
||||||
|
|
@ -225,13 +229,29 @@ pub(super) enum LineType {
|
||||||
// #[regex(r"[\) ]*\(\./[A-z/]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
// #[regex(r"[\) ]*\(\./[A-z/]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
||||||
// #[regex(r"[\) ]*(\[[0-9]+\] )?\(\./[A-z/-_]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
// #[regex(r"[\) ]*(\[[0-9]+\] )?\(\./[A-z/-_]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
||||||
// #[regex(r"[\) 0-9\[\]]*\(\./[A-z/-_]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
// #[regex(r"[\) 0-9\[\]]*\(\./[A-z/-_]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
||||||
#[regex(r"\(\./[A-z/_-]+\.(gls|tex)", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
#[regex(r"\(\./[A-z/0-9_-]+\.(gls|tex)", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
||||||
EnteringDocument(String),
|
EnteringDocument(String),
|
||||||
|
|
||||||
/// Info on the loading of a library
|
/// Info on the loading of a library
|
||||||
#[regex(r"Library \(\w+\)[^\n]+", |lex| split_by(":",&lex.slice()[8..]), allow_greedy=true)]
|
#[regex(r"Library \(\w+\)[^\n]+", |lex| split_by(":",&lex.slice()[8..]), allow_greedy=true)]
|
||||||
Library((String, String)),
|
Library((String, String)),
|
||||||
|
|
||||||
|
/// Glossary will not be built
|
||||||
|
#[token("This document will not have a glossary.")]
|
||||||
|
#[token("Remove .makeglossaries if you don't want any glossaries.")]
|
||||||
|
NoGlossary,
|
||||||
|
|
||||||
|
#[regex(r"No file [^$]+\.gls\.", |lex| lex.slice().replace("No file ", ""))]
|
||||||
|
/// The glossary file wasn't found
|
||||||
|
NoGlossaryFile(String),
|
||||||
|
|
||||||
|
#[regex(
|
||||||
|
r" ?\)?<?/usr/share/texlive/texmf.dist/fonts/type1/public/fontawesome5[^\n]+",
|
||||||
|
allow_greedy = true
|
||||||
|
)]
|
||||||
|
/// The fontawesome package has loaded it's fonts
|
||||||
|
FontAwesome,
|
||||||
|
|
||||||
/// The warning generated by a package
|
/// The warning generated by a package
|
||||||
#[regex(r"Package [A-z_-]+ Warning: [^\n]+", |lex| split_by(":",lex.slice()), allow_greedy=true)]
|
#[regex(r"Package [A-z_-]+ Warning: [^\n]+", |lex| split_by(":",lex.slice()), allow_greedy=true)]
|
||||||
PackageWarningPrs((String, String)),
|
PackageWarningPrs((String, String)),
|
||||||
|
|
@ -246,6 +266,15 @@ pub(super) enum LineType {
|
||||||
#[regex(r"\([A-z_-]+\) [^\n]+", |lex| split_by(")",&lex.slice()[1..]), allow_greedy=true)]
|
#[regex(r"\([A-z_-]+\) [^\n]+", |lex| split_by(")",&lex.slice()[1..]), allow_greedy=true)]
|
||||||
PackageContext((String, String)),
|
PackageContext((String, String)),
|
||||||
|
|
||||||
|
/// You should read the LaTex manual
|
||||||
|
#[token("See the pdftex.def package documentation for explanation.", |lex| lex.slice().to_string())]
|
||||||
|
#[token("See the LaTeX manual or LaTeX Companion for explanation.", |lex| lex.slice().to_string())]
|
||||||
|
HelpGiven(String),
|
||||||
|
|
||||||
|
/// Interactive prompt
|
||||||
|
#[token("Type H for immediate help.")]
|
||||||
|
Prompt,
|
||||||
|
|
||||||
/// Loading (Load something)
|
/// Loading (Load something)
|
||||||
#[regex(r"(\)+ )?\(/usr[^)]*", |lex| lex.slice().split("/").last().unwrap_or("").to_string())]
|
#[regex(r"(\)+ )?\(/usr[^)]*", |lex| lex.slice().split("/").last().unwrap_or("").to_string())]
|
||||||
Loading(String),
|
Loading(String),
|
||||||
|
|
@ -268,9 +297,10 @@ pub(super) enum LineType {
|
||||||
#[token("Transcript written on")]
|
#[token("Transcript written on")]
|
||||||
Log,
|
Log,
|
||||||
|
|
||||||
// /// Barely parsable data
|
/// Useless help line
|
||||||
// #[regex(r"\)+")]
|
#[regex(r"\.\.\.")]
|
||||||
// Garbage,
|
Garbage,
|
||||||
|
|
||||||
/// Empty line, to discard
|
/// Empty line, to discard
|
||||||
Empty,
|
Empty,
|
||||||
|
|
||||||
|
|
@ -285,6 +315,22 @@ pub(super) enum LineType {
|
||||||
/// Transcript
|
/// Transcript
|
||||||
#[token("(see the transcript file for additional information)")]
|
#[token("(see the transcript file for additional information)")]
|
||||||
Transcript,
|
Transcript,
|
||||||
|
// /// Known Errors
|
||||||
|
|
||||||
|
// ! Package pdftex.def Error: File `./Images/Bestiaire/Mjonn Alpha des Brumes.jpg' not found: using draft setting. // ! LaTeX Error: \begin{tblr} on input line 587 ended by \end{longtblr}.
|
||||||
|
// /// Unmatch begin and end environement
|
||||||
|
// #[token("! LeTex Error")]
|
||||||
|
// UnmatchedSequences,
|
||||||
|
// /// A \ something was used without being defined
|
||||||
|
// #[token("! Undefined control sequence.")]
|
||||||
|
// UndefinedControlSequence,
|
||||||
|
|
||||||
|
// /// Error Context
|
||||||
|
// #[regex(r"l\.\d+ [^\n]+", |lex| split_by(" ",lex.slice()), allow_greedy=true) ]
|
||||||
|
// #[regex(r".+\[^\]+", |lex| split_by("\\",lex.slice()), allow_greedy=true) ]
|
||||||
|
// #[regex(" +\\[^\n]+", |lex|{("".to_string(),lex.slice().trim_start().to_string())},allow_greedy = true)]
|
||||||
|
// // #[regex(r"\(\./[A-z/_-]+\.(gls|tex)", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())]
|
||||||
|
// ErrorContext((String, String)),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineType {
|
impl LineType {
|
||||||
|
|
@ -330,6 +376,15 @@ impl LineType {
|
||||||
LineType::MissingReferencePrs => VerboseLevel::Critical,
|
LineType::MissingReferencePrs => VerboseLevel::Critical,
|
||||||
LineType::BoxFullnessPrs => VerboseLevel::Critical,
|
LineType::BoxFullnessPrs => VerboseLevel::Critical,
|
||||||
LineType::PackageWarningPrs(_) => VerboseLevel::Critical,
|
LineType::PackageWarningPrs(_) => VerboseLevel::Critical,
|
||||||
|
LineType::NoGlossary => VerboseLevel::Warning,
|
||||||
|
LineType::FontAwesome => VerboseLevel::Info,
|
||||||
|
LineType::NoGlossaryFile(_) => VerboseLevel::Warning,
|
||||||
|
LineType::HelpGiven(_) => VerboseLevel::Context,
|
||||||
|
LineType::Prompt => VerboseLevel::InteractiveContext,
|
||||||
|
LineType::Garbage => VerboseLevel::None,
|
||||||
|
// LineType::ErrorContext(_) => VerboseLevel::Error,
|
||||||
|
// LineType::UndefinedControlSequence => VerboseLevel::Error,
|
||||||
|
// LineType::UnmatchedSequences => VerboseLevel::Error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -353,8 +408,8 @@ pub(super) struct Status {
|
||||||
pub(super) warnings: usize,
|
pub(super) warnings: usize,
|
||||||
/// Only makes sense with non-interactie builds
|
/// Only makes sense with non-interactie builds
|
||||||
pub(super) errors: usize,
|
pub(super) errors: usize,
|
||||||
// /// List of all recoverable
|
/// List of all recoverable
|
||||||
// pub(super) v_errors: Vec<String>,
|
pub(super) first_error: OnceCell<LineType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
|
|
@ -364,6 +419,7 @@ impl Status {
|
||||||
info: 0,
|
info: 0,
|
||||||
warnings: 0,
|
warnings: 0,
|
||||||
errors: 0,
|
errors: 0,
|
||||||
|
first_error: OnceCell::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,6 +431,16 @@ impl Status {
|
||||||
file_info: BuilderParseResult,
|
file_info: BuilderParseResult,
|
||||||
) {
|
) {
|
||||||
let col_bld = COL_INFO.clone().bold();
|
let col_bld = COL_INFO.clone().bold();
|
||||||
|
if self.errors > 3 {
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
col_bld.apply_to("[RCAP]"),
|
||||||
|
COL_NORMAL.apply_to(format!(
|
||||||
|
"The first error encountered was: {:?}",
|
||||||
|
self.first_error.get()
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
println!();
|
println!();
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
[package]
|
||||||
|
name = "monsters"
|
||||||
|
version.workspace = true
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
config = {workspace = true}
|
||||||
|
cli_parser = {workspace = true}
|
||||||
|
more_fields = {workspace = true}
|
||||||
|
anyhow = {workspace = true}
|
||||||
|
indexmap = {workspace = true}
|
||||||
|
serde = {workspace = true}
|
||||||
|
rusqlite = {workspace = true}
|
||||||
|
serde_rusqlite = {workspace = true}
|
||||||
|
serde_json = {workspace = true}
|
||||||
|
handlebars = {workspace = true}
|
||||||
|
strum = {workspace = true}
|
||||||
|
probability = {workspace = true}
|
||||||
|
comfy-table = "7.2.2"
|
||||||
|
colored = "3.1.1"
|
||||||
|
# derive_more = "2.1.1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
regex = {workspace = true}
|
||||||
|
pretty_assertions = {workspace = true}
|
||||||
|
clap = {workspace = true}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
//! # Monsters Module
|
||||||
|
//!
|
||||||
|
//! The `monsters` crate orchestrates the processing of *ravenous* monster data.
|
||||||
|
//!
|
||||||
|
//! It can:
|
||||||
|
//! * **Parse** raw monster definitions into ergonomic Rust structs.
|
||||||
|
//! * Perform **balancing** calculations to keep encounters fair.
|
||||||
|
//! * **Show** concise, human‑readable summaries in the terminal.
|
||||||
|
//! * **Export** processed data as LaTeX/TeX for printing or further editing.
|
||||||
|
//!
|
||||||
|
//! All functionality is exposed through a single entry point:
|
||||||
|
//! [`monsters_dispatch`]. The dispatcher interprets command‑line arguments
|
||||||
|
//! (`MonsterConfig`) and delegates to the appropriate sub‑routine (clean, export or show).
|
||||||
|
//!
|
||||||
|
|
||||||
|
use crate::{monster_analysis::show_balancing_data, monster_export::generate_monsters_tex};
|
||||||
|
|
||||||
|
use config::monsters::MonsterTarget;
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
|
mod monster_analysis;
|
||||||
|
mod monster_database;
|
||||||
|
mod monster_export;
|
||||||
|
mod monster_render;
|
||||||
|
pub mod monster_structs;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use cli_parser::Config;
|
||||||
|
use config::monsters::MonsterConfig;
|
||||||
|
use rusqlite::Connection;
|
||||||
|
|
||||||
|
/// Dispatches the chosen monster action.
|
||||||
|
pub fn monsters_dispatch(args: &MonsterConfig, config: &Config) -> Result<()> {
|
||||||
|
// use config::monsters::MonsterTarget;
|
||||||
|
|
||||||
|
match args.target {
|
||||||
|
// MonsterTarget::Clean => unimplemented!("implement cleaning logic"),
|
||||||
|
MonsterTarget::Export(ref args) => {
|
||||||
|
let connection = Connection::open(&args.db.database)
|
||||||
|
.context(format!("Opening database {}", args.db.database))?;
|
||||||
|
generate_monsters_tex(args, config, connection)?
|
||||||
|
}
|
||||||
|
// MonsterTarget::Show => unimplemented!("implement show logic"),
|
||||||
|
MonsterTarget::Balance(ref args) => {
|
||||||
|
let connection = Connection::open(&args.db.database)
|
||||||
|
.context(format!("Opening database {}", args.db.database))?;
|
||||||
|
show_balancing_data(args, config, connection)?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
//! Monster export module
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use comfy_table::modifiers;
|
||||||
|
use config::monsters::BalanceArgs;
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
Config, Connection,
|
||||||
|
monster_analysis::monster_analysis_structs::DefenseMode,
|
||||||
|
monster_database::{fetch_all_creature_data, fetch_all_player_data},
|
||||||
|
monster_render::ToCell,
|
||||||
|
monster_structs::{PlayerBalancing, ProfileStance},
|
||||||
|
};
|
||||||
|
pub mod attack_analysis;
|
||||||
|
pub mod defense_analysis;
|
||||||
|
pub mod helpers;
|
||||||
|
pub mod monster_analysis_structs;
|
||||||
|
|
||||||
|
/// Shows balancing information for monsters and players.
|
||||||
|
pub fn show_balancing_data(
|
||||||
|
args: &BalanceArgs,
|
||||||
|
config: &Config,
|
||||||
|
connection: Connection,
|
||||||
|
) -> Result<(), anyhow::Error> {
|
||||||
|
let _ = args;
|
||||||
|
let data = fetch_all_creature_data(&connection, config, args.filter.filter.as_deref())?;
|
||||||
|
let player_data = fetch_all_player_data(&connection, config)?;
|
||||||
|
|
||||||
|
for creature in data {
|
||||||
|
// println!("{}", creature.name);
|
||||||
|
let mut table = comfy_table::Table::new();
|
||||||
|
table
|
||||||
|
.load_preset(comfy_table::presets::UTF8_FULL_CONDENSED)
|
||||||
|
.apply_modifier(modifiers::UTF8_ROUND_CORNERS)
|
||||||
|
.set_width(120)
|
||||||
|
.set_content_arrangement(comfy_table::ContentArrangement::Dynamic);
|
||||||
|
table.add_row(vec![
|
||||||
|
creature.id.to_cell(),
|
||||||
|
match creature.balancing.monster_groupsize {
|
||||||
|
1. => creature.name.clone(),
|
||||||
|
n => format!("{} x {}", creature.name, n),
|
||||||
|
}
|
||||||
|
.to_cell()
|
||||||
|
.fg(comfy_table::Color::Blue), // .add_attribute(comfy_table::Attribute::Reverse),
|
||||||
|
]);
|
||||||
|
|
||||||
|
println!("{table}");
|
||||||
|
let player_level = &creature.balancing.profile_hse;
|
||||||
|
let available_profiles = player_data
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|v| &v.profile_hse == player_level)
|
||||||
|
.collect::<Vec<PlayerBalancing>>();
|
||||||
|
|
||||||
|
let profiles: IndexMap<ProfileStance, PlayerBalancing> = available_profiles
|
||||||
|
.into_iter()
|
||||||
|
.map(|profile| (profile.profile_stance, profile))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
defense_analysis::display_player_attacks(args, &creature, &profiles, DefenseMode::Worst);
|
||||||
|
defense_analysis::display_monster_attacks(args, creature, &profiles, DefenseMode::Best);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
use crate::{
|
||||||
|
monster_analysis::{
|
||||||
|
helpers,
|
||||||
|
monster_analysis_structs::{
|
||||||
|
self, ArmorBreakCategory, DamageCategory, DefenseMode, Showcase,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
monster_structs::{PlayerBalancing, ProfileStance},
|
||||||
|
};
|
||||||
|
use config::monsters::BalanceArgs;
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use more_fields::FieldsAsSlice;
|
||||||
|
use std::cmp::max;
|
||||||
|
|
||||||
|
/// Returns the Balancing profile, and eventually the other profiles as well
|
||||||
|
pub fn all_attacks(
|
||||||
|
args: &BalanceArgs,
|
||||||
|
attack: &monster_analysis_structs::MonsterBalancingAttack,
|
||||||
|
victims: &IndexMap<ProfileStance, PlayerBalancing>,
|
||||||
|
mode: DefenseMode,
|
||||||
|
) -> Vec<DamageReport> {
|
||||||
|
let mut balancing = vec![
|
||||||
|
attack_player(
|
||||||
|
attack,
|
||||||
|
&victims[&attack.target_stance],
|
||||||
|
mode,
|
||||||
|
Showcase::Balancing,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
];
|
||||||
|
if !args.show_balanced
|
||||||
|
&& balancing[0].damage_category == attack.target_damage
|
||||||
|
&& balancing[0].armor_category == attack.target_ab
|
||||||
|
{
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
if !args.show_extra {
|
||||||
|
return balancing;
|
||||||
|
}
|
||||||
|
let mut v = victims
|
||||||
|
.iter()
|
||||||
|
.filter(|&(stance, _)| *stance != attack.target_stance) // keep only non‑targets
|
||||||
|
.map(|(_, victim)| attack_player(attack, victim, mode, Showcase::Display))
|
||||||
|
.collect::<Option<Vec<DamageReport>>>()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
balancing.append(&mut v);
|
||||||
|
balancing
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn attack_player(
|
||||||
|
attack: &monster_analysis_structs::MonsterBalancingAttack,
|
||||||
|
victim: &PlayerBalancing,
|
||||||
|
mode: DefenseMode,
|
||||||
|
showcase: Showcase,
|
||||||
|
) -> Option<DamageReport> {
|
||||||
|
// How much successes left
|
||||||
|
let threshold = match mode {
|
||||||
|
DefenseMode::Best => max(attack.threshold_parry, attack.threshold_dodge),
|
||||||
|
DefenseMode::Worst => max(attack.threshold_parry, attack.threshold_dodge),
|
||||||
|
} + victim.specialty_def;
|
||||||
|
|
||||||
|
let bin = helpers::binomial_dice_distribution(threshold, victim.successes_def);
|
||||||
|
let avg_successes_left: f64 = bin
|
||||||
|
.iter()
|
||||||
|
.map(|(dice, p)| (attack.successes - dice) as f64 * p)
|
||||||
|
.sum::<f64>();
|
||||||
|
let avg_damage_incomming: f64 = bin
|
||||||
|
.iter()
|
||||||
|
.map(|(dices, p)| {
|
||||||
|
helpers::how_much_with_succeses(&attack.damage, attack.successes - dices) as f64 * p
|
||||||
|
})
|
||||||
|
.sum::<f64>();
|
||||||
|
let damage_incoming = avg_damage_incomming;
|
||||||
|
let mut damage_tanked =
|
||||||
|
(damage_incoming - (victim.protection + victim.strength) as f64).max(0.0);
|
||||||
|
let mut armor_loss =
|
||||||
|
(damage_incoming - victim.protection as f64).clamp(0.0, attack.armor_break as f64);
|
||||||
|
if avg_successes_left > 0. {
|
||||||
|
armor_loss += attack.antimaterial as f64;
|
||||||
|
damage_tanked += attack.armor_pierce.min(victim.protection) as f64;
|
||||||
|
}
|
||||||
|
let report = DamageReport {
|
||||||
|
damage_incoming,
|
||||||
|
damage_tanked,
|
||||||
|
armor_loss,
|
||||||
|
successes_left: avg_successes_left,
|
||||||
|
damage_category: DamageCategory::from_percent(damage_tanked as f64 / victim.health as f64),
|
||||||
|
armor_expected: attack.target_ab,
|
||||||
|
name: attack.name.clone(),
|
||||||
|
damage_expected: attack.target_damage,
|
||||||
|
armor_category: ArmorBreakCategory::from_percent(
|
||||||
|
armor_loss as f64 / victim.integrity as f64,
|
||||||
|
),
|
||||||
|
player_health: victim.health,
|
||||||
|
player_integrity: victim.integrity,
|
||||||
|
threshold,
|
||||||
|
attack_successes: attack.successes,
|
||||||
|
mode,
|
||||||
|
showcase,
|
||||||
|
fatigue: attack.fatigue,
|
||||||
|
stance: victim.profile_stance,
|
||||||
|
};
|
||||||
|
Some(report)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, FieldsAsSlice)]
|
||||||
|
pub struct DamageReport {
|
||||||
|
pub name: String,
|
||||||
|
#[INTEGER(name = "dmg_inc")]
|
||||||
|
pub damage_incoming: f64,
|
||||||
|
#[INTEGER(name = "F")]
|
||||||
|
pub fatigue: i64,
|
||||||
|
#[INTEGER(name = "r_left")]
|
||||||
|
pub successes_left: f64,
|
||||||
|
#[INTEGER(name = "dmg_tak")]
|
||||||
|
pub damage_tanked: f64,
|
||||||
|
#[TEXT(name = "dmg_cat")]
|
||||||
|
pub damage_category: DamageCategory,
|
||||||
|
#[TEXT(name = "dmg_expt")]
|
||||||
|
pub damage_expected: DamageCategory,
|
||||||
|
#[INTEGER(name = "arm_loss")]
|
||||||
|
pub armor_loss: f64,
|
||||||
|
#[TEXT(name = "arm_cat")]
|
||||||
|
pub armor_category: ArmorBreakCategory,
|
||||||
|
#[TEXT(name = "arm_expt")]
|
||||||
|
pub armor_expected: ArmorBreakCategory,
|
||||||
|
#[SKIP]
|
||||||
|
pub player_health: i64,
|
||||||
|
#[SKIP]
|
||||||
|
pub player_integrity: i64,
|
||||||
|
#[SKIP]
|
||||||
|
pub threshold: i64,
|
||||||
|
#[SKIP]
|
||||||
|
pub mode: DefenseMode,
|
||||||
|
#[SKIP]
|
||||||
|
pub stance: ProfileStance,
|
||||||
|
#[SKIP]
|
||||||
|
pub attack_successes: i64,
|
||||||
|
#[SKIP]
|
||||||
|
pub showcase: monster_analysis_structs::Showcase,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,424 @@
|
||||||
|
use crate::{
|
||||||
|
monster_analysis::{
|
||||||
|
DefenseMode, attack_analysis,
|
||||||
|
helpers::{binomial_dice_distribution, how_much_with_succeses},
|
||||||
|
monster_analysis_structs::{self, Showcase},
|
||||||
|
},
|
||||||
|
monster_render::ToTable,
|
||||||
|
monster_structs::{CreatureBodyPart, FullMonster, PlayerBalancing, ProfileHSE, ProfileStance},
|
||||||
|
};
|
||||||
|
use config::monsters::BalanceArgs;
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use more_fields::FieldsAsSlice;
|
||||||
|
use std::ops::AddAssign;
|
||||||
|
|
||||||
|
pub(crate) fn display_player_attacks(
|
||||||
|
args: &BalanceArgs,
|
||||||
|
creature: &FullMonster,
|
||||||
|
profiles: &IndexMap<ProfileStance, PlayerBalancing>,
|
||||||
|
mode: DefenseMode,
|
||||||
|
) {
|
||||||
|
let _ = mode;
|
||||||
|
let r = report_from_profile(args, creature, profiles);
|
||||||
|
println!("{}", r.to_table());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn report_from_profile(
|
||||||
|
args: &BalanceArgs,
|
||||||
|
creature: &FullMonster,
|
||||||
|
profiles: &IndexMap<ProfileStance, PlayerBalancing>,
|
||||||
|
) -> Vec<DefenseReport> {
|
||||||
|
creature
|
||||||
|
.body_parts
|
||||||
|
.body_parts
|
||||||
|
.iter()
|
||||||
|
.flat_map(|body_part| {
|
||||||
|
match args.show_extra {
|
||||||
|
true => vec![
|
||||||
|
(ProfileStance::Neutral, Showcase::Display),
|
||||||
|
(ProfileStance::Defensive, Showcase::Balancing),
|
||||||
|
(ProfileStance::Offensive, Showcase::Balancing),
|
||||||
|
],
|
||||||
|
false => vec![(ProfileStance::Neutral, Showcase::Display)],
|
||||||
|
}
|
||||||
|
.into_iter()
|
||||||
|
.map(|(p, show)| damage_report_on_part(creature, &profiles[&p], body_part, show))
|
||||||
|
.collect::<Vec<DefenseReport>>()
|
||||||
|
})
|
||||||
|
.collect::<Vec<DefenseReport>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ChunkIter {
|
||||||
|
remaining: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChunkIter {
|
||||||
|
fn new(remaining: f64) -> Self {
|
||||||
|
Self { remaining }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for ChunkIter {
|
||||||
|
type Target = f64;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.remaining
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for ChunkIter {
|
||||||
|
type Item = f64;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
if self.remaining >= 1.0 {
|
||||||
|
self.remaining -= 1.0;
|
||||||
|
Some(1.0)
|
||||||
|
} else if self.remaining > 0.0 {
|
||||||
|
// Last piece – whatever is left.
|
||||||
|
let r = self.remaining;
|
||||||
|
self.remaining = 0.0;
|
||||||
|
Some(r)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DamageTransfer<'a> {
|
||||||
|
body_part: &'a CreatureBodyPart,
|
||||||
|
profile: &'a PlayerBalancing,
|
||||||
|
max_parried: i64,
|
||||||
|
phase: Phases,
|
||||||
|
strength: i64,
|
||||||
|
}
|
||||||
|
fn damage_report_on_part(
|
||||||
|
creature: &FullMonster,
|
||||||
|
profile: &PlayerBalancing,
|
||||||
|
body_part: &CreatureBodyPart,
|
||||||
|
display: Showcase,
|
||||||
|
) -> DefenseReport {
|
||||||
|
// Every round need to eliminate X dices from the pool
|
||||||
|
let mut dice_left_to_parry = creature.balancing.average_defensive_successes;
|
||||||
|
let players = ChunkIter::new(creature.balancing.player_groupsize);
|
||||||
|
let mut total_damage_done_p1 = DamageDealtByPlayer::default();
|
||||||
|
let mut total_damage_done_p2 = DamageDealtByPlayer::default();
|
||||||
|
|
||||||
|
for player_chunk in players {
|
||||||
|
let max_parried = dice_left_to_parry.min(profile.successes_off);
|
||||||
|
let mut damage_done_p1 = damage_done_to_part(&DamageTransfer {
|
||||||
|
body_part,
|
||||||
|
profile,
|
||||||
|
max_parried,
|
||||||
|
phase: Phases::P1,
|
||||||
|
strength: creature.stats.strength,
|
||||||
|
});
|
||||||
|
let mut damage_done_p2 = damage_done_to_part(&DamageTransfer {
|
||||||
|
body_part,
|
||||||
|
profile,
|
||||||
|
max_parried,
|
||||||
|
phase: Phases::P2,
|
||||||
|
strength: creature.stats.strength,
|
||||||
|
});
|
||||||
|
dice_left_to_parry = (dice_left_to_parry - max_parried).max(0);
|
||||||
|
if player_chunk < 1. {
|
||||||
|
damage_done_p1.mult(player_chunk);
|
||||||
|
damage_done_p2.mult(player_chunk);
|
||||||
|
}
|
||||||
|
total_damage_done_p1 += damage_done_p1;
|
||||||
|
total_damage_done_p2 += damage_done_p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
let damage_done_p1 = total_damage_done_p1;
|
||||||
|
let damage_done_p2 = total_damage_done_p2;
|
||||||
|
let ratio = 1.0;
|
||||||
|
// let damage_done_p1 = damage_done_to_part(body_part, profile, dice_left_to_parry, Phases::P1);
|
||||||
|
// let damage_done_p2 = damage_done_to_part(body_part, profile, dice_left_to_parry, Phases::P2);
|
||||||
|
// let ratio = creature.balancing.monster_groupsize / creature.balancing.player_groupsize;
|
||||||
|
|
||||||
|
let time_to_p2 = ratio * body_part.life_points_p1.unwrap() as f64 / damage_done_p1.hp_t;
|
||||||
|
let time_to_kill = ratio
|
||||||
|
* (
|
||||||
|
//body_part.life_points_p1.unwrap() as f64 / damage_done_p1.hp_t +
|
||||||
|
body_part.life_points_p2.unwrap_or(0) as f64 / damage_done_p2.hp_t
|
||||||
|
);
|
||||||
|
let time_to_armorbreak = ratio * (body_part.integrity_p1.unwrap() as f64 / damage_done_p1.ab_t);
|
||||||
|
let time_to_kill_through = ratio
|
||||||
|
* (body_part.life_points_p1.unwrap() as f64
|
||||||
|
/ (damage_done_p1.damage_through - creature.stats.strength as f64).max(0.)
|
||||||
|
+ body_part.life_points_p2.unwrap_or(0) as f64
|
||||||
|
/ (damage_done_p2.damage_through - creature.stats.strength as f64).max(0.));
|
||||||
|
DefenseReport {
|
||||||
|
id: creature.balancing.creature_id,
|
||||||
|
name: creature.name.clone(),
|
||||||
|
part_name: body_part.body_part_name.clone(),
|
||||||
|
profile_hse: creature.balancing.profile_hse.clone(),
|
||||||
|
time_to_p2,
|
||||||
|
time_to_p2_target: creature.balancing.time_to_p2,
|
||||||
|
time_to_armorbreak,
|
||||||
|
time_to_player_kill: creature.balancing.time_to_player_kill,
|
||||||
|
monster_groupsize: creature.balancing.monster_groupsize,
|
||||||
|
player_groupsize: creature.balancing.player_groupsize,
|
||||||
|
time_to_kill,
|
||||||
|
time_to_kill_target: creature.balancing.time_to_kill,
|
||||||
|
damage_per_turn_p1: damage_done_p1.hp_t,
|
||||||
|
damage_per_turn_p2: damage_done_p2.hp_t,
|
||||||
|
health_p1: body_part.life_points_p1.unwrap(),
|
||||||
|
health_p2: body_part.life_points_p2.unwrap_or(0),
|
||||||
|
time_to_armorbreak_target: creature.balancing.time_to_armorbreak,
|
||||||
|
armor_break_per_turn: damage_done_p1.ab_t,
|
||||||
|
integrity_p1: body_part.integrity_p1.unwrap(),
|
||||||
|
damage_through_p1: damage_done_p1.damage_through,
|
||||||
|
damage_through_p2: damage_done_p2.damage_through,
|
||||||
|
time_to_kill_through,
|
||||||
|
target_stance: profile.profile_stance,
|
||||||
|
showcase: display,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resist_physical(part: &CreatureBodyPart, mode: DefenseMode) -> i64 {
|
||||||
|
let res = [&part.slash, &part.blunt, &part.piercing]
|
||||||
|
.into_iter()
|
||||||
|
.map(value_resist);
|
||||||
|
match mode {
|
||||||
|
DefenseMode::Best => res.max().unwrap_or(0),
|
||||||
|
DefenseMode::Worst => res.min().unwrap_or(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn value_resist(resist: &Option<String>) -> i64 {
|
||||||
|
match resist {
|
||||||
|
None => 0,
|
||||||
|
Some(s) => {
|
||||||
|
let mut sum = 0;
|
||||||
|
for c in s.chars() {
|
||||||
|
match c {
|
||||||
|
'+' => sum += 2,
|
||||||
|
'-' => sum -= 2,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn damage_done_to_part(info: &DamageTransfer) -> DamageDealtByPlayer {
|
||||||
|
let part = info.body_part;
|
||||||
|
let profile = info.profile;
|
||||||
|
let dice_parried = info.max_parried;
|
||||||
|
let phase = info.phase;
|
||||||
|
let threshold = match phase {
|
||||||
|
Phases::P1 => part.threshold_p1,
|
||||||
|
Phases::P2 => part.threshold_p2,
|
||||||
|
}
|
||||||
|
.unwrap()
|
||||||
|
+ profile.precision;
|
||||||
|
let (_integrity, protection, resist) = match phase {
|
||||||
|
Phases::P1 => (
|
||||||
|
part.integrity_p1.unwrap(),
|
||||||
|
part.protection_p1.unwrap(),
|
||||||
|
resist_physical(part, DefenseMode::Worst) as f64,
|
||||||
|
),
|
||||||
|
Phases::P2 => (
|
||||||
|
part.integrity_p2.unwrap(),
|
||||||
|
part.protection_p2.unwrap(),
|
||||||
|
resist_physical(part, DefenseMode::Worst) as f64,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
let damage_profile: Vec<i64> = (1..profile.max_successes_off)
|
||||||
|
.map(|v| (v as f64 * profile.damage_per_s) as i64)
|
||||||
|
.collect();
|
||||||
|
// Pick the best damage out of all scenarios:
|
||||||
|
// Scenario A : One big hit
|
||||||
|
// Scenario B : Two half hits
|
||||||
|
let dices = (profile.successes_off - dice_parried).clamp(0, profile.successes_off);
|
||||||
|
let damage_a = (damage_with_profile(&damage_profile, threshold, dices) - resist).max(0.);
|
||||||
|
let damage_b1 = (damage_with_profile(&damage_profile, threshold, dices / 2) - resist).max(0.);
|
||||||
|
let damage_b2 =
|
||||||
|
(damage_with_profile(&damage_profile, threshold, dices - dices / 2) - resist).max(0.);
|
||||||
|
let dt_a = (damage_a - protection as f64 - info.strength as f64).max(0.);
|
||||||
|
let dt_b1 = (damage_b1 - protection as f64 - info.strength as f64).max(0.);
|
||||||
|
let dt_b2 = (damage_b2 - protection as f64 - info.strength as f64).max(0.);
|
||||||
|
|
||||||
|
let ab_a = (damage_a - protection as f64).clamp(0., profile.armor_break as f64);
|
||||||
|
let ab_b1 = (damage_b1 - protection as f64).clamp(0., profile.armor_break as f64);
|
||||||
|
let ab_b2 = (damage_b2 - protection as f64).clamp(0., profile.armor_break as f64);
|
||||||
|
let hp_t = damage_a.max(damage_b1 + damage_b2);
|
||||||
|
let ab_t = ab_a.max(ab_b1 + ab_b2);
|
||||||
|
let damage_through = dt_a.max(dt_b2 + dt_b1);
|
||||||
|
|
||||||
|
DamageDealtByPlayer {
|
||||||
|
damage_a,
|
||||||
|
damage_b1,
|
||||||
|
damage_b2,
|
||||||
|
ab_a,
|
||||||
|
ab_b1,
|
||||||
|
ab_b2,
|
||||||
|
hp_t,
|
||||||
|
ab_t,
|
||||||
|
damage_through,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum Phases {
|
||||||
|
P1,
|
||||||
|
P2,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct DamageDealtByPlayer {
|
||||||
|
pub damage_a: f64,
|
||||||
|
pub damage_b1: f64,
|
||||||
|
pub damage_b2: f64,
|
||||||
|
pub ab_a: f64,
|
||||||
|
pub ab_b1: f64,
|
||||||
|
pub ab_b2: f64,
|
||||||
|
pub hp_t: f64,
|
||||||
|
pub ab_t: f64,
|
||||||
|
pub damage_through: f64,
|
||||||
|
}
|
||||||
|
impl AddAssign for DamageDealtByPlayer {
|
||||||
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
|
self.damage_a += rhs.damage_a;
|
||||||
|
self.damage_b1 += rhs.damage_b1;
|
||||||
|
self.damage_b2 += rhs.damage_b2;
|
||||||
|
self.ab_a += rhs.ab_a;
|
||||||
|
self.ab_b1 += rhs.ab_b1;
|
||||||
|
self.ab_b2 += rhs.ab_b2;
|
||||||
|
self.hp_t += rhs.hp_t;
|
||||||
|
self.ab_t += rhs.ab_t;
|
||||||
|
self.damage_through += rhs.damage_through;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DamageDealtByPlayer {
|
||||||
|
fn mult(&mut self, rhs: f64) {
|
||||||
|
self.damage_a *= rhs;
|
||||||
|
self.damage_b1 *= rhs;
|
||||||
|
self.damage_b2 *= rhs;
|
||||||
|
self.ab_a *= rhs;
|
||||||
|
self.ab_b1 *= rhs;
|
||||||
|
self.ab_b2 *= rhs;
|
||||||
|
self.hp_t *= rhs;
|
||||||
|
self.ab_t *= rhs;
|
||||||
|
self.damage_through *= rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn damage_with_profile(damage_profile: &[i64], threshold: i64, dices: i64) -> f64 {
|
||||||
|
let damage = binomial_dice_distribution(threshold, dices);
|
||||||
|
damage
|
||||||
|
.iter()
|
||||||
|
.map(|(d, p)| how_much_with_succeses(damage_profile, *d) as f64 * p)
|
||||||
|
.sum::<f64>()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A snapshot of all defensive metrics for a single monster encounter.
|
||||||
|
/// Each field has one of three semantic labels:
|
||||||
|
/// * **Fixed** – inherent properties that do not change during the fight.
|
||||||
|
/// * **Actual** – metrics computed from a simulation or run‑time analysis.
|
||||||
|
/// * **Goal** – target values you want to achieve in an optimal strategy.
|
||||||
|
#[derive(Debug, FieldsAsSlice)]
|
||||||
|
pub struct DefenseReport {
|
||||||
|
/// Unique identifier for the monster definition.
|
||||||
|
#[SKIP]
|
||||||
|
pub id: i64,
|
||||||
|
/// Display name of the monster (human‑readable).
|
||||||
|
#[SKIP]
|
||||||
|
pub name: String,
|
||||||
|
/// The part of the monster’s body that is currently active
|
||||||
|
pub part_name: String,
|
||||||
|
/// (Fixed) HSE profile of the hunter.
|
||||||
|
#[SKIP(name = "Profile")]
|
||||||
|
pub profile_hse: ProfileHSE,
|
||||||
|
/// (Fixed) Stance of the player.
|
||||||
|
#[SKIP(name = "Stance")]
|
||||||
|
pub target_stance: ProfileStance,
|
||||||
|
/// (Actual) Armor‑breaking damage per turn.
|
||||||
|
/// This is the rate at which the monster’s armor is degraded during combat.
|
||||||
|
#[INTEGER(name = "AbPT P1")]
|
||||||
|
pub armor_break_per_turn: f64,
|
||||||
|
/// (Actual) Turns until this monster’s armor breaks, i.e. the point
|
||||||
|
/// at which it stops being able to mitigate incoming damage.
|
||||||
|
#[INTEGER(name = "TT AB")]
|
||||||
|
pub time_to_armorbreak: f64,
|
||||||
|
/// Damage per turn while in phase 1.
|
||||||
|
/// Used when the monster changes behaviour between phases.
|
||||||
|
#[INTEGER(name = "DPT P1")]
|
||||||
|
pub damage_per_turn_p1: f64,
|
||||||
|
/// (Actual) Turns needed to reach phase 2.
|
||||||
|
/// Computed from the monster’s health and damage output or from simulation data.
|
||||||
|
#[REAL(name = "P1 🠲 P2")]
|
||||||
|
pub time_to_p2: f64,
|
||||||
|
/// (Goal) Desired turns to reach phase 2.
|
||||||
|
/// If the current `time_to_p2` exceeds this value, the fight is considered inefficient.
|
||||||
|
#[SKIP]
|
||||||
|
pub time_to_p2_target: f64,
|
||||||
|
/// Damage per turn while in phase 2.
|
||||||
|
#[INTEGER(name = "DPT P2")]
|
||||||
|
pub damage_per_turn_p2: f64,
|
||||||
|
/// (Actual) Turns needed to kill the monster.
|
||||||
|
/// Derived from its health and damage per turn or from a run‑time simulation.
|
||||||
|
#[INTEGER(name = "P2 ➜ 🕇")]
|
||||||
|
pub time_to_kill: f64,
|
||||||
|
/// (Goal) Desired turns to kill the monster.
|
||||||
|
/// If actual `time_to_kill` is larger, you may need to adjust attack power or strategy.
|
||||||
|
#[SKIP]
|
||||||
|
pub time_to_kill_target: f64,
|
||||||
|
/// (Goal) Desired turns until the monster’s armor breaks.
|
||||||
|
/// A lower value indicates a more aggressive strategy.
|
||||||
|
#[SKIP(name = "ttAB")]
|
||||||
|
pub time_to_armorbreak_target: f64,
|
||||||
|
/// (Goal) Average turns to kill a single player
|
||||||
|
#[SKIP(name = "ttPK")]
|
||||||
|
pub time_to_player_kill: f64,
|
||||||
|
/// (Fixed) The number of monsters in a single group.
|
||||||
|
/// Usually `1`, but can be > 1 for bosses that spawn multiple instances.
|
||||||
|
#[SKIP]
|
||||||
|
pub monster_groupsize: f64,
|
||||||
|
/// (Fixed) Number of players this fight was designed for.
|
||||||
|
#[SKIP]
|
||||||
|
pub player_groupsize: f64,
|
||||||
|
/// (Fixed) Health points during phase 1.
|
||||||
|
#[SKIP]
|
||||||
|
pub health_p1: i64,
|
||||||
|
/// (Fixed) Health points during phase 2.
|
||||||
|
#[SKIP]
|
||||||
|
pub health_p2: i64,
|
||||||
|
/// (Fixed) Integrity points during phase 1, representing how many
|
||||||
|
/// damage points the monster can take before losing its first phase.
|
||||||
|
#[SKIP]
|
||||||
|
pub integrity_p1: i64,
|
||||||
|
/// (Actual) Damage going through the creature during p1
|
||||||
|
#[SKIP]
|
||||||
|
pub damage_through_p1: f64,
|
||||||
|
/// (Actual) Damage going through the creature during p2
|
||||||
|
#[SKIP]
|
||||||
|
pub damage_through_p2: f64,
|
||||||
|
/// (Actual) Time to kill through armor
|
||||||
|
#[INTEGER(name = "P1 ⇝ P2 ⇝ 🕇")]
|
||||||
|
pub time_to_kill_through: f64,
|
||||||
|
/// (Misc) Display name or target of balancing
|
||||||
|
#[SKIP]
|
||||||
|
pub showcase: Showcase,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn display_monster_attacks(
|
||||||
|
args: &BalanceArgs,
|
||||||
|
creature: FullMonster,
|
||||||
|
profiles: &IndexMap<ProfileStance, PlayerBalancing>,
|
||||||
|
mode: DefenseMode,
|
||||||
|
) {
|
||||||
|
let attacks: Vec<monster_analysis_structs::MonsterBalancingAttack> = creature.into();
|
||||||
|
if args.show_profiles {
|
||||||
|
let table = attacks.to_table();
|
||||||
|
println!("{table}");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut res = Vec::new();
|
||||||
|
for attack in attacks {
|
||||||
|
let mut report = attack_analysis::all_attacks(args, &attack, profiles, mode);
|
||||||
|
res.append(&mut report);
|
||||||
|
}
|
||||||
|
println!("{}", res.to_table());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
|
use probability::distribution::Discrete;
|
||||||
|
use probability::prelude::Binomial;
|
||||||
|
|
||||||
|
// Binomial damage distribution
|
||||||
|
// As a (0s, p), (1s, p) etc
|
||||||
|
// can be used to calc avg damage
|
||||||
|
// with avg(dmg_with_successes(i)*j)
|
||||||
|
/// Calculate the binomial distribution and average the damage from there
|
||||||
|
pub(super) fn binomial_dice_distribution(threshold: i64, dices: i64) -> Vec<(i64, f64)> {
|
||||||
|
let p = ((threshold as f64) / 10.).clamp(0. + 1E-10, 1. - 1E-10);
|
||||||
|
let binomial = Binomial::new(dices as usize, p);
|
||||||
|
|
||||||
|
(0..(dices + 1) as usize)
|
||||||
|
.map(|target_dices| {
|
||||||
|
let probability_success = binomial.mass(target_dices);
|
||||||
|
(target_dices as i64, probability_success)
|
||||||
|
})
|
||||||
|
.collect::<Vec<(i64, f64)>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn thld(r_succeses: i64, threshold_parry: i64) -> i64 {
|
||||||
|
(r_succeses * min(threshold_parry, 10)) / 10
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn how_much_with_succeses(damage: &[i64], succeses: i64) -> i64 {
|
||||||
|
if succeses <= 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
damage[(succeses - 1).clamp(0_i64, damage.len() as i64 - 1) as usize]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Shorten a string so that its final length (including the three‑dot marker) does not exceed `size`.
|
||||||
|
///
|
||||||
|
/// If `size` is smaller than four the function simply truncates to that length
|
||||||
|
/// (there’s no room for “…”).
|
||||||
|
///
|
||||||
|
/// # Parameters
|
||||||
|
/// * `s` – The string slice to shorten.
|
||||||
|
/// * `size` – Maximum length of the returned string, including the ellipsis.
|
||||||
|
pub fn shorten_string(s: &str, size: usize) -> String {
|
||||||
|
// If it already fits, just return a copy.
|
||||||
|
if s.len() <= size {
|
||||||
|
return s.to_owned();
|
||||||
|
}
|
||||||
|
|
||||||
|
// No room for "…" + at least one char each side → just cut off.
|
||||||
|
if size < 4 {
|
||||||
|
return s.chars().take(size).collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
// How many chars we keep from the front / back?
|
||||||
|
let usable = size - 3; // length available for real characters
|
||||||
|
let half = usable / 2; // baseline number of chars per side
|
||||||
|
let extra = usable % 2; // if odd, give one more to the front
|
||||||
|
|
||||||
|
let front_len = half + extra;
|
||||||
|
let back_len = half;
|
||||||
|
|
||||||
|
// Grab the required portions.
|
||||||
|
let front: String = s.chars().take(front_len).collect();
|
||||||
|
let back: String = s
|
||||||
|
.chars()
|
||||||
|
.rev() // reverse for an easy “take last N”
|
||||||
|
.take(back_len)
|
||||||
|
.collect::<String>()
|
||||||
|
.chars()
|
||||||
|
.rev() // bring them back to normal order
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
format!("{}...{}", front, back)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,243 @@
|
||||||
|
use crate::monster_structs::{FullMonster, PlayerBalancing, ProfileStance};
|
||||||
|
use more_fields::FieldsAsSlice;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use strum::{Display, EnumString};
|
||||||
|
|
||||||
|
impl From<FullMonster> for Vec<MonsterBalancingAttack> {
|
||||||
|
fn from(creature: FullMonster) -> Self {
|
||||||
|
creature
|
||||||
|
.all_attacks
|
||||||
|
.phases
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|(_, phases)| {
|
||||||
|
phases.into_iter().flat_map(|monster_full_attack| {
|
||||||
|
// let mut cumul = 0;
|
||||||
|
monster_full_attack
|
||||||
|
.attacklist
|
||||||
|
.into_iter()
|
||||||
|
.map(move |sub_attack| {
|
||||||
|
// cumul += from_successes(sub_attack.success.as_ref());
|
||||||
|
MonsterBalancingAttack {
|
||||||
|
damage: damage_from_string(sub_attack.damage_regular.as_ref()),
|
||||||
|
successes: from_successes(sub_attack.success.as_ref()),
|
||||||
|
armor_break: from_opt_i64(sub_attack.armor_break.as_ref()),
|
||||||
|
action_cost: from_actions(sub_attack.cost_action.as_ref()),
|
||||||
|
fatigue: from_opt_fatigue(sub_attack.damage_fatigue.as_ref()),
|
||||||
|
name: sub_attack.name,
|
||||||
|
threshold_parry: from_opt_i64(sub_attack.threshold_parry.as_ref()),
|
||||||
|
threshold_dodge: from_opt_i64(sub_attack.threshold_dodge.as_ref()),
|
||||||
|
target_damage: sub_attack.target_damage_category.into(),
|
||||||
|
target_ab: sub_attack.target_ab_category.into(),
|
||||||
|
target_stance: sub_attack.target_stance.into(),
|
||||||
|
antimaterial: from_opt_i64(sub_attack.antimaterial.as_ref()),
|
||||||
|
armor_pierce: from_opt_i64(sub_attack.armor_pierce.as_ref()),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(|sub| !sub.damage.is_empty())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerBalancing {
|
||||||
|
// /// Estimate what an attack does to a player
|
||||||
|
// pub fn estimate_attack(&self, atk: MonsterAttack) {}
|
||||||
|
|
||||||
|
/// Apply an attack to a player, returns the damage done but "healing" afterwards
|
||||||
|
pub fn apply_attack(&mut self, atk: &MonsterBalancingAttack) -> DamageDone {
|
||||||
|
let _ = atk;
|
||||||
|
self.health -= 1;
|
||||||
|
DamageDone {
|
||||||
|
armor: 0,
|
||||||
|
health: 0,
|
||||||
|
category: DamageCategory::Chip,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, FieldsAsSlice)]
|
||||||
|
pub struct MonsterBalancingAttack {
|
||||||
|
pub name: String,
|
||||||
|
pub damage: Vec<i64>,
|
||||||
|
#[INTEGER(name = "r")]
|
||||||
|
pub successes: i64,
|
||||||
|
#[INTEGER(name = "ab")]
|
||||||
|
pub armor_break: i64,
|
||||||
|
#[INTEGER(name = "A")]
|
||||||
|
pub action_cost: i64,
|
||||||
|
#[INTEGER(name = "F")]
|
||||||
|
pub fatigue: i64,
|
||||||
|
#[SKIP(name = "parry_t")]
|
||||||
|
pub threshold_parry: i64,
|
||||||
|
#[SKIP(name = "dodge_t")]
|
||||||
|
pub threshold_dodge: i64,
|
||||||
|
#[TEXT(name = "damage_t")]
|
||||||
|
pub target_damage: DamageCategory,
|
||||||
|
#[TEXT(name = "arbreak_t")]
|
||||||
|
pub target_ab: ArmorBreakCategory,
|
||||||
|
#[TEXT(name = "stance_t")]
|
||||||
|
pub target_stance: ProfileStance,
|
||||||
|
#[SKIP(name = "AM")]
|
||||||
|
pub antimaterial: i64,
|
||||||
|
#[SKIP(name = "AP")]
|
||||||
|
pub armor_pierce: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DamageDone {
|
||||||
|
pub(crate) armor: i64,
|
||||||
|
pub(crate) health: i64,
|
||||||
|
pub(crate) category: DamageCategory,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumString, Default, strum::Display, PartialEq)]
|
||||||
|
pub enum DamageCategory {
|
||||||
|
/// Malformed data
|
||||||
|
#[default]
|
||||||
|
Malformed,
|
||||||
|
/// No lasting damage
|
||||||
|
None,
|
||||||
|
/// Chip damage
|
||||||
|
Chip,
|
||||||
|
/// Average, under half
|
||||||
|
Moderate,
|
||||||
|
/// High, above half
|
||||||
|
High,
|
||||||
|
/// Near death 90%
|
||||||
|
NearDeath,
|
||||||
|
/// Kill, above > 100%
|
||||||
|
Kill,
|
||||||
|
/// Complete overkill > 200%
|
||||||
|
Overkill,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumString, Default, strum::Display, PartialEq, Eq)]
|
||||||
|
pub enum ArmorBreakCategory {
|
||||||
|
/// Malformed data
|
||||||
|
#[default]
|
||||||
|
Malformed,
|
||||||
|
/// No lasting damage
|
||||||
|
None,
|
||||||
|
/// Chip damage
|
||||||
|
Chip,
|
||||||
|
/// Moderate
|
||||||
|
Moderate,
|
||||||
|
/// High, above half
|
||||||
|
High,
|
||||||
|
/// Full destruction
|
||||||
|
FullBreak,
|
||||||
|
/// Complete overkill > 200%
|
||||||
|
Overkill,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum Showcase {
|
||||||
|
Display,
|
||||||
|
Balancing,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Display)]
|
||||||
|
pub enum DefenseMode {
|
||||||
|
Best,
|
||||||
|
Worst,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ArmorBreakCategory {
|
||||||
|
pub fn from_percent(value: f64) -> Self {
|
||||||
|
match value {
|
||||||
|
..0.01 => ArmorBreakCategory::None,
|
||||||
|
0.01..0.3 => ArmorBreakCategory::Chip,
|
||||||
|
0.3..0.5 => ArmorBreakCategory::Moderate,
|
||||||
|
0.5..0.9 => ArmorBreakCategory::High,
|
||||||
|
0.8..1.2 => ArmorBreakCategory::FullBreak,
|
||||||
|
1.2.. => ArmorBreakCategory::Overkill,
|
||||||
|
_ => ArmorBreakCategory::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<Option<String>> for DamageCategory {
|
||||||
|
fn from(value: Option<String>) -> Self {
|
||||||
|
if let Some(value) = value {
|
||||||
|
Self::from_str(&value).unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
Self::Malformed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Option<String>> for ArmorBreakCategory {
|
||||||
|
fn from(value: Option<String>) -> Self {
|
||||||
|
if let Some(value) = value {
|
||||||
|
Self::from_str(&value).unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
Self::Malformed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Option<String>> for ProfileStance {
|
||||||
|
fn from(value: Option<String>) -> Self {
|
||||||
|
if let Some(value) = value {
|
||||||
|
Self::from_str(&value).unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
Self::Neutral
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn damage_from_string(str: Option<&String>) -> Vec<i64> {
|
||||||
|
match str {
|
||||||
|
Some(str) => str.split("/").map(|v| v.parse().ok()).collect(),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_successes(str: Option<&String>) -> i64 {
|
||||||
|
match str {
|
||||||
|
Some(str) => str.replace("r", "").parse().unwrap_or_default(),
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_actions(str: Option<&String>) -> i64 {
|
||||||
|
match str {
|
||||||
|
Some(str) => str.replace("A", "").parse().unwrap_or_default(),
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn from_opt_fatigue(str: Option<&String>) -> i64 {
|
||||||
|
match str {
|
||||||
|
Some(str) => str.replace("F", "").parse().unwrap_or_default(),
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_opt_str(str: Option<&String>) -> i64 {
|
||||||
|
match str {
|
||||||
|
Some(str) => str.parse().unwrap_or_default(),
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_opt_i64(val: Option<&i64>) -> i64 {
|
||||||
|
match val {
|
||||||
|
Some(val) => *val,
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DamageCategory {
|
||||||
|
pub fn from_percent(percent: f64) -> Self {
|
||||||
|
match percent {
|
||||||
|
..0.01 => Self::None,
|
||||||
|
0.01..0.25 => Self::Chip,
|
||||||
|
0.25..0.5 => Self::Moderate,
|
||||||
|
0.5..0.8 => Self::High,
|
||||||
|
0.8..1.0 => Self::NearDeath,
|
||||||
|
1.0..1.5 => Self::Kill,
|
||||||
|
1.5.. => Self::Overkill,
|
||||||
|
_ => Self::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,165 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use crate::monster_structs::{
|
||||||
|
self, CreatureReward, MonsterAllAttacks, MonsterRepetableInitRow, PlayerBalancing,
|
||||||
|
};
|
||||||
|
use crate::monster_structs::{
|
||||||
|
CreatureBodyPart, CreatureData, CreatureListAttacks, CreatureStats, FullMonster,
|
||||||
|
MonsterSingleAttack,
|
||||||
|
};
|
||||||
|
use anyhow::{Context, anyhow};
|
||||||
|
use cli_parser::Config;
|
||||||
|
use more_fields::FieldsAsSlice;
|
||||||
|
use rusqlite::Connection;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
|
/// Deserialise a table row (or rows) into the given type and add a nice context message.
|
||||||
|
macro_rules! fetch_from {
|
||||||
|
($ty:ty, $connection:expr,$name:expr, $table:expr, $cols_opt:expr) => {{
|
||||||
|
// `connection` and `creature.name` must be in scope when the macro is expanded
|
||||||
|
generic_deserialize::<$ty>(
|
||||||
|
&$connection,
|
||||||
|
$table,
|
||||||
|
Some(&format!("creature_id={}", $name.id)),
|
||||||
|
$cols_opt,
|
||||||
|
)
|
||||||
|
.context(format!("Fetching {} from {}", $table, $name.name))?
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch all data from the database
|
||||||
|
pub(crate) fn fetch_all_creature_data(
|
||||||
|
connection: &Connection,
|
||||||
|
config: &Config,
|
||||||
|
filter: Option<&str>,
|
||||||
|
) -> Result<Vec<FullMonster>, anyhow::Error> {
|
||||||
|
let list_creatures =
|
||||||
|
generic_deserialize::<CreatureData>(connection, "creature", filter, Some("sort_id"))?;
|
||||||
|
let mut finished_creatures = Vec::new();
|
||||||
|
for creature in list_creatures.iter() {
|
||||||
|
// println!("Working on {}@{}", creature.id, creature.name);
|
||||||
|
let creature_stats: CreatureStats =
|
||||||
|
fetch_one_field(connection, creature, "creature_stats")?;
|
||||||
|
finished_creatures.push(FullMonster {
|
||||||
|
id: creature.id,
|
||||||
|
name: creature.name.clone(),
|
||||||
|
init_full: MonsterRepetableInitRow::vec_from(
|
||||||
|
&creature_stats.p1_init,
|
||||||
|
&creature_stats.p2_init,
|
||||||
|
&creature_stats.p1_actions,
|
||||||
|
&creature_stats.p2_actions,
|
||||||
|
),
|
||||||
|
stats: creature_stats, // fetch_one_field(connection, creature, "creature_stats")?,
|
||||||
|
all_attacks: MonsterAllAttacks::from_retrieved_data(
|
||||||
|
&fetch_from!(
|
||||||
|
MonsterSingleAttack,
|
||||||
|
connection,
|
||||||
|
creature,
|
||||||
|
"creature_abilities",
|
||||||
|
Some("phase, attack_group, ordering")
|
||||||
|
),
|
||||||
|
config,
|
||||||
|
),
|
||||||
|
attacks: CreatureListAttacks {
|
||||||
|
attacks: fetch_from!(
|
||||||
|
MonsterSingleAttack,
|
||||||
|
connection,
|
||||||
|
creature,
|
||||||
|
"creature_abilities",
|
||||||
|
Some("phase, attack_group, ordering")
|
||||||
|
),
|
||||||
|
},
|
||||||
|
body_parts: monster_structs::CreatureListBodyParts {
|
||||||
|
body_parts: fetch_from!(
|
||||||
|
CreatureBodyPart,
|
||||||
|
connection,
|
||||||
|
creature,
|
||||||
|
"creature_body_parts",
|
||||||
|
None
|
||||||
|
),
|
||||||
|
},
|
||||||
|
rewards: monster_structs::CreatureListRewards {
|
||||||
|
rewards: fetch_from!(
|
||||||
|
CreatureReward,
|
||||||
|
connection,
|
||||||
|
creature,
|
||||||
|
"creature_rewards",
|
||||||
|
None
|
||||||
|
),
|
||||||
|
},
|
||||||
|
balancing: fetch_one_field(connection, creature, "creature_balancing")?,
|
||||||
|
data: creature.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(finished_creatures)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn fetch_all_player_data(
|
||||||
|
connection: &Connection,
|
||||||
|
config: &Config,
|
||||||
|
) -> Result<Vec<PlayerBalancing>, anyhow::Error> {
|
||||||
|
let _ = config;
|
||||||
|
generic_deserialize::<PlayerBalancing>(connection, "player_balancing", None, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetches **the single** row that matches `creature` from the given `table_name`.
|
||||||
|
///
|
||||||
|
/// The query is performed through the `fetch_from!` macro, which returns a vector of
|
||||||
|
/// values deserialised into `T`. If the resulting vector does not contain exactly
|
||||||
|
/// one element an error is returned; otherwise the sole value is extracted.
|
||||||
|
fn fetch_one_field<T: DeserializeOwned + FieldsAsSlice>(
|
||||||
|
connection: &Connection,
|
||||||
|
creature: &CreatureData,
|
||||||
|
table_name: &str,
|
||||||
|
) -> Result<T, anyhow::Error> {
|
||||||
|
let mut creature_stats = fetch_from!(T, connection, creature, table_name, None);
|
||||||
|
if creature_stats.len() != 1 {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"The number of {} entries for the creature {} should be exactly one found {}",
|
||||||
|
table_name,
|
||||||
|
creature.name,
|
||||||
|
creature_stats.len()
|
||||||
|
));
|
||||||
|
};
|
||||||
|
Ok(creature_stats.pop().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A generic Deserialisation from a database
|
||||||
|
fn generic_deserialize<T: more_fields::FieldsAsSlice + DeserializeOwned>(
|
||||||
|
connection: &Connection,
|
||||||
|
table_name: &str,
|
||||||
|
filter: Option<&str>,
|
||||||
|
sort: Option<&str>,
|
||||||
|
) -> Result<Vec<T>, anyhow::Error> {
|
||||||
|
let info = format!(
|
||||||
|
"Querying data on {} with {} WHERE {:?} ORDER BY {:?}",
|
||||||
|
table_name,
|
||||||
|
std::any::type_name::<T>(),
|
||||||
|
filter,
|
||||||
|
sort,
|
||||||
|
);
|
||||||
|
let generate_select_query = generate_select_query::<T>(table_name, filter, sort);
|
||||||
|
// println!("{}", generate_select_query);
|
||||||
|
let mut r = connection.prepare(&generate_select_query).context(info)?;
|
||||||
|
let rows = r.query([])?;
|
||||||
|
let r = serde_rusqlite::from_rows::<T>(rows).collect::<Result<Vec<T>, serde_rusqlite::Error>>();
|
||||||
|
r.context("No")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_select_query<T: more_fields::FieldsAsSlice>(
|
||||||
|
table_name: &str,
|
||||||
|
filter: Option<&str>,
|
||||||
|
sort: Option<&str>,
|
||||||
|
) -> String {
|
||||||
|
format!(
|
||||||
|
"SELECT {} FROM {}{}{};",
|
||||||
|
T::attributes_slice()
|
||||||
|
.iter()
|
||||||
|
.map(|(k, _v)| k.to_owned())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(","),
|
||||||
|
table_name,
|
||||||
|
filter.map_or_else(String::default, |j| " WHERE ".to_string() + j),
|
||||||
|
sort.map_or_else(String::default, |j| " ORDER BY ".to_string() + j)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,169 @@
|
||||||
|
//! Monster export module
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
use cli_parser::Config;
|
||||||
|
use config::monsters::ExportArgs;
|
||||||
|
use handlebars::{Handlebars, handlebars_helper};
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use rusqlite::Connection;
|
||||||
|
use std::{fmt::Write, fs::File, io::Write as OtherWrite};
|
||||||
|
|
||||||
|
use crate::monster_database::fetch_all_creature_data;
|
||||||
|
use crate::monster_structs::{MonsterAllAttacks, MonsterFullAttack, MonsterSingleAttack};
|
||||||
|
|
||||||
|
/// Load a template from a struct field into a `templates` collection.
|
||||||
|
///
|
||||||
|
/// $templates – the variable that holds the template collection
|
||||||
|
/// $cfg_path – any path (e.g. `config`, `self.cfg`, …) that points to a
|
||||||
|
/// struct containing the field we want
|
||||||
|
/// $name – the identifier of the field / template name
|
||||||
|
macro_rules! template_load {
|
||||||
|
($templates:ident, $cfg_path:expr, $name:ident) => {{
|
||||||
|
$templates
|
||||||
|
.register_template_string(
|
||||||
|
stringify!($name), // "intro"
|
||||||
|
&$cfg_path.$name, // &config.monster.intro
|
||||||
|
)
|
||||||
|
.context(concat!("Registering ", stringify!($name), " template"))? // ? propagates errors
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
handlebars_helper!(plus: |x:i64 ,y:Option<i64>| x+y.unwrap_or(0));
|
||||||
|
handlebars_helper!(threshold_bonus: |threshold:i64, size:i64| {
|
||||||
|
let mal = (threshold-6-size).min(-2);
|
||||||
|
let bon = threshold-mal-6;
|
||||||
|
format!("{:+}{:+}",mal,bon)
|
||||||
|
});
|
||||||
|
|
||||||
|
fn load_templates(config: &Config) -> Result<Handlebars<'_>> {
|
||||||
|
let mut templates = Handlebars::new();
|
||||||
|
template_load!(templates, &config.monster, common_part);
|
||||||
|
template_load!(templates, &config.monster, master_part);
|
||||||
|
templates.register_helper("plus", Box::new(plus));
|
||||||
|
templates.register_helper("threshold_bonus", Box::new(threshold_bonus));
|
||||||
|
Ok(templates)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Export a tex with the given config and arguments
|
||||||
|
pub fn generate_monsters_tex(
|
||||||
|
args: &ExportArgs,
|
||||||
|
config: &Config,
|
||||||
|
connection: Connection,
|
||||||
|
) -> std::result::Result<(), anyhow::Error> {
|
||||||
|
let all_monsters = fetch_all_creature_data(&connection, config, args.filter.filter.as_deref())?;
|
||||||
|
let templates = load_templates(config)?;
|
||||||
|
println!("Processing");
|
||||||
|
let mut m_out = String::new();
|
||||||
|
let mut p_out = String::new();
|
||||||
|
|
||||||
|
for creature in &all_monsters {
|
||||||
|
if !creature.data.show_to_master.is_none_or(|v| v == 0) {
|
||||||
|
println!(" > {}", creature.name);
|
||||||
|
};
|
||||||
|
write!(p_out, "{}", templates.render("common_part", &creature)?)?;
|
||||||
|
if args.master || args.all {
|
||||||
|
write!(m_out, "{}", templates.render("common_part", &creature)?)?;
|
||||||
|
write!(m_out, "{}", templates.render("master_part", &creature)?)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if args.player || args.all {
|
||||||
|
println!("Generating Player Bestiaire");
|
||||||
|
let path = format!("./{}/player_bestiaire.tex", args.destination);
|
||||||
|
let mut f = File::create(&path).context(format!("Opening file {}", path))?;
|
||||||
|
write!(f, "{}", p_out).context(format!("Writing {}", path))?;
|
||||||
|
}
|
||||||
|
if args.master || args.all {
|
||||||
|
println!("Generating Master Bestiaire");
|
||||||
|
let path = format!("./{}/master_bestiaire.tex", args.destination);
|
||||||
|
let mut f = File::create(&path).context(format!("Opening file {}", path))?;
|
||||||
|
write!(f, "{}", m_out).context(format!("Writing {}", path))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MonsterAllAttacks {
|
||||||
|
pub fn from_retrieved_data(
|
||||||
|
original_data: &[MonsterSingleAttack],
|
||||||
|
config: &Config,
|
||||||
|
) -> MonsterAllAttacks {
|
||||||
|
let mut initial_phases: IndexMap<&String, Vec<&MonsterSingleAttack>> = IndexMap::new();
|
||||||
|
let mut phases: IndexMap<String, Vec<MonsterFullAttack>> = IndexMap::new();
|
||||||
|
// Intermediate split with hashmaps
|
||||||
|
for atk in original_data {
|
||||||
|
if let Some(values) = initial_phases.get_mut(&atk.phase) {
|
||||||
|
values.push(atk);
|
||||||
|
} else {
|
||||||
|
initial_phases.insert(&atk.phase, vec![atk]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (phase, phase_atks) in initial_phases.iter() {
|
||||||
|
let mut grouped_attacks: IndexMap<&Option<String>, Vec<&MonsterSingleAttack>> =
|
||||||
|
IndexMap::new();
|
||||||
|
let phase_name = phase.to_string();
|
||||||
|
phases.insert(phase_name.clone(), Vec::new());
|
||||||
|
// Pregroup attacks
|
||||||
|
for &atk in phase_atks {
|
||||||
|
if let Some(values) = grouped_attacks.get_mut(&atk.attack_group) {
|
||||||
|
values.push(atk);
|
||||||
|
} else {
|
||||||
|
grouped_attacks.insert(&atk.attack_group, vec![atk]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ungroup them to have nice bundles
|
||||||
|
for (group, atk) in grouped_attacks {
|
||||||
|
if group.is_some() {
|
||||||
|
let monster_first_atk = atk.first().unwrap();
|
||||||
|
let color = color(monster_first_atk, config);
|
||||||
|
let group_attack = MonsterFullAttack {
|
||||||
|
color,
|
||||||
|
attacklist: atk.iter().map(|&v| v.clone()).collect(),
|
||||||
|
size: atk.len() + number_of_description(monster_first_atk),
|
||||||
|
description_final: monster_first_atk
|
||||||
|
.description_all
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
};
|
||||||
|
// println!("group: {:#?}", group_attack.description_final);
|
||||||
|
phases.get_mut(&phase_name).unwrap().push(group_attack);
|
||||||
|
} else {
|
||||||
|
for single_atk in atk {
|
||||||
|
// println!("single: {:#?}", single_atk.description_all);
|
||||||
|
phases
|
||||||
|
.get_mut(&phase_name)
|
||||||
|
.unwrap()
|
||||||
|
.push(MonsterFullAttack {
|
||||||
|
color: color(single_atk, config),
|
||||||
|
attacklist: vec![single_atk.clone()],
|
||||||
|
size: 1 + number_of_description(&single_atk),
|
||||||
|
description_final: single_atk
|
||||||
|
.description_all
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self { phases }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn color(atk: &MonsterSingleAttack, config: &Config) -> String {
|
||||||
|
config
|
||||||
|
.monster
|
||||||
|
.color_table
|
||||||
|
.inner
|
||||||
|
.get(&atk.attack_type)
|
||||||
|
.unwrap_or(&config.monster.default_color)
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The number of description fields
|
||||||
|
fn number_of_description(monster_first_atk: &&MonsterSingleAttack) -> usize {
|
||||||
|
if monster_first_atk.description_all.is_some() {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,363 @@
|
||||||
|
use crate::monster_analysis::{
|
||||||
|
defense_analysis::DefenseReport,
|
||||||
|
helpers::{self, shorten_string},
|
||||||
|
monster_analysis_structs::Showcase,
|
||||||
|
};
|
||||||
|
use comfy_table::{Color, Table, *};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
monster_analysis::{
|
||||||
|
attack_analysis::DamageReport,
|
||||||
|
monster_analysis_structs::{ArmorBreakCategory, DamageCategory, MonsterBalancingAttack},
|
||||||
|
},
|
||||||
|
monster_structs::{PlayerBalancing, ProfileHSE, ProfileStance},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Handy trait: “give me the table row that represents this record”
|
||||||
|
pub trait ToCell {
|
||||||
|
fn to_cell(&self) -> Cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ToRow {
|
||||||
|
fn to_row(&self) -> Row;
|
||||||
|
}
|
||||||
|
pub trait ToTable {
|
||||||
|
fn to_table(&self) -> Table;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> ToTable for Vec<T>
|
||||||
|
where
|
||||||
|
T: more_fields::FieldsAsSlice + ToRow,
|
||||||
|
{
|
||||||
|
fn to_table(&self) -> Table {
|
||||||
|
let mut table = Table::new();
|
||||||
|
table
|
||||||
|
.load_preset(presets::UTF8_FULL_CONDENSED)
|
||||||
|
.apply_modifier(modifiers::UTF8_ROUND_CORNERS)
|
||||||
|
.set_content_arrangement(ContentArrangement::Dynamic)
|
||||||
|
.set_width(120)
|
||||||
|
.set_header(T::attributes_slice().iter().map(|(a, _b)| Cell::new(a)));
|
||||||
|
// table.add_row(player_data.as_slice());
|
||||||
|
|
||||||
|
for entry in self {
|
||||||
|
table.add_row(entry.to_row());
|
||||||
|
}
|
||||||
|
table
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToRow for MonsterBalancingAttack {
|
||||||
|
fn to_row(&self) -> Row {
|
||||||
|
vec![
|
||||||
|
self.name.to_cell(),
|
||||||
|
self.damage.to_cell(),
|
||||||
|
self.successes.to_cell(),
|
||||||
|
self.armor_break.to_cell(),
|
||||||
|
self.fatigue.to_cell(),
|
||||||
|
self.action_cost.to_cell(),
|
||||||
|
self.target_damage.to_cell(),
|
||||||
|
self.target_ab.to_cell(),
|
||||||
|
self.target_stance.to_cell(),
|
||||||
|
]
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToRow for PlayerBalancing {
|
||||||
|
fn to_row(&self) -> Row {
|
||||||
|
vec![
|
||||||
|
self.profile_hse.to_cell(),
|
||||||
|
self.profile_stance.to_cell(),
|
||||||
|
Cell::new(format!("{:?}", self.damage_per_s)),
|
||||||
|
Cell::new(format!("{:?}", self.successes_off)),
|
||||||
|
Cell::new(format!("{:?}", self.protection)),
|
||||||
|
Cell::new(format!("{:?}", self.strength)),
|
||||||
|
Cell::new(format!("{:?}", self.integrity)),
|
||||||
|
Cell::new(format!("{:?}", self.health)),
|
||||||
|
]
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// macro_rules! show_if {
|
||||||
|
// ($self:ident, $content:expr) => {{
|
||||||
|
// match $self.showcase {
|
||||||
|
// Showcase::Display => String::new().to_cell(),
|
||||||
|
// Showcase::Balancing => $content,
|
||||||
|
// }
|
||||||
|
// }};
|
||||||
|
// }
|
||||||
|
macro_rules! dim_if_not {
|
||||||
|
($self:ident, $content:expr) => {{
|
||||||
|
match $self.showcase {
|
||||||
|
Showcase::Display => $content
|
||||||
|
// .add_attribute(Attribute::Dim)
|
||||||
|
.add_attribute(Attribute::NoReverse),
|
||||||
|
// .fg(Color::DarkGrey)
|
||||||
|
Showcase::Balancing => $content,
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
macro_rules! attr_if_not {
|
||||||
|
($self:ident, $content:expr, $attribute:expr) => {{
|
||||||
|
match $self.showcase {
|
||||||
|
Showcase::Display => $content
|
||||||
|
// .add_attribute(Attribute::Dim)
|
||||||
|
.add_attribute($attribute),
|
||||||
|
// .fg(Color::DarkGrey)
|
||||||
|
Showcase::Balancing => $content,
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
impl ToRow for DamageReport {
|
||||||
|
fn to_row(&self) -> Row {
|
||||||
|
vec![
|
||||||
|
match self.showcase {
|
||||||
|
Showcase::Balancing => format!(
|
||||||
|
"[{}]{}",
|
||||||
|
self.stance.to_string().chars().nth(0).unwrap_or(' '),
|
||||||
|
shorten_string(&self.name, 15)
|
||||||
|
)
|
||||||
|
.to_cell()
|
||||||
|
.fg(Color::Green),
|
||||||
|
Showcase::Display => self.stance.to_string().to_cell().fg(Color::DarkGrey),
|
||||||
|
},
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!(
|
||||||
|
"{:.1} [{:.1}r]",
|
||||||
|
self.damage_incoming, self.attack_successes,
|
||||||
|
)
|
||||||
|
.to_cell()
|
||||||
|
),
|
||||||
|
attr_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{}", self.fatigue,)
|
||||||
|
.to_cell()
|
||||||
|
.add_attribute(match self.fatigue == 0 {
|
||||||
|
true => Attribute::Hidden,
|
||||||
|
false => Attribute::NoHidden,
|
||||||
|
}),
|
||||||
|
Attribute::Hidden
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{:.1} [>{:.1}]", self.successes_left, self.threshold)
|
||||||
|
.to_cell()
|
||||||
|
.fg(if self.successes_left > 0.0 {
|
||||||
|
Color::Blue
|
||||||
|
} else {
|
||||||
|
Color::Red
|
||||||
|
})
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{:.1}/{:.1}", self.damage_tanked, self.player_health)
|
||||||
|
.to_cell()
|
||||||
|
.fg(self.damage_category.get_color())
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
self.damage_category.to_cell().add_attribute(
|
||||||
|
if self.damage_expected != self.damage_category {
|
||||||
|
Attribute::Reverse
|
||||||
|
} else {
|
||||||
|
Attribute::Dim
|
||||||
|
},
|
||||||
|
)
|
||||||
|
),
|
||||||
|
attr_if_not!(self, self.damage_expected.to_cell(), Attribute::Hidden),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{:.1}/{:.1}", self.armor_loss, self.player_integrity)
|
||||||
|
.to_cell()
|
||||||
|
.fg(self.armor_category.get_color())
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
self.armor_category.to_cell().add_attribute(
|
||||||
|
if self.armor_expected != self.armor_category {
|
||||||
|
Attribute::Reverse
|
||||||
|
} else {
|
||||||
|
Attribute::Dim
|
||||||
|
},
|
||||||
|
)
|
||||||
|
),
|
||||||
|
attr_if_not!(self, self.armor_expected.to_cell(), Attribute::Hidden),
|
||||||
|
]
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToCell for DamageCategory {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
Into::<Cell>::into(format!("{self:?}")).fg(self.get_color())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub trait ToColor {
|
||||||
|
fn get_color(&self) -> Color;
|
||||||
|
}
|
||||||
|
impl ToColor for DamageCategory {
|
||||||
|
fn get_color(&self) -> Color {
|
||||||
|
match self {
|
||||||
|
DamageCategory::None => Color::DarkGrey,
|
||||||
|
DamageCategory::Chip => Color::DarkBlue,
|
||||||
|
DamageCategory::Moderate => Color::Blue,
|
||||||
|
DamageCategory::High => Color::Green,
|
||||||
|
DamageCategory::NearDeath => Color::Yellow,
|
||||||
|
DamageCategory::Kill => Color::Red,
|
||||||
|
DamageCategory::Overkill => Color::DarkRed,
|
||||||
|
DamageCategory::Malformed => Color::Black,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToCell for ArmorBreakCategory {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
Into::<Cell>::into(format!("{self:?}")).fg(self.get_color())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToColor for ArmorBreakCategory {
|
||||||
|
fn get_color(&self) -> Color {
|
||||||
|
match self {
|
||||||
|
ArmorBreakCategory::None => Color::DarkGrey,
|
||||||
|
ArmorBreakCategory::Chip => Color::Green,
|
||||||
|
ArmorBreakCategory::Moderate => Color::Blue,
|
||||||
|
ArmorBreakCategory::High => Color::Yellow,
|
||||||
|
ArmorBreakCategory::FullBreak => Color::Red,
|
||||||
|
ArmorBreakCategory::Overkill => Color::DarkRed,
|
||||||
|
ArmorBreakCategory::Malformed => Color::Black,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToCell for i64 {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
format!("{}", self).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToCell for Vec<i64> {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
format!("{self:?}").into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToCell for String {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ToCell for ProfileHSE {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
match self {
|
||||||
|
ProfileHSE::Lowest => Into::<Cell>::into(format!("{self:?}")).fg(Color::DarkRed),
|
||||||
|
ProfileHSE::Low => Into::<Cell>::into(format!("{self:?}")).fg(Color::Red),
|
||||||
|
ProfileHSE::Mid => Into::<Cell>::into(format!("{self:?}")).fg(Color::Yellow),
|
||||||
|
ProfileHSE::High => Into::<Cell>::into(format!("{self:?}")).fg(Color::Green),
|
||||||
|
ProfileHSE::Highest => Into::<Cell>::into(format!("{self:?}")).fg(Color::Blue),
|
||||||
|
ProfileHSE::HighestPlus => Into::<Cell>::into(format!("{self:?}")).fg(Color::DarkBlue),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCell for ProfileStance {
|
||||||
|
fn to_cell(&self) -> Cell {
|
||||||
|
match self {
|
||||||
|
ProfileStance::Defensive => Into::<Cell>::into(format!("{self:?}")).fg(Color::Blue),
|
||||||
|
ProfileStance::Offensive => Into::<Cell>::into(format!("{self:?}")).fg(Color::Red),
|
||||||
|
ProfileStance::Neutral => Into::<Cell>::into(format!("{self:?}")).fg(Color::Yellow),
|
||||||
|
ProfileStance::NoDefense => Into::<Cell>::into(format!("{self:?}")).fg(Color::DarkRed),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 🠰
|
||||||
|
impl ToRow for DefenseReport {
|
||||||
|
fn to_row(&self) -> comfy_table::Row {
|
||||||
|
let row: Vec<Cell> = vec![
|
||||||
|
// format!("{:?}", self.id).to_cell(),
|
||||||
|
match self.showcase {
|
||||||
|
Showcase::Display => {
|
||||||
|
helpers::shorten_string(&self.part_name.to_string(), 18).to_cell()
|
||||||
|
}
|
||||||
|
Showcase::Balancing => self.target_stance.to_cell().fg(Color::DarkGrey),
|
||||||
|
},
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{:.1?}/{}", self.armor_break_per_turn, self.integrity_p1)
|
||||||
|
.to_cell()
|
||||||
|
.fg(Color::DarkGrey)
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
compare_vals("t", self.time_to_armorbreak, self.time_to_armorbreak_target)
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{:.1?}/{}", self.damage_per_turn_p1, self.health_p1)
|
||||||
|
.to_cell()
|
||||||
|
.fg(Color::DarkGrey)
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
compare_vals("t", self.time_to_p2, self.time_to_p2_target)
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!("{:.1?}/{}", self.damage_per_turn_p2, self.health_p2)
|
||||||
|
.to_cell()
|
||||||
|
.fg(Color::DarkGrey)
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
compare_vals("t", self.time_to_kill, self.time_to_kill_target)
|
||||||
|
),
|
||||||
|
dim_if_not!(
|
||||||
|
self,
|
||||||
|
format!(
|
||||||
|
"[{:.0} & {:.0}] ⇝ {}",
|
||||||
|
self.damage_through_p1,
|
||||||
|
self.damage_per_turn_p2,
|
||||||
|
fmt_target(self.time_to_kill_through)
|
||||||
|
)
|
||||||
|
.to_cell()
|
||||||
|
.fg(Color::DarkGrey)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
row.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn fmt_target(v: f64) -> String {
|
||||||
|
const TOO_MUCH: f64 = 1_000_000_000_000_000.0;
|
||||||
|
const TRILLION: f64 = 1_000_000_000_000.0;
|
||||||
|
const BILLION: f64 = 1_000_000_000.0;
|
||||||
|
const MILLION: f64 = 1_000_000.0;
|
||||||
|
const THOUSAND: f64 = 1_000.0;
|
||||||
|
|
||||||
|
match v {
|
||||||
|
_ if v >= TOO_MUCH => "⇑⇑⇑⇑T".to_string(),
|
||||||
|
_ if v >= TRILLION => format!("⇑{:.1}T", v / TRILLION),
|
||||||
|
_ if v >= BILLION => format!("⇑{:.1}B", v / BILLION),
|
||||||
|
_ if v >= MILLION => format!("⇑{:.1}M", v / MILLION),
|
||||||
|
_ if v >= THOUSAND => format!("⇑{:.1}k", v / THOUSAND),
|
||||||
|
_ => format!("{:.1}", v),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_vals(unit: &str, actual: f64, target: f64) -> Cell {
|
||||||
|
let pct_diff = ((actual - target).abs() / target) * 100.0; // % diff
|
||||||
|
// let actual = 100000000000.;
|
||||||
|
let actual = if pct_diff > 1.0 {
|
||||||
|
fmt_target(actual)
|
||||||
|
} else {
|
||||||
|
format!("{:.1?}", actual)
|
||||||
|
};
|
||||||
|
format!("{}/{:.0?}{}", actual, target, unit)
|
||||||
|
.to_cell()
|
||||||
|
.fg(pct_diff_to_colour(pct_diff))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Turn percent‑difference into one of four hard‑coded colours.
|
||||||
|
pub(crate) fn pct_diff_to_colour(pct_diff: f64) -> Color {
|
||||||
|
match pct_diff {
|
||||||
|
p if p < 20.0 => Color::Green,
|
||||||
|
p if p < 30.0 => Color::Blue,
|
||||||
|
p if p < 40.0 => Color::Red,
|
||||||
|
_ => Color::DarkRed,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,546 @@
|
||||||
|
//! # Monster Structures
|
||||||
|
//!
|
||||||
|
//! The `monster_structs` module defines the data model that represents a monster
|
||||||
|
//! as it is loaded from the database. All structs are intentionally kept
|
||||||
|
//!
|
||||||
|
//! ## Overview
|
||||||
|
//! ```text
|
||||||
|
//! FullMonster → MonsterStats
|
||||||
|
//! ↘ MonsterAttacks → Vec<MonsterSingleAttack>
|
||||||
|
//! ↗ MonsterResistances → Vec<MonsterSingleResistance>
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use more_fields::FieldsAsSlice;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum::{Display, EnumString};
|
||||||
|
|
||||||
|
/// Full data, including monster_data & balancing data
|
||||||
|
pub struct FullData {}
|
||||||
|
|
||||||
|
/// A monster ready for consumption by other modules.
|
||||||
|
///
|
||||||
|
/// This struct is extremely export centric
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct FullMonster {
|
||||||
|
/// Unique identifier, derived when the monster is instantiated.
|
||||||
|
pub id: i64,
|
||||||
|
|
||||||
|
/// Monster’s name.
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
/// Serialized generic data directly copied from the database table.
|
||||||
|
pub data: CreatureData,
|
||||||
|
|
||||||
|
/// Weird init & actions repeat
|
||||||
|
pub init_full: Vec<MonsterRepetableInitRow>,
|
||||||
|
|
||||||
|
/// Collection of attacks, wrapped in a helper that exposes useful functions.
|
||||||
|
pub attacks: CreatureListAttacks,
|
||||||
|
|
||||||
|
/// Merge of all attacks in a convenient-ish hashmap
|
||||||
|
pub all_attacks: MonsterAllAttacks,
|
||||||
|
|
||||||
|
/// Collection of resistances, wrapped in a helper for convenient iteration.
|
||||||
|
pub body_parts: CreatureListBodyParts,
|
||||||
|
|
||||||
|
/// Collection of all the rewards, wraped in a helper for iteration.
|
||||||
|
pub rewards: CreatureListRewards,
|
||||||
|
|
||||||
|
/// Serialized stats directly copied from the database table.
|
||||||
|
pub stats: CreatureStats,
|
||||||
|
|
||||||
|
/// Serialized balancing data
|
||||||
|
pub balancing: CreatureBalancing,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One row from the `creature` table.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, FieldsAsSlice)]
|
||||||
|
pub struct CreatureData {
|
||||||
|
/// Primary key – auto‑incremented by SQLite.
|
||||||
|
#[INTEGER]
|
||||||
|
pub id: i64, // INTEGER primary key
|
||||||
|
/// Text columns – stored as plain UTF‑8 text in SQLite.
|
||||||
|
#[TEXT]
|
||||||
|
pub name: String,
|
||||||
|
#[TEXT]
|
||||||
|
pub denomination: Option<String>,
|
||||||
|
/// The calamity type of the creature
|
||||||
|
#[TEXT]
|
||||||
|
pub calamity: String,
|
||||||
|
/// The image describing the creature
|
||||||
|
#[TEXT]
|
||||||
|
pub image: String,
|
||||||
|
/// The HSE danger level
|
||||||
|
#[REAL]
|
||||||
|
pub danger_level: f64,
|
||||||
|
/// The footprints and such
|
||||||
|
#[TEXT]
|
||||||
|
pub traces: Option<String>,
|
||||||
|
/// Type of habitat
|
||||||
|
#[TEXT]
|
||||||
|
pub habitat: Option<String>,
|
||||||
|
/// Wether a dismorphism exists
|
||||||
|
#[TEXT]
|
||||||
|
pub dysmorphism: Option<String>,
|
||||||
|
/// Monster size
|
||||||
|
#[TEXT]
|
||||||
|
pub size: Option<String>,
|
||||||
|
/// Generic color describing the creature
|
||||||
|
#[TEXT]
|
||||||
|
pub colors: Option<String>,
|
||||||
|
/// Default reaction to human presence
|
||||||
|
#[TEXT]
|
||||||
|
pub default_human_reaction: Option<String>,
|
||||||
|
/// Known variants
|
||||||
|
#[TEXT]
|
||||||
|
pub variants: Option<String>,
|
||||||
|
/// General habits
|
||||||
|
#[TEXT]
|
||||||
|
pub habits: Option<String>,
|
||||||
|
/// Generic creature description
|
||||||
|
#[TEXT]
|
||||||
|
pub description: Option<String>,
|
||||||
|
/// Annotations
|
||||||
|
#[TEXT]
|
||||||
|
pub annotations: Option<String>,
|
||||||
|
/// Annotations GM
|
||||||
|
#[TEXT]
|
||||||
|
pub annotations_master: Option<String>,
|
||||||
|
/// The battle plan of the creature
|
||||||
|
#[TEXT]
|
||||||
|
pub battle_plan: Option<String>,
|
||||||
|
/// The graph of intents (image)
|
||||||
|
#[TEXT]
|
||||||
|
pub intent_graph: Option<String>,
|
||||||
|
/// Wether to show it to players
|
||||||
|
#[INTEGER]
|
||||||
|
pub show_to_master: Option<i64>,
|
||||||
|
/// Wether to show it to masters
|
||||||
|
#[INTEGER]
|
||||||
|
pub show_to_players: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper wrapper around all rewards
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct CreatureListRewards {
|
||||||
|
pub rewards: Vec<CreatureReward>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One row from the `rewards` table.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)]
|
||||||
|
pub struct CreatureReward {
|
||||||
|
/// The id of the creature that owns the reward (FOREIGN KEY to `creature_data.id`).
|
||||||
|
#[INTEGER]
|
||||||
|
pub creature_id: i64,
|
||||||
|
/// Full name of the reward.
|
||||||
|
#[TEXT]
|
||||||
|
pub name: String,
|
||||||
|
/// Category of the ability
|
||||||
|
#[TEXT]
|
||||||
|
pub category: String,
|
||||||
|
/// The cost of the reward
|
||||||
|
#[TEXT]
|
||||||
|
pub cost: Option<String>,
|
||||||
|
/// Effect of the ability
|
||||||
|
pub effect: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper wrapper around all attacks belonging to a monster.
|
||||||
|
///
|
||||||
|
/// The inner vector holds individual attack rows (`MonsterSingleAttack`);
|
||||||
|
/// helper methods on this struct (not shown here) can split or aggregate
|
||||||
|
/// these rows into more ergonomic data structures.
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct CreatureListAttacks {
|
||||||
|
/// All attack rows for the monster, as read from the database.
|
||||||
|
pub attacks: Vec<MonsterSingleAttack>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper wrapper around all resistances belonging to a monster.
|
||||||
|
///
|
||||||
|
/// The inner vector contains `MonsterSingleResistance` entries; methods
|
||||||
|
/// on this struct can provide iterators or lookup functions that are
|
||||||
|
/// easier to consume than raw rows.
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct CreatureListBodyParts {
|
||||||
|
/// All resistance rows for the monster, as read from the database.
|
||||||
|
pub body_parts: Vec<CreatureBodyPart>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents a single attack entry as deserialized from the database.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)]
|
||||||
|
pub struct MonsterSingleAttack {
|
||||||
|
/// The id of the creature that owns the ability (FOREIGN KEY to `creature_data.id`).
|
||||||
|
#[INTEGER]
|
||||||
|
pub creature_id: i64,
|
||||||
|
/// Full name of the ability.
|
||||||
|
#[TEXT]
|
||||||
|
pub name: String,
|
||||||
|
/// Short trigram used in combat logs, etc.
|
||||||
|
#[TEXT]
|
||||||
|
pub short_name: String,
|
||||||
|
/// Which phase(s) of a turn can the ability be used
|
||||||
|
#[TEXT]
|
||||||
|
pub phase: String,
|
||||||
|
/// Attack grouping, for multiple entries in one attack
|
||||||
|
#[INTEGER]
|
||||||
|
pub attack_group: Option<String>,
|
||||||
|
/// Ability “type” as a trigram
|
||||||
|
#[TEXT]
|
||||||
|
pub attack_type: String,
|
||||||
|
/// Prerequisite necessesary for the attack to resolve.
|
||||||
|
#[INTEGER]
|
||||||
|
pub prerequisites: Option<String>,
|
||||||
|
/// How the ability targets opponents (e.g. “single”, “area” …).
|
||||||
|
#[TEXT]
|
||||||
|
pub targetting: Option<String>,
|
||||||
|
/// Fatigue cost for activating the ability.
|
||||||
|
#[INTEGER]
|
||||||
|
pub cost_fatigue: Option<String>,
|
||||||
|
/// Armor_break of the ability.
|
||||||
|
#[INTEGER]
|
||||||
|
pub armor_break: Option<i64>,
|
||||||
|
/// armor_pierce of the ability.
|
||||||
|
#[INTEGER]
|
||||||
|
pub armor_pierce: Option<i64>,
|
||||||
|
/// antimaterial of the ability.
|
||||||
|
#[INTEGER]
|
||||||
|
pub antimaterial: Option<i64>,
|
||||||
|
/// Action‑point cost (used in systems where actions and fatigue are separate).
|
||||||
|
#[INTEGER]
|
||||||
|
pub cost_action: Option<String>,
|
||||||
|
/// Element or school that powers the ability.
|
||||||
|
#[TEXT]
|
||||||
|
pub element: Option<String>,
|
||||||
|
/// Damage dealt as a *fatigue* penalty (i.e. non‑instant death).
|
||||||
|
#[INTEGER]
|
||||||
|
pub damage_fatigue: Option<String>,
|
||||||
|
/// Regular textual description
|
||||||
|
#[TEXT]
|
||||||
|
pub damage_regular: Option<String>,
|
||||||
|
/// All “effects” that happen when the ability resolves.
|
||||||
|
/// The string format is up‑to‑you – many people store JSON or a custom DSL here.
|
||||||
|
#[TEXT]
|
||||||
|
pub effects: String,
|
||||||
|
/// The number of success for the attack
|
||||||
|
#[TEXT]
|
||||||
|
pub success: Option<String>,
|
||||||
|
/// The description of the whole attack
|
||||||
|
#[TEXT]
|
||||||
|
pub description_all: Option<String>,
|
||||||
|
/// Minimum parry rating required to avoid the ability’s effect.
|
||||||
|
#[INTEGER]
|
||||||
|
pub threshold_parry: Option<i64>,
|
||||||
|
/// Minimum dodge rating required to avoid the ability’s effect.
|
||||||
|
#[INTEGER]
|
||||||
|
pub threshold_dodge: Option<i64>,
|
||||||
|
/// Target level of damage
|
||||||
|
pub target_damage_category: Option<String>,
|
||||||
|
/// Target level of damage
|
||||||
|
pub target_ab_category: Option<String>,
|
||||||
|
/// Target stance of players
|
||||||
|
pub target_stance: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default, FieldsAsSlice)]
|
||||||
|
/// All different body parts and their different resists
|
||||||
|
pub struct CreatureBodyPart {
|
||||||
|
#[INTEGER]
|
||||||
|
pub creature_id: i64,
|
||||||
|
#[TEXT]
|
||||||
|
pub body_part_name: String,
|
||||||
|
#[INTEGER]
|
||||||
|
pub threshold_p1: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub threshold_p2: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub protection_p1: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub protection_p2: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub integrity_p1: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub integrity_p2: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub life_points_p1: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub life_points_p2: Option<i64>,
|
||||||
|
#[TEXT]
|
||||||
|
pub slash: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub blunt: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub piercing: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub celestial: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub fire: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub magma: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub earth: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub wood: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub abyssal: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub wind: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub water: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub ice: Option<String>,
|
||||||
|
#[TEXT]
|
||||||
|
pub thunder: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenient wrapper to allow fetching easily resists to show
|
||||||
|
pub struct GroupedResists {
|
||||||
|
inner: IndexMap<String, Vec<Option<String>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)]
|
||||||
|
/// All creature stats used in combat calculations.
|
||||||
|
pub struct CreatureStats {
|
||||||
|
#[INTEGER]
|
||||||
|
pub creature_id: i64,
|
||||||
|
#[TEXT]
|
||||||
|
pub p1_init: MonsterInitString,
|
||||||
|
#[TEXT]
|
||||||
|
pub p2_init: MonsterInitString,
|
||||||
|
#[TEXT]
|
||||||
|
pub p1_actions: MonsterInitString,
|
||||||
|
#[TEXT]
|
||||||
|
pub p2_actions: MonsterInitString,
|
||||||
|
#[INTEGER]
|
||||||
|
pub strength: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub perception: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub willpower: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub alteration_resistance: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub torque: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub awareness: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub fatigue: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub physical_bonus_dmg: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub elemental_bonus_dmg: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub resistance_transcendentale: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub size_bonus_to_hit: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub mvt_walk: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub mvt_trot: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub mvt_run: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub mvt_flight: Option<i64>,
|
||||||
|
#[INTEGER]
|
||||||
|
pub blood_base: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub blood_battle: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
pub blood_carve: i64,
|
||||||
|
}
|
||||||
|
/// Balancing metadata for a creature.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, FieldsAsSlice)]
|
||||||
|
pub struct CreatureBalancing {
|
||||||
|
#[INTEGER]
|
||||||
|
pub creature_id: i64,
|
||||||
|
#[TEXT]
|
||||||
|
/// (Fixed) HSE profile of the monster (see `ProfileHSE`).
|
||||||
|
pub profile_hse: ProfileHSE,
|
||||||
|
#[REAL]
|
||||||
|
/// (Goal) Turns needed to reach phase 2.
|
||||||
|
pub time_to_p2: f64,
|
||||||
|
#[REAL]
|
||||||
|
/// (Goal) Turns needed to kill from phase 2.
|
||||||
|
pub time_to_kill: f64,
|
||||||
|
#[REAL]
|
||||||
|
/// (Goal) Turns until the monster’s armor breaks.
|
||||||
|
pub time_to_armorbreak: f64,
|
||||||
|
#[REAL]
|
||||||
|
/// (GOAL) Avg. turns to kill a single target.
|
||||||
|
pub time_to_player_kill: f64,
|
||||||
|
#[REAL]
|
||||||
|
/// (FIXED) Size of a single monster group (usually one).
|
||||||
|
pub monster_groupsize: f64,
|
||||||
|
#[REAL]
|
||||||
|
/// (FIXED) The number of players this fight was designed for
|
||||||
|
pub player_groupsize: f64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// (FIXED) The average number of defence dice the creature will be using
|
||||||
|
pub average_defensive_successes: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Balancing info on all the player depending on their level
|
||||||
|
///
|
||||||
|
/// All this info is FIXED and calculated based on average game data
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, FieldsAsSlice)]
|
||||||
|
pub struct PlayerBalancing {
|
||||||
|
#[INTEGER]
|
||||||
|
/// HSE profile of the player (see `ProfileHSE`).
|
||||||
|
pub profile_hse: ProfileHSE,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Stance used in this datapoint.
|
||||||
|
pub profile_stance: ProfileStance,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Damage dealt per success.
|
||||||
|
pub damage_per_s: f64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Number of offensive successes per round.
|
||||||
|
pub successes_off: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Maximum number of offensive successes per round.
|
||||||
|
pub max_successes_off: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Number of deffensive successes per round.
|
||||||
|
pub successes_def: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Amount of protection (e.g., armor) the player has.
|
||||||
|
pub protection: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Strength stat of the player.
|
||||||
|
pub strength: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Integrity / hit‑point reserve of the player.
|
||||||
|
pub integrity: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Current health points.
|
||||||
|
pub health: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Current precision.
|
||||||
|
pub precision: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Current deffensive specialty.
|
||||||
|
pub specialty_def: i64,
|
||||||
|
#[INTEGER]
|
||||||
|
/// Current armor_break.
|
||||||
|
pub armor_break: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, EnumString, Hash, Display,
|
||||||
|
)]
|
||||||
|
/// Player stance preference used for balance tables.
|
||||||
|
pub enum ProfileStance {
|
||||||
|
Defensive,
|
||||||
|
Offensive,
|
||||||
|
NoDefense,
|
||||||
|
#[default]
|
||||||
|
Neutral,
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
/// Hunter Star Equivalent (roughly level+skill) profile used throughout the system.
|
||||||
|
pub enum ProfileHSE {
|
||||||
|
Lowest,
|
||||||
|
Low,
|
||||||
|
Mid,
|
||||||
|
High,
|
||||||
|
Highest,
|
||||||
|
HighestPlus,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- HERE BE WARCRIMES -------------
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
/// A custom string used to avoid work
|
||||||
|
pub struct MonsterInitString {
|
||||||
|
inner: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A monster init row (entire)
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct MonsterRepetableInitRow {
|
||||||
|
pub turn: usize,
|
||||||
|
pub p1_value: String,
|
||||||
|
pub p1_actions: String,
|
||||||
|
pub p2_value: String,
|
||||||
|
pub p2_actions: String,
|
||||||
|
}
|
||||||
|
impl MonsterRepetableInitRow {
|
||||||
|
pub fn vec_from(
|
||||||
|
p1_vals: &MonsterInitString,
|
||||||
|
p2_vals: &MonsterInitString,
|
||||||
|
p1_acts: &MonsterInitString,
|
||||||
|
p2_acts: &MonsterInitString,
|
||||||
|
) -> Vec<Self> {
|
||||||
|
let p1_vals = MonsterRepetableInitValue::from(p1_vals);
|
||||||
|
let p2_vals = MonsterRepetableInitValue::from(p2_vals);
|
||||||
|
let p1_acts = MonsterRepetableInitValue::from(p1_acts);
|
||||||
|
let p2_acts = MonsterRepetableInitValue::from(p2_acts);
|
||||||
|
p1_acts
|
||||||
|
.inner
|
||||||
|
.iter()
|
||||||
|
.zip(p2_acts.inner.iter())
|
||||||
|
.zip(p1_vals.inner.iter())
|
||||||
|
.zip(p2_vals.inner.iter())
|
||||||
|
.enumerate()
|
||||||
|
.map(|(turn, (((p1_actions, p2_actions), p1_value), p2_value))| {
|
||||||
|
MonsterRepetableInitRow {
|
||||||
|
p1_value: p1_value.clone(),
|
||||||
|
p1_actions: p1_actions.clone(),
|
||||||
|
p2_value: p2_value.clone(),
|
||||||
|
p2_actions: p2_actions.clone(),
|
||||||
|
turn: turn + 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<Self>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
/// A repeteable init string
|
||||||
|
pub struct MonsterRepetableInitValue {
|
||||||
|
inner: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&MonsterInitString> for MonsterRepetableInitValue {
|
||||||
|
fn from(value: &MonsterInitString) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: value.inner.split(',').map(|s| s.to_string()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for MonsterInitString {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
let mut c = self.inner.split(',');
|
||||||
|
serializer.collect_str(
|
||||||
|
c.next()
|
||||||
|
.unwrap_or_else(|| panic!("Trying to split {} by ','", self.inner)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The full list of all monster attacks
|
||||||
|
///
|
||||||
|
/// Split by phasing
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct MonsterAllAttacks {
|
||||||
|
// #[serde(flatten)]
|
||||||
|
// #[serde(with = "indexmap::map::serde_seq")]
|
||||||
|
pub phases: IndexMap<String, Vec<MonsterFullAttack>>,
|
||||||
|
}
|
||||||
|
/// A single attack, grouping all sub attacks
|
||||||
|
/// Also extract extra info to allow easier insertions
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct MonsterFullAttack {
|
||||||
|
pub attacklist: Vec<MonsterSingleAttack>,
|
||||||
|
pub color: String,
|
||||||
|
pub size: usize,
|
||||||
|
pub description_final: String,
|
||||||
|
}
|
||||||
|
|
@ -5,28 +5,24 @@
|
||||||
//! however this limitation is completely artificial
|
//! however this limitation is completely artificial
|
||||||
|
|
||||||
pub use more_fields_macro::FieldsAsSlice;
|
pub use more_fields_macro::FieldsAsSlice;
|
||||||
|
pub use more_fields_macro::InstanceAsArray;
|
||||||
|
|
||||||
pub trait FieldsAsSlice {
|
pub trait FieldsAsSlice {
|
||||||
fn attributes_slice() -> &'static [(&'static str, &'static str)];
|
fn attributes_slice() -> &'static [(&'static str, &'static str)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn iter(&self) -> std::vec::IntoIter<(&'static str, &'static str)>;
|
/// Converts an instance into a homogeneous array.
|
||||||
|
///
|
||||||
|
/// The array length is determined by the derive macro.
|
||||||
|
pub trait InstanceAsArray {
|
||||||
|
/// Element type of the generated array.
|
||||||
|
type Item;
|
||||||
|
|
||||||
// #[cfg(feature = "expand_macro")]
|
// /// Concrete array type, e.g. `[Value; 5]`.
|
||||||
// #[derive(FieldsAsSlice, Default)]
|
// type Array: AsRef<Vec<Self::Item>>;
|
||||||
// struct Bob {
|
|
||||||
// #[TEXT]
|
fn instance_as_array(&self) -> Vec<Self::Item>;
|
||||||
// field_ouane: u16,
|
}
|
||||||
// #[INTEGER]
|
|
||||||
// field_2: u16,
|
|
||||||
// #[BLOB]
|
|
||||||
// field_3: u16,
|
|
||||||
// #[NULL]
|
|
||||||
// field_4: u16,
|
|
||||||
// #[REAL]
|
|
||||||
// field_5: u16,
|
|
||||||
// field_6: u16,
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
@ -63,4 +59,67 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(Bob::attributes_slice(), b_hash);
|
assert_eq!(Bob::attributes_slice(), b_hash);
|
||||||
}
|
}
|
||||||
|
use crate::InstanceAsArray;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
enum Value {
|
||||||
|
Integer(i64),
|
||||||
|
Text(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<i32> for Value {
|
||||||
|
fn from(v: i32) -> Self {
|
||||||
|
Value::Integer(v as i64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<String> for Value {
|
||||||
|
fn from(v: String) -> Self {
|
||||||
|
Value::Text(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FieldsAsSlice, InstanceAsArray)]
|
||||||
|
#[InstanceAsArray(Type = String)]
|
||||||
|
struct Person {
|
||||||
|
#[INTEGER]
|
||||||
|
id: String,
|
||||||
|
|
||||||
|
#[TEXT]
|
||||||
|
name: String,
|
||||||
|
|
||||||
|
#[SKIP]
|
||||||
|
cached: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn instance_as_array_works() {
|
||||||
|
let person = Person {
|
||||||
|
id: "Alice".into(),
|
||||||
|
name: "Alice".into(),
|
||||||
|
cached: "Alice".into(),
|
||||||
|
};
|
||||||
|
assert!(person.cached == "Alice",);
|
||||||
|
let array = person.instance_as_array();
|
||||||
|
let slice = array.as_ref();
|
||||||
|
|
||||||
|
assert_eq!(slice, &["Alice".to_string(), "Alice".to_string(),]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
|
// fn attributes_slice_matches_instance_array() {
|
||||||
|
// let attrs = Person::attributes_slice();
|
||||||
|
|
||||||
|
// assert_eq!(attrs, &[("id", "INTEGER"), ("name", "TEXT"),]);
|
||||||
|
|
||||||
|
// let values = Person {
|
||||||
|
// id: 1,
|
||||||
|
// name: "Bob".into(),
|
||||||
|
// cached: false,
|
||||||
|
// }
|
||||||
|
// .instance_as_array();
|
||||||
|
|
||||||
|
// assert_eq!(attrs.len(), values.as_ref().len());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,4 @@ proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "1.0.46"
|
quote = "1.0.46"
|
||||||
syn = "2.0.118"
|
syn = {version= "2.0.118", features=["full"]}
|
||||||
|
|
|
||||||
|
|
@ -12,64 +12,109 @@
|
||||||
// use proc_macro::TokenStream;
|
// use proc_macro::TokenStream;
|
||||||
// use quote::quote;
|
// use quote::quote;
|
||||||
// use syn::{Data, DeriveInput, Fields, parse_macro_input};
|
// use syn::{Data, DeriveInput, Fields, parse_macro_input};
|
||||||
#![feature(coverage_attribute)]
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use proc_macro::{Span, TokenStream};
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::DeriveInput;
|
use syn::{Data, DeriveInput, Fields, parse_macro_input};
|
||||||
use syn::Ident;
|
|
||||||
use syn::parse_macro_input;
|
|
||||||
use syn::{Data, Fields};
|
|
||||||
|
|
||||||
#[coverage(off)]
|
/// The macro can now be used on structs that have a mix of the
|
||||||
#[proc_macro_derive(FieldsAsSlice, attributes(INTEGER, NULL, REAL, TEXT, BLOB))]
|
/// following field‑level attributes:
|
||||||
|
/// * INTEGER, NULL, REAL, TEXT, BLOB → SQLite column type
|
||||||
|
/// * SKIP → omit this field from the slice
|
||||||
|
///
|
||||||
|
/// Example usage
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// #[derive(FieldsAsSlice)]
|
||||||
|
/// struct Person {
|
||||||
|
/// #[INTEGER] id: i32,
|
||||||
|
/// #[TEXT] name: String,
|
||||||
|
/// #[SKIP] secret_code: String, // will not appear in `attributes_slice()`
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[proc_macro_derive(FieldsAsSlice, attributes(INTEGER, NULL, REAL, TEXT, BLOB, SKIP))]
|
||||||
pub fn derive_iterable(input: TokenStream) -> TokenStream {
|
pub fn derive_iterable(input: TokenStream) -> TokenStream {
|
||||||
let input = parse_macro_input!(input as DeriveInput);
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
|
|
||||||
let struct_name = input.ident;
|
let struct_name = input.ident;
|
||||||
|
|
||||||
|
// collect named fields only
|
||||||
let fields = match input.data {
|
let fields = match input.data {
|
||||||
Data::Struct(data_struct) => {
|
Data::Struct(data_struct) => match data_struct.fields {
|
||||||
// let list_attrs = input.attrs.iter().map(|v| v.path());
|
Fields::Named(f_named) => f_named.named,
|
||||||
match data_struct.fields {
|
_ => panic!("Only structs with named fields are supported"),
|
||||||
Fields::Named(fields_named) => fields_named.named,
|
},
|
||||||
_ => panic!("Only structs with named fields are supported"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => panic!("Only structs are supported"),
|
_ => panic!("Only structs are supported"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let fields_iter = fields.iter().map(|field| {
|
// For each field: * skip if `#[SKIP]` is present
|
||||||
let field_ident = &field.ident;
|
// * otherwise find the first of the type attributes, or default to TEXT
|
||||||
let val = field
|
let fields_iter = fields.iter().filter_map(|field| {
|
||||||
.attrs
|
// Skip fields marked with #[SKIP]
|
||||||
.iter()
|
if field.attrs.iter().any(|a| a.path().is_ident("SKIP")) {
|
||||||
.map(|v| v.path().get_ident())
|
return None;
|
||||||
.next()
|
|
||||||
.flatten()
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| syn::Ident::new("TEXT", Span::call_site().into()))
|
|
||||||
.to_string();
|
|
||||||
let field_name = field_ident.as_ref().unwrap().to_string();
|
|
||||||
quote! {
|
|
||||||
(#field_name, #val)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut sqlite_type = "TEXT".to_string();
|
||||||
|
let mut exported_name = field
|
||||||
|
.ident
|
||||||
|
.as_ref()
|
||||||
|
.expect("Expected named field")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
for attr in &field.attrs {
|
||||||
|
let ident = match attr.path().get_ident() {
|
||||||
|
Some(i) => i.to_string(),
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
if !matches!(
|
||||||
|
ident.as_str(),
|
||||||
|
"INTEGER" | "NULL" | "REAL" | "TEXT" | "BLOB"
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite_type = ident;
|
||||||
|
|
||||||
|
// Parse optional: #[TEXT(name = "...")]
|
||||||
|
let _ = attr.parse_nested_meta(|meta| {
|
||||||
|
if meta.path.is_ident("name") {
|
||||||
|
let value = meta.value()?;
|
||||||
|
let lit: syn::LitStr = value.parse()?;
|
||||||
|
exported_name = lit.value();
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(meta.error("expected `name = \"...\"`"))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(quote! {
|
||||||
|
(#exported_name, #sqlite_type)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
// Build a unique static name for the slice.
|
||||||
|
let const_name_str = format!(
|
||||||
|
"{}_ATTR_SLICE",
|
||||||
|
struct_name.to_string().to_ascii_uppercase()
|
||||||
|
);
|
||||||
|
let const_name = syn::Ident::new(&const_name_str, proc_macro::Span::call_site().into());
|
||||||
|
|
||||||
let name_of_static_str = struct_name.to_string().to_ascii_uppercase() + "_ATTR_SLICE";
|
// Finally emit the implementation
|
||||||
let name_of_static = Ident::new(&name_of_static_str, Span::call_site().into());
|
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
/// Derived implementation of a (attribute, type) slice
|
/// Generated slice containing `(field_name, sqlite_type)` pairs.
|
||||||
/// allowing a constant time serialisation & deserialisation into rusqlite
|
///
|
||||||
const #name_of_static: &[(&str, &str)] = &[
|
/// The slice is `static` so it can be used in zero‑alloc scenarios.
|
||||||
|
const #const_name: &[(&str, &str)] = &[
|
||||||
#(#fields_iter),*
|
#(#fields_iter),*
|
||||||
];
|
];
|
||||||
|
|
||||||
impl FieldsAsSlice for #struct_name {
|
impl FieldsAsSlice for #struct_name {
|
||||||
/// Gives a precompiled slice of the &[(fields: &str, sqlite_type: &str)]
|
|
||||||
fn attributes_slice<'a>() -> &'static [(&'static str, &'static str)] {
|
fn attributes_slice<'a>() -> &'static [(&'static str, &'static str)] {
|
||||||
#name_of_static
|
&#const_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -77,7 +122,63 @@ pub fn derive_iterable(input: TokenStream) -> TokenStream {
|
||||||
TokenStream::from(expanded)
|
TokenStream::from(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
// As an hashmap (incorrect as of no ordering)
|
#[proc_macro_derive(InstanceAsArray, attributes(InstanceAsArray, SKIP))]
|
||||||
// let mut h = std::collections::HashMap::new();
|
pub fn derive_instance_as_array(input: TokenStream) -> TokenStream {
|
||||||
// #(h.insert(#fields_iter);)*
|
use syn::{Data, DeriveInput, Fields, Type, parse_macro_input};
|
||||||
// h
|
|
||||||
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
|
let struct_name = &input.ident;
|
||||||
|
|
||||||
|
// Read #[InstanceAsSlice(Type = "...")]
|
||||||
|
let mut output_ty: Option<Type> = None;
|
||||||
|
|
||||||
|
for attr in &input.attrs {
|
||||||
|
if !attr.path().is_ident("InstanceAsArray") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
attr.parse_nested_meta(|meta| {
|
||||||
|
if meta.path.is_ident("Type") {
|
||||||
|
let value = meta.value()?;
|
||||||
|
let ty: Type = value.parse()?;
|
||||||
|
output_ty = Some(ty);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(meta.error("expected `Type = ...`"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let output_ty = output_ty.expect("Missing #[InstanceAsArray(Type = YourType)] attribute.");
|
||||||
|
|
||||||
|
let fields = match &input.data {
|
||||||
|
Data::Struct(data) => match &data.fields {
|
||||||
|
Fields::Named(fields) => &fields.named,
|
||||||
|
_ => panic!("Only named structs are supported."),
|
||||||
|
},
|
||||||
|
_ => panic!("Only structs are supported."),
|
||||||
|
};
|
||||||
|
|
||||||
|
let field_idents: Vec<_> = fields
|
||||||
|
.iter()
|
||||||
|
.filter(|field| !field.attrs.iter().any(|a| a.path().is_ident("SKIP")))
|
||||||
|
.map(|field| field.ident.as_ref().unwrap())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let field_count = field_idents.len();
|
||||||
|
|
||||||
|
let expanded = quote! {
|
||||||
|
impl #struct_name {
|
||||||
|
pub fn instance_as_array(&self) -> [#output_ty; #field_count] {
|
||||||
|
[
|
||||||
|
#(
|
||||||
|
::core::convert::Into::<#output_ty>::into(&self.#field_idents)
|
||||||
|
),*
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TokenStream::from(expanded)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# cargo-features = ["codegen-backend"]
|
# cargo-features = ["codegen-backend"]
|
||||||
[package]
|
[package]
|
||||||
name = "ravenous-tools"
|
name = "ravenous-tools"
|
||||||
version = "0.1.8"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -17,6 +17,7 @@ clap = {workspace = true}
|
||||||
tokio = {workspace = true}
|
tokio = {workspace = true}
|
||||||
formatter = {workspace = true}
|
formatter = {workspace = true}
|
||||||
weaponry = {workspace = true}
|
weaponry = {workspace = true}
|
||||||
|
monsters = {workspace = true}
|
||||||
|
|
||||||
[package.metadata.cargo-machete]
|
[package.metadata.cargo-machete]
|
||||||
ignored = ["tokio"]
|
ignored = ["tokio"]
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,10 @@ use fast_class::make_better_gen;
|
||||||
use formatter::format_file;
|
use formatter::format_file;
|
||||||
use graphs::make_graphs;
|
use graphs::make_graphs;
|
||||||
use make::make_pdf;
|
use make::make_pdf;
|
||||||
|
use monsters::monsters_dispatch;
|
||||||
use stats::stat_solver;
|
use stats::stat_solver;
|
||||||
use tablegen::table_gen;
|
use tablegen::table_gen;
|
||||||
use weaponry::analysis::launch_analysis;
|
use weaponry::{analysis::launch_analysis, export_tex::export_weapons};
|
||||||
|
|
||||||
// External imports
|
// External imports
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
@ -36,7 +37,9 @@ fn main() -> Result<()> {
|
||||||
Commands::Graphs(args) => make_graphs(&args, &config),
|
Commands::Graphs(args) => make_graphs(&args, &config),
|
||||||
Commands::Format(args) => format_file(&args, &config),
|
Commands::Format(args) => format_file(&args, &config),
|
||||||
Commands::Analysis(args) => Ok(launch_analysis(&args, &config)?), // Not using anyhow but a custom error
|
Commands::Analysis(args) => Ok(launch_analysis(&args, &config)?), // Not using anyhow but a custom error
|
||||||
|
Commands::Weapons(args) => Ok(export_weapons(&args, &config)?), // Not using anyhow but a custom error
|
||||||
Commands::BetterGen(args) => make_better_gen(&args, &config),
|
Commands::BetterGen(args) => make_better_gen(&args, &config),
|
||||||
|
Commands::Monsters(args) => monsters_dispatch(&args, &config),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "stats"
|
name = "stats"
|
||||||
version = "0.1.1"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tablegen"
|
name = "tablegen"
|
||||||
version = "0.1.2"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ impl WriteTable for ClassesArray {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if lvl != 0 {
|
if lvl != 0 {
|
||||||
writeln!(buffer, "{}", &config.classes.sep)?;
|
writeln!(buffer, "{}", config.classes.sep)?;
|
||||||
}
|
}
|
||||||
writeln!(buffer, "{}", formatted_tier)?;
|
writeln!(buffer, "{}", formatted_tier)?;
|
||||||
for elem in tier {
|
for elem in tier {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "weaponry"
|
name = "weaponry"
|
||||||
version = "0.1.1"
|
version.workspace = true
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -11,11 +11,12 @@ regex = {workspace = true}
|
||||||
csv = {workspace = true}
|
csv = {workspace = true}
|
||||||
serde = {workspace = true}
|
serde = {workspace = true}
|
||||||
comfy-table = "7.2.2"
|
comfy-table = "7.2.2"
|
||||||
probability = "0.20.3"
|
probability = {workspace = true}
|
||||||
rusqlite = { version = "0.40.1" } # , features = ["bundled"]
|
rusqlite = {workspace = true}
|
||||||
serde_rusqlite = "0.43.0"
|
serde_rusqlite = {workspace = true}
|
||||||
serde_json = { version = "1.0.150", features = ["alloc"] }
|
serde_json = {workspace = true}
|
||||||
strum = { version = "0.28.0", features = ["derive"] }
|
handlebars = {workspace = true}
|
||||||
|
strum = {workspace = true}
|
||||||
thiserror = "2.0.18"
|
thiserror = "2.0.18"
|
||||||
charming = { version = "0.4.0", features = [] }
|
charming = { version = "0.4.0", features = [] }
|
||||||
|
|
||||||
|
|
@ -33,5 +34,8 @@ rayon = "1.12.0"
|
||||||
name = "iter_creation"
|
name = "iter_creation"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
dev-analysis = [] # gate for the feature flag
|
||||||
|
|
||||||
# [lints.rust]
|
# [lints.rust]
|
||||||
# unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
|
# unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ fn export_as_csv(refined_list: &RefinedEquipementList, save_path: &str) {
|
||||||
|
|
||||||
type DynamicFilterType = Box<dyn FnMut(&RefinedEquipement, &RefinedEquipement) -> Ordering>;
|
type DynamicFilterType = Box<dyn FnMut(&RefinedEquipement, &RefinedEquipement) -> Ordering>;
|
||||||
|
|
||||||
fn cmd_to_filter(og_entry: &str) -> Result<DynamicFilterType, FatalEquipementError> {
|
pub fn cmd_to_filter(og_entry: &str) -> Result<DynamicFilterType, FatalEquipementError> {
|
||||||
let (category, entry) = if og_entry.starts_with("cat+") {
|
let (category, entry) = if og_entry.starts_with("cat+") {
|
||||||
(true, og_entry.split_at(4).1)
|
(true, og_entry.split_at(4).1)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use config::analysis::AnalysisConfig;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::FatalEquipementError,
|
error::FatalEquipementError,
|
||||||
interfaces::{Reportable, Scenario, ToAnalysis, ToCSV, ToTex},
|
interfaces::{Reportable, Scenario, ToAnalysis, ToCSV},
|
||||||
weaponry_structs::{
|
weaponry_structs::{
|
||||||
CrossRecipeScenario, RefinedEquipement, RefinedEquipementList,
|
CrossRecipeScenario, RefinedEquipement, RefinedEquipementList,
|
||||||
equipement_scenario::ConfigEquipementScenario,
|
equipement_scenario::ConfigEquipementScenario,
|
||||||
|
|
@ -81,14 +81,7 @@ fn create_graphs(args: &AnalysisConfig, config: &Config, filter: DynamicFilterTy
|
||||||
}
|
}
|
||||||
Err(e) => panic!("{e}"),
|
Err(e) => panic!("{e}"),
|
||||||
}
|
}
|
||||||
// if args.html_export{}
|
|
||||||
refined_list.write_html(&save_path).unwrap();
|
refined_list.write_html(&save_path).unwrap();
|
||||||
|
|
||||||
// if args.csv_export{}
|
|
||||||
// export_as_csv(&refined_list, &save_path);
|
|
||||||
|
|
||||||
// if args.tex_export{}
|
|
||||||
// export_as_tex(&refined_list, &save_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -103,20 +96,20 @@ fn export_as_csv(refined_list: &RefinedEquipementList, save_path: &str) {
|
||||||
refined_list.write_csv(Path::new(&format!("{save_path}.csv")))
|
refined_list.write_csv(Path::new(&format!("{save_path}.csv")))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/// Export as a tex file in the given directory
|
// /// Export as a tex file in the given directory
|
||||||
///
|
// ///
|
||||||
/// Generic function dispatching any specific demand to different functions
|
// /// Generic function dispatching any specific demand to different functions
|
||||||
/// TODO: FINISH IMPLEMENTATION
|
// /// TODO: FINISH IMPLEMENTATION
|
||||||
#[allow(dead_code)]
|
// #[allow(dead_code)]
|
||||||
fn export_as_tex(refined_list: &RefinedEquipementList, save_path: &str) {
|
// fn export_as_tex(refined_list: &RefinedEquipementList, config: &Config, save_path: &str) {
|
||||||
let _ = save_path;
|
// let _ = save_path;
|
||||||
println!("{}", refined_list.to_tex()); // TexType
|
// println!("{}", refined_list.to_tex(config)); // TexType
|
||||||
// println!(
|
// // println!(
|
||||||
// "Saved initial data as {}.html: {:?}",
|
// // "Saved initial data as {}.html: {:?}",
|
||||||
// save_path,
|
// // save_path,
|
||||||
// refined_list.write_csv(Path::new(&format!("{save_path}.csv")))
|
// // refined_list.write_csv(Path::new(&format!("{save_path}.csv")))
|
||||||
// );
|
// // );
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// A dynamic filtertype, as a boxed function over two equipement references
|
/// A dynamic filtertype, as a boxed function over two equipement references
|
||||||
// #[allow(dead_code)]
|
// #[allow(dead_code)]
|
||||||
|
|
@ -129,7 +122,7 @@ type DynamicFilterType = Box<dyn FnMut(&RefinedEquipement) -> bool>;
|
||||||
///
|
///
|
||||||
/// This informal implementation function as a mini language,
|
/// This informal implementation function as a mini language,
|
||||||
/// without any form of formalism, consistency or fixed API
|
/// without any form of formalism, consistency or fixed API
|
||||||
fn cmd_to_filter(og_entry: &str) -> Result<DynamicSortType, FatalEquipementError> {
|
pub fn cmd_to_filter(og_entry: &str) -> Result<DynamicSortType, FatalEquipementError> {
|
||||||
let (category, entry) = if og_entry.starts_with("cat+") {
|
let (category, entry) = if og_entry.starts_with("cat+") {
|
||||||
(true, og_entry.split_at(4).1)
|
(true, og_entry.split_at(4).1)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ where
|
||||||
|
|
||||||
/// Generate a SELECT query with fields generated from a struct. Returns a SQL request as a String
|
/// Generate a SELECT query with fields generated from a struct. Returns a SQL request as a String
|
||||||
#[inline]
|
#[inline]
|
||||||
#[coverage(off)] // INCORRECT: Error with line report
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // INCORRECT: Error with line report
|
||||||
fn generate_select_query<T: more_fields::FieldsAsSlice>(
|
fn generate_select_query<T: more_fields::FieldsAsSlice>(
|
||||||
table_name: &str,
|
table_name: &str,
|
||||||
filter: Option<&str>,
|
filter: Option<&str>,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,12 @@ pub enum FatalEquipementError {
|
||||||
#[error("Deserialisation from json failed : {0}")]
|
#[error("Deserialisation from json failed : {0}")]
|
||||||
SerdeJSON(#[from] serde_json::Error),
|
SerdeJSON(#[from] serde_json::Error),
|
||||||
|
|
||||||
|
#[error("Error making the template: {0}")]
|
||||||
|
TemplatingError(#[from] handlebars::TemplateError),
|
||||||
|
|
||||||
|
#[error("Error rendering the template: {0}")]
|
||||||
|
RenderError(#[from] handlebars::RenderError),
|
||||||
|
|
||||||
#[error(
|
#[error(
|
||||||
"Deserialisation from json failed at line {line} on file {file} while trying to parse the value: {parsed_value}: {error}]"
|
"Deserialisation from json failed at line {line} on file {file} while trying to parse the value: {parsed_value}: {error}]"
|
||||||
)]
|
)]
|
||||||
|
|
@ -47,6 +53,19 @@ pub enum FatalEquipementError {
|
||||||
SerdeRSQLite(#[from] serde_rusqlite::Error),
|
SerdeRSQLite(#[from] serde_rusqlite::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
/// Generic error handling
|
||||||
|
pub enum WeaponGenerationError {
|
||||||
|
#[error("An unexpected error occured")]
|
||||||
|
Unexpected,
|
||||||
|
|
||||||
|
#[error("An error was encountered while generating equipement")]
|
||||||
|
FatalEquipementError(#[from] FatalEquipementError),
|
||||||
|
|
||||||
|
#[error("An error occured while writing the file")]
|
||||||
|
IOError(#[from] std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
// #[derive(Error, Debug)]
|
// #[derive(Error, Debug)]
|
||||||
// /// Recoverable error, all these error exist to signal a retry or another path that should be taken by the program
|
// /// Recoverable error, all these error exist to signal a retry or another path that should be taken by the program
|
||||||
// pub enum LocalEquipementError {
|
// pub enum LocalEquipementError {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Workspace: weaponry
|
||||||
|
// File: weaponry/src/export_tex.rs
|
||||||
|
//! Module regrouping all generic function related to the exporting as tex
|
||||||
|
//!
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use crate::interfaces::ToTex;
|
||||||
|
use crate::weaponry_structs::equipement_scenario::ConfigEquipementScenario;
|
||||||
|
use crate::{interfaces::Scenario, weaponry_structs::RefinedEquipementList};
|
||||||
|
use cli_parser::Config;
|
||||||
|
use config::analysis::WeaponConfig;
|
||||||
|
|
||||||
|
use crate::{error::WeaponGenerationError, weaponry_structs::CrossRecipeScenario};
|
||||||
|
|
||||||
|
/// Export as a tex file in the given directory
|
||||||
|
///
|
||||||
|
/// Generic function dispatching any specific demand to different functions
|
||||||
|
/// TODO: FINISH IMPLEMENTATION
|
||||||
|
pub fn export_as_tex(refined_list: &RefinedEquipementList, config: &Config, save_path: &str) {
|
||||||
|
let _ = save_path;
|
||||||
|
println!("{}", refined_list.to_tex(config).unwrap()); // TexType
|
||||||
|
// println!(
|
||||||
|
// "Saved initial data as {}.html: {:?}",
|
||||||
|
// save_path,
|
||||||
|
// refined_list.write_csv(Path::new(&format!("{save_path}.csv")))
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Export all weapon database as a tex data
|
||||||
|
pub fn export_weapons(args: &WeaponConfig, config: &Config) -> Result<(), WeaponGenerationError> {
|
||||||
|
let scenarios = CrossRecipeScenario::new_with_config(ConfigEquipementScenario {
|
||||||
|
table_name: "Equipements".into(),
|
||||||
|
db_path: config.data_generation.database.clone(),
|
||||||
|
shape: Some(()),
|
||||||
|
materials: None,
|
||||||
|
nature: Some(()), //(!args.no_natures).then_some(()),
|
||||||
|
finishing: None, //args.finishing.then_some(()),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// let filter = Box::new(|_: &RefinedEquipement| true);
|
||||||
|
let refined_list = scenarios.generate_refined_recipes()?;
|
||||||
|
// .inner_filter(filter);
|
||||||
|
|
||||||
|
let tex = refined_list.to_tex(config)?;
|
||||||
|
|
||||||
|
let name = format!("{}/gen-forge-table.tex", args.export);
|
||||||
|
println!("Writing to file {name}");
|
||||||
|
let mut f = fs::File::create(name)?;
|
||||||
|
writeln!(f, "{}", tex)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
use std::{path::Path, rc::Rc};
|
use std::{path::Path, rc::Rc};
|
||||||
|
|
||||||
|
use cli_parser::Config;
|
||||||
use more_fields::FieldsAsSlice;
|
use more_fields::FieldsAsSlice;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
|
|
@ -61,7 +62,7 @@ where
|
||||||
/// A blanket implementation giving all combinaisons of recipes with another RecipeCollection
|
/// A blanket implementation giving all combinaisons of recipes with another RecipeCollection
|
||||||
///
|
///
|
||||||
/// This method doesn't make use of parallel iterators as the workload is way faster than would be the memory dispatch
|
/// This method doesn't make use of parallel iterators as the workload is way faster than would be the memory dispatch
|
||||||
#[coverage(off)] // Tarpaulin cannot deal with iter and long lines
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // Tarpaulin cannot deal with iter and long lines
|
||||||
fn combine_all<G>(&mut self, other: &G)
|
fn combine_all<G>(&mut self, other: &G)
|
||||||
where
|
where
|
||||||
G: RecipeCollection<Recipes = Self::Recipes>,
|
G: RecipeCollection<Recipes = Self::Recipes>,
|
||||||
|
|
@ -95,7 +96,7 @@ where
|
||||||
fn from_vectored(list: Vec<Self::Recipes>) -> Self;
|
fn from_vectored(list: Vec<Self::Recipes>) -> Self;
|
||||||
|
|
||||||
/// Create a collection from an iterator of intermediate values T
|
/// Create a collection from an iterator of intermediate values T
|
||||||
#[coverage(off)] // INCORRECT: Error with line report
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // INCORRECT: Error with line report
|
||||||
fn from_iter_intermediate<T>(
|
fn from_iter_intermediate<T>(
|
||||||
iter_inter: impl Iterator<Item = Result<T, FatalEquipementError>>,
|
iter_inter: impl Iterator<Item = Result<T, FatalEquipementError>>,
|
||||||
) -> Result<Self, FatalEquipementError>
|
) -> Result<Self, FatalEquipementError>
|
||||||
|
|
@ -162,7 +163,7 @@ pub(crate) struct FilterFunction<T>(pub(super) FilterType<T>);
|
||||||
/// This element can be converted to tex
|
/// This element can be converted to tex
|
||||||
pub trait ToTex {
|
pub trait ToTex {
|
||||||
/// Export the object to a Tex string
|
/// Export the object to a Tex string
|
||||||
fn to_tex(&self) -> String;
|
fn to_tex(&self, config: &Config) -> Result<String, FatalEquipementError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This element can be converted to a csv for further analysis
|
/// This element can be converted to a csv for further analysis
|
||||||
|
|
@ -232,7 +233,7 @@ pub trait RecipeDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a row inside the database, while mostly unused this function is needed to initialize the empty table with an empty row if needed
|
/// Insert a row inside the database, while mostly unused this function is needed to initialize the empty table with an empty row if needed
|
||||||
#[coverage(off)] // INCORRECT: Error with line report
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // INCORRECT: Error with line report
|
||||||
fn insert_row<T: FieldsAsSlice + Serialize>(
|
fn insert_row<T: FieldsAsSlice + Serialize>(
|
||||||
&self,
|
&self,
|
||||||
table_name: &str,
|
table_name: &str,
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@
|
||||||
// File: weaponry/src/lib.rs
|
// File: weaponry/src/lib.rs
|
||||||
//! Weaponry module, handling all weaponry creation and analysis
|
//! Weaponry module, handling all weaponry creation and analysis
|
||||||
|
|
||||||
#![feature(coverage_attribute)]
|
#![cfg_attr(feature = "dev-analysis", feature(coverage_attribute))]
|
||||||
// #![feature(int_roundings)]
|
|
||||||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||||
#![feature(iter_intersperse)]
|
// #![feature(iter_intersperse)]
|
||||||
|
|
||||||
pub mod analysis;
|
pub mod analysis;
|
||||||
mod database;
|
mod database;
|
||||||
|
|
@ -14,6 +13,7 @@ pub mod export;
|
||||||
pub mod interfaces;
|
pub mod interfaces;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod weaponry_structs;
|
pub mod weaponry_structs;
|
||||||
|
pub mod export_tex;
|
||||||
|
|
||||||
/// Signals the function running is unfinished
|
/// Signals the function running is unfinished
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ use crate::{
|
||||||
export::{initial_chart, initial_plot_chart},
|
export::{initial_chart, initial_plot_chart},
|
||||||
interfaces::{RecipeCollection, RefinedList, ToAnalysis},
|
interfaces::{RecipeCollection, RefinedList, ToAnalysis},
|
||||||
weaponry_structs::{
|
weaponry_structs::{
|
||||||
Equipement, InitialEquipementList,
|
Equipement, InitialEquipementList, WeaponBaseShape,
|
||||||
|
equipement_fields::WeaponBaseSize,
|
||||||
equipement_structs::InnerEquipementStats,
|
equipement_structs::InnerEquipementStats,
|
||||||
equipement_thin_types::{Dices, Precision},
|
equipement_thin_types::{Dices, Precision},
|
||||||
},
|
},
|
||||||
|
|
@ -49,6 +50,107 @@ pub struct RefinedEquipementList {
|
||||||
pub inner: Vec<RefinedEquipement>,
|
pub inner: Vec<RefinedEquipement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::missing_docs_in_private_items)]
|
||||||
|
/// The exportable equipement minimum precalculated stats
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct ExportableEquipement {
|
||||||
|
pub name: String,
|
||||||
|
pub category: Option<WeaponBaseShape>,
|
||||||
|
pub maniement: String,
|
||||||
|
pub damage_base: i8,
|
||||||
|
pub damage_per: i8,
|
||||||
|
pub rmax: i8,
|
||||||
|
pub arbreak: i8,
|
||||||
|
pub protection: i8,
|
||||||
|
pub integrity: i8,
|
||||||
|
pub torque_one_handed: Option<i8>,
|
||||||
|
pub torque_two_handed: Option<i8>,
|
||||||
|
pub modes: String,
|
||||||
|
pub esquive: String,
|
||||||
|
pub parrade: String,
|
||||||
|
pub vitesse: String,
|
||||||
|
pub discretion: String,
|
||||||
|
pub difficulty: String,
|
||||||
|
pub cost: String,
|
||||||
|
pub special: String,
|
||||||
|
pub needs_break: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Put half numbers
|
||||||
|
fn halves(f: f32) -> String {
|
||||||
|
let base = f.floor();
|
||||||
|
let extra = f - base;
|
||||||
|
if !(-0.1..=0.1).contains(&extra) {
|
||||||
|
if base == 0. {
|
||||||
|
"\\half{}".to_string()
|
||||||
|
} else {
|
||||||
|
format!("{base:0}\\half{{}}")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
format!("{base}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<&RefinedEquipement> for ExportableEquipement {
|
||||||
|
fn from(value: &RefinedEquipement) -> Self {
|
||||||
|
let mut special = Vec::new();
|
||||||
|
if value.inner.action_cost != 0 && value.inner.action_cost != 1 {
|
||||||
|
special.push(format!(r"{}A", value.inner.action_cost));
|
||||||
|
}
|
||||||
|
if let Some(cost) = value.inner.reload_cost {
|
||||||
|
special.push(format!(r"{cost}\reload{{}}"));
|
||||||
|
};
|
||||||
|
if value.inner.armor_pierce != 0 {
|
||||||
|
let mut parmure = value.inner.armor_pierce;
|
||||||
|
match (&value.inner.category_base, &value.inner.category_size) {
|
||||||
|
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::Heavy)) => parmure += 1,
|
||||||
|
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::SuperHeavy)) => parmure += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
special.push(format!(r"\glssymbol{{parmure}} {parmure}"));
|
||||||
|
}
|
||||||
|
if value.inner.range != 0 {
|
||||||
|
let mut range = value.inner.range;
|
||||||
|
match (&value.inner.category_base, &value.inner.category_size) {
|
||||||
|
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::Heavy)) => range += 30,
|
||||||
|
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::SuperHeavy)) => range += 60,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
special.push(format!(r"{range}m"));
|
||||||
|
}
|
||||||
|
if value.inner.precision != 0 {
|
||||||
|
special.push(format!(
|
||||||
|
r"\glssymbol{{precision}} {:+}",
|
||||||
|
value.inner.precision
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if value.inner.agility_bonus != 0. {
|
||||||
|
special.push(format!(r"Ag {}", halves(value.inner.agility_bonus)));
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
name: value.advanced.display_name.clone(),
|
||||||
|
maniement: value.inner.get_maniement(),
|
||||||
|
damage_base: value.inner.damage,
|
||||||
|
damage_per: value.inner.p_damage,
|
||||||
|
rmax: value.inner.rmax,
|
||||||
|
arbreak: value.inner.armor_break,
|
||||||
|
protection: value.inner.protection,
|
||||||
|
integrity: value.inner.integrity,
|
||||||
|
torque_one_handed: value.inner.torque_one_handed,
|
||||||
|
torque_two_handed: value.inner.torque_two_handed,
|
||||||
|
modes: value.inner.get_modes(),
|
||||||
|
esquive: halves(value.inner.dodge),
|
||||||
|
parrade: value.inner.parry.to_string(),
|
||||||
|
vitesse: value.inner.speed.to_string(),
|
||||||
|
discretion: value.inner.stealth.to_string(),
|
||||||
|
difficulty: value.inner.difficulty.to_string(),
|
||||||
|
category: value.inner.category_base,
|
||||||
|
special: special.join(", "),
|
||||||
|
needs_break: false,
|
||||||
|
cost: value.inner.cost.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DONE: The use of Deref could be a subtle gotcha
|
// DONE: The use of Deref could be a subtle gotcha
|
||||||
impl Deref for RefinedEquipementList {
|
impl Deref for RefinedEquipementList {
|
||||||
type Target = Vec<RefinedEquipement>;
|
type Target = Vec<RefinedEquipement>;
|
||||||
|
|
@ -82,7 +184,7 @@ impl ToAnalysis for RefinedEquipementList {
|
||||||
|
|
||||||
// DONE: While a custom config would allow some personalisation, there is no reason to beleive a more meaningfull name would be choosen
|
// DONE: While a custom config would allow some personalisation, there is no reason to beleive a more meaningfull name would be choosen
|
||||||
fn write_html(&self, save_path: &str) -> Result<(), FatalEquipementError> {
|
fn write_html(&self, save_path: &str) -> Result<(), FatalEquipementError> {
|
||||||
let mut renderer = charming::HtmlRenderer::new("Ravenous Bob", 4000, 2000)
|
let mut renderer = charming::HtmlRenderer::new("Ravenous Bob", 1920, 900)
|
||||||
.theme(charming::theme::Theme::Dark);
|
.theme(charming::theme::Theme::Dark);
|
||||||
|
|
||||||
let initial_chart = self.make_regular_graph();
|
let initial_chart = self.make_regular_graph();
|
||||||
|
|
@ -255,7 +357,7 @@ pub struct AdvancedStats {
|
||||||
}
|
}
|
||||||
impl From<&InnerEquipementStats> for AdvancedStats {
|
impl From<&InnerEquipementStats> for AdvancedStats {
|
||||||
fn from(value: &InnerEquipementStats) -> Self {
|
fn from(value: &InnerEquipementStats) -> Self {
|
||||||
let max_damage_per_attack = (value.damage + value.p_damage * (value.rmax)) as f64;
|
let max_damage_per_attack = (value.damage + value.p_damage * (value.rmax - 1)) as f64;
|
||||||
let armor_break_per_attack =
|
let armor_break_per_attack =
|
||||||
(value.armor_break as f64 + value.antimaterial as f64).min(max_damage_per_attack);
|
(value.armor_break as f64 + value.antimaterial as f64).min(max_damage_per_attack);
|
||||||
let variance = (value.p_damage * value.rmax) as f64;
|
let variance = (value.p_damage * value.rmax) as f64;
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,8 @@ pub(super) fn binomial_dice_distribution(
|
||||||
+ equipement.p_damage as f64
|
+ equipement.p_damage as f64
|
||||||
* (target_dices
|
* (target_dices
|
||||||
.saturating_sub(1)
|
.saturating_sub(1)
|
||||||
.clamp(0, equipement.rmax as usize)) as f64)
|
.clamp(0, (equipement.rmax - 1) as usize))
|
||||||
|
as f64)
|
||||||
* probability_success
|
* probability_success
|
||||||
} else {
|
} else {
|
||||||
0.
|
0.
|
||||||
|
|
@ -354,12 +355,9 @@ mod test {
|
||||||
let eq = new_inner_eq();
|
let eq = new_inner_eq();
|
||||||
assert_close!(
|
assert_close!(
|
||||||
average_damage(&eq, &[Precision(9)], &[Dices(9)]),
|
average_damage(&eq, &[Precision(9)], &[Dices(9)]),
|
||||||
13.999999999
|
11.999999826
|
||||||
);
|
|
||||||
assert_close!(
|
|
||||||
average_damage(&eq, &[Precision(4)], &[Dices(4)]),
|
|
||||||
10.1119999
|
|
||||||
);
|
);
|
||||||
|
assert_close!(average_damage(&eq, &[Precision(4)], &[Dices(4)]), 9.753599);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -400,7 +398,7 @@ mod test {
|
||||||
Dices(3),
|
Dices(3),
|
||||||
Precision(10),
|
Precision(10),
|
||||||
),
|
),
|
||||||
14.,
|
12.,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
BestDamageScenarios::from_action_constraints_it(
|
BestDamageScenarios::from_action_constraints_it(
|
||||||
|
|
@ -460,7 +458,7 @@ mod test {
|
||||||
Dices(3),
|
Dices(3),
|
||||||
Precision(10),
|
Precision(10),
|
||||||
),
|
),
|
||||||
14.,
|
12.,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
BestDamageScenarios::from_action_constraints_it(
|
BestDamageScenarios::from_action_constraints_it(
|
||||||
|
|
@ -480,7 +478,7 @@ mod test {
|
||||||
Dices(6),
|
Dices(6),
|
||||||
Precision(10),
|
Precision(10),
|
||||||
),
|
),
|
||||||
28.,
|
24.,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
BestDamageScenarios::from_action_constraints_it(
|
BestDamageScenarios::from_action_constraints_it(
|
||||||
|
|
@ -500,7 +498,7 @@ mod test {
|
||||||
Dices(3),
|
Dices(3),
|
||||||
Precision(10),
|
Precision(10),
|
||||||
),
|
),
|
||||||
14.,
|
12.,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
BestDamageScenarios::from_action_constraints_it(
|
BestDamageScenarios::from_action_constraints_it(
|
||||||
|
|
@ -510,7 +508,7 @@ mod test {
|
||||||
Dices(3),
|
Dices(3),
|
||||||
Precision(10),
|
Precision(10),
|
||||||
),
|
),
|
||||||
14.,
|
12.,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
BestDamageScenarios::from_action_constraints_it(
|
BestDamageScenarios::from_action_constraints_it(
|
||||||
|
|
@ -530,7 +528,7 @@ mod test {
|
||||||
Dices(6),
|
Dices(6),
|
||||||
Precision(10),
|
Precision(10),
|
||||||
),
|
),
|
||||||
28.,
|
24.,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
BestDamageScenarios::from_action_constraints_it(
|
BestDamageScenarios::from_action_constraints_it(
|
||||||
|
|
@ -580,15 +578,15 @@ mod test {
|
||||||
};
|
};
|
||||||
assert_close!(
|
assert_close!(
|
||||||
get_damage_with_simulation(&eq1, Actions(2), Attacks(1)),
|
get_damage_with_simulation(&eq1, Actions(2), Attacks(1)),
|
||||||
8.3998
|
7.1999
|
||||||
);
|
);
|
||||||
assert_close!(
|
assert_close!(
|
||||||
get_damage_with_simulation(&eq2, Actions(2), Attacks(1)),
|
get_damage_with_simulation(&eq2, Actions(2), Attacks(1)),
|
||||||
9.6936
|
8.3624
|
||||||
);
|
);
|
||||||
assert_close!(
|
assert_close!(
|
||||||
get_damage_with_simulation(&eq3, Actions(2), Attacks(1)),
|
get_damage_with_simulation(&eq3, Actions(2), Attacks(1)),
|
||||||
9.6936
|
8.36249
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -48,26 +48,65 @@ pub enum NatureTarget {
|
||||||
|
|
||||||
/// Enum of all different physical weapon damage types
|
/// Enum of all different physical weapon damage types
|
||||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
// #[cfg_attr(test, derive(PartialEq))]
|
||||||
pub enum PhysicalDamageType {
|
pub enum PhysicalDamageType {
|
||||||
Blunt,
|
Blunt,
|
||||||
Slash,
|
Slash,
|
||||||
Pierce,
|
Pierce,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PhysicalDamageType {
|
||||||
|
/// Get a exportable representation
|
||||||
|
pub fn export(&self) -> String {
|
||||||
|
match self {
|
||||||
|
PhysicalDamageType::Blunt => "\\blunt".to_string(),
|
||||||
|
PhysicalDamageType::Slash => "\\slash".to_string(),
|
||||||
|
PhysicalDamageType::Pierce => "\\pierce".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Weapon damage, combining the base weapon damage type and it's level
|
/// Weapon damage, combining the base weapon damage type and it's level
|
||||||
///
|
///
|
||||||
/// Signifying wether the damage is pure or \[secondary\] or \[\[tertiary\]\]
|
/// Signifying wether the damage is pure or \[secondary\] or \[\[tertiary\]\]
|
||||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||||
#[derive(Clone, Debug, Display, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Display, Deserialize, Serialize, Eq, PartialEq, PartialOrd, Ord)]
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
|
||||||
pub enum DamageMod {
|
pub enum DamageMod {
|
||||||
Primary(PhysicalDamageType),
|
Primary(PhysicalDamageType),
|
||||||
Secondary(PhysicalDamageType),
|
Secondary(PhysicalDamageType),
|
||||||
Tertiary(PhysicalDamageType),
|
Tertiary(PhysicalDamageType),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DamageMod {
|
||||||
|
/// Get the underlying value of the mod
|
||||||
|
pub fn underlying(&self) -> PhysicalDamageType {
|
||||||
|
match self {
|
||||||
|
DamageMod::Primary(physical_damage_type) => *physical_damage_type,
|
||||||
|
DamageMod::Secondary(physical_damage_type) => *physical_damage_type,
|
||||||
|
DamageMod::Tertiary(physical_damage_type) => *physical_damage_type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get a exportable representation
|
||||||
|
pub fn export(&self) -> String {
|
||||||
|
match self {
|
||||||
|
DamageMod::Primary(phy) => phy.export(),
|
||||||
|
DamageMod::Secondary(phy) => format!(r"[{}]", phy.export()),
|
||||||
|
DamageMod::Tertiary(phy) => format!(r"[[{}]]", phy.export()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Does the damagemode contain this physical type
|
||||||
|
pub fn contains(&self, value: &PhysicalDamageType) -> bool {
|
||||||
|
self.underlying() == *value
|
||||||
|
}
|
||||||
|
|
||||||
|
// /// Does the other mod have a better mod variant, only true if the underlying value is the same
|
||||||
|
// pub fn upgrade(&self, value: &DamageMod) -> bool {
|
||||||
|
// value > self
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
/// Combined damage type, as a vector of all damage types
|
/// Combined damage type, as a vector of all damage types
|
||||||
///
|
///
|
||||||
/// Meant to be serialised to tex and deserialized directly from the table
|
/// Meant to be serialised to tex and deserialized directly from the table
|
||||||
|
|
@ -76,6 +115,20 @@ pub enum DamageMod {
|
||||||
// TODO: avoid pub make an impl ?
|
// TODO: avoid pub make an impl ?
|
||||||
pub struct DamageType(Vec<DamageMod>);
|
pub struct DamageType(Vec<DamageMod>);
|
||||||
|
|
||||||
|
impl DamageType {
|
||||||
|
/// Get the best modes from self, stripping redundant ones
|
||||||
|
pub fn get_best_modes(&self) -> DamageType {
|
||||||
|
let mut best: Vec<DamageMod> = Vec::new();
|
||||||
|
for m in self.iter() {
|
||||||
|
if let Some(_v) = best.iter().find(|v| v.contains(&m.underlying())) {
|
||||||
|
} else {
|
||||||
|
best.push(m.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self(best)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Deref for DamageType {
|
impl Deref for DamageType {
|
||||||
type Target = Vec<DamageMod>;
|
type Target = Vec<DamageMod>;
|
||||||
|
|
||||||
|
|
@ -229,8 +282,9 @@ pub enum EquipementSerializedCategory {
|
||||||
// : This should replace the used MacroCategory
|
// : This should replace the used MacroCategory
|
||||||
/// The Base Shape of the weapon, used to infer the final category of the weapon
|
/// The Base Shape of the weapon, used to infer the final category of the weapon
|
||||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||||
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
|
#[derive(
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
Copy, Clone, Debug, Display, Deserialize, Serialize, strum::EnumString, Default, PartialEq,
|
||||||
|
)]
|
||||||
pub enum WeaponBaseShape {
|
pub enum WeaponBaseShape {
|
||||||
Staves,
|
Staves,
|
||||||
Blunt,
|
Blunt,
|
||||||
|
|
@ -239,6 +293,7 @@ pub enum WeaponBaseShape {
|
||||||
Armors,
|
Armors,
|
||||||
Shields,
|
Shields,
|
||||||
Exotic,
|
Exotic,
|
||||||
|
#[default]
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,8 +318,7 @@ impl EquipementTargets {
|
||||||
(EquipementTargets::Weapons, WeaponBaseShape::Slash) => true,
|
(EquipementTargets::Weapons, WeaponBaseShape::Slash) => true,
|
||||||
(EquipementTargets::Weapons, WeaponBaseShape::Ranged) => true,
|
(EquipementTargets::Weapons, WeaponBaseShape::Ranged) => true,
|
||||||
(EquipementTargets::Weapons, WeaponBaseShape::Exotic) => true,
|
(EquipementTargets::Weapons, WeaponBaseShape::Exotic) => true,
|
||||||
// You can apply weapon modifiers to shields, not the best behaviour but well
|
// (EquipementTargets::Weapons, WeaponBaseShape::Shields) => true,
|
||||||
(EquipementTargets::Weapons, WeaponBaseShape::Shields) => true,
|
|
||||||
(EquipementTargets::Armors, WeaponBaseShape::Armors) => true,
|
(EquipementTargets::Armors, WeaponBaseShape::Armors) => true,
|
||||||
(EquipementTargets::Shields, WeaponBaseShape::Shields) => true,
|
(EquipementTargets::Shields, WeaponBaseShape::Shields) => true,
|
||||||
(EquipementTargets::Ranged, WeaponBaseShape::Ranged) => true,
|
(EquipementTargets::Ranged, WeaponBaseShape::Ranged) => true,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
use super::equipement_structs::InnerEquipementStats;
|
use super::equipement_structs::InnerEquipementStats;
|
||||||
use crate::interfaces::{FilterFunction, Reportable};
|
use crate::interfaces::{FilterFunction, Reportable};
|
||||||
|
use crate::weaponry_structs::equipement_fields::WeaponBaseSize;
|
||||||
use crate::weaponry_structs::{SpecialField, WeaponBaseShape};
|
use crate::weaponry_structs::{SpecialField, WeaponBaseShape};
|
||||||
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
|
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -86,7 +87,6 @@ impl Display for InnerEquipementStats {
|
||||||
self.difficulty,
|
self.difficulty,
|
||||||
self.tier,
|
self.tier,
|
||||||
self.category_base
|
self.category_base
|
||||||
.clone()
|
|
||||||
.map_or_else(|| "ø".to_string(), |v| v.to_string()),
|
.map_or_else(|| "ø".to_string(), |v| v.to_string()),
|
||||||
self.category_size
|
self.category_size
|
||||||
.clone()
|
.clone()
|
||||||
|
|
@ -136,7 +136,7 @@ impl Display for InnerEquipementStats {
|
||||||
vec![
|
vec![
|
||||||
self.special
|
self.special
|
||||||
.iter()
|
.iter()
|
||||||
.intersperse(&",".to_string())
|
// .intersperse(&",".to_string())
|
||||||
.fold(String::new(), |res, new| format!("{}; {}", res, new)),
|
.fold(String::new(), |res, new| format!("{}; {}", res, new)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
@ -190,7 +190,7 @@ impl<T> Default for FilterFunction<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T> PartialEq for FilterFunction<T> {
|
impl<T> PartialEq for FilterFunction<T> {
|
||||||
#[coverage(off)] // INCORRECT: Error with line report
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // INCORRECT: Error with line report
|
||||||
fn eq(&self, _other: &Self) -> bool {
|
fn eq(&self, _other: &Self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -228,13 +228,38 @@ macro_rules! first_correct_option {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fixing the french grammar in the worst way possible
|
||||||
|
fn stupid_adjective_fix(name_base: &str, adj: String) -> String {
|
||||||
|
let plur = || format!("{adj}s");
|
||||||
|
let masc = || match adj.as_str() {
|
||||||
|
"moyenne" => "moyen".to_owned(),
|
||||||
|
"légère" => "léger".to_owned(),
|
||||||
|
_ => adj[..adj.len() - 1].to_string(),
|
||||||
|
};
|
||||||
|
match name_base {
|
||||||
|
"Griffes" => plur(),
|
||||||
|
"Hast" => masc(),
|
||||||
|
"Marteau" => masc(),
|
||||||
|
"Arc" => masc(),
|
||||||
|
// "Bouclier" => masc(),
|
||||||
|
_ => adj,
|
||||||
|
}
|
||||||
|
}
|
||||||
impl std::ops::Add for &InnerEquipementStats {
|
impl std::ops::Add for &InnerEquipementStats {
|
||||||
type Output = InnerEquipementStats;
|
type Output = InnerEquipementStats;
|
||||||
|
|
||||||
fn add(self, rhs: Self) -> Self::Output {
|
fn add(self, rhs: Self) -> Self::Output {
|
||||||
InnerEquipementStats {
|
InnerEquipementStats {
|
||||||
id: add_to_vec!(self.id, rhs.id),
|
id: add_to_vec!(self.id, rhs.id),
|
||||||
name: add_to_vec!(self.name, rhs.name),
|
name: add_to_vec!(
|
||||||
|
self.name,
|
||||||
|
if let Some(ad) = &rhs.adjective {
|
||||||
|
vec![stupid_adjective_fix(&self.name[0], ad.clone())]
|
||||||
|
} else {
|
||||||
|
rhs.name.clone()
|
||||||
|
}
|
||||||
|
),
|
||||||
|
adjective: rhs.adjective.clone(),
|
||||||
rarity: self.rarity + rhs.rarity,
|
rarity: self.rarity + rhs.rarity,
|
||||||
cost: self.cost + rhs.cost,
|
cost: self.cost + rhs.cost,
|
||||||
difficulty: self.difficulty + rhs.difficulty,
|
difficulty: self.difficulty + rhs.difficulty,
|
||||||
|
|
@ -285,6 +310,45 @@ impl std::ops::Add for SpecialField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InnerEquipementStats {
|
||||||
|
/// Get the maniement as a printable string
|
||||||
|
pub fn get_maniement(&self) -> String {
|
||||||
|
match &self.category_size {
|
||||||
|
Some(WeaponBaseSize::SuperHeavy) => match self.name[0].as_str() {
|
||||||
|
"Griffes" => "Frienzä",
|
||||||
|
"Marteau" => "Rhödarak",
|
||||||
|
"Épée" => "Haroth",
|
||||||
|
"Hache" => "Kahml",
|
||||||
|
"Hast" => "Paysagiste",
|
||||||
|
"Arc" => "Distance",
|
||||||
|
"Arbalète" => "Distance",
|
||||||
|
_ => "-",
|
||||||
|
}
|
||||||
|
.to_string(),
|
||||||
|
|
||||||
|
_ => match &self.category_base {
|
||||||
|
Some(WeaponBaseShape::Staves) => "Hast".to_string(),
|
||||||
|
Some(WeaponBaseShape::Blunt) => "Contondante".to_string(),
|
||||||
|
Some(WeaponBaseShape::Slash) => "Tranchante".to_string(),
|
||||||
|
Some(WeaponBaseShape::Ranged) => "Distance".to_string(),
|
||||||
|
_ => "-".to_string(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the modes as a printable string
|
||||||
|
pub fn get_modes(&self) -> String {
|
||||||
|
match &self.damage_type {
|
||||||
|
Some(t) => t
|
||||||
|
.get_best_modes()
|
||||||
|
.iter()
|
||||||
|
.map(|v| v.export())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(","),
|
||||||
|
None => "-".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ impl RecipeDatabase for EquipementDatabase {
|
||||||
&self.conn
|
&self.conn
|
||||||
}
|
}
|
||||||
|
|
||||||
#[coverage(off)] // INCORRECT: Error with line report
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // INCORRECT: Error with line report
|
||||||
fn serialize_into_intermediate<T>(
|
fn serialize_into_intermediate<T>(
|
||||||
&self,
|
&self,
|
||||||
table: &str,
|
table: &str,
|
||||||
|
|
@ -92,6 +92,7 @@ impl TryFrom<DatabaseEquipementStats> for InnerEquipementStats {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id: vec![value.id], // Special case where manual is better than serde
|
id: vec![value.id], // Special case where manual is better than serde
|
||||||
name: vec![value.name],
|
name: vec![value.name],
|
||||||
|
adjective: value.adjective,
|
||||||
rarity: value.rarity, // Generic case, into(), serde or cast are equivalent
|
rarity: value.rarity, // Generic case, into(), serde or cast are equivalent
|
||||||
cost: value.cost,
|
cost: value.cost,
|
||||||
difficulty: value.difficulty,
|
difficulty: value.difficulty,
|
||||||
|
|
@ -131,7 +132,7 @@ impl TryFrom<DatabaseEquipementStats> for InnerEquipementStats {
|
||||||
type SubCategories = (Option<WeaponBaseShape>, Option<WeaponBaseSize>);
|
type SubCategories = (Option<WeaponBaseShape>, Option<WeaponBaseSize>);
|
||||||
|
|
||||||
/// Infer all subcategories from a deserialized DatabaseCategory
|
/// Infer all subcategories from a deserialized DatabaseCategory
|
||||||
#[coverage(off)] // A test would literally be a copy paste of this match
|
#[cfg_attr(feature = "dev-analysis", coverage(off))] // A test would literally be a copy paste of this match
|
||||||
fn get_sub_categories_from_serde(category: &str) -> Result<SubCategories, FatalEquipementError> {
|
fn get_sub_categories_from_serde(category: &str) -> Result<SubCategories, FatalEquipementError> {
|
||||||
Ok(if let Some(category) = from_serde!(category)? {
|
Ok(if let Some(category) = from_serde!(category)? {
|
||||||
match category {
|
match category {
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,15 @@
|
||||||
// File: weaponry/src/weaponry_structs/equipement_impl_io.rs
|
// File: weaponry/src/weaponry_structs/equipement_impl_io.rs
|
||||||
//! All implementation IO specific (mainly export and serde)
|
//! All implementation IO specific (mainly export and serde)
|
||||||
|
|
||||||
|
use cli_parser::Config;
|
||||||
|
use handlebars::Handlebars;
|
||||||
|
|
||||||
use super::equipement_advanced_repr::RefinedEquipementList;
|
use super::equipement_advanced_repr::RefinedEquipementList;
|
||||||
use crate::interfaces::{ToCSV, ToTex};
|
use crate::{
|
||||||
|
error::FatalEquipementError,
|
||||||
|
interfaces::{ToCSV, ToTex},
|
||||||
|
weaponry_structs::equipement_advanced_repr::ExportableEquipement,
|
||||||
|
};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
impl ToCSV for RefinedEquipementList {
|
impl ToCSV for RefinedEquipementList {
|
||||||
|
|
@ -17,10 +24,24 @@ impl ToCSV for RefinedEquipementList {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToTex for RefinedEquipementList {
|
impl ToTex for RefinedEquipementList {
|
||||||
// Nom & \rotbx{Rareté} & \rotbx{Dégâts} & + & \rotbx{R.Max} & \rotbx{Armr.B} & \rotbx{Protbx} & \rotbx{Int.} & \rotbx{Deux M} & \rotbx{Une M} & \rotbx{Esq.} & \rotbx{Parr.} & \rotbx{Vitesse} & \rotbx{Discr.} & \rotbx{Catégorie} & \rotbx{Modes} & \rotbx{Spécial} \\
|
fn to_tex(&self, config: &Config) -> Result<String, FatalEquipementError> {
|
||||||
fn to_tex(&self) -> String {
|
let mut template = Handlebars::new();
|
||||||
self.inner.iter().for_each(|m| println!("{:?}", m.inner));
|
template.register_template_string("weapons", &config.weapons.template)?;
|
||||||
todo!()
|
let mut data = self
|
||||||
|
.iter()
|
||||||
|
.map(std::convert::Into::<ExportableEquipement>::into)
|
||||||
|
.collect::<Vec<ExportableEquipement>>();
|
||||||
|
|
||||||
|
for i in 0..data.len() - 1 {
|
||||||
|
if data[i].category != data[i + 1].category
|
||||||
|
// && data[i + 1].category == Some(super::WeaponBaseShape::Shields)
|
||||||
|
{
|
||||||
|
data[i].needs_break = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let r = template.render("weapons", &data)?;
|
||||||
|
// println!("{}", r);
|
||||||
|
Ok(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ impl<T> FilterFunction<T> {
|
||||||
pub struct InnerEquipementStats {
|
pub struct InnerEquipementStats {
|
||||||
pub id: Vec<u8>,
|
pub id: Vec<u8>,
|
||||||
pub name: Vec<String>,
|
pub name: Vec<String>,
|
||||||
|
pub adjective: Option<String>,
|
||||||
pub(super) rarity: i8,
|
pub(super) rarity: i8,
|
||||||
pub(super) cost: i8,
|
pub(super) cost: i8,
|
||||||
pub(super) difficulty: i8,
|
pub(super) difficulty: i8,
|
||||||
|
|
@ -130,6 +131,8 @@ pub struct DatabaseEquipementStats {
|
||||||
pub id: u8,
|
pub id: u8,
|
||||||
pub meta_category: String,
|
pub meta_category: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
#[TEXT]
|
||||||
|
pub adjective: Option<String>,
|
||||||
#[INTEGER]
|
#[INTEGER]
|
||||||
pub rarity: i8,
|
pub rarity: i8,
|
||||||
#[INTEGER]
|
#[INTEGER]
|
||||||
|
|
@ -212,6 +215,7 @@ impl Default for DatabaseEquipementStats {
|
||||||
range: 0,
|
range: 0,
|
||||||
agility_bonus: 0.,
|
agility_bonus: 0.,
|
||||||
action_cost: 0,
|
action_cost: 0,
|
||||||
|
adjective: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
# This value should be overwriten by a relative path
|
# This value should be overwriten by a relative path
|
||||||
database = "./ravenous_databases/weapons.db"
|
database = "./ravenous_databases/weapons.db"
|
||||||
|
|
||||||
|
|
||||||
[classes]
|
[classes]
|
||||||
header = '''\begin{}[
|
header = '''\begin{}[
|
||||||
presep = 0pt, postsep = 0pt,
|
presep = 0pt, postsep = 0pt,
|
||||||
|
|
@ -146,3 +145,223 @@ end_long_side = ''' \hline
|
||||||
\end{longtblr}
|
\end{longtblr}
|
||||||
\end{center}\end{landscape}'''
|
\end{center}\end{landscape}'''
|
||||||
end_empty = ""
|
end_empty = ""
|
||||||
|
|
||||||
|
[monster]
|
||||||
|
common_part = '''
|
||||||
|
{{#with data}}
|
||||||
|
\section{ {{{~name~}}} }
|
||||||
|
\begin{tblr}{
|
||||||
|
vspan=even, hspan=minimal,
|
||||||
|
colspec={X[-1] X[-1]},
|
||||||
|
cell{1}{1}={c=2}{c},
|
||||||
|
}
|
||||||
|
|
||||||
|
{{#if image}}\includegraphics[height=5cm]{ {{{~image~}}} } & \\ {{/if}}
|
||||||
|
& \\
|
||||||
|
Nom & {{{name}}} \\
|
||||||
|
{{#if denomination}}Dénomination & {{{denomination}}} \\
|
||||||
|
{{/if}}{{#if calamity}}Calamité & {{{calamity}}} \\
|
||||||
|
{{/if}}{{#if danger_level}}Niveau de danger (HSE) & {{{danger_level}}} \\
|
||||||
|
{{/if}}& \\
|
||||||
|
{{#if habitat}}Habitat & \SetCell{font=\footnotesize} {{{habitat}}} \\
|
||||||
|
{{/if}}{{#if dysmorphism}}Dysmorphisme & \SetCell{font=\footnotesize} {{{dysmorphism}}} \\
|
||||||
|
{{/if}}{{#if colors}}Couleurs & \SetCell{font=\footnotesize} {{{colors}}} \\
|
||||||
|
{{/if}}{{#if default_human_reaction}}Réaction à l'homme & \SetCell{font=\footnotesize} {{{default_human_reaction}}} \\
|
||||||
|
{{/if}}{{#if variants}}Variantes & \SetCell{font=\footnotesize} {{{variants}}}\\
|
||||||
|
{{/if}}{{#if size}}Taille & \SetCell{font=\footnotesize} {{{size}}}\\
|
||||||
|
{{/if}}{{#if traces}}Traces & \SetCell{font=\footnotesize} {{{traces}}}\\
|
||||||
|
{{/if}}{{#if habits}}Mœurs & \SetCell{font=\footnotesize} {{{habits}}} \\
|
||||||
|
{{/if}}\end{tblr}
|
||||||
|
\vfill
|
||||||
|
\begin{tblr}{
|
||||||
|
colspec={X[-1]},
|
||||||
|
hline{2,4,6},
|
||||||
|
row{2,4,6}={font=\footnotesize}
|
||||||
|
}
|
||||||
|
{{#if description}}\textbf{Description} \\
|
||||||
|
{{{description}}} \\ {{/if}}
|
||||||
|
{{#if annotations}}\textbf{Annotations} \\
|
||||||
|
{{{annotations}}} \\ {{/if}}
|
||||||
|
\textbf{Récompenses} \\
|
||||||
|
\end{tblr}
|
||||||
|
\begin{tblr}{
|
||||||
|
colspec={X[1] X[1,c] X[2,c] X[3,j]},
|
||||||
|
vspan=even, hspan=minimal,
|
||||||
|
row{1-Z}={font=\footnotesize},
|
||||||
|
rows={m},
|
||||||
|
} {{/with}}{{#with stats}}
|
||||||
|
\SetCell[c=3]{j} Sang (base, combat, dépeçage) & & & {{{blood_base}}}, {{{blood_battle}}}, {{{blood_carve}}} \\ {{/with}}{{#with rewards}}{{#each rewards}}
|
||||||
|
{{{name}}} & {{{category}}} & {{#if cost}} {{{cost}}} & {{{effect}}} {{else}} \SetCell[c=2]{j} {{{effect}}} & {{/if}} \\ {{/each}}{{/with}}
|
||||||
|
\end{tblr}
|
||||||
|
\vfill
|
||||||
|
\pagebreak
|
||||||
|
'''
|
||||||
|
master_part = '''
|
||||||
|
\begin{tblr}{
|
||||||
|
colspec={X[l,-1] X[-1] X[-1] X[] X[] X[-1] X[-1] X[] X[]},
|
||||||
|
rowspec={X[t] X[t,c] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[j,5em]},
|
||||||
|
hspan=minimal,
|
||||||
|
cell{1}{2}={c=4}{c},
|
||||||
|
cell{1}{6}={c=4}{c},
|
||||||
|
row{2,12}={font=\footnotesize},
|
||||||
|
vline{6} = {2-11}{solid},
|
||||||
|
}
|
||||||
|
& P1 & & & & P2 & \\
|
||||||
|
& Seuil & Prot & Intégrité & PV & Seuil & Prot & Intégrité & PV\\
|
||||||
|
\hline
|
||||||
|
{{#with stats as |s|}}
|
||||||
|
{{#each ../body_parts.body_parts}}
|
||||||
|
\SetCell{font=\footnotesize} {{{body_part_name}}} & ${{{threshold_p1}}} ${\tiny ({{{threshold_bonus threshold_p1 ../../stats/size_bonus_to_hit~}}}) } & ${{{plus s.strength protection_p1}}}[{{{protection_p1}}}]$ & \SetCell{r,f}\tiny ${{{integrity_p1}}} $ & \SetCell{r,f}\tiny ${{{life_points_p1}}} $ & ${{{threshold_p2}}} ${\tiny ({{{threshold_bonus threshold_p1 ../../stats/size_bonus_to_hit~}}}) } & ${{{plus s.strength protection_p1}}}[{{{protection_p1}}}]$ & \SetCell{r,f}\tiny ${{{integrity_p2}}} $ & \SetCell{r,f}\tiny ${{{life_points_p2}}} $\\
|
||||||
|
{{/each}}
|
||||||
|
{{/with}}
|
||||||
|
{{#if data.annotations_master}}
|
||||||
|
\hline
|
||||||
|
\SetCell[c=9]{j,h} {\textbf{Notes} \\ {{{data.annotations_master}}}}\\
|
||||||
|
{{/if}}
|
||||||
|
\hline
|
||||||
|
\end{tblr}
|
||||||
|
\begin{center}
|
||||||
|
\begin{tblr}{
|
||||||
|
colspec={Q[3.5em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em]},
|
||||||
|
rowspec={Q[c,f] Q[c,m] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c]},
|
||||||
|
row{3-11}={font=\tiny},
|
||||||
|
}
|
||||||
|
& & & & & & & & & & & & & \\
|
||||||
|
\SetCell{c} Res & \slash & \pierce & \blunt & \symceleste & \symfire & \symearth & \symwood & \symmagma & \symabyss & \symwater & \symwind & \symice & \symthunder \\
|
||||||
|
\hline
|
||||||
|
{{#each body_parts.body_parts}}
|
||||||
|
\SetCell{font=\footnotesize} {{{body_part_name}}} & ${{{slash}}} $ & ${{{piercing}}} $ & ${{{blunt}}} $ & ${{{celestial}}} $ & ${{{fire}}} $ & ${{{earth}}} $ & ${{{wood}}} $ & ${{{magma}}} $ & ${{{celeste}}} $ & ${{{water}}} $ & ${{{wind}}} $ & ${{{ice}}} $ & ${{{thunder}}} $ \\
|
||||||
|
{{/each}}
|
||||||
|
\end{tblr}
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
\begin{tblr}{
|
||||||
|
colspec={c c c c c c c c c c c c c c c c c c c c c c {{#if elemental_bonus}}c{{/if}}},
|
||||||
|
row{2}={font=\footnotesize},
|
||||||
|
row{3-6}={font=\tiny},
|
||||||
|
}
|
||||||
|
& \SetCell[c=2]{c} P1 & & \SetCell[c=2]{c} P2 & & & \SetCell[c=7]{c} Stats & & & & & & & & \SetCell[c=4]{c} Mouvement & & & & & Extra & \\
|
||||||
|
\cline{2-3} \cline{4-5} \cline{7-13} \cline{15-18} \cline{20-{{#if stats.elemental_bonus_dmg}}22{{else}}21{{/if}} }
|
||||||
|
\rb{Initiative} & \rb{Valeur} & \rb{Actions} & \rb{Valeur} & \rb{Actions} & & \rb{Force} & \rb{Perception} & \rb{Volonté} & \rb{Res Alt} & \rb{Torque} & \rb{Vigilance} & \rb{Fatigue} & & \rb{Marche} & \rb{Trot} & \rb{Course} & \rb{Vol} & &\rb{Res. \symtranscendental} & \rb{Bon. Phy} {{#if stats.elemental_bonus_dmg}}& \rb{Bon. Élém} {{/if}} \\
|
||||||
|
{{#each init_full}}
|
||||||
|
{{#if @index}}
|
||||||
|
\SetCell{font=\footnotesize} $i_{{(plus @index 1)}} $ & ${{{p1_value}}} $ & ${{{p1_actions}}}$ & ${{{p2_value}}} $ & ${{{p2_actions}}}$ \\
|
||||||
|
{{else}}
|
||||||
|
{{#with ../stats~}}
|
||||||
|
\SetCell{font=\footnotesize} $i_1 $ & ${{{p1_init}}} $ & ${{{p1_actions}}} $ & ${{{p2_init}}} $ & ${{{p1_actions}}} $ & & ${{{strength}}} $ & ${{{perception}}} $ & ${{{willpower}}} $ & ${{{alteration_resistance}}} $ & ${{{torque}}} $ & ${{{awareness}}} $ & ${{{fatigue}}} $ & & ${{{mvt_walk}}} $ & ${{{mvt_trot}}} $ & ${{{mvt_run}}} $ & ${{{mvt_flight}}} $ & & ${{{resistance_transcendentale}}} $ & ${{{physical_bonus_dmg}}} $ {{#if elemental_bonus_dmg}} & ${{elemental_bonus_dmg}} $ {{/if}} \\
|
||||||
|
{{/with}}
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
\end{tblr}
|
||||||
|
\vfill
|
||||||
|
|
||||||
|
{{#if (len all_attacks.phases)}}
|
||||||
|
\pagebreak
|
||||||
|
{\scriptsize
|
||||||
|
\begin{longtblr}{
|
||||||
|
colspec={X[0.05] X[2.5,l] X[1,c] X[1,c] X[0.3,c] X[0.3,c] X[0.3,c] X[0.3,c] X[0.3,c] X[2,r] X[4,l] X[0.3,c] X[0.3,c]},
|
||||||
|
hspan=minimal,
|
||||||
|
colsep=2pt,
|
||||||
|
row{2}={font=\tiny},
|
||||||
|
rowhead=2,
|
||||||
|
}
|
||||||
|
& & & & & \SetCell[c=2]{c} Coûts & & & \SetCell[c=2]{c} Dégâts & & & \SetCell[c=2]{c} Seuils & \\
|
||||||
|
\cline{6-7} \cline{9-10} \cline{12-13}
|
||||||
|
{{#each all_attacks.phases as | phase |}}
|
||||||
|
\SetHline{1}{0pt}
|
||||||
|
{{#if @first}}
|
||||||
|
& {\scriptsize\SetCell{white} \textsc{ {{{~@key~}}} }} & {Type} & {Préquis} & \rb{Ciblage} & \rb{Fatigue} & \rb{Action} & \rb{Élément} & \rb{Fatigue} & \SetCell{c} \rb{Normaux} & {Effets} & \rb{Parade} & \rb{Esquive} \\
|
||||||
|
{{else}}
|
||||||
|
\SetCell[c=13]{white} \textsc{ {{{~@key~}}} } & & & & & & & & & & \\
|
||||||
|
{{/if}}
|
||||||
|
{{#each phase as | attack_group |}}
|
||||||
|
\hline
|
||||||
|
{{#each attack_group.attacklist}}
|
||||||
|
\SetCell{bg={{{../color}}}} & {{{name}}} & {{{attack_type}}} & {{{prerequisites}}} & {{{targetting}}} & {{{cost_fatigue}}} & {{{cost_action}}} & {{{element}}} & {{{damage_fatigue}}} & {{{damage_regular}}} {{{success}}} & {{#if armor_break}} {{{armor_break}}}\arbreakk{} {{/if}}{{#if armor_pierce}} {{{armor_pierce}}}\arpierce{} {{/if}}{{#if antimaterial}} {{{antimaterial}}}\antimateriel{} {{/if}} {{{effects}}} & {{{threshold_parry}}} & {{{threshold_dodge}}} \\
|
||||||
|
{{/each}}
|
||||||
|
{{#if description_final}}\SetCell{bg={{{color}}}} & \SetCell[c=12]{j} {{{description_final}}} & & & & & & & & & & \\
|
||||||
|
{{/if}} \hline
|
||||||
|
{{/each}}
|
||||||
|
{{/each}}
|
||||||
|
\end{longtblr}
|
||||||
|
}
|
||||||
|
\vfill
|
||||||
|
{{/if}}
|
||||||
|
{{#with data}}
|
||||||
|
\pagebreak
|
||||||
|
\begin{tblr}{
|
||||||
|
colspec={X[7] {{#if intent_graph}}|X[3] {{/if~}} },
|
||||||
|
rowspec={X[c] X[j,h,8cm]},
|
||||||
|
hline{2},
|
||||||
|
row{2}={font=\footnotesize},
|
||||||
|
}
|
||||||
|
Plan de combat {{#if intent_graph}}& Graphique d'intentions{{/if}} \\
|
||||||
|
{{{battle_plan}}} {{#if intent_graph}}& {{{intent_graph}}}{{/if}} \\
|
||||||
|
\end{tblr}
|
||||||
|
\vfill
|
||||||
|
\pagebreak
|
||||||
|
{{/with}}
|
||||||
|
'''
|
||||||
|
color_table='''
|
||||||
|
ATK: ravred
|
||||||
|
MVT: ravblu
|
||||||
|
DEF: ravgrn
|
||||||
|
PAS: ravgrnL
|
||||||
|
REV: ravgrn
|
||||||
|
CLM: ravgrnD
|
||||||
|
TRA: ravora
|
||||||
|
ASE: ravred
|
||||||
|
STA: ravwhi
|
||||||
|
CMB: ravred
|
||||||
|
FLR: ravred
|
||||||
|
GRB: ravred
|
||||||
|
TBU: ravredD
|
||||||
|
TSH: ravredD
|
||||||
|
TBZ: ravredD
|
||||||
|
CLV: ravred
|
||||||
|
AOE: ravred
|
||||||
|
WID: ravred
|
||||||
|
WIP: ravredD
|
||||||
|
SZO: ravwhi
|
||||||
|
SIT: ravwhi
|
||||||
|
SRG: ravpur
|
||||||
|
HRG: ravpur
|
||||||
|
BAD: ravora
|
||||||
|
BIS: ravredD
|
||||||
|
BYP: ravredD
|
||||||
|
'''
|
||||||
|
default_color=''
|
||||||
|
|
||||||
|
|
||||||
|
[weapons]
|
||||||
|
template='''
|
||||||
|
\begin{landscape}\begin{center}
|
||||||
|
\begin{longtblr}[
|
||||||
|
entry = none,
|
||||||
|
label = none,
|
||||||
|
]{
|
||||||
|
colspec = {|QQQQQQQQQQQQQQQQQ|},
|
||||||
|
cells = {font = \footnotesize\selectfont},
|
||||||
|
row{1} = {bg=cobluel, fg=white},
|
||||||
|
row{even} = {coblueL},
|
||||||
|
hspan = minimal, vspan=minimal,
|
||||||
|
colsep = 2mm, abovesep=0px,belowsep=0px, leftsep=3px, rightsep=3px,
|
||||||
|
rowhead = 1,
|
||||||
|
}
|
||||||
|
\hline
|
||||||
|
{Forme} & {Maniement} & {\damagew} & + & {R.Max} & \arbreakk & \protection & \integrite & $\mathbb{T}$2 & $\mathbb{T}$1 & {Modes} & {Esq.} & {Par.} & {Vit.} & {Disc.} & {Spécial} & {\aLvl} & {\aCst} \\
|
||||||
|
\hline
|
||||||
|
{{#each this}}
|
||||||
|
{{name}} & {{maniement}} & {{damage_base}} & {{damage_per}} & {{rmax}} & {{arbreak}} & {{protection}} & {{integrity}} & {{torque_two_handed}} & {{torque_one_handed}} & $\mathbf{ {{{~modes~}}} }$ & {{esquive}} & {{parrade}} & {{vitesse}} & {{discretion}} & {{{special}}} & \ddlvl{ {{~difficulty~}} } & \ddlvl{ {{~cost~}} } \\
|
||||||
|
{{#if needs_break}}
|
||||||
|
\hline
|
||||||
|
\hline
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
\hline
|
||||||
|
\end{longtblr}
|
||||||
|
\end{center}
|
||||||
|
\end{landscape}
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Nom & \rotbx{Rareté} & \rotbx{Dégâts} & + & \rotbx{R.Max} & \rotbx{Armr.B} & \rotbx{Protbx} & \rotbx{Int.} & \rotbx{Deux M} & \rotbx{Une M} & \rotbx{Esq.} & \rotbx{Parr.} & \rotbx{Vitesse} & \rotbx{Discr.} & \rotbx{Catégorie} & \rotbx{Modes} & \rotbx{Spécial} \\
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit ee3b7ffd5fa4e3bfbcd13cb5d69b9c0e3e9b06e5
|
Subproject commit c5af8a89ccb47b4a4bd57412a13bec90809fc61a
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly"
|
channel = "stable"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue