|
|
@ -2,6 +2,7 @@ use std::convert::TryInto; |
|
|
|
use networking::serverstate::{ClientId, ServerState};
|
|
|
|
use entity::gateway::{EntityGateway, InMemoryGateway};
|
|
|
|
use entity::item;
|
|
|
|
use libpso::item::weapon;
|
|
|
|
use ship_server::{ShipServerState, RecvShipPacket, SendShipPacket};
|
|
|
|
use entity::item::{Meseta, ItemEntity, InventoryItemEntity};
|
|
|
|
use ship_server::trade::TradeError;
|
|
|
@ -118,7 +119,7 @@ async fn test_trade_one_individual_item() { |
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
@ -209,7 +210,7 @@ async fn test_trade_player2_to_player1() { |
|
|
|
|
|
|
|
let mut p2_inv = Vec::new();
|
|
|
|
p2_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
@ -300,7 +301,7 @@ async fn test_reverse_trade_ack_order() { |
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
@ -590,12 +591,12 @@ async fn test_trade_individual_both() { |
|
|
|
|
|
|
|
let p1_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap()];
|
|
|
|
let p2_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap()];
|
|
|
|
|
|
|
@ -722,10 +723,10 @@ async fn test_trade_individual_both() { |
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
|
assert!(matches!(p1_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Handgun, ..}), ..}));
|
|
|
|
assert!(matches!(p1_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Handgun, ..}), ..}));
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
assert_eq!(p2_items.items.len(), 1);
|
|
|
|
assert!(matches!(p2_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Saber, ..}), ..}));
|
|
|
|
assert!(matches!(p2_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Saber, ..}), ..}));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -1355,7 +1356,7 @@ async fn test_trade_individual_for_stacked() { |
|
|
|
|
|
|
|
let p1_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap()];
|
|
|
|
|
|
|
@ -1499,7 +1500,7 @@ async fn test_trade_individual_for_stacked() { |
|
|
|
assert!(matches!(p1_items.items[0].with_stacked(|i| i.clone()).unwrap()[0], item::ItemEntity{item: item::ItemDetail::Tool(item::tool::Tool {tool: item::tool::ToolType::Monomate, ..}), ..}));
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
assert_eq!(p2_items.items.len(), 1);
|
|
|
|
assert!(matches!(p2_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Saber, ..}), ..}));
|
|
|
|
assert!(matches!(p2_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Saber, ..}), ..}));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -1511,21 +1512,21 @@ async fn test_trade_multiple_individual() { |
|
|
|
|
|
|
|
let p1_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Buster)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Buster)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
];
|
|
|
|
let p2_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Autogun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Autogun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
];
|
|
|
@ -1717,12 +1718,12 @@ async fn test_trade_multiple_individual() { |
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 2);
|
|
|
|
assert!(matches!(p1_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Handgun, ..}), ..}));
|
|
|
|
assert!(matches!(p1_items.items[1].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Autogun, ..}), ..}));
|
|
|
|
assert!(matches!(p1_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Handgun, ..}), ..}));
|
|
|
|
assert!(matches!(p1_items.items[1].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Autogun, ..}), ..}));
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
assert_eq!(p2_items.items.len(), 2);
|
|
|
|
assert!(matches!(p2_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Saber, ..}), ..}));
|
|
|
|
assert!(matches!(p2_items.items[1].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(item::weapon::Weapon {weapon: item::weapon::WeaponType::Buster, ..}), ..}));
|
|
|
|
assert!(matches!(p2_items.items[0].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Saber, ..}), ..}));
|
|
|
|
assert!(matches!(p2_items.items[1].with_individual(|i| i.clone()).unwrap(), item::ItemEntity{item: item::ItemDetail::Weapon(weapon::Weapon {weapon: weapon::WeaponType::Buster, ..}), ..}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1986,7 +1987,7 @@ async fn test_trade_not_enough_inventory_space_individual() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -1999,7 +2000,7 @@ async fn test_trade_not_enough_inventory_space_individual() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -2102,7 +2103,7 @@ async fn test_trade_not_enough_inventory_space_stacked() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -2553,7 +2554,7 @@ async fn test_back_out_of_trade_last_minute() { |
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
@ -2611,7 +2612,7 @@ async fn test_valid_trade_when_both_inventories_are_full() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -2624,7 +2625,7 @@ async fn test_valid_trade_when_both_inventories_are_full() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -2714,12 +2715,12 @@ async fn test_valid_trade_when_both_inventories_are_full() { |
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 30);
|
|
|
|
assert_eq!(p1_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(item::weapon::Weapon { weapon: item::weapon::WeaponType::Saber, ..}, ..))).count(), 28);
|
|
|
|
assert_eq!(p1_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(item::weapon::Weapon { weapon: item::weapon::WeaponType::Handgun, ..}, ..))).count(), 2);
|
|
|
|
assert_eq!(p1_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(weapon::Weapon { weapon: weapon::WeaponType::Saber, ..}, ..))).count(), 28);
|
|
|
|
assert_eq!(p1_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(weapon::Weapon { weapon: weapon::WeaponType::Handgun, ..}, ..))).count(), 2);
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
assert_eq!(p2_items.items.len(), 30);
|
|
|
|
assert_eq!(p2_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(item::weapon::Weapon { weapon: item::weapon::WeaponType::Saber, ..}, ..))).count(), 2);
|
|
|
|
assert_eq!(p2_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(item::weapon::Weapon { weapon: item::weapon::WeaponType::Handgun, ..}, ..))).count(), 28);
|
|
|
|
assert_eq!(p2_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(weapon::Weapon { weapon: weapon::WeaponType::Saber, ..}, ..))).count(), 2);
|
|
|
|
assert_eq!(p2_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(weapon::Weapon { weapon: weapon::WeaponType::Handgun, ..}, ..))).count(), 28);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -2733,7 +2734,7 @@ async fn test_invalid_trade_when_both_inventories_are_full() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -2746,7 +2747,7 @@ async fn test_invalid_trade_when_both_inventories_are_full() { |
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
async move {
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await
|
|
|
|
}}))
|
|
|
@ -2847,10 +2848,10 @@ async fn test_invalid_trade_when_both_inventories_are_full() { |
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 30);
|
|
|
|
assert_eq!(p1_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(item::weapon::Weapon { weapon: item::weapon::WeaponType::Saber, ..}, ..))).count(), 30);
|
|
|
|
assert_eq!(p1_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(weapon::Weapon { weapon: weapon::WeaponType::Saber, ..}, ..))).count(), 30);
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
assert_eq!(p2_items.items.len(), 30);
|
|
|
|
assert_eq!(p2_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(item::weapon::Weapon { weapon: item::weapon::WeaponType::Handgun, ..}, ..))).count(), 30);
|
|
|
|
assert_eq!(p2_items.items.iter().filter(|i| matches!(i.individual().unwrap().item, item::ItemDetail::Weapon(weapon::Weapon { weapon: weapon::WeaponType::Handgun, ..}, ..))).count(), 30);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -2932,7 +2933,7 @@ async fn test_add_then_remove_individual_item() { |
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
for _ in 0..2 {
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
}
|
|
|
@ -3357,7 +3358,7 @@ async fn test_items_to_trade_data_does_not_match() { |
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
@ -3394,8 +3395,8 @@ async fn test_items_to_trade_data_does_not_match() { |
|
|
|
ItemEntity {
|
|
|
|
id: p1_items.items[0].with_individual(|i| i.id).unwrap(),
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
item::weapon::Weapon {
|
|
|
|
weapon: item::weapon::WeaponType::Handgun,
|
|
|
|
weapon::Weapon {
|
|
|
|
weapon: weapon::WeaponType::Handgun,
|
|
|
|
grind: 2,
|
|
|
|
special: None,
|
|
|
|
attrs: [None, None, None],
|
|
|
@ -3430,7 +3431,7 @@ async fn test_items_to_trade_id_does_not_match() { |
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
@ -3627,15 +3628,15 @@ async fn test_items_to_trade_count_less_than() { |
|
|
|
|
|
|
|
let p1_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Brand)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Brand)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Buster)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Buster)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
];
|
|
|
@ -3705,15 +3706,15 @@ async fn test_items_to_trade_count_greater_than() { |
|
|
|
|
|
|
|
let p1_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Brand)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Brand)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Buster)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Buster)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
];
|
|
|
@ -3787,15 +3788,15 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { |
|
|
|
|
|
|
|
let p1_inv = vec![
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Saber)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Saber)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Brand)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Brand)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Buster)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Buster)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap(),
|
|
|
|
];
|
|
|
@ -3863,7 +3864,7 @@ async fn test_dropping_item_after_trade() { |
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
ItemBuilder::weapon(item::weapon::WeaponType::Handgun)
|
|
|
|
ItemBuilder::weapon(weapon::WeaponType::Handgun)
|
|
|
|
.as_new()
|
|
|
|
).await.unwrap());
|
|
|
|
|
|
|
|