2026-03-21 23:57:44 -05:00
|
|
|
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 }
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 03:12:58 -05:00
|
|
|
pub trait Stat {
|
|
|
|
|
fn score(&self) -> u8;
|
|
|
|
|
|
|
|
|
|
fn modifier(&self) -> i8 {
|
|
|
|
|
return (self.score() as i8 / 2) - 5;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-21 23:57:44 -05:00
|
|
|
fn skill_modifier(&self, proficiency_modifier: u8, proficiency: SkillProficiency) -> i8 {
|
2026-03-20 03:12:58 -05:00
|
|
|
let modifier : i8 = self.modifier();
|
2026-03-21 23:57:44 -05:00
|
|
|
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;
|
2026-03-20 03:12:58 -05:00
|
|
|
return modifier + (proficiency_boost as i8) + (expertise_boost as i8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait StatSet {
|
2026-03-21 23:57:44 -05:00
|
|
|
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;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-21 23:57:44 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub trait SkillSet {
|
|
|
|
|
// fn get_skill() {
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2026-03-20 03:12:58 -05:00
|
|
|
impl Stat for u8 {
|
|
|
|
|
fn score(&self) -> u8 {
|
|
|
|
|
return *self;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-21 23:57:44 -05:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Player {
|
2026-03-20 03:12:58 -05:00
|
|
|
strength_score: u8,
|
|
|
|
|
dexterity_score: u8,
|
|
|
|
|
constitution_score: u8,
|
|
|
|
|
intelligence_score: u8,
|
|
|
|
|
wisdom_score: u8,
|
2026-03-21 23:57:44 -05:00
|
|
|
charisma_score: u8,
|
|
|
|
|
level: u8,
|
|
|
|
|
|
|
|
|
|
// saves
|
|
|
|
|
dexterity_save_proficiency: SkillProficiency,
|
|
|
|
|
strength_save_proficiency: SkillProficiency,
|
|
|
|
|
constitution_save_proficiency: SkillProficiency,
|
|
|
|
|
intelligence_save_proficiency: SkillProficiency,
|
|
|
|
|
wisdom_save_proficiency: SkillProficiency,
|
|
|
|
|
charisma_save_proficiency: SkillProficiency,
|
|
|
|
|
|
|
|
|
|
// skills
|
|
|
|
|
// dexterity: Acrobatics, SleightOfHand, Stealth
|
|
|
|
|
acrobatics_proficiency: SkillProficiency,
|
|
|
|
|
sleight_of_hand_proficiency: SkillProficiency,
|
|
|
|
|
stealth_proficiency: SkillProficiency,
|
|
|
|
|
// strength: Athletics
|
|
|
|
|
athletics_proficiency: SkillProficiency,
|
|
|
|
|
// constitution: none
|
|
|
|
|
// intelligence: Arcana, History, Investigation, Nature, Religion
|
|
|
|
|
arcana_proficiency: SkillProficiency,
|
|
|
|
|
history_proficiency: SkillProficiency,
|
|
|
|
|
investigation_proficiency: SkillProficiency,
|
|
|
|
|
nature_proficiency: SkillProficiency,
|
|
|
|
|
religion_proficiency: SkillProficiency,
|
|
|
|
|
// wisdom: Animal Handling, Insight, Medicine, Perception, Survival
|
|
|
|
|
animal_handling_proficiency: SkillProficiency,
|
|
|
|
|
insight_proficiency: SkillProficiency,
|
|
|
|
|
medicine_proficiency: SkillProficiency,
|
|
|
|
|
perception_proficiency: SkillProficiency,
|
|
|
|
|
survival_proficiency: SkillProficiency,
|
|
|
|
|
// charisma: Deception, Intimidation, Performance, Persuasion
|
|
|
|
|
deception_proficiency: SkillProficiency,
|
|
|
|
|
intimidation_proficiency: SkillProficiency,
|
|
|
|
|
performance_proficiency: SkillProficiency,
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl StatSet for Player {
|
2026-03-21 23:57:44 -05:00
|
|
|
fn strength(&self) -> &impl Stat {
|
|
|
|
|
return &self.strength_score;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
2026-03-21 23:57:44 -05:00
|
|
|
fn dexterity(&self) -> &impl Stat {
|
|
|
|
|
return &self.dexterity_score;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
2026-03-21 23:57:44 -05:00
|
|
|
fn constitution(&self) -> &impl Stat {
|
|
|
|
|
return &self.constitution_score;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
2026-03-21 23:57:44 -05:00
|
|
|
fn intelligence(&self) -> &impl Stat {
|
|
|
|
|
return &self.intelligence_score;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
2026-03-21 23:57:44 -05:00
|
|
|
fn wisdom(&self) -> &impl Stat {
|
|
|
|
|
return &self.wisdom_score;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
2026-03-21 23:57:44 -05:00
|
|
|
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;
|
2026-03-20 03:12:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-03-20 02:33:29 -05:00
|
|
|
fn main() {
|
2026-03-20 03:12:58 -05:00
|
|
|
let demo : Player = Player {
|
|
|
|
|
strength_score: 12,
|
|
|
|
|
dexterity_score: 20,
|
|
|
|
|
constitution_score: 15,
|
|
|
|
|
intelligence_score: 10,
|
|
|
|
|
wisdom_score: 5,
|
2026-03-21 23:57:44 -05:00
|
|
|
charisma_score: 1,
|
|
|
|
|
stealth_proficiency: SkillProficiency::Expert,
|
|
|
|
|
..Default::default()
|
2026-03-20 03:12:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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());
|
2026-03-21 23:57:44 -05:00
|
|
|
|
|
|
|
|
println!("Stealth Modifier: {}", StandardSkills::Stealth.get_modifier(&demo, demo.get_proficiency(StandardSkills::Stealth), demo.get_proficiency_modifier()));
|
2026-03-20 02:33:29 -05:00
|
|
|
}
|