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.

105 lines
3.9 KiB

4 years ago
4 years ago
  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. wrapping: None,
  27. }
  28. ),
  29. location: item::ItemLocation::Inventory {
  30. character_id: char1.id,
  31. }
  32. }).await.unwrap());
  33. }
  34. let mut p2_inv = Vec::new();
  35. for _ in 0..10usize {
  36. p2_inv.push(entity_gateway.create_item(
  37. item::NewItemEntity {
  38. item: item::ItemDetail::Weapon(
  39. item::weapon::Weapon {
  40. weapon: item::weapon::WeaponType::Saber,
  41. grind: 0,
  42. special: None,
  43. attrs: [None, None, None],
  44. tekked: true,
  45. wrapping: None,
  46. }
  47. ),
  48. location: item::ItemLocation::Inventory {
  49. character_id: char2.id,
  50. }
  51. }).await.unwrap());
  52. }
  53. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  54. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap();
  55. let mut ship = Box::new(ShipServerState::builder()
  56. .gateway(entity_gateway.clone())
  57. .build());
  58. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  59. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  60. join_lobby(&mut ship, ClientId(1)).await;
  61. join_lobby(&mut ship, ClientId(2)).await;
  62. create_room(&mut ship, ClientId(1), "room", "").await;
  63. let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
  64. menu: ROOM_MENU_ID,
  65. item: 0,
  66. })).await.unwrap().collect::<Vec<_>>();
  67. ship.handle(ClientId(2), &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  68. match &p[1].1 {
  69. SendShipPacket::AddToRoom(add_to) => {
  70. println!("addto {:?}", add_to);
  71. assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
  72. vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
  73. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
  74. },
  75. _ => panic!(),
  76. }
  77. leave_room(&mut ship, ClientId(2)).await;
  78. let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
  79. menu: ROOM_MENU_ID,
  80. item: 0,
  81. })).await.unwrap().collect::<Vec<_>>();
  82. match &p[1].1 {
  83. SendShipPacket::AddToRoom(add_to) => {
  84. assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
  85. vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
  86. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
  87. },
  88. _ => panic!(),
  89. }
  90. }