Compare commits
7 Commits
rc-ac80022
...
rc-9e1d511
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e1d51175b | ||
|
|
ae6e46f147 | ||
|
|
a3f2b91119 | ||
|
|
7e41aecd56 | ||
|
|
d37c4fdb4b | ||
|
|
a00fd7e526 | ||
| 7e374bfb8b |
@@ -3,7 +3,7 @@ on: [push]
|
||||
name: Continuous Releases
|
||||
|
||||
env:
|
||||
TARGET_PLATFORM: x86_64-pc-windows-gnu
|
||||
TARGET_PLATFORM_WINDOWS: x86_64-pc-windows-gnu
|
||||
APT_PACKAGES: mingw-w64
|
||||
|
||||
jobs:
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- run: echo "/root/.cargo/bin" >> $GITHUB_PATH
|
||||
- run: cargo build --release --target "${{ env.TARGET_PLATFORM }}"
|
||||
- run: cargo build --release --target "${{ env.TARGET_PLATFORM_WINDOWS }}"
|
||||
- uses: https://gitea.com/actions/gitea-release-action@main
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
|
||||
404
Cargo.lock
generated
404
Cargo.lock
generated
@@ -2,6 +2,410 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.102"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dndcli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"rand_core",
|
||||
"wasip2",
|
||||
"wasip3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.16.1",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "leb128fmt"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.183"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8"
|
||||
dependencies = [
|
||||
"chacha20",
|
||||
"getrandom",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.2+wasi-0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasip3"
|
||||
version = "0.4.0+wasi-0.3.0-rc-2026-01-06"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
|
||||
dependencies = [
|
||||
"leb128fmt",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"hashbrown 0.15.5",
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
|
||||
dependencies = [
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"prettyplease",
|
||||
"syn",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
|
||||
@@ -4,3 +4,4 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.10.0"
|
||||
|
||||
89
src/classes.rs
Normal file
89
src/classes.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use crate::dice::{DieRoll, RollResult, RollCalculation, Rollable};
|
||||
|
||||
pub trait ShortRestRecovery {
|
||||
fn on_short_rest(&mut self);
|
||||
}
|
||||
|
||||
pub trait LongRestRecovery {
|
||||
fn on_long_rest(&mut self);
|
||||
}
|
||||
|
||||
pub trait LevelAndHitDieManagement {
|
||||
fn get_hit_die() -> u8;
|
||||
|
||||
fn max_hit_die(&self) -> DieRoll {
|
||||
return DieRoll {
|
||||
sides: Self::get_hit_die(),
|
||||
count: self.get_total_levels()
|
||||
}
|
||||
}
|
||||
|
||||
fn expended_hit_die(&self) -> u8;
|
||||
fn get_total_levels(&self) -> u8;
|
||||
fn single_hit_die(&self) -> DieRoll {
|
||||
return DieRoll {
|
||||
sides: Self::get_hit_die(),
|
||||
count: 1
|
||||
}
|
||||
}
|
||||
fn available_hit_die(&self) -> DieRoll {
|
||||
let max = self.max_hit_die();
|
||||
let expended = self.expended_hit_die();
|
||||
return DieRoll {
|
||||
sides: max.sides,
|
||||
count: max.count - expended
|
||||
}
|
||||
}
|
||||
fn get_historical_hit_die(&self) -> &Vec<RollResult>;
|
||||
fn get_total_hp(&self) -> i32 {
|
||||
let mut max_hp = 0;
|
||||
let historical_hp_rolls = self.get_historical_hit_die();
|
||||
for roll in historical_hp_rolls {
|
||||
max_hp += roll.total;
|
||||
}
|
||||
return max_hp;
|
||||
}
|
||||
|
||||
fn level_up(&mut self);
|
||||
}
|
||||
|
||||
pub struct UniversalClass {
|
||||
pub levels: u8,
|
||||
// reset to 0 on long rest
|
||||
pub expended_hit_die: u8,
|
||||
// historical, each should be immutable.
|
||||
pub hit_die_history: Vec<RollResult>
|
||||
}
|
||||
|
||||
impl LongRestRecovery for UniversalClass {
|
||||
fn on_long_rest(&mut self) {
|
||||
self.expended_hit_die = 0;
|
||||
}
|
||||
}
|
||||
|
||||
impl LevelAndHitDieManagement for UniversalClass {
|
||||
fn get_hit_die() -> u8 {
|
||||
return 6;
|
||||
}
|
||||
|
||||
fn get_total_levels(&self) -> u8 {
|
||||
return self.levels;
|
||||
}
|
||||
|
||||
fn expended_hit_die(&self) -> u8 {
|
||||
return self.expended_hit_die;
|
||||
}
|
||||
|
||||
fn get_historical_hit_die(&self) -> &Vec<RollResult> {
|
||||
return &self.hit_die_history;
|
||||
}
|
||||
|
||||
fn level_up(&mut self) {
|
||||
self.levels += 1;
|
||||
let new_hit_die = self.single_hit_die();
|
||||
self.hit_die_history.push(RollResult {
|
||||
total: new_hit_die.roll(),
|
||||
calculation: new_hit_die.calculation()
|
||||
});
|
||||
}
|
||||
}
|
||||
41
src/dice.rs
Normal file
41
src/dice.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use rand::prelude::*;
|
||||
|
||||
pub struct DieRoll {
|
||||
pub sides: u8,
|
||||
pub count: u8
|
||||
}
|
||||
|
||||
pub struct RollCalculation {
|
||||
pub rolls: Vec<DieRoll>,
|
||||
pub modifier: i8
|
||||
}
|
||||
|
||||
pub struct RollResult {
|
||||
pub total: i32,
|
||||
pub calculation: RollCalculation
|
||||
}
|
||||
|
||||
pub trait Rollable {
|
||||
fn calculation(&self) -> RollCalculation;
|
||||
|
||||
fn roll(&self) -> i32 {
|
||||
let calculation = self.calculation();
|
||||
let mut total : i32 = calculation.modifier as i32;
|
||||
let mut _rng = rand::rng();
|
||||
for die in calculation.rolls {
|
||||
for _ in 0..die.count {
|
||||
total += (rand::random::<u8>() % die.sides + 1) as i32;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
impl Rollable for DieRoll {
|
||||
fn calculation(&self) -> RollCalculation {
|
||||
return RollCalculation {
|
||||
rolls: vec![DieRoll { sides: self.sides, count: self.count }],
|
||||
modifier: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/main.rs
28
src/main.rs
@@ -1,3 +1,29 @@
|
||||
mod dice;
|
||||
mod stats_skills;
|
||||
mod player;
|
||||
mod classes;
|
||||
|
||||
use stats_skills::{StandardSkills, SkillProficiency, Skill, ProficiencySet, StatSet, Stat};
|
||||
use player::Player;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let demo : Player = Player {
|
||||
strength_score: 12,
|
||||
dexterity_score: 20,
|
||||
constitution_score: 15,
|
||||
intelligence_score: 10,
|
||||
wisdom_score: 5,
|
||||
charisma_score: 1,
|
||||
stealth_proficiency: SkillProficiency::Expert,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
println!("STR Modifier: {}", demo.strength().modifier());
|
||||
println!("DEX Modifier: {}", demo.dexterity().modifier());
|
||||
println!("CON Modifier: {}", demo.constitution().modifier());
|
||||
println!("INT Modifier: {}", demo.intelligence().modifier());
|
||||
println!("WIS Modifier: {}", demo.wisdom().modifier());
|
||||
println!("CHA Modifier: {}", demo.charisma().modifier());
|
||||
|
||||
println!("Stealth Modifier: {}", StandardSkills::Stealth.get_modifier(&demo, demo.get_proficiency(StandardSkills::Stealth), demo.get_proficiency_modifier()));
|
||||
}
|
||||
|
||||
146
src/player.rs
Normal file
146
src/player.rs
Normal file
@@ -0,0 +1,146 @@
|
||||
use crate::stats_skills::{Stat, StatSet, ProficiencySet, SkillProficiency, StandardSkills};
|
||||
|
||||
pub struct Player {
|
||||
pub strength_score: u8,
|
||||
pub dexterity_score: u8,
|
||||
pub constitution_score: u8,
|
||||
pub intelligence_score: u8,
|
||||
pub wisdom_score: u8,
|
||||
pub charisma_score: u8,
|
||||
pub level: u8,
|
||||
|
||||
// saves
|
||||
pub dexterity_save_proficiency: SkillProficiency,
|
||||
pub strength_save_proficiency: SkillProficiency,
|
||||
pub constitution_save_proficiency: SkillProficiency,
|
||||
pub intelligence_save_proficiency: SkillProficiency,
|
||||
pub wisdom_save_proficiency: SkillProficiency,
|
||||
pub charisma_save_proficiency: SkillProficiency,
|
||||
|
||||
// skills
|
||||
// dexterity: Acrobatics, SleightOfHand, Stealth
|
||||
pub acrobatics_proficiency: SkillProficiency,
|
||||
pub sleight_of_hand_proficiency: SkillProficiency,
|
||||
pub stealth_proficiency: SkillProficiency,
|
||||
// strength: Athletics
|
||||
pub athletics_proficiency: SkillProficiency,
|
||||
// constitution: none
|
||||
// intelligence: Arcana, History, Investigation, Nature, Religion
|
||||
pub arcana_proficiency: SkillProficiency,
|
||||
pub history_proficiency: SkillProficiency,
|
||||
pub investigation_proficiency: SkillProficiency,
|
||||
pub nature_proficiency: SkillProficiency,
|
||||
pub religion_proficiency: SkillProficiency,
|
||||
// wisdom: Animal Handling, Insight, Medicine, Perception, Survival
|
||||
pub animal_handling_proficiency: SkillProficiency,
|
||||
pub insight_proficiency: SkillProficiency,
|
||||
pub medicine_proficiency: SkillProficiency,
|
||||
pub perception_proficiency: SkillProficiency,
|
||||
pub survival_proficiency: SkillProficiency,
|
||||
// charisma: Deception, Intimidation, Performance, Persuasion
|
||||
pub deception_proficiency: SkillProficiency,
|
||||
pub intimidation_proficiency: SkillProficiency,
|
||||
pub performance_proficiency: SkillProficiency,
|
||||
pub persuasion_proficiency: SkillProficiency
|
||||
}
|
||||
|
||||
impl Default for Player {
|
||||
fn default() -> Self {
|
||||
return Player {
|
||||
strength_score: 10,
|
||||
dexterity_score: 10,
|
||||
constitution_score: 10,
|
||||
intelligence_score: 10,
|
||||
wisdom_score: 10,
|
||||
charisma_score: 10,
|
||||
|
||||
level: 1,
|
||||
|
||||
dexterity_save_proficiency: SkillProficiency::None,
|
||||
strength_save_proficiency: SkillProficiency::None,
|
||||
constitution_save_proficiency: SkillProficiency::None,
|
||||
intelligence_save_proficiency: SkillProficiency::None,
|
||||
wisdom_save_proficiency: SkillProficiency::None,
|
||||
charisma_save_proficiency: SkillProficiency::None,
|
||||
|
||||
acrobatics_proficiency: SkillProficiency::None,
|
||||
sleight_of_hand_proficiency: SkillProficiency::None,
|
||||
stealth_proficiency: SkillProficiency::None,
|
||||
|
||||
athletics_proficiency: SkillProficiency::None,
|
||||
|
||||
arcana_proficiency: SkillProficiency::None,
|
||||
history_proficiency: SkillProficiency::None,
|
||||
investigation_proficiency: SkillProficiency::None,
|
||||
nature_proficiency: SkillProficiency::None,
|
||||
religion_proficiency: SkillProficiency::None,
|
||||
|
||||
animal_handling_proficiency: SkillProficiency::None,
|
||||
insight_proficiency: SkillProficiency::None,
|
||||
medicine_proficiency: SkillProficiency::None,
|
||||
perception_proficiency: SkillProficiency::None,
|
||||
survival_proficiency: SkillProficiency::None,
|
||||
|
||||
deception_proficiency: SkillProficiency::None,
|
||||
intimidation_proficiency: SkillProficiency::None,
|
||||
performance_proficiency: SkillProficiency::None,
|
||||
persuasion_proficiency: SkillProficiency::None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StatSet for Player {
|
||||
fn strength(&self) -> &impl Stat {
|
||||
return &self.strength_score;
|
||||
}
|
||||
fn dexterity(&self) -> &impl Stat {
|
||||
return &self.dexterity_score;
|
||||
}
|
||||
fn constitution(&self) -> &impl Stat {
|
||||
return &self.constitution_score;
|
||||
}
|
||||
fn intelligence(&self) -> &impl Stat {
|
||||
return &self.intelligence_score;
|
||||
}
|
||||
fn wisdom(&self) -> &impl Stat {
|
||||
return &self.wisdom_score;
|
||||
}
|
||||
fn charisma(&self) -> &impl Stat {
|
||||
return &self.charisma_score;
|
||||
}
|
||||
}
|
||||
|
||||
impl ProficiencySet for Player {
|
||||
fn get_proficiency(&self, skill: StandardSkills) -> SkillProficiency {
|
||||
match skill {
|
||||
StandardSkills::DexteritySave => self.dexterity_save_proficiency,
|
||||
StandardSkills::StrengthSave => self.strength_save_proficiency,
|
||||
StandardSkills::ConstitutionSave => self.constitution_save_proficiency,
|
||||
StandardSkills::IntelligenceSave => self.intelligence_save_proficiency,
|
||||
StandardSkills::WisdomSave => self.wisdom_save_proficiency,
|
||||
StandardSkills::CharismaSave => self.charisma_save_proficiency,
|
||||
StandardSkills::Acrobatics => self.acrobatics_proficiency,
|
||||
StandardSkills::SleightOfHand => self.sleight_of_hand_proficiency,
|
||||
StandardSkills::Stealth => self.stealth_proficiency,
|
||||
StandardSkills::Athletics => self.athletics_proficiency,
|
||||
StandardSkills::Arcana => self.arcana_proficiency,
|
||||
StandardSkills::History => self.history_proficiency,
|
||||
StandardSkills::Investigation => self.investigation_proficiency,
|
||||
StandardSkills::Nature => self.nature_proficiency,
|
||||
StandardSkills::Religion => self.religion_proficiency,
|
||||
StandardSkills::AnimalHandling => self.animal_handling_proficiency,
|
||||
StandardSkills::Insight => self.insight_proficiency,
|
||||
StandardSkills::Medicine => self.medicine_proficiency,
|
||||
StandardSkills::Perception => self.perception_proficiency,
|
||||
StandardSkills::Survival => self.survival_proficiency,
|
||||
StandardSkills::Deception => self.deception_proficiency,
|
||||
StandardSkills::Intimidation => self.intimidation_proficiency,
|
||||
StandardSkills::Performance => self.performance_proficiency,
|
||||
StandardSkills::Persuasion => self.persuasion_proficiency
|
||||
}
|
||||
}
|
||||
|
||||
fn get_proficiency_modifier(&self) -> u8 {
|
||||
return ((self.level - 1) / 4) + 2;
|
||||
}
|
||||
}
|
||||
102
src/stats_skills.rs
Normal file
102
src/stats_skills.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
pub enum StandardSkills {
|
||||
Acrobatics,
|
||||
AnimalHandling,
|
||||
Arcana,
|
||||
Athletics,
|
||||
Deception,
|
||||
History,
|
||||
Insight,
|
||||
Intimidation,
|
||||
Investigation,
|
||||
Medicine,
|
||||
Nature,
|
||||
Perception,
|
||||
Performance,
|
||||
Persuasion,
|
||||
Religion,
|
||||
SleightOfHand,
|
||||
Stealth,
|
||||
Survival,
|
||||
StrengthSave,
|
||||
DexteritySave,
|
||||
ConstitutionSave,
|
||||
IntelligenceSave,
|
||||
WisdomSave,
|
||||
CharismaSave
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum SkillProficiency {
|
||||
None,
|
||||
Proficient,
|
||||
Expert,
|
||||
}
|
||||
|
||||
impl Default for SkillProficiency {
|
||||
fn default() -> Self { SkillProficiency::None }
|
||||
}
|
||||
|
||||
pub trait Stat {
|
||||
fn score(&self) -> u8;
|
||||
|
||||
fn modifier(&self) -> i8 {
|
||||
return (self.score() as i8 / 2) - 5;
|
||||
}
|
||||
|
||||
fn skill_modifier(&self, proficiency_modifier: u8, proficiency: SkillProficiency) -> i8 {
|
||||
let modifier : i8 = self.modifier();
|
||||
let expert = proficiency == SkillProficiency::Expert; // are they an expert?
|
||||
let proficient = expert || proficiency == SkillProficiency::Proficient; // are they at least proficient?
|
||||
let proficiency_boost : u8 = proficiency_modifier * proficient as u8;
|
||||
let expertise_boost : u8 = proficiency_modifier * expert as u8;
|
||||
return modifier + (proficiency_boost as i8) + (expertise_boost as i8);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait StatSet {
|
||||
fn strength(&self) -> &impl Stat;
|
||||
fn dexterity(&self) -> &impl Stat;
|
||||
fn constitution(&self) -> &impl Stat;
|
||||
fn intelligence(&self) -> &impl Stat;
|
||||
fn wisdom(&self) -> &impl Stat;
|
||||
fn charisma(&self) -> &impl Stat;
|
||||
}
|
||||
|
||||
pub trait ProficiencySet {
|
||||
fn get_proficiency(&self, skill: StandardSkills) -> SkillProficiency;
|
||||
|
||||
fn get_proficiency_modifier(&self) -> u8;
|
||||
}
|
||||
|
||||
pub trait Skill {
|
||||
fn select_stat<'a>(&self, set: &'a impl StatSet) -> &'a dyn Stat;
|
||||
|
||||
fn get_modifier(&self, set: &impl StatSet, proficiency: SkillProficiency, proficiency_modifier: u8) -> i8 {
|
||||
return self.select_stat(set).skill_modifier(proficiency_modifier, proficiency);
|
||||
}
|
||||
|
||||
fn is_save(&self) -> bool;
|
||||
}
|
||||
|
||||
impl Skill for StandardSkills {
|
||||
fn select_stat<'a>(&self, set: &'a impl StatSet) -> &'a dyn Stat {
|
||||
match self {
|
||||
StandardSkills::DexteritySave | StandardSkills::Acrobatics | StandardSkills::SleightOfHand | StandardSkills::Stealth => set.dexterity(),
|
||||
StandardSkills::StrengthSave | StandardSkills::Athletics => set.strength(),
|
||||
StandardSkills::ConstitutionSave => set.constitution(),
|
||||
StandardSkills::IntelligenceSave | StandardSkills::Arcana | StandardSkills::History | StandardSkills::Investigation | StandardSkills::Nature | StandardSkills::Religion => set.intelligence(),
|
||||
StandardSkills::WisdomSave | StandardSkills::AnimalHandling | StandardSkills::Insight | StandardSkills::Medicine | StandardSkills::Perception | StandardSkills::Survival => set.wisdom(),
|
||||
StandardSkills::CharismaSave | StandardSkills::Deception | StandardSkills::Intimidation | StandardSkills::Performance | StandardSkills::Persuasion => set.charisma(),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_save(&self) -> bool {
|
||||
return matches!(self, StandardSkills::StrengthSave | StandardSkills::DexteritySave | StandardSkills::ConstitutionSave | StandardSkills::IntelligenceSave | StandardSkills::WisdomSave | StandardSkills::CharismaSave);
|
||||
}
|
||||
}
|
||||
|
||||
impl Stat for u8 {
|
||||
fn score(&self) -> u8 {
|
||||
return *self;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user