|
|
@@ -1,3 +1,89 @@ |
|
|
|
use rand::{ distributions:: {Distribution, Standard}, |
|
|
|
Rng |
|
|
|
}; |
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
enum Cls { |
|
|
|
Artificer, |
|
|
|
Barbarian, |
|
|
|
Bard, |
|
|
|
Cleric, |
|
|
|
Druid, |
|
|
|
Fighter, |
|
|
|
Monk, |
|
|
|
Paladin, |
|
|
|
Ranger, |
|
|
|
Rogue, |
|
|
|
Sorcerer, |
|
|
|
Warlock, |
|
|
|
Wizard |
|
|
|
} |
|
|
|
|
|
|
|
impl Default for Cls { |
|
|
|
fn default() -> Self { Cls::Fighter } |
|
|
|
} |
|
|
|
|
|
|
|
impl Distribution<Cls> for Standard { |
|
|
|
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cls { |
|
|
|
match rng.gen_range(0..=12) { |
|
|
|
0 => Cls::Artificer, |
|
|
|
1 => Cls::Barbarian, |
|
|
|
2 => Cls::Bard, |
|
|
|
3 => Cls::Cleric, |
|
|
|
4 => Cls::Druid, |
|
|
|
5 => Cls::Fighter, |
|
|
|
6 => Cls::Monk, |
|
|
|
7 => Cls::Paladin, |
|
|
|
8 => Cls::Ranger, |
|
|
|
9 => Cls::Rogue, |
|
|
|
10 => Cls::Sorcerer, |
|
|
|
11 => Cls::Warlock, |
|
|
|
12 => Cls::Wizard, |
|
|
|
_ => Cls::Fighter |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Debug, Default)] |
|
|
|
struct Character { |
|
|
|
cls: Cls, |
|
|
|
strength: u32, |
|
|
|
dexterity: u32, |
|
|
|
constitution: u32, |
|
|
|
intelligence: u32, |
|
|
|
wisdom: u32, |
|
|
|
charisma: u32, |
|
|
|
} |
|
|
|
|
|
|
|
// impl Character { |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
fn roll_stat() -> u32 { |
|
|
|
let mut rolls = Vec::new(); |
|
|
|
while rolls.len()<4 { |
|
|
|
let roll = rand::thread_rng().gen_range(1..=6); |
|
|
|
if roll == 1 { |
|
|
|
continue; |
|
|
|
} |
|
|
|
rolls.push(roll); |
|
|
|
} |
|
|
|
println!("{:?}", rolls); |
|
|
|
rolls.sort_by(|a,b| b.cmp(a)); |
|
|
|
println!("{:?}", rolls); |
|
|
|
rolls.pop(); |
|
|
|
println!("{:?}", rolls); |
|
|
|
rolls.iter().sum() |
|
|
|
} |
|
|
|
|
|
|
|
fn main() { |
|
|
|
println!("Hello, world!"); |
|
|
|
let mut chr: Character = Default::default(); |
|
|
|
chr.cls = rand::random(); |
|
|
|
chr.strength = roll_stat(); |
|
|
|
chr.dexterity = roll_stat(); |
|
|
|
chr.constitution = roll_stat(); |
|
|
|
chr.intelligence = roll_stat(); |
|
|
|
chr.wisdom = roll_stat(); |
|
|
|
chr.charisma = roll_stat(); |
|
|
|
println!("{:?}", chr); |
|
|
|
} |