|
|
@ -2,7 +2,7 @@ use elseware::common::serverstate::{ClientId, ServerState}; |
|
|
|
use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
|
|
|
|
use elseware::entity::item;
|
|
|
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket};
|
|
|
|
use elseware::ship::items::{ClientItemId, ActiveItemEntityId, HeldItemType, FloorItemType};
|
|
|
|
use elseware::ship::items::{ClientItemId};
|
|
|
|
|
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use libpso::packet::messages::*;
|
|
|
@ -79,11 +79,21 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
assert!(p1_inventory.count() == 1);
|
|
|
|
let inventory_item = p1_inventory.slot(0).unwrap();
|
|
|
|
assert!(inventory_item.entity_id == ActiveItemEntityId::Stacked(vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5), item::ItemEntityId(6)]));
|
|
|
|
assert!(inventory_item.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 6));
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 6);
|
|
|
|
|
|
|
|
let p1_item_ids = p1_items.iter().map(|item| {
|
|
|
|
item.id
|
|
|
|
}).collect::<Vec<_>>();
|
|
|
|
assert!(p1_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5), item::ItemEntityId(6)]);
|
|
|
|
|
|
|
|
let all_items_are_monomates = p1_items.iter().all(|item| {
|
|
|
|
match item.item {
|
|
|
|
item::ItemDetail::Tool(tool) => tool.tool == item::tool::ToolType::Monomate,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert!(all_items_are_monomates);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -136,19 +146,22 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
assert!(p1_inventory.count() == 1);
|
|
|
|
let inventory_item = p1_inventory.slot(0).unwrap();
|
|
|
|
assert!(inventory_item.entity_id == ActiveItemEntityId::Stacked(vec![item::ItemEntityId(1)]));
|
|
|
|
assert!(inventory_item.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 1));
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 1);
|
|
|
|
|
|
|
|
let first_item = p1_items.get(0).unwrap();
|
|
|
|
assert!(first_item.id == item::ItemEntityId(1));
|
|
|
|
assert!(first_item.item == item::ItemDetail::Tool(item::tool::Tool {
|
|
|
|
tool: item::tool::ToolType::Monomate,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_pick_up_meseta_when_inventory_full() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
for slot in 0..30 {
|
|
|
|
entity_gateway.create_item(
|
|
|
@ -207,13 +220,15 @@ async fn test_pick_up_meseta_when_inventory_full() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
assert!(p1_inventory.count() == 30);
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 30);
|
|
|
|
|
|
|
|
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
|
|
|
let c2 = ship.clients.get(&ClientId(2)).unwrap();
|
|
|
|
assert!(c1.character.meseta == 23);
|
|
|
|
assert!(c2.character.meseta == 277);
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
let characters2 = entity_gateway.get_characters_by_user(&user2).await;
|
|
|
|
let c2 = characters2.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
assert!(c1.meseta == 23);
|
|
|
|
assert!(c2.meseta == 277);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -299,11 +314,17 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
assert!(p1_inventory.count() == 30);
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 31);
|
|
|
|
|
|
|
|
let monomates = p1_inventory.slot(29).unwrap();
|
|
|
|
assert!(monomates.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 2));
|
|
|
|
let monomate1 = p1_items.get(29).unwrap();
|
|
|
|
assert!(monomate1.item == item::ItemDetail::Tool(item::tool::Tool {
|
|
|
|
tool: item::tool::ToolType::Monomate,
|
|
|
|
}));
|
|
|
|
let monomate2 = p1_items.get(30).unwrap();
|
|
|
|
assert!(monomate2.item == item::ItemDetail::Tool(item::tool::Tool {
|
|
|
|
tool: item::tool::ToolType::Monomate,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -380,17 +401,29 @@ async fn test_can_not_pick_up_item_when_inventory_full() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
assert!(p1_inventory.count() == 30);
|
|
|
|
let floor_item = ship.item_manager.get_floor_item_by_id(&char1, ClientItemId(0x210000)).unwrap();
|
|
|
|
assert!(floor_item.item_id == ClientItemId(0x210000));
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 30);
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2).await;
|
|
|
|
assert!(p2_items.len() == 0);
|
|
|
|
|
|
|
|
ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x210000,
|
|
|
|
area: 0,
|
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2).await;
|
|
|
|
assert!(p2_items.len() == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_can_not_drop_more_meseta_than_is_held() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
char1.meseta = 300;
|
|
|
|
entity_gateway.save_character(&char1).await;
|
|
|
@ -419,9 +452,9 @@ async fn test_can_not_drop_more_meseta_than_is_held() { |
|
|
|
})))).await;
|
|
|
|
assert!(split_attempt.is_err());
|
|
|
|
|
|
|
|
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
|
|
|
assert!(c1.character.meseta == 300);
|
|
|
|
assert!(ship.item_manager.get_floor_item_by_id(&char1, ClientItemId(0xF0000001)).is_err())
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
assert!(c1.meseta == 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -483,27 +516,28 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { |
|
|
|
z: 0.0,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x210000,
|
|
|
|
area: 0,
|
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert!(packets.len() == 0);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
let monomates = p1_inventory.slot(0).unwrap();
|
|
|
|
assert!(monomates.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 6));
|
|
|
|
let floor_monomates = ship.item_manager.get_floor_item_by_id(&char1, ClientItemId(0x210000)).unwrap();
|
|
|
|
assert!(floor_monomates.item == FloorItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 6));
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 6);
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2).await;
|
|
|
|
assert!(p2_items.len() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_can_not_pick_up_meseta_when_full() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
char1.meseta = 999999;
|
|
|
|
entity_gateway.save_character(&char1).await;
|
|
|
@ -536,29 +570,30 @@ async fn test_can_not_pick_up_meseta_when_full() { |
|
|
|
amount: 23,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0xF0000001,
|
|
|
|
area: 0,
|
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
|
|
|
let c2 = ship.clients.get(&ClientId(2)).unwrap();
|
|
|
|
assert!(c1.character.meseta == 999999);
|
|
|
|
assert!(c2.character.meseta == 277);
|
|
|
|
|
|
|
|
let floor_meseta = ship.item_manager.get_floor_item_by_id(&char1, ClientItemId(0xF0000001)).unwrap();
|
|
|
|
assert!(floor_meseta.item == FloorItemType::Meseta(item::Meseta(23)));
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
println!("pkts {:?}", packets);
|
|
|
|
assert!(packets.len() == 0);
|
|
|
|
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
let characters2 = entity_gateway.get_characters_by_user(&user2).await;
|
|
|
|
let c2 = characters2.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
assert!(c1.meseta == 999999);
|
|
|
|
assert!(c2.meseta == 277);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
char1.meseta = 999998;
|
|
|
|
entity_gateway.save_character(&char1).await;
|
|
|
@ -599,13 +634,12 @@ async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1 = ship.clients.get(&ClientId(1)).unwrap();
|
|
|
|
let c2 = ship.clients.get(&ClientId(2)).unwrap();
|
|
|
|
assert!(c1.character.meseta == 999999);
|
|
|
|
assert!(c2.character.meseta == 277);
|
|
|
|
|
|
|
|
let floor_meseta = ship.item_manager.get_floor_item_by_id(&char1, ClientItemId(0xF0000001));
|
|
|
|
assert!(floor_meseta.is_err());
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
let characters2 = entity_gateway.get_characters_by_user(&user2).await;
|
|
|
|
let c2 = characters2.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
|
assert!(c1.meseta == 999999);
|
|
|
|
assert!(c2.meseta == 277);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -665,13 +699,35 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { |
|
|
|
unknown: [0; 3]
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let p1_inventory = ship.item_manager.get_character_inventory(&char1).unwrap();
|
|
|
|
assert!(p1_inventory.count() == 1);
|
|
|
|
let inventory_item = p1_inventory.slot(0).unwrap();
|
|
|
|
assert!(inventory_item.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 3));
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
assert!(p1_items.len() == 3);
|
|
|
|
|
|
|
|
let p1_item_ids = p1_items.iter().map(|item| {
|
|
|
|
item.id
|
|
|
|
}).collect::<Vec<_>>();
|
|
|
|
assert!(p1_item_ids == vec![item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5)]);
|
|
|
|
|
|
|
|
let all_items_are_monomates = p1_items.iter().all(|item| {
|
|
|
|
match item.item {
|
|
|
|
item::ItemDetail::Tool(tool) => tool.tool == item::tool::ToolType::Monomate,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert!(all_items_are_monomates);
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2).await;
|
|
|
|
assert!(p2_items.len() == 2);
|
|
|
|
|
|
|
|
let p2_inventory = ship.item_manager.get_character_inventory(&char2).unwrap();
|
|
|
|
assert!(p2_inventory.count() == 1);
|
|
|
|
let inventory_item = p2_inventory.slot(0).unwrap();
|
|
|
|
assert!(inventory_item.item == HeldItemType::Stacked(item::tool::Tool {tool: item::tool::ToolType::Monomate}, 2));
|
|
|
|
let p2_item_ids = p2_items.iter().map(|item| {
|
|
|
|
item.id
|
|
|
|
}).collect::<Vec<_>>();
|
|
|
|
assert!(p2_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
|
|
|
|
|
|
|
|
let all_items_are_monomates = p1_items.iter().all(|item| {
|
|
|
|
match item.item {
|
|
|
|
item::ItemDetail::Tool(tool) => tool.tool == item::tool::ToolType::Monomate,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert!(all_items_are_monomates);
|
|
|
|
}
|