|
|
@ -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::*;
|
|
|
@ -190,16 +191,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 {..})));
|
|
|
@ -292,15 +293,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 {..})));
|
|
|
@ -392,16 +393,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 {..})));
|
|
|
@ -496,16 +497,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 {..})));
|
|
|
@ -601,16 +602,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 {..})));
|
|
|
@ -727,32 +728,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
|
|
|
@ -761,19 +761,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -899,30 +900,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,
|
|
|
@ -930,18 +931,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1069,31 +1070,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,
|
|
|
@ -1101,19 +1103,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1245,31 +1246,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,
|
|
|
@ -1277,19 +1279,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1407,16 +1408,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,
|
|
|
@ -1426,10 +1427,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],
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1554,32 +1555,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],
|
|
|
@ -1588,19 +1588,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1758,53 +1759,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1812,8 +1811,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -1821,42 +1820,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2030,49 +2031,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2080,7 +2081,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2088,39 +2089,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,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
@ -2251,12 +2252,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);
|
|
|
@ -2368,12 +2364,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);
|
|
|
@ -2482,12 +2473,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);
|
|
|
@ -2557,16 +2543,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 {..})));
|
|
|
@ -3109,12 +3095,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);
|
|
|
@ -3124,6 +3105,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();
|
|
|
@ -3153,7 +3135,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]
|
|
|
@ -3185,14 +3168,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]
|
|
|
@ -3287,16 +3270,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 {..})));
|
|
|
@ -3418,16 +3401,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 {..})));
|
|
|
@ -3632,16 +3615,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 {..})));
|
|
|
@ -4349,16 +4332,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 {..})));
|
|
|
|