diff --git a/src/main.rs b/src/main.rs index d0eb075..5071065 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use rand::prelude::*; + pub enum StandardSkills { Acrobatics, AnimalHandling, @@ -78,11 +80,133 @@ pub trait Skill { fn is_save(&self) -> bool; } -// pub trait SkillSet { -// fn get_skill() { +pub struct DieRoll { + sides: u8, + count: u8 +} -// } -// } +pub struct RollCalculation { + rolls: Vec, + modifier: i8 +} + +pub struct RollResult { + total: i32, + 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::() % 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 + } + } +} + +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; + 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 { + levels: u8, + // reset to 0 on long rest + expended_hit_die: u8, + // historical, each should be immutable. + hit_die_history: Vec +} + +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 { + 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() + }); + } +} impl Stat for u8 { fn score(&self) -> u8 {