From eb23cc2dfd17ee43fb5c32851c73048b67156496 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 19 May 2022 22:22:54 -0600 Subject: [PATCH] fix item pickup tests --- src/ship/items/actions.rs | 3 ++- src/ship/items/state.rs | 20 +++++++++----------- tests/test_item_pickup.rs | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ship/items/actions.rs b/src/ship/items/actions.rs index 85e8f34..51e644c 100644 --- a/src/ship/items/actions.rs +++ b/src/ship/items/actions.rs @@ -63,6 +63,7 @@ fn add_floor_item_to_inventory(character: &CharacterEntity) let add_result = inventory.add_floor_item(floor_item)?; transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; + transaction.gateway().set_character_meseta(&character_id, inventory.meseta).await?; item_state.set_inventory(inventory); Ok(((item_state, transaction), @@ -158,7 +159,7 @@ where entity_gateway.with_transaction(|transaction| async move { let item_state_proxy = ItemStateProxy::new(item_state); let ((item_state_proxy, transaction), result) = ItemStateAction::default() - .act(take_item_from_inventory(character.id, *item_id, 1)) + .act(take_item_from_inventory(character.id, *item_id, 0)) .act(add_inventory_item_to_shared_floor(character.id, map_area, drop_position)) .commit((item_state_proxy, transaction)) .await?; diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index 0284b2a..92f7a44 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -358,7 +358,7 @@ impl BankItem { } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum FloorItemDetail { Individual(IndividualItemDetail), Stacked(StackedItemDetail), @@ -374,7 +374,7 @@ impl FloorItemDetail { } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct FloorItem { pub item_id: ClientItemId, pub item: FloorItemDetail, @@ -465,12 +465,10 @@ pub enum AddItemResult { Meseta, } -#[derive(Clone, Default)] +#[derive(Debug, Clone, Default)] pub struct LocalFloor(Vec); -#[derive(Clone, Default)] +#[derive(Debug, Clone, Default)] pub struct SharedFloor(Vec); -#[derive(Clone)] -pub struct RoomFloorItems(Vec); #[derive(Clone)] pub struct InventoryState { @@ -549,7 +547,7 @@ impl InventoryState { Err(InventoryError::MesetaFull) } else { - self.meseta.0 = std::cmp::min(self.meseta.0 + meseta.0 ,999999); + self.meseta.0 = std::cmp::min(self.meseta.0 + meseta.0, 999999); Ok(AddItemResult::Meseta) } }, @@ -607,7 +605,7 @@ impl InventoryState { Some(self.inventory.0.remove(idx)) }, InventoryItemDetail::Stacked(stacked_item) => { - let remove_all = match stacked_item.entity_ids.len().cmp(&(amount as usize)) { + let remove_all = (amount == 0) || match stacked_item.entity_ids.len().cmp(&(amount as usize)) { Ordering::Equal => true, Ordering::Greater => false, Ordering::Less => return None, @@ -708,7 +706,6 @@ impl InventoryState { match (a_index, b_index) { (Some(a_index), Some(b_index)) => { - dbg!("sort!", a.item_id, a_index, b.item_id, b_index); a_index.cmp(&b_index) }, _ => Ordering::Equal @@ -1025,6 +1022,7 @@ impl std::cmp::Ord for BankItem { } } +#[derive(Debug)] pub struct FloorState { character_id: CharacterEntityId, local: LocalFloor, @@ -1123,7 +1121,7 @@ impl ItemState { Ok(match item { InventoryItemEntity::Individual(item) => { InventoryItem { - item_id: self.new_item_id()?, + item_id: ClientItemId(0), item: InventoryItemDetail::Individual(IndividualItemDetail { entity_id: item.id, item: item.item, @@ -1132,7 +1130,7 @@ impl ItemState { }, InventoryItemEntity::Stacked(items) => { InventoryItem { - item_id: self.new_item_id()?, + item_id: ClientItemId(0), item: InventoryItemDetail::Stacked(StackedItemDetail { entity_ids: items.iter().map(|i| i.id).collect(), tool: items.get(0) diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index 9520527..b2d2ce3 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -734,7 +734,7 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem { client: 0, target: 0, - item_id: 0x00810001, + item_id: 0x10003, map_area: 0, unknown: [0; 3] })))).await.unwrap().for_each(drop);