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.

74 lines
2.3 KiB

4 years ago
  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::entity::item;
  4. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  5. use libpso::packet::ship::*;
  6. use libpso::packet::messages::*;
  7. #[path = "common.rs"]
  8. mod common;
  9. use common::*;
  10. #[async_std::test]
  11. async fn test_mag_feed() {
  12. let mut entity_gateway = InMemoryGateway::new();
  13. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  14. entity_gateway.create_item(
  15. item::NewItemEntity {
  16. item: item::ItemDetail::Mag(
  17. item::mag::Mag::baby_mag(0)
  18. ),
  19. location: item::ItemLocation::Inventory {
  20. character_id: char1.id,
  21. slot: 0,
  22. equipped: true,
  23. }
  24. }).await;
  25. for _ in 0..7 {
  26. entity_gateway.create_item(
  27. item::NewItemEntity {
  28. item: item::ItemDetail::Tool(
  29. item::tool::Tool {
  30. tool: item::tool::ToolType::Monomate,
  31. }
  32. ),
  33. location: item::ItemLocation::Inventory {
  34. character_id: char1.id,
  35. slot: 1,
  36. equipped: false,
  37. }
  38. }).await;
  39. }
  40. let mut ship = ShipServerState::builder()
  41. .gateway(entity_gateway.clone())
  42. .build();
  43. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  44. join_lobby(&mut ship, ClientId(1)).await;
  45. create_room(&mut ship, ClientId(1), "room", "").await;
  46. for _ in 0..7 {
  47. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(PlayerFeedMag {
  48. client: 0,
  49. target: 0,
  50. mag_id: 0x10000,
  51. item_id: 0x10001,
  52. })))).await.unwrap().for_each(drop);
  53. }
  54. let p1_items = entity_gateway.get_items_by_character(&char1).await;
  55. let mag = p1_items.get(0).unwrap();
  56. match &mag.item {
  57. item::ItemDetail::Mag(mag) => {
  58. assert!(mag.level() == 7);
  59. assert!(mag.def() == 5);
  60. assert!(mag.pow() == 2);
  61. assert!(mag.dex() == 0);
  62. assert!(mag.mind() == 0);
  63. }
  64. _ => panic!()
  65. }
  66. }