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.

213 lines
9.5 KiB

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