You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use crate::{character::Character, dice::successes};
|
|
|
|
#[derive(Debug,PartialEq, Eq, Clone, Copy)]
|
|
pub enum EncounterType {
|
|
Physical,
|
|
Mental,
|
|
}
|
|
|
|
impl Character {
|
|
pub fn attacks(&mut self, opponent: &mut Character) {
|
|
let (margin, _succ, _fail, _succ_dice, fail_dice) = successes(
|
|
self.dice_pool().max(0) as usize,
|
|
(opponent.ac() - self.weapon_proficiency() as i64).clamp(1, 12),
|
|
);
|
|
|
|
let damage = self.compute_damage(margin);//(margin + self.weapon_proficiency()).max(0) * self.weapon.damage_dice;
|
|
|
|
opponent.hp = opponent.hp - damage as i64;
|
|
|
|
self.adjust_dice_pool((-fail_dice).min(0), EncounterType::Physical);
|
|
|
|
// println!(
|
|
// "{} attacks {} getting a margin of {} (s: {}, f: {}) and dealing {} damage.",
|
|
// self.name, opponent.name, margin, succ, fail, damage
|
|
// )
|
|
}
|
|
}
|
|
|
|
pub fn make_them_fight(character1: &mut Character, character2: &mut Character) -> Option<i64> {
|
|
character1.init_encounter(EncounterType::Physical);
|
|
character2.init_encounter(EncounterType::Physical);
|
|
|
|
let mut turn = 0;
|
|
|
|
loop {
|
|
turn += 1;
|
|
character1.attacks(character2);
|
|
if character2.hp <= 0 {
|
|
break;
|
|
}
|
|
|
|
character2.attacks(character1);
|
|
if character1.hp <= 0 {
|
|
break;
|
|
}
|
|
|
|
if turn > 15 {
|
|
return None
|
|
}
|
|
}
|
|
|
|
Some(turn)
|
|
}
|