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.

192 lines
6.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use entity::item;
  4. use ship_server::RecvShipPacket;
  5. use entity::character::{CharacterClass, SectionID};
  6. use libpso::packet::ship::*;
  7. use libpso::packet::messages::*;
  8. #[path = "common.rs"]
  9. mod common;
  10. use common::*;
  11. #[async_std::test]
  12. async fn test_mag_feed() {
  13. let mut entity_gateway = InMemoryGateway::default();
  14. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  15. let mag = entity_gateway.create_item(
  16. ItemBuilder::baby_mag()
  17. .as_new()
  18. ).await.unwrap();
  19. let mut monomates = Vec::new();
  20. for _ in 0..7usize {
  21. monomates.push(entity_gateway.create_item(
  22. ItemBuilder::tool(item::tool::ToolType::Monomate)
  23. .as_new()
  24. ).await.unwrap());
  25. }
  26. let equipped = item::EquippedEntity {
  27. weapon: None,
  28. armor: None,
  29. shield: None,
  30. unit: [None; 4],
  31. mag: Some(mag.id),
  32. };
  33. entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
  34. let mut inventory = Vec::new();
  35. inventory.push(mag.into());
  36. inventory.push(item::InventoryItemEntity::Stacked(monomates));
  37. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  38. let mut ship = standard_ship(entity_gateway.clone());
  39. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  40. join_lobby(&mut ship, ClientId(1)).await;
  41. create_room(&mut ship, ClientId(1), "room", "").await;
  42. for _ in 0..7usize {
  43. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(PlayerFeedMag {
  44. client: 0,
  45. target: 0,
  46. mag_id: 0x10000,
  47. item_id: 0x10001,
  48. })))).await.unwrap();
  49. }
  50. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  51. assert_eq!(inventory_items.items.len(), 1);
  52. inventory_items.items[0].with_individual(|item| {
  53. match &item.item {
  54. item::ItemDetail::Mag(mag) => {
  55. println!("mag! {:?}", mag);
  56. assert!(mag.level() == 7);
  57. assert!(mag.def() == 5);
  58. assert!(mag.pow() == 2);
  59. assert!(mag.dex() == 0);
  60. assert!(mag.mind() == 0);
  61. }
  62. _ => panic!()
  63. }
  64. }).unwrap();
  65. }
  66. #[async_std::test]
  67. async fn test_mag_change_owner() {
  68. let mut entity_gateway = InMemoryGateway::default();
  69. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  70. let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  71. char1.char_class = CharacterClass::RAmarl;
  72. char1.section_id = SectionID::Redria;
  73. entity_gateway.save_character(&char1).await.unwrap();
  74. char2.char_class = CharacterClass::FOmarl;
  75. char2.section_id = SectionID::Whitill;
  76. entity_gateway.save_character(&char2).await.unwrap();
  77. let mag = entity_gateway.create_item(
  78. ItemBuilder::baby_mag()
  79. .as_new()
  80. ).await.unwrap();
  81. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![mag])).await.unwrap();
  82. let mut ship = standard_ship(entity_gateway.clone());
  83. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  84. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  85. join_lobby(&mut ship, ClientId(1)).await;
  86. join_lobby(&mut ship, ClientId(2)).await;
  87. create_room(&mut ship, ClientId(1), "room", "").await;
  88. join_room(&mut ship, ClientId(2), 0).await;
  89. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  90. client: 0,
  91. target: 0,
  92. unknown1: 0,
  93. map_area: 0,
  94. item_id: 0x10000,
  95. x: 0.0,
  96. y: 0.0,
  97. z: 0.0,
  98. })))).await.unwrap();
  99. ship.handle(ClientId(2), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  100. client: 0,
  101. target: 0,
  102. item_id: 0x10000,
  103. map_area: 0,
  104. unknown: [0; 3]
  105. })))).await.unwrap();
  106. let inventory_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  107. assert_eq!(inventory_items.items.len(), 1);
  108. inventory_items.items[0].with_individual(|item| {
  109. match &item.item {
  110. item::ItemDetail::Mag(mag) => {
  111. assert!(mag.class == CharacterClass::FOmarl);
  112. assert!(mag.id == SectionID::Whitill);
  113. }
  114. _ => panic!()
  115. }
  116. }).unwrap();
  117. }
  118. #[async_std::test]
  119. async fn test_mag_cell() {
  120. let mut entity_gateway = InMemoryGateway::default();
  121. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  122. let mag = entity_gateway.create_item(
  123. ItemBuilder::baby_mag()
  124. .as_new()
  125. ).await.unwrap();
  126. for _ in 0..1000usize {
  127. let fed_tool = entity_gateway.create_item(
  128. ItemBuilder::tool(item::tool::ToolType::Monomate)
  129. .as_new()
  130. ).await.unwrap();
  131. entity_gateway.feed_mag(&mag.id, &fed_tool.id).await.unwrap();
  132. }
  133. let mag_cell = entity_gateway.create_item(
  134. ItemBuilder::tool(item::tool::ToolType::CellOfMag502)
  135. .as_new()
  136. ).await.unwrap();
  137. let equipped = item::EquippedEntity {
  138. weapon: None,
  139. armor: None,
  140. shield: None,
  141. unit: [None; 4],
  142. mag: Some(mag.id),
  143. };
  144. entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
  145. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![mag, mag_cell])).await.unwrap();
  146. let mut ship = standard_ship(entity_gateway.clone());
  147. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  148. join_lobby(&mut ship, ClientId(1)).await;
  149. create_room(&mut ship, ClientId(1), "room", "").await;
  150. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  151. client: 0,
  152. target: 0,
  153. item_id: 0x10001,
  154. })))).await.unwrap();
  155. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  156. inventory_items.items[0].with_individual(|item| {
  157. match &item.item {
  158. item::ItemDetail::Mag(mag) => {
  159. assert_eq!(mag.mag, item::mag::MagType::Soniti);
  160. }
  161. _ => panic!()
  162. }
  163. }).unwrap();
  164. }