1mod levels;
2use std::time::Duration;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct DoctorLevelDB {
7 exp: Vec<usize>,
9 ap: Vec<usize>,
11}
12
13impl DoctorLevelDB {
14 pub fn cost(&self, from: usize, to: usize) -> Result<usize, String> {
16 if to < from {
17 return Err(format!("目标等级 `{}` 小于起始等级 `{}`", to, from));
18 }
19 Ok(self.exp.iter().skip(from - 1).take(to - from).cloned().sum())
20 }
21 pub fn action_points_max(&self, level: usize) -> usize {
23 self.ap[level.saturating_sub(1)]
24 }
25 pub fn action_point_regen_time(&self, level: usize, current: usize) -> Duration {
27 let rest = self.action_points_max(level).saturating_sub(current);
28 let time = rest * Self::ACTION_POINT_REGEN * 60;
29 Duration::from_secs(time as u64)
30 }
31}