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.

177 lines
7.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use stats::leveltable::CharacterLevelTable;
  4. use elseware::ship::ship::{ShipServerState, SendShipPacket, RecvShipPacket};
  5. use maps::variant::{MapVariant, MapVariantMode};
  6. use maps::maps::Maps;
  7. use maps::area::MapArea;
  8. use maps::enemy::MapEnemy;
  9. use maps::monster::MonsterType;
  10. use libpso::packet::ship::*;
  11. use libpso::packet::messages::*;
  12. #[path = "common.rs"]
  13. mod common;
  14. use common::*;
  15. #[async_std::test]
  16. async fn test_character_gains_exp() {
  17. let mut entity_gateway = InMemoryGateway::default();
  18. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  19. let mut ship = Box::new(ShipServerState::builder()
  20. .gateway(entity_gateway.clone())
  21. .map_builder(Box::new(|_room_mode, _event| {
  22. Maps::new(
  23. vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
  24. vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
  25. Vec::new(),
  26. )
  27. }))
  28. .build());
  29. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  30. join_lobby(&mut ship, ClientId(1)).await;
  31. create_room(&mut ship, ClientId(1), "room", "").await;
  32. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
  33. client: 0,
  34. target: 16,
  35. enemy_id: 0,
  36. client_id: 0,
  37. unused: 0,
  38. last_hitter: 1,
  39. })))).await.unwrap();
  40. ship.clients.with(ClientId(1), |client| Box::pin(async move {
  41. assert!(13 == client.character.exp);
  42. })).await.unwrap();
  43. }
  44. #[async_std::test]
  45. async fn test_character_levels_up() {
  46. let mut entity_gateway = InMemoryGateway::default();
  47. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  48. char1.exp = 49;
  49. entity_gateway.save_character(&char1).await.unwrap();
  50. let mut ship = Box::new(ShipServerState::builder()
  51. .gateway(entity_gateway.clone())
  52. .map_builder(Box::new(|_room_mode, _event| {
  53. Maps::new(
  54. vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
  55. vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
  56. Vec::new(),
  57. )
  58. }))
  59. .build());
  60. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  61. join_lobby(&mut ship, ClientId(1)).await;
  62. create_room(&mut ship, ClientId(1), "room", "").await;
  63. let levelup_pkt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
  64. client: 0 as u8,
  65. target: 16,
  66. enemy_id: 0 as u16,
  67. client_id: 0,
  68. unused: 0,
  69. last_hitter: 1,
  70. })))).await.unwrap();
  71. assert!(matches!(levelup_pkt[1].1, SendShipPacket::Message(Message {msg: GameMessage::PlayerLevelUp(PlayerLevelUp {lvl: 1, ..})})));
  72. let leveltable = CharacterLevelTable::default();
  73. ship.clients.with(ClientId(1), |client| Box::pin(async move {
  74. assert!(leveltable.get_level_from_exp(client.character.char_class, client.character.exp) == 2)
  75. })).await.unwrap();
  76. }
  77. #[async_std::test]
  78. async fn test_character_levels_up_multiple_times() {
  79. let mut entity_gateway = InMemoryGateway::default();
  80. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  81. let mut ship = Box::new(ShipServerState::builder()
  82. .gateway(entity_gateway.clone())
  83. .map_builder(Box::new(|_room_mode, _event| {
  84. Maps::new(
  85. vec![MapVariant::new(MapArea::DarkFalz, MapVariantMode::Online)],
  86. vec![Some(MapEnemy::new(MonsterType::DarkFalz2, MapArea::DarkFalz))],
  87. Vec::new(),
  88. )
  89. }))
  90. .build());
  91. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  92. join_lobby(&mut ship, ClientId(1)).await;
  93. create_room(&mut ship, ClientId(1), "room", "").await;
  94. let levelup_pkt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
  95. client: 0 as u8,
  96. target: 16,
  97. enemy_id: 0 as u16,
  98. client_id: 0,
  99. unused: 0,
  100. last_hitter: 1,
  101. })))).await.unwrap();
  102. assert!(matches!(levelup_pkt[1].1, SendShipPacket::Message(Message {msg: GameMessage::PlayerLevelUp(PlayerLevelUp {lvl: 7, ..})})));
  103. ship.clients.with(ClientId(1), |client| Box::pin(async move {
  104. assert!(3000 == client.character.exp);
  105. })).await.unwrap();
  106. }
  107. #[async_std::test]
  108. async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() {
  109. let mut entity_gateway = InMemoryGateway::default();
  110. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  111. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  112. let mut ship = Box::new(ShipServerState::builder()
  113. .gateway(entity_gateway.clone())
  114. .map_builder(Box::new(|_room_mode, _event| {
  115. Maps::new(
  116. vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
  117. vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
  118. Vec::new(),
  119. )
  120. }))
  121. .build());
  122. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  123. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  124. join_lobby(&mut ship, ClientId(1)).await;
  125. join_lobby(&mut ship, ClientId(2)).await;
  126. create_room(&mut ship, ClientId(1), "room", "").await;
  127. join_room(&mut ship, ClientId(2), 0).await;
  128. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
  129. client: 0,
  130. target: 16,
  131. enemy_id: 0,
  132. client_id: 0,
  133. unused: 0,
  134. last_hitter: 1,
  135. })))).await.unwrap();
  136. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
  137. client: 0,
  138. target: 16,
  139. enemy_id: 0,
  140. client_id: 0,
  141. unused: 0,
  142. last_hitter: 0,
  143. })))).await.unwrap();
  144. ship.clients.with(ClientId(1), |client| Box::pin(async move {
  145. assert_eq!(client.character.exp, 13);
  146. })).await.unwrap();
  147. ship.clients.with(ClientId(2), |client| Box::pin(async move {
  148. assert_eq!(client.character.exp, 10);
  149. })).await.unwrap();
  150. }