| use rand::{ distributions:: {Distribution, Standard}, Rng }; | use rand::{ distributions:: {Distribution, Standard}, Rng }; | ||||
| use std::fmt::Debug; | |||||
| //use dict::{ Dict, DictIface }; | //use dict::{ Dict, DictIface }; | ||||
| //use std::collections::HashMap; | //use std::collections::HashMap; | ||||
| #[derive(Debug)] | |||||
| const DBG_LVL: u32 = 0; | |||||
| fn dbg_print(msg: &impl Debug, lvl: u32) { | |||||
| if lvl <= DBG_LVL { | |||||
| println!("{:?}", msg); | |||||
| } | |||||
| } | |||||
| #[derive(Debug, Copy, Clone)] | |||||
| enum Cls { | enum Cls { | ||||
| Artificer = 0, | Artificer = 0, | ||||
| Barbarian, | Barbarian, | ||||
| } | } | ||||
| } | } | ||||
| #[derive(Debug, Default)] | |||||
| #[derive(Debug, Default, Copy, Clone)] | |||||
| struct Character { | struct Character { | ||||
| class: Cls, | class: Cls, | ||||
| strength: u32, | strength: u32, | ||||
| } | } | ||||
| fn gen_stats(&mut self) { | fn gen_stats(&mut self) { | ||||
| let associated_stats = vec!( | let associated_stats = vec!( | ||||
| [3,1,2,5,4,0], | |||||
| [0,2,1,5,4,3], | |||||
| [5,1,3,4,2,0], | |||||
| [4,2,0,3,5,1], | |||||
| [4,2,3,1,0,5], | |||||
| [0,2,1,3,4,5], | |||||
| [1,4,2,0,3,5], | |||||
| [0,5,2,4,1,3], | |||||
| [1,4,0,2,3,5], | |||||
| [1,3,5,2,0,4], | |||||
| [5,2,3,4,1,0], | |||||
| [5,2,3,4,1,0], | |||||
| [3,4,2,5,1,0] | |||||
| [0,4,3,5,1,2], // Artificer | |||||
| [5,3,4,0,1,2], // Barbarian | |||||
| [0,4,1,3,2,5], // Bard | |||||
| [3,0,4,2,5,1], // Cleric | |||||
| [1,2,4,3,5,0], // Druid | |||||
| [5,3,4,2,1,0], // Fighter | |||||
| [2,5,3,1,4,0], // Monk | |||||
| [5,1,3,0,2,4], // Paladin | |||||
| [3,5,2,1,4,0], // Ranger | |||||
| [1,5,2,4,0,3], // Rogue | |||||
| [0,1,4,3,2,5], // Sorcerer | |||||
| [0,1,4,3,2,5], // Warlock | |||||
| [0,1,3,5,4,2] // Wizard | |||||
| ); | ); | ||||
| let cls = self.class as u32; | let cls = self.class as u32; | ||||
| println!("{:?}", associated_stats[cls]); | |||||
| // println!("{:?}", associated_stats); | |||||
| self.strength = roll_stat(); | |||||
| self.dexterity = roll_stat(); | |||||
| self.constitution = roll_stat(); | |||||
| self.intelligence = roll_stat(); | |||||
| self.wisdom = roll_stat(); | |||||
| self.charisma = roll_stat(); | |||||
| let statblock = associated_stats[cls as usize]; | |||||
| dbg_print(&statblock, 2); | |||||
| let mut rolled_stats = Vec::new(); | |||||
| while rolled_stats.len() < 6 { | |||||
| rolled_stats.push(roll_stat()); | |||||
| } | |||||
| dbg_print(&rolled_stats, 2); | |||||
| rolled_stats.sort(); | |||||
| dbg_print(&rolled_stats, 2); | |||||
| self.strength = rolled_stats[statblock[0]]; | |||||
| self.dexterity = rolled_stats[statblock[1]]; | |||||
| self.constitution = rolled_stats[statblock[2]]; | |||||
| self.intelligence = rolled_stats[statblock[3]]; | |||||
| self.wisdom = rolled_stats[statblock[4]]; | |||||
| self.charisma = rolled_stats[statblock[5]]; | |||||
| } | } | ||||
| } | } | ||||
| fn roll_stat() -> u32 { | fn roll_stat() -> u32 { | ||||
| let mut rolls = Vec::new(); | let mut rolls = Vec::new(); | ||||
| while rolls.len()<4 { | while rolls.len()<4 { | ||||
| let roll = rand::thread_rng().gen_range(1..=6); | |||||
| let mut roll = rand::thread_rng().gen_range(1..=6); | |||||
| if roll == 1 { | if roll == 1 { | ||||
| continue; | |||||
| roll = rand::thread_rng().gen_range(1..=6); | |||||
| } | } | ||||
| rolls.push(roll); | rolls.push(roll); | ||||
| } | } |