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.

178 lines
7.1 KiB

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