diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index 5e5bd0c..084dd19 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -986,13 +986,17 @@ impl ItemManager { item_ids: [u32; 30]) -> Result<(), ItemManagerError> { let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let sorted_inventory_items: Vec<(usize, Option<&InventoryItem>)> = item_ids.iter() - .enumerate() - .filter(|(slot, &client_item_id)| client_item_id < 0xFFFFFFFF) - .map(|(slot, &client_item_id)| (slot, inventory.get_item_by_id(ClientItemId(client_item_id)))) - .collect(); + + let sorted_inventory_items: Vec<(usize, &InventoryItem)> = item_ids.iter() + .filter(|&client_item_id| *client_item_id < 0xFFFFFFFF) + .enumerate() + .map(|(slot, &client_item_id)| (slot, inventory.get_item_by_id(ClientItemId(client_item_id)).unwrap())) + .collect(); + println!("sorted_inventory_items: {:?}", sorted_inventory_items); + + // wait how is this different than update_inventory_slots() ??? for (slot, item) in sorted_inventory_items { - match item.unwrap() { + match item { InventoryItem::Individual(i) => { entity_gateway.change_item_location(&i.entity_id, ItemLocation::Inventory { character_id: character.id, @@ -1011,6 +1015,16 @@ impl ItemManager { }, }; } + + /* + let sorted_inventory_items: Vec = item_ids.iter() + .filter(|&client_item_id| *client_item_id < 0xFFFFFFFF) + .map(|&client_item_id| inventory.get_item_by_id(ClientItemId(client_item_id)).cloned().unwrap()) + .collect(); + + let sorted_inventory = CharacterInventory::new(sorted_inventory_items); + update_inventory_slots(entity_gateway, character, &sorted_inventory).await; + */ Ok(()) } } diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 489c3a5..c1efe6b 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -360,7 +360,6 @@ where pub async fn player_sorts_items(id: ClientId, pkt: &SortItems, entity_gateway: &mut EG, - client_location: &ClientLocation, clients: &Clients, item_manager: &mut ItemManager) -> Result + Send>, ShipError> @@ -368,9 +367,6 @@ where EG: EntityGateway { let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; - let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?; - let clients_in_area = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?; item_manager.player_sorts_items(entity_gateway, &client.character, pkt.item_ids).await?; - let sort_packet = pkt.clone(); Ok(Box::new(None.into_iter())) // Do clients care about the order of other clients items? -} +} \ No newline at end of file diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 53357a1..610b1be 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -401,7 +401,7 @@ impl ShipServerState { handler::message::player_unequips_item(id, &player_unequip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await }, GameMessage::SortItems(sort_items) => { - handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await + handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await }, _ => { let cmsg = msg.clone(); diff --git a/tests/common.rs b/tests/common.rs index 7e7c925..6c8d24b 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -80,3 +80,10 @@ pub async fn join_room(ship: &mut ShipServerState, id: Cl item: room_id, })).await.unwrap().for_each(drop); } + +pub async fn change_lobby(ship: &mut ShipServerState, id: ClientId, lobby: u32) { + ship.handle(id, &RecvShipPacket::LobbySelect(LobbySelect{ + menu: LOBBY_MENU_ID, + lobby: lobby, + })).await.unwrap().for_each(drop); +} \ No newline at end of file diff --git a/tests/test_item_equip.rs b/tests/test_item_equip.rs index b948684..1e22d2d 100644 --- a/tests/test_item_equip.rs +++ b/tests/test_item_equip.rs @@ -277,6 +277,13 @@ async fn test_sort_items() { join_lobby(&mut ship, ClientId(1)).await; create_room(&mut ship, ClientId(1), "room", "").await; + let old_items = entity_gateway.get_items_by_character(&char1).await; + assert!(old_items[0].location == item::ItemLocation::Inventory{ + character_id: char1.id, + slot: 0, + equipped: true, + }); + ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::SortItems(SortItems { client: 255, target: 255, @@ -286,5 +293,10 @@ async fn test_sort_items() { })))).await.unwrap().for_each(drop); let items = entity_gateway.get_items_by_character(&char1).await; - assert!(items[2].item.item_type() == item::ItemType::Armor(item::armor::ArmorType::Frame)); + assert!(items[0].item.item_type() == item::ItemType::Armor(item::armor::ArmorType::Frame)); + assert!(items[0].location == item::ItemLocation::Inventory{ + character_id: char1.id, + slot: 2, + equipped: true, + }); } \ No newline at end of file