Fix overflow in PickupItem::amount and set persistence stack_size to i64

This commit is contained in:
crabman 2024-05-22 22:14:12 +00:00
parent 9264c10289
commit 7dd2072ced
No known key found for this signature in database
3 changed files with 9 additions and 3 deletions

View File

@ -1585,7 +1585,12 @@ impl PickupItem {
pub fn next_merge_check_mut(&mut self) -> &mut ProgramTime { &mut self.next_merge_check }
// Get the total amount of items in here
pub fn amount(&self) -> u32 { self.items.iter().map(Item::amount).sum() }
pub fn amount(&self) -> u32 {
self.items
.iter()
.map(Item::amount)
.fold(0, |total, amount| total.saturating_add(amount))
}
/// Remove any debug items if this is a container, used before dropping an
/// item from an inventory

View File

@ -187,7 +187,7 @@ pub fn convert_items_to_database_items(
parent_container_item_id,
item_id,
stack_size: if item.is_stackable() {
item.amount() as i32
item.amount().into()
} else {
1
},

View File

@ -11,7 +11,8 @@ pub struct Item {
pub item_id: i64,
pub parent_container_item_id: i64,
pub item_definition_id: String,
pub stack_size: i32,
/// `u32::MAX` must fit inside this type
pub stack_size: i64,
pub position: String,
pub properties: String,
}