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.

158 lines
6.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 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::default();
  13. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  14. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).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. }).await.unwrap());
  29. }
  30. let mut p2_inv = Vec::new();
  31. for _ in 0..10usize {
  32. p2_inv.push(entity_gateway.create_item(
  33. item::NewItemEntity {
  34. item: item::ItemDetail::Weapon(
  35. item::weapon::Weapon {
  36. weapon: item::weapon::WeaponType::Saber,
  37. grind: 0,
  38. special: None,
  39. attrs: [None, None, None],
  40. tekked: true,
  41. }
  42. ),
  43. }).await.unwrap());
  44. }
  45. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  46. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap();
  47. let mut ship = Box::new(ShipServerState::builder()
  48. .gateway(entity_gateway.clone())
  49. .build());
  50. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  51. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  52. join_lobby(&mut ship, ClientId(1)).await;
  53. join_lobby(&mut ship, ClientId(2)).await;
  54. create_room(&mut ship, ClientId(1), "room", "").await;
  55. let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
  56. menu: ROOM_MENU_ID,
  57. item: 0,
  58. })).await.unwrap().collect::<Vec<_>>();
  59. ship.handle(ClientId(2), &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  60. match &p[1].1 {
  61. SendShipPacket::AddToRoom(add_to) => {
  62. println!("addto {:?}", add_to);
  63. assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
  64. vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
  65. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
  66. },
  67. _ => panic!(),
  68. }
  69. leave_room(&mut ship, ClientId(2)).await;
  70. let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
  71. menu: ROOM_MENU_ID,
  72. item: 0,
  73. })).await.unwrap().collect::<Vec<_>>();
  74. match &p[1].1 {
  75. SendShipPacket::AddToRoom(add_to) => {
  76. assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
  77. vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
  78. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
  79. },
  80. _ => panic!(),
  81. }
  82. }
  83. #[async_std::test]
  84. async fn test_load_rare_monster_default_appear_rates() {
  85. let mut entity_gateway = InMemoryGateway::default();
  86. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  87. let mut ship = Box::new(ShipServerState::builder()
  88. .gateway(entity_gateway.clone())
  89. .build());
  90. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  91. join_lobby(&mut ship, ClientId(1)).await;
  92. create_room(&mut ship, ClientId(1), "room", "").await;
  93. // assume episode 1
  94. let room = ship.blocks.0[0].rooms[0].as_ref().unwrap();
  95. println!("rare monster table: {:?}", room.rare_monster_table);
  96. let rates = &*room.rare_monster_table;
  97. for (_monster, rate) in rates.clone().appear_rate {
  98. assert_eq!(rate, 0.001953125f32); // 1/512 = 0.001953125
  99. }
  100. }
  101. #[async_std::test]
  102. async fn test_set_valid_quest_group() {
  103. let mut entity_gateway = InMemoryGateway::default();
  104. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  105. let mut ship = Box::new(ShipServerState::builder()
  106. .gateway(entity_gateway.clone())
  107. .build());
  108. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  109. join_lobby(&mut ship, ClientId(1)).await;
  110. create_room(&mut ship, ClientId(1), "room", "").await;
  111. let packets = ship.handle(ClientId(1), &RecvShipPacket::RequestQuestList(RequestQuestList{flag: 0})).await.unwrap().collect::<Vec<_>>();
  112. match &packets[0].1 {
  113. SendShipPacket::QuestCategoryList(quest_cat) => {
  114. assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Retrieval"));
  115. },
  116. _ => panic!("Wrong quest category"),
  117. }
  118. }
  119. #[async_std::test]
  120. async fn test_set_invalid_quest_group() {
  121. let mut entity_gateway = InMemoryGateway::default();
  122. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  123. let mut ship = Box::new(ShipServerState::builder()
  124. .gateway(entity_gateway.clone())
  125. .build());
  126. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  127. join_lobby(&mut ship, ClientId(1)).await;
  128. create_room(&mut ship, ClientId(1), "room", "").await;
  129. let packets = ship.handle(ClientId(1), &RecvShipPacket::RequestQuestList(RequestQuestList{flag: 100})).await.unwrap().collect::<Vec<_>>();
  130. match &packets[0].1 {
  131. SendShipPacket::QuestCategoryList(quest_cat) => {
  132. // flag > quest category length should take the highest value allowed for quest category which is 1 in multimode (for govt quests) and 0 in other modes.
  133. // assuming we create an ep1 room in multimode, we should load the government quests in this test case
  134. assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Government"));
  135. },
  136. _ => panic!("Wrong quest category"),
  137. }
  138. }