mod levels;
use std::time::Duration;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DoctorLevelDB {
exp: Vec<usize>,
ap: Vec<usize>,
}
impl DoctorLevelDB {
pub fn cost(&self, from: usize, to: usize) -> Result<usize, String> {
if to < from {
return Err(format!("目标等级 `{}` 小于起始等级 `{}`", to, from));
}
Ok(self.exp.iter().skip(from - 1).take(to - from).cloned().sum())
}
pub fn action_points_max(&self, level: usize) -> usize {
self.ap[level.saturating_sub(1)]
}
pub fn action_point_regen_time(&self, level: usize, current: usize) -> Duration {
let rest = self.action_points_max(level).saturating_sub(current);
let time = rest * Self::ACTION_POINT_REGEN * 60;
Duration::from_secs(time as u64)
}
}