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.

116 lines
4.4 KiB

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. }