|
|
@ -2,10 +2,11 @@ use std::convert::TryInto; |
|
|
|
use elseware::common::serverstate::{ClientId, ServerState};
|
|
|
|
use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
|
|
|
|
use elseware::entity::item;
|
|
|
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
|
|
|
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket, ShipError};
|
|
|
|
use elseware::entity::item::{Meseta, ItemEntity};
|
|
|
|
use elseware::ship::items::transaction::TransactionError;
|
|
|
|
use elseware::ship::packet::handler::trade::TradeError;
|
|
|
|
use elseware::ship::items::state::{ItemStateError, InventoryError};
|
|
|
|
|
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use libpso::packet::messages::*;
|
|
|
@ -191,16 +192,16 @@ async fn test_trade_one_individual_item() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -294,15 +295,15 @@ async fn test_trade_player2_to_player1() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -395,16 +396,16 @@ async fn test_reverse_trade_ack_order() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -499,16 +500,16 @@ async fn test_trade_one_stacked_item() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -604,16 +605,16 @@ async fn test_trade_partial_stacked_item() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -732,32 +733,31 @@ async fn test_trade_individual_both() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 8);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_id: 0x10000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
@ -766,19 +766,20 @@ async fn test_trade_individual_both() { |
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -904,30 +905,30 @@ async fn test_trade_stacked_both() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 8);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_id: 0x10000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810002,
|
|
|
@ -935,18 +936,18 @@ async fn test_trade_stacked_both() { |
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1074,31 +1075,32 @@ async fn test_trade_partial_stack_both() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 8);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
amount: 2,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
amount: 2,
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810002,
|
|
|
@ -1106,19 +1108,18 @@ async fn test_trade_partial_stack_both() { |
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1250,31 +1251,32 @@ async fn test_trade_same_stacked_item_to_eachother() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 8);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
amount: 3,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
amount: 3,
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810002,
|
|
|
@ -1282,19 +1284,18 @@ async fn test_trade_same_stacked_item_to_eachother() { |
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1412,16 +1413,16 @@ async fn test_trade_stacked_when_already_have_partial_stack() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_data: [3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 2,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810001,
|
|
|
@ -1431,10 +1432,10 @@ async fn test_trade_stacked_when_already_have_partial_stack() { |
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 2,
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_data: [3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1560,32 +1561,31 @@ async fn test_trade_individual_for_stacked() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 8);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
|
|
|
|
item_id: 0x810001,
|
|
|
|
item_id: 0x10000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
@ -1594,19 +1594,20 @@ async fn test_trade_individual_for_stacked() { |
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 0,
|
|
|
|
item_data: [3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
item_data: [3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1768,53 +1769,51 @@ async fn test_trade_multiple_individual() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 14);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810002,
|
|
|
|
item_id: 0x10001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810003,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210001,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810003,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1822,8 +1821,8 @@ async fn test_trade_multiple_individual() { |
|
|
|
assert!(matches!(ack[6], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810003,
|
|
|
|
item_data: [0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810004,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1831,42 +1830,44 @@ async fn test_trade_multiple_individual() { |
|
|
|
assert!(matches!(ack[7], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810003,
|
|
|
|
item_data: [0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810004,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[8], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
assert!(matches!(ack[8], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[9], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[9], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810004,
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[10], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[10], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_data: [0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], // saber
|
|
|
|
item_id: 0x810004,
|
|
|
|
client: 0,
|
|
|
|
item_data: [0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[11], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10001,
|
|
|
|
item_data: [0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], // handgun
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2040,49 +2041,49 @@ async fn test_trade_multiple_stacked() { |
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 14);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210000,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810002,
|
|
|
|
item_id: 0x10001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[4], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810002,
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810003,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[5], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
assert!(matches!(ack[5], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x210001,
|
|
|
|
item_id: 0x810003,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2090,7 +2091,7 @@ async fn test_trade_multiple_stacked() { |
|
|
|
assert!(matches!(ack[6], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810003,
|
|
|
|
item_id: 0x810004,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2098,39 +2099,39 @@ async fn test_trade_multiple_stacked() { |
|
|
|
assert!(matches!(ack[7], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810003,
|
|
|
|
item_id: 0x810004,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[8], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
assert!(matches!(ack[8], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[9], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[9], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810004,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810001,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[10], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[10], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 1,
|
|
|
|
item_id: 0x810004,
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[11], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {
|
|
|
|
client: 0,
|
|
|
|
item_id: 0x10001,
|
|
|
|
item_id: 0x810002,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2263,12 +2264,7 @@ async fn test_trade_not_enough_inventory_space_individual() { |
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.err().unwrap();
|
|
|
|
match ack.downcast::<TransactionError<anyhow::Error>>().unwrap() {
|
|
|
|
TransactionError::Action(a) => {
|
|
|
|
assert_eq!(a.downcast::<TradeError>().unwrap(), TradeError::NoInventorySpace);
|
|
|
|
},
|
|
|
|
_ => panic!()
|
|
|
|
}
|
|
|
|
assert!(matches!(ack.downcast::<ItemStateError>().unwrap(), ItemStateError::InventoryError(InventoryError::InventoryFull)));
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 2);
|
|
|
@ -2381,12 +2377,7 @@ async fn test_trade_not_enough_inventory_space_stacked() { |
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.err().unwrap();
|
|
|
|
match ack.downcast::<TransactionError<anyhow::Error>>().unwrap() {
|
|
|
|
TransactionError::Action(a) => {
|
|
|
|
assert_eq!(a.downcast::<TradeError>().unwrap(), TradeError::NoInventorySpace);
|
|
|
|
},
|
|
|
|
_ => panic!()
|
|
|
|
}
|
|
|
|
assert!(matches!(ack.downcast::<ItemStateError>().unwrap(), ItemStateError::InventoryError(InventoryError::InventoryFull)));
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
@ -2495,12 +2486,7 @@ async fn test_trade_stack_too_big() { |
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.err().unwrap();
|
|
|
|
match ack.downcast::<TransactionError<anyhow::Error>>().unwrap() {
|
|
|
|
TransactionError::Action(a) => {
|
|
|
|
assert_eq!(a.downcast::<TradeError>().unwrap(), TradeError::NoStackSpace);
|
|
|
|
},
|
|
|
|
_ => panic!()
|
|
|
|
}
|
|
|
|
assert!(matches!(ack.downcast::<ItemStateError>().unwrap(), ItemStateError::InventoryError(InventoryError::StackFull)));
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
@ -2570,16 +2556,16 @@ async fn test_trade_meseta() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -3127,12 +3113,7 @@ async fn test_invalid_trade_when_both_inventories_are_full() { |
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.err().unwrap();
|
|
|
|
match ack.downcast::<TransactionError<anyhow::Error>>().unwrap() {
|
|
|
|
TransactionError::Action(a) => {
|
|
|
|
assert_eq!(a.downcast::<TradeError>().unwrap(), TradeError::NoInventorySpace);
|
|
|
|
},
|
|
|
|
_ => panic!()
|
|
|
|
}
|
|
|
|
assert!(matches!(ack.downcast::<ItemStateError>().unwrap(), ItemStateError::InventoryError(InventoryError::InventoryFull)));
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 30);
|
|
|
@ -3142,6 +3123,7 @@ async fn test_invalid_trade_when_both_inventories_are_full() { |
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_client_tries_to_start_two_trades() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
@ -3171,7 +3153,8 @@ async fn test_client_tries_to_start_two_trades() { |
|
|
|
target: 0,
|
|
|
|
trade: TradeRequestCommand::Initialize(TradeRequestInitializeCommand::Initialize, 0)
|
|
|
|
})))).await.err().unwrap();
|
|
|
|
assert_eq!(ack.downcast::<TradeError>().unwrap(), TradeError::ClientAlreadyInTrade);
|
|
|
|
|
|
|
|
assert!(matches!(ack.downcast::<ShipError>().unwrap(), ShipError::TradeError(TradeError::ClientAlreadyInTrade)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -3203,14 +3186,14 @@ async fn test_client_tries_trading_with_client_already_trading() { |
|
|
|
target: 0,
|
|
|
|
trade: TradeRequestCommand::Initialize(TradeRequestInitializeCommand::Initialize, 0)
|
|
|
|
})))).await.err().unwrap();
|
|
|
|
assert_eq!(ack.downcast::<TradeError>().unwrap(), TradeError::OtherAlreadyInTrade);
|
|
|
|
assert!(matches!(ack.downcast::<ShipError>().unwrap(), ShipError::TradeError(TradeError::OtherAlreadyInTrade)));
|
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(3), &RecvShipPacket::DirectMessage(DirectMessage::new(1, GameMessage::TradeRequest(TradeRequest {
|
|
|
|
client: 2,
|
|
|
|
target: 0,
|
|
|
|
trade: TradeRequestCommand::Initialize(TradeRequestInitializeCommand::Initialize, 1)
|
|
|
|
})))).await.err().unwrap();
|
|
|
|
assert_eq!(ack.downcast::<TradeError>().unwrap(), TradeError::OtherAlreadyInTrade);
|
|
|
|
assert!(matches!(ack.downcast::<ShipError>().unwrap(), ShipError::TradeError(TradeError::OtherAlreadyInTrade)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -3306,16 +3289,16 @@ async fn test_add_then_remove_individual_item() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -3437,16 +3420,16 @@ async fn test_add_then_remove_stacked_item() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -3651,16 +3634,16 @@ async fn test_add_then_remove_meseta() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
@ -4381,16 +4364,16 @@ async fn test_dropping_item_after_trade() { |
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(ack.len(), 5);
|
|
|
|
assert!(matches!(ack[0], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
..
|
|
|
|
}))));
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
|