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.

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