|
@ -3726,7 +3726,6 @@ async fn test_items_to_trade_data_does_not_match() { |
|
|
count: 1,
|
|
|
count: 1,
|
|
|
items: titems,
|
|
|
items: titems,
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
dbg!(&ack);
|
|
|
|
|
|
assert_eq!(ack.len(), 2);
|
|
|
assert_eq!(ack.len(), 2);
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::CancelTrade(..))));
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::CancelTrade(..))));
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::CancelTrade(..))));
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::CancelTrade(..))));
|
|
@ -4269,3 +4268,115 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { |
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_dropping_item_after_trade() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Handgun,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::<item::InventoryItemEntity>::new())).await.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
|
|
|
|
.gateway(entity_gateway.clone())
|
|
|
|
|
|
.build());
|
|
|
|
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
|
|
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
join_lobby(&mut ship, ClientId(1)).await;
|
|
|
|
|
|
join_lobby(&mut ship, ClientId(2)).await;
|
|
|
|
|
|
|
|
|
|
|
|
create_room(&mut ship, ClientId(1), "room", "").await;
|
|
|
|
|
|
join_room(&mut ship, ClientId(2), 0).await;
|
|
|
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
initialize_trade(&mut ship, ClientId(1), ClientId(2)).await;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(1, GameMessage::TradeRequest(TradeRequest {
|
|
|
|
|
|
client: 1,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
trade: TradeRequestCommand::AddItem(0x10000, 1)
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
confirm_trade(&mut ship, ClientId(1), ClientId(2)).await;
|
|
|
|
|
|
finalconfirm_trade(&mut ship, ClientId(1), ClientId(2)).await;
|
|
|
|
|
|
|
|
|
|
|
|
let titems = TradeItemBuilder::default()
|
|
|
|
|
|
.individual(&p1_items.items[0], 0x10000)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
let ack = ship.handle(ClientId(1), &RecvShipPacket::ItemsToTrade(ItemsToTrade {
|
|
|
|
|
|
trade_target: 1,
|
|
|
|
|
|
unknown2: 0,
|
|
|
|
|
|
count: 1,
|
|
|
|
|
|
items: titems,
|
|
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
assert_eq!(ack.len(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::ItemsToTrade(ItemsToTrade {
|
|
|
|
|
|
trade_target: 0,
|
|
|
|
|
|
unknown2: 0,
|
|
|
|
|
|
count: 0,
|
|
|
|
|
|
items: Default::default(),
|
|
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
assert_eq!(ack.len(), 2);
|
|
|
|
|
|
assert!(matches!(ack[0], (ClientId(2), SendShipPacket::AcknowledgeTrade(AcknowledgeTrade {}))));
|
|
|
|
|
|
assert!(matches!(ack[1], (ClientId(1), SendShipPacket::AcknowledgeTrade(AcknowledgeTrade {}))));
|
|
|
|
|
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(1), &RecvShipPacket::TradeConfirmed(TradeConfirmed {
|
|
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
assert_eq!(ack.len(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
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[1], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
|
|
msg: GameMessage::CreateItem(CreateItem {..}),
|
|
|
|
|
|
..
|
|
|
|
|
|
}))));
|
|
|
|
|
|
assert!(matches!(ack[2], (ClientId(2), SendShipPacket::Message(Message {
|
|
|
|
|
|
msg: GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {..}),
|
|
|
|
|
|
..
|
|
|
|
|
|
}))));
|
|
|
|
|
|
assert!(matches!(ack[3], (ClientId(2), SendShipPacket::TradeSuccessful {..})));
|
|
|
|
|
|
assert!(matches!(ack[4], (ClientId(1), SendShipPacket::TradeSuccessful {..})));
|
|
|
|
|
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(2), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown1: 0,
|
|
|
|
|
|
map_area: 0,
|
|
|
|
|
|
item_id: 0x810001,
|
|
|
|
|
|
x: 0.0,
|
|
|
|
|
|
y: 0.0,
|
|
|
|
|
|
z: 0.0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p1_items.items.len(), 0);
|
|
|
|
|
|
let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
|
|
|
|
|
|
assert_eq!(p2_items.items.len(), 0);
|
|
|
|
|
|
}
|