Skip to content

modify message notification to player #62

@fidaperkasa

Description

@fidaperkasa

modifiying notification to player to give some information regarding weapon cost airplane cost

also is possible to add the msg for player like this :

fn compute_flight_cost(&self, sifo: &SlotInfo, unit: &Unit) -> Result<(u32, bool, String)> {
    use std::fmt::Write;
    let mut m = String::from("");
    match self.ephemeral.cfg.points.as_ref() {
        None => Ok((0, false, m)),
        Some(points) => {
            // Airframe cost
            let airframe_cost = *points.airframe_cost.get(&sifo.typ).unwrap_or(&0);
            let mut total_cost = airframe_cost;
            let mut weapon_details = String::new();
            let mut total_weapon_cost = 0;

            // Calculate weapon/ammo cost
            if !points.weapon_cost.is_empty() {
                for ammo in unit.get_ammo().context("getting ammo")? {
                    let ammo = ammo.context("unwrapping ammo")?;
                    let typ = ammo.type_name().context("getting ammo type name")?;
                    info!("ammo of type {typ} loaded");

                    if let Some(unit_cost) = points.weapon_cost.get(&typ) {
                        let n = ammo.count().context("getting ammo count")?;
                        let wcost = n * (*unit_cost);
                        total_weapon_cost += wcost;
                        
                        write!(weapon_details, "\n- {typ}: {wcost}").unwrap();
                    }
                }
                total_cost += total_weapon_cost;
            }
            
            // Build formatted message
            write!(m, "Aircraft ({}): {}\n", sifo.typ, airframe_cost).unwrap();
            write!(m, "Weapons total: {}", total_weapon_cost).unwrap();
            if !weapon_details.is_empty() {
                write!(m, "{}", weapon_details).unwrap();
            }
            write!(m, "\n\nTotal cost: {}", total_cost).unwrap();
            
            Ok((total_cost, points.strict, m))
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions