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.

209 lines
9.3 KiB

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