|
@ -10,6 +10,80 @@ use libpso::packet::messages::*; |
|
|
mod common;
|
|
|
mod common;
|
|
|
use common::*;
|
|
|
use common::*;
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_pick_up_individual_item() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Handgun,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::<item::InventoryItemEntity>::new())).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
|
|
|
.gateway(entity_gateway.clone())
|
|
|
|
|
|
.build());
|
|
|
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
join_lobby(&mut ship, ClientId(1)).await;
|
|
|
|
|
|
join_lobby(&mut ship, ClientId(2)).await;
|
|
|
|
|
|
|
|
|
|
|
|
create_room(&mut ship, ClientId(1), "room", "").await;
|
|
|
|
|
|
join_room(&mut ship, ClientId(2), 0).await;
|
|
|
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown1: 0,
|
|
|
|
|
|
map_area: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
x: 0.0,
|
|
|
|
|
|
y: 0.0,
|
|
|
|
|
|
z: 0.0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 0);
|
|
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
map_area: 0,
|
|
|
|
|
|
unknown: [0; 3]
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 0);
|
|
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p2_items.items.len(), 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
#[async_std::test]
|
|
|
async fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
|
|
async fn test_pick_up_item_stack_of_items_already_in_inventory() {
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|