arknights/doctor/
mod.rs

1mod levels;
2use std::time::Duration;
3
4/// 博士升级需要的所有数据
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct DoctorLevelDB {
7    /// 经验表
8    exp: Vec<usize>,
9    /// 理智表
10    ap: Vec<usize>,
11}
12
13impl DoctorLevelDB {
14    /// 升级需要的经验值
15    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    /// 给出对应等级的理智上线
22    pub fn action_points_max(&self, level: usize) -> usize {
23        self.ap[level.saturating_sub(1)]
24    }
25    /// 理智回满需要的时间(秒)
26    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}