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.

76 lines
3.4 KiB

  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::entity::character::SectionID;
  4. use elseware::common::leveltable::CharacterLevelTable;
  5. use elseware::ship::ship::{ShipServerState, SendShipPacket, RecvShipPacket};
  6. use elseware::ship::room::{Episode, Difficulty};
  7. use elseware::ship::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 elseware::ship::map::{Maps, MapVariant, MapArea, MapVariantMode, MapEnemy};
  12. use elseware::entity::item::weapon::WeaponType;
  13. use libpso::packet::ship::*;
  14. use libpso::packet::messages::*;
  15. #[path = "common.rs"]
  16. mod common;
  17. use common::*;
  18. #[async_std::test]
  19. async fn test_enemy_drops_item() {
  20. let mut entity_gateway = InMemoryGateway::default();
  21. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  22. let mut ship = Box::new(ShipServerState::builder()
  23. .gateway(entity_gateway.clone())
  24. .map_builder(Box::new(|_room_mode, _event| {
  25. Maps::new(
  26. vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
  27. vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
  28. Vec::new(),
  29. )
  30. }))
  31. .drop_table_builder(Box::new(|episode, difficulty, section_id| {
  32. DropTable::builder()
  33. .monster_stat(MonsterType::Hildebear, MonsterDropStats {
  34. dar: 100,
  35. drop_type: MonsterDropType::Weapon,
  36. min_meseta: 0,
  37. max_meseta: 0,
  38. })
  39. .rare_table(RareDropTable::builder()
  40. .rate(MonsterType::Hildebear, RareDropRate {
  41. rate: 1.0,
  42. item: RareDropItem::Weapon(WeaponType::DarkFlow)
  43. })
  44. .build(episode, difficulty, section_id))
  45. .build(episode, difficulty, section_id)
  46. }))
  47. .build());
  48. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  49. join_lobby(&mut ship, ClientId(1)).await;
  50. create_room(&mut ship, ClientId(1), "room", "").await;
  51. let pkt = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem {
  52. client: 0,
  53. target: 0,
  54. map_area: 2,
  55. pt_index: 0,
  56. enemy_id: 0,
  57. x: 0.0,
  58. z: 0.0,
  59. y: 0.0,
  60. })))).await.unwrap();
  61. match &pkt[0].1 {
  62. SendShipPacket::Message(Message{msg: GameMessage::ItemDrop(item_drop)}) => {
  63. assert_eq!(item_drop.item_id, 0x810001);
  64. assert_eq!(item_drop.item_bytes[1], 0x9D);
  65. },
  66. _ => panic!(),
  67. }
  68. }