diff --git a/src/main.rs b/src/main.rs index e7a11a9..32dcc56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,78 @@ -fn main() { - println!("Hello, world!"); +pub trait Stat { + fn score(&self) -> u8; + + fn modifier(&self) -> i8 { + return (self.score() as i8 / 2) - 5; + } + + fn skill(&self, proficiency: u8, proficient : bool, expert : bool) -> i8 { + let modifier : i8 = self.modifier(); + let proficiency_boost : u8 = proficiency * proficient as u8; + let expertise_boost : u8 = proficiency * 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; +} + +impl Stat for u8 { + fn score(&self) -> u8 { + return *self; + } +} + +struct Player { + strength_score: u8, + dexterity_score: u8, + constitution_score: u8, + intelligence_score: u8, + wisdom_score: u8, + charisma_score: u8 +} + +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; + } +} + + +fn main() { + let demo : Player = Player { + strength_score: 12, + dexterity_score: 20, + constitution_score: 15, + intelligence_score: 10, + wisdom_score: 5, + charisma_score: 1 + }; + + 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()); }