Browse Source

sort items packets and dont equip multiple items in main it's confusing

pbs
andy 4 years ago
committed by andy
parent
commit
45d9b82598
  1. 4
      src/bin/main.rs
  2. 34
      src/ship/items/manager.rs
  3. 20
      src/ship/packet/handler/message.rs
  4. 4
      src/ship/ship.rs

4
src/bin/main.rs

@ -185,7 +185,7 @@ fn main() {
location: ItemLocation::Inventory {
character_id: character.id,
slot: 3,
equipped: true,
equipped: false,
}
}).await.unwrap();
entity_gateway.create_item(
@ -205,7 +205,7 @@ fn main() {
location: ItemLocation::Inventory {
character_id: character.id,
slot: 4,
equipped: true,
equipped: false,
}
}).await.unwrap();

34
src/ship/items/manager.rs

@ -979,4 +979,38 @@ impl ItemManager {
}).await;
Ok(())
}
pub async fn player_sorts_items<EG: EntityGateway>(&mut self,
entity_gateway: &mut EG,
character: &CharacterEntity,
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();
for (slot, item) in sorted_inventory_items {
match item.unwrap() {
InventoryItem::Individual(i) => {
entity_gateway.change_item_location(&i.entity_id, ItemLocation::Inventory {
character_id: character.id,
slot: slot,
equipped: i.equipped,
}).await
},
InventoryItem::Stacked(s) => {
for entity_id in s.entity_ids.iter() {
entity_gateway.change_item_location(&entity_id, ItemLocation::Inventory {
character_id: character.id,
slot: slot,
equipped: false,
}).await
}
},
};
}
Ok(())
}
}

20
src/ship/packet/handler/message.rs

@ -6,7 +6,7 @@ use crate::common::serverstate::ClientId;
use crate::common::leveltable::CharacterLevelTable;
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
use crate::ship::location::{ClientLocation, ClientLocationError};
use crate::ship::items::{ItemManager, ClientItemId};
use crate::ship::items::{ItemManager, ClientItemId, InventoryItem};
use crate::ship::packet::builder;
pub async fn request_exp<EG: EntityGateway>(id: ClientId,
@ -356,3 +356,21 @@ where
Ok(Box::new(None.into_iter()))
}
pub async fn player_sorts_items<EG>(id: ClientId,
pkt: &SortItems,
entity_gateway: &mut EG,
client_location: &ClientLocation,
clients: &Clients,
item_manager: &mut ItemManager)
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError>
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?
}

4
src/ship/ship.rs

@ -400,7 +400,9 @@ impl<EG: EntityGateway> ShipServerState<EG> {
GameMessage::PlayerUnequipItem(player_unequip_item) => {
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
},
_ => {
let cmsg = msg.clone();
Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()

Loading…
Cancel
Save