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.

104 lines
3.7 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. for slot in 0..3 {
  16. entity_gateway.create_item(
  17. item::NewItemEntity {
  18. item: item::ItemDetail::Weapon(
  19. item::weapon::Weapon {
  20. weapon: item::weapon::WeaponType::Saber,
  21. grind: 0,
  22. special: None,
  23. attrs: [None, None, None],
  24. tekked: true,
  25. modifiers: Vec::new(),
  26. }
  27. ),
  28. location: item::ItemLocation::Inventory {
  29. character_id: char1.id,
  30. slot: slot,
  31. equipped: false,
  32. }
  33. }).await.unwrap();
  34. }
  35. for slot in 0..10 {
  36. 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. modifiers: Vec::new(),
  46. }
  47. ),
  48. location: item::ItemLocation::Inventory {
  49. character_id: char2.id,
  50. slot: slot,
  51. equipped: false,
  52. }
  53. }).await.unwrap();
  54. }
  55. let mut ship = 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. }