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.

206 lines
7.8 KiB

  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::InMemoryGateway;
  3. use ship_server::{SendShipPacket, RecvShipPacket};
  4. use maps::monster::MonsterType;
  5. use drops::{StandardDropTable, MonsterDropStats, MonsterDropType};
  6. use drops::rare_drop_table::{RareDropTable, RareDropRate, RareDropItem};
  7. use maps::maps::Maps;
  8. use maps::area::MapArea;
  9. use maps::variant::{MapVariant, MapVariantMode};
  10. use maps::enemy::MapEnemy;
  11. use libpso::item::weapon::WeaponType;
  12. use libpso::packet::ship::*;
  13. use libpso::packet::messages::*;
  14. #[path = "common.rs"]
  15. mod common;
  16. use common::*;
  17. #[async_std::test]
  18. async fn test_enemy_drops_item() {
  19. let mut entity_gateway = InMemoryGateway::default();
  20. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  21. let mut ship = standard_ship_buildable(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. .drop_table_builder(Box::new(|episode, difficulty, section_id| {
  30. StandardDropTable::builder()
  31. .monster_stat(MonsterType::Hildebear, MonsterDropStats {
  32. dar: 100,
  33. drop_type: MonsterDropType::Weapon,
  34. min_meseta: 0,
  35. max_meseta: 0,
  36. })
  37. .rare_table(RareDropTable::builder()
  38. .rate(MonsterType::Hildebear, RareDropRate {
  39. rate: 1.0,
  40. item: RareDropItem::Weapon(WeaponType::DarkFlow)
  41. })
  42. .build(episode, difficulty, section_id))
  43. .build(episode, difficulty, section_id)
  44. }))
  45. .build();
  46. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  47. join_lobby(&mut ship, ClientId(1)).await;
  48. create_room(&mut ship, ClientId(1), "room", "").await;
  49. let pkt = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem {
  50. client: 0,
  51. target: 0,
  52. map_area: 2,
  53. pt_index: 0,
  54. enemy_id: 0,
  55. x: 0.0,
  56. z: 0.0,
  57. y: 0.0,
  58. })))).await.unwrap();
  59. match &pkt[0].1 {
  60. SendShipPacket::Message(Message{msg: GameMessage::ItemDrop(item_drop)}) => {
  61. assert_eq!(item_drop.item_id, 0x810001);
  62. assert_eq!(item_drop.item_bytes[1], 0x9D);
  63. },
  64. _ => panic!(),
  65. }
  66. }
  67. #[async_std::test]
  68. async fn test_enemy_drops_item_for_two_players() {
  69. let mut entity_gateway = InMemoryGateway::default();
  70. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  71. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  72. let mut ship = standard_ship_buildable(entity_gateway.clone())
  73. .map_builder(Box::new(|_room_mode, _event| {
  74. Maps::new(
  75. vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
  76. vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
  77. Vec::new(),
  78. )
  79. }))
  80. .drop_table_builder(Box::new(|episode, difficulty, section_id| {
  81. StandardDropTable::builder()
  82. .monster_stat(MonsterType::Hildebear, MonsterDropStats {
  83. dar: 100,
  84. drop_type: MonsterDropType::Weapon,
  85. min_meseta: 0,
  86. max_meseta: 0,
  87. })
  88. .rare_table(RareDropTable::builder()
  89. .rate(MonsterType::Hildebear, RareDropRate {
  90. rate: 1.0,
  91. item: RareDropItem::Weapon(WeaponType::DarkFlow)
  92. })
  93. .build(episode, difficulty, section_id))
  94. .build(episode, difficulty, section_id)
  95. }))
  96. .build();
  97. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  98. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  99. join_lobby(&mut ship, ClientId(1)).await;
  100. join_lobby(&mut ship, ClientId(2)).await;
  101. create_room(&mut ship, ClientId(1), "room", "").await;
  102. join_room(&mut ship, ClientId(2), 0).await;
  103. let pkt = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem {
  104. client: 0,
  105. target: 0,
  106. map_area: 2,
  107. pt_index: 0,
  108. enemy_id: 0,
  109. x: 0.0,
  110. z: 0.0,
  111. y: 0.0,
  112. })))).await.unwrap();
  113. assert_eq!(pkt[0].0, ClientId(1));
  114. match &pkt[0].1 {
  115. SendShipPacket::Message(Message{msg: GameMessage::ItemDrop(item_drop)}) => {
  116. assert_eq!(item_drop.item_id, 0x810001);
  117. assert_eq!(item_drop.item_bytes[1], 0x9D);
  118. },
  119. _ => panic!(),
  120. }
  121. assert_eq!(pkt[1].0, ClientId(2));
  122. match &pkt[1].1 {
  123. SendShipPacket::Message(Message{msg: GameMessage::ItemDrop(item_drop)}) => {
  124. assert_eq!(item_drop.item_id, 0x810002);
  125. assert_eq!(item_drop.item_bytes[1], 0x9D);
  126. },
  127. _ => panic!(),
  128. }
  129. }
  130. #[async_std::test]
  131. async fn test_enemy_drops_item_for_two_players_and_pick_up() {
  132. let mut entity_gateway = InMemoryGateway::default();
  133. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  134. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  135. let mut ship = standard_ship_buildable(entity_gateway.clone())
  136. .map_builder(Box::new(|_room_mode, _event| {
  137. Maps::new(
  138. vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
  139. vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
  140. Vec::new(),
  141. )
  142. }))
  143. .drop_table_builder(Box::new(|episode, difficulty, section_id| {
  144. StandardDropTable::builder()
  145. .monster_stat(MonsterType::Hildebear, MonsterDropStats {
  146. dar: 100,
  147. drop_type: MonsterDropType::Weapon,
  148. min_meseta: 0,
  149. max_meseta: 0,
  150. })
  151. .rare_table(RareDropTable::builder()
  152. .rate(MonsterType::Hildebear, RareDropRate {
  153. rate: 1.0,
  154. item: RareDropItem::Weapon(WeaponType::DarkFlow)
  155. })
  156. .build(episode, difficulty, section_id))
  157. .build(episode, difficulty, section_id)
  158. }))
  159. .build();
  160. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  161. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  162. join_lobby(&mut ship, ClientId(1)).await;
  163. join_lobby(&mut ship, ClientId(2)).await;
  164. create_room(&mut ship, ClientId(1), "room", "").await;
  165. join_room(&mut ship, ClientId(2), 0).await;
  166. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem {
  167. client: 0,
  168. target: 0,
  169. map_area: 2,
  170. pt_index: 0,
  171. enemy_id: 0,
  172. x: 0.0,
  173. z: 0.0,
  174. y: 0.0,
  175. })))).await.unwrap();
  176. ship.handle(ClientId(2), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  177. client: 0,
  178. target: 0,
  179. item_id: 0x810002,
  180. map_area: 0,
  181. unknown: [0; 3]
  182. })))).await.unwrap();
  183. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  184. client: 0,
  185. target: 0,
  186. item_id: 0x810001,
  187. map_area: 0,
  188. unknown: [0; 3]
  189. })))).await.unwrap();
  190. }