ravenous-tools/crates/monsters/src/monster_structs.rs

401 lines
11 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! # 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};
/// A monster ready for consumption by other modules.
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,
/// Collection of attacks, wrapped in a helper that exposes useful functions.
pub attacks: CreatureListAttacks,
/// 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,
}
/// One row from the `creature` table.
#[derive(Debug, Clone, PartialEq, Eq, 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
#[INTEGER]
pub danger_level: i64,
/// 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
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.
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.
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>,
/// 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>,
}
#[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>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)]
/// All creature stats
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 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,
}
// ----------- 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)]
pub struct MonsterAllAttacks {
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,
}