You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.8 KiB

  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::entity::item;
  4. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  5. use libpso::packet::ship::*;
  6. use libpso::packet::messages::*;
  7. #[path = "common.rs"]
  8. mod common;
  9. use common::*;
  10. #[async_std::test]
  11. async fn test_item_ids_reset_when_rejoining_rooms() {
  12. let mut entity_gateway = InMemoryGateway::new();
  13. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  14. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  15. let mut p1_inv = Vec::new();
  16. for _ in 0..3usize {
  17. p1_inv.push(entity_gateway.create_item(
  18. item::NewItemEntity {
  19. item: item::ItemDetail::Weapon(
  20. item::weapon::Weapon {
  21. weapon: item::weapon::WeaponType::Saber,
  22. grind: 0,
  23. special: None,
  24. attrs: [None, None, None],
  25. tekked: true,
  26. }
  27. ),
  28. location: item::ItemLocation::Inventory {
  29. character_id: char1.id,
  30. }
  31. }).await.unwrap());
  32. }
  33. let mut p2_inv = Vec::new();
  34. for _ in 0..10usize {
  35. p2_inv.push(entity_gateway.create_item(
  36. item::NewItemEntity {
  37. item: item::ItemDetail::Weapon(
  38. item::weapon::Weapon {
  39. weapon: item::weapon::WeaponType::Saber,
  40. grind: 0,
  41. special: None,
  42. attrs: [None, None, None],
  43. tekked: true,
  44. }
  45. ),
  46. location: item::ItemLocation::Inventory {
  47. character_id: char2.id,
  48. }
  49. }).await.unwrap());
  50. }
  51. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  52. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap();
  53. let mut ship = Box::new(ShipServerState::builder()
  54. .gateway(entity_gateway.clone())
  55. .build());
  56. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  57. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  58. join_lobby(&mut ship, ClientId(1)).await;
  59. join_lobby(&mut ship, ClientId(2)).await;
  60. create_room(&mut ship, ClientId(1), "room", "").await;
  61. let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
  62. menu: ROOM_MENU_ID,
  63. item: 0,
  64. })).await.unwrap().collect::<Vec<_>>();
  65. ship.handle(ClientId(2), &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  66. match &p[1].1 {
  67. SendShipPacket::AddToRoom(add_to) => {
  68. println!("addto {:?}", add_to);
  69. assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
  70. vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
  71. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
  72. },
  73. _ => panic!(),
  74. }
  75. leave_room(&mut ship, ClientId(2)).await;
  76. let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
  77. menu: ROOM_MENU_ID,
  78. item: 0,
  79. })).await.unwrap().collect::<Vec<_>>();
  80. match &p[1].1 {
  81. SendShipPacket::AddToRoom(add_to) => {
  82. assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
  83. vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
  84. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
  85. },
  86. _ => panic!(),
  87. }
  88. }