|
@ -17,7 +17,8 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { |
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
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 (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p1_monomate = Vec::new();
|
|
|
|
|
|
p1_monomate.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -26,14 +27,14 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
let mut p2_items = Vec::new();
|
|
|
for (slot, tool) in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter().enumerate() {
|
|
|
for (slot, tool) in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter().enumerate() {
|
|
|
for _ in 0..5 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut item = Vec::new();
|
|
|
|
|
|
for _ in 0..5usize {
|
|
|
|
|
|
item.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -42,16 +43,18 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char2.id,
|
|
|
character_id: char2.id,
|
|
|
slot: slot,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
p2_items.push(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![p1_monomate])).await.unwrap();
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_items)).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -80,21 +83,13 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(inventory_items.items.len(), 1);
|
|
|
|
|
|
inventory_items.items[0].with_stacked(|items| {
|
|
|
|
|
|
assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
|
|
|
|
|
|
vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5), item::ItemEntityId(6)]);
|
|
|
|
|
|
assert!(items.iter().all(|item| item.item.item_type() == item::ItemType::Tool(item::tool::ToolType::Monomate)));
|
|
|
|
|
|
}).unwrap();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
#[async_std::test]
|
|
@ -104,7 +99,8 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { |
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
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 (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p2_monomate = Vec::new();
|
|
|
|
|
|
p2_monomate.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -113,14 +109,14 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char2.id,
|
|
|
character_id: char2.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomate])).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -149,14 +145,13 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
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,
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(inventory_items.items.len(), 1);
|
|
|
|
|
|
inventory_items.items[0].with_stacked(|items| {
|
|
|
|
|
|
assert_eq!(items.len(), 1);
|
|
|
|
|
|
assert_eq!(items[0].id, item::ItemEntityId(1));
|
|
|
|
|
|
assert_eq!(items[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
|
|
|
|
|
|
}).unwrap();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
#[async_std::test]
|
|
@ -166,8 +161,9 @@ async fn test_pick_up_meseta_when_inventory_full() { |
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "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;
|
|
|
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
for slot in 0..30 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p1_items = Vec::new();
|
|
|
|
|
|
for _ in 0..30usize {
|
|
|
|
|
|
p1_items.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item::weapon::Weapon {
|
|
|
item::weapon::Weapon {
|
|
@ -181,18 +177,18 @@ async fn test_pick_up_meseta_when_inventory_full() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: slot,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap();
|
|
|
|
|
|
|
|
|
char2.meseta = 300;
|
|
|
char2.meseta = 300;
|
|
|
entity_gateway.save_character(&char2).await.unwrap();
|
|
|
entity_gateway.save_character(&char2).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -227,8 +223,8 @@ async fn test_pick_up_meseta_when_inventory_full() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
assert!(p1_items.len() == 30);
|
|
|
|
|
|
|
|
|
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(inventory_items.items.len(), 30);
|
|
|
|
|
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
@ -245,8 +241,9 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { |
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
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 (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
for slot in 0..29 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
for slot in 0..29usize {
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item::weapon::Weapon {
|
|
|
item::weapon::Weapon {
|
|
@ -260,13 +257,11 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: slot,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap().into());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -275,11 +270,11 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: 29,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
}).await.unwrap()]));
|
|
|
|
|
|
|
|
|
|
|
|
let mut p2_monomates = Vec::new();
|
|
|
|
|
|
p2_monomates.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -288,14 +283,15 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char2.id,
|
|
|
character_id: char2.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).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![p2_monomates])).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -324,17 +320,11 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
assert!(p1_items.len() == 31);
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(inventory_items.items.len(), 30);
|
|
|
|
|
|
inventory_items.items[29].with_stacked(|items| {
|
|
|
|
|
|
assert_eq!(items.len(), 2);
|
|
|
|
|
|
}).unwrap();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
#[async_std::test]
|
|
@ -344,8 +334,9 @@ async fn test_can_not_pick_up_item_when_inventory_full() { |
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
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 (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
for slot in 0..30 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
for slot in 0..30usize {
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item::weapon::Weapon {
|
|
|
item::weapon::Weapon {
|
|
@ -359,13 +350,12 @@ async fn test_can_not_pick_up_item_when_inventory_full() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: slot,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p2_inv = Vec::new();
|
|
|
|
|
|
p2_inv.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
item::weapon::Weapon {
|
|
|
item::weapon::Weapon {
|
|
@ -379,14 +369,15 @@ async fn test_can_not_pick_up_item_when_inventory_full() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char2.id,
|
|
|
character_id: char2.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -415,11 +406,10 @@ async fn test_can_not_pick_up_item_when_inventory_full() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
assert!(p1_items.len() == 30);
|
|
|
|
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap();
|
|
|
|
|
|
assert!(p2_items.len() == 0);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 30);
|
|
|
|
|
|
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 {
|
|
|
ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
|
client: 0,
|
|
|
client: 0,
|
|
@ -429,8 +419,10 @@ async fn test_can_not_pick_up_item_when_inventory_full() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap();
|
|
|
|
|
|
assert!(p2_items.len() == 1);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 30);
|
|
|
|
|
|
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]
|
|
@ -442,9 +434,9 @@ async fn test_can_not_drop_more_meseta_than_is_held() { |
|
|
char1.meseta = 300;
|
|
|
char1.meseta = 300;
|
|
|
entity_gateway.save_character(&char1).await.unwrap();
|
|
|
entity_gateway.save_character(&char1).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
|
|
|
|
|
|
join_lobby(&mut ship, ClientId(1)).await;
|
|
|
join_lobby(&mut ship, ClientId(1)).await;
|
|
@ -481,8 +473,9 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { |
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
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 (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
for _ in 0..6 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut p1_monomates = Vec::new();
|
|
|
|
|
|
for _ in 0..6usize {
|
|
|
|
|
|
p1_monomates.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -491,13 +484,13 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
}
|
|
|
}
|
|
|
for _ in 0..6 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut p2_monomates = Vec::new();
|
|
|
|
|
|
for _ in 0..6usize {
|
|
|
|
|
|
p2_monomates.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -506,15 +499,15 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char2.id,
|
|
|
character_id: char2.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![p1_monomates])).await.unwrap();
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -544,11 +537,13 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { |
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
assert!(packets.len() == 0);
|
|
|
assert!(packets.len() == 0);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
assert!(p1_items.len() == 6);
|
|
|
|
|
|
|
|
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap();
|
|
|
|
|
|
assert!(p2_items.len() == 0);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
|
|
|
p1_items.items[0].with_stacked(|items| {
|
|
|
|
|
|
assert_eq!(items.len(), 6);
|
|
|
|
|
|
}).unwrap();
|
|
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
#[async_std::test]
|
|
@ -563,9 +558,9 @@ async fn test_can_not_pick_up_meseta_when_full() { |
|
|
char2.meseta = 300;
|
|
|
char2.meseta = 300;
|
|
|
entity_gateway.save_character(&char2).await.unwrap();
|
|
|
entity_gateway.save_character(&char2).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -621,9 +616,9 @@ async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() { |
|
|
char2.meseta = 300;
|
|
|
char2.meseta = 300;
|
|
|
entity_gateway.save_character(&char2).await.unwrap();
|
|
|
entity_gateway.save_character(&char2).await.unwrap();
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -673,8 +668,9 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { |
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
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 (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
for _ in 0..5 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
|
|
|
let mut monomates = Vec::new();
|
|
|
|
|
|
for _ in 0..5usize {
|
|
|
|
|
|
monomates.push(entity_gateway.create_item(
|
|
|
item::NewItemEntity {
|
|
|
item::NewItemEntity {
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item: item::ItemDetail::Tool(
|
|
|
item::tool::Tool {
|
|
|
item::tool::Tool {
|
|
@ -683,15 +679,15 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { |
|
|
),
|
|
|
),
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
character_id: char1.id,
|
|
|
character_id: char1.id,
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}).await.unwrap();
|
|
|
|
|
|
|
|
|
}).await.unwrap());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.gateway(entity_gateway.clone())
|
|
|
.build();
|
|
|
|
|
|
|
|
|
.build());
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
@ -726,35 +722,17 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { |
|
|
unknown: [0; 3]
|
|
|
unknown: [0; 3]
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
|
|
|
|
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.id).await.unwrap();
|
|
|
|
|
|
assert!(p2_items.len() == 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);
|
|
|
|
|
|
|
|
|
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(inventory_items.items.len(), 1);
|
|
|
|
|
|
inventory_items.items[0].with_stacked(|items| {
|
|
|
|
|
|
assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
|
|
|
|
|
|
vec![item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5)]);
|
|
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let inventory_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(inventory_items.items.len(), 1);
|
|
|
|
|
|
inventory_items.items[0].with_stacked(|items| {
|
|
|
|
|
|
assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
|
|
|
|
|
|
vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
|
|
|
|
|
|
}).unwrap();
|
|
|
}
|
|
|
}
|