use crate::{ db::DBTrans, DResult, }; pub enum CapacityLevel { Unburdened, SlightlyBurdened, HeavilyBurdened, OverBurdened, AboveItemLimit, } pub async fn check_item_capacity(trans: &DBTrans, container: &str, proposed_weight: u64) -> DResult { let stats = trans.get_location_stats( container ).await?; if stats.total_count >= 50 || proposed_weight > 0 && stats.total_count >= 49 { return Ok(CapacityLevel::AboveItemLimit); } if let Some((item_type, _item_code)) = container.split_once("/") { if item_type == "player" || item_type == "npc" { let max_weight = 20000; // TODO Calculate properly let new_weight = stats.total_weight + proposed_weight; if new_weight >= max_weight { return Ok(CapacityLevel::OverBurdened); } else if new_weight >= max_weight * 4 / 5 { return Ok(CapacityLevel::HeavilyBurdened); } else if new_weight >= max_weight / 2 { return Ok(CapacityLevel::SlightlyBurdened); } } } Ok(CapacityLevel::Unburdened) }