rocalc 0.3.0

一款用于计算洛克王国:世界精灵对决的Rust库
Documentation
/// 简单公式(Simple formula)所需的攻击力、防御值和技能威力
#[derive(Debug)]
pub struct Sfor {
    pub atk: f32,
    pub dfe: f32,
    pub pow: f32,
}

impl Sfor {
    /// 简易公式计算伤害
    pub fn simple_dmg(&self) -> f32 {
        let dmg = (37.0 * self.atk * self.pow / 41.0).round() / self.dfe;
        return dmg;
    }
}

/// 复杂公式(Complex formula)
#[derive(Debug)]
pub struct Cfor {
    pub atk: f32, // 攻击力
    pub dfe: f32, // 防御力
    pub pow: f32, // 技能威力
    pub deal: f32, // 应对倍率(技能效果)
    pub pow_appd: f32, // 技能威力附加(技能效果)
    pub atk_buff: f32, // 攻击加成
    pub dfe_buff: f32, // 防御加成
    pub pow_buff: f32, // 技能威力加成
    pub prop: f32, // 本系加成,若有取1.25
    pub count: f32, // 克制加成,若有取2.0或3.0 
    pub reduce: f32, // 减伤
}

impl Cfor {
    /// 创建复杂公式,输入攻击值、防御值和技能威力,剩余值为默认
    pub fn new(atk: f32, dfe:f32, pow:f32) -> Self {
        Self {
            atk,
            dfe,
            pow,
            deal: 1.0,
            pow_appd: 0.0,
            atk_buff: 1.0,
            dfe_buff: 1.0,
            pow_buff: 1.0,
            prop: 1.0,
            count: 1.0,
            reduce: 0.0,
        }
    }

    /// 计算伤害
    pub fn cal(&self) -> f32 {
        (37.0 * (self.atk * self.atk_buff) * (self.pow * self.deal + self.pow_appd) * self.pow_buff * self.prop * self.count * (1.0 - self.reduce)).round() / 41.0 / (self.dfe * self.dfe_buff)
    }

}