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.

238 lines
8.1 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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 elseware::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::new();
  14. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  15. let mag = entity_gateway.create_item(
  16. item::NewItemEntity {
  17. item: item::ItemDetail::Mag(
  18. item::mag::Mag::baby_mag(0)
  19. ),
  20. location: item::ItemLocation::Inventory {
  21. character_id: char1.id,
  22. //equipped: true,
  23. }
  24. }).await.unwrap();
  25. let mut monomates = Vec::new();
  26. for _ in 0..7usize {
  27. monomates.push(entity_gateway.create_item(
  28. item::NewItemEntity {
  29. item: item::ItemDetail::Tool(
  30. item::tool::Tool {
  31. tool: item::tool::ToolType::Monomate,
  32. wrapping: None,
  33. }
  34. ),
  35. location: item::ItemLocation::Inventory {
  36. character_id: char1.id,
  37. }
  38. }).await.unwrap());
  39. }
  40. let equipped = item::EquippedEntity {
  41. weapon: None,
  42. armor: None,
  43. shield: None,
  44. unit: [None; 4],
  45. mag: Some(mag.id),
  46. };
  47. entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
  48. let mut inventory = Vec::new();
  49. inventory.push(mag.into());
  50. inventory.push(item::InventoryItemEntity::Stacked(monomates));
  51. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  52. let mut ship = Box::new(ShipServerState::builder()
  53. .gateway(entity_gateway.clone())
  54. .build());
  55. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  56. join_lobby(&mut ship, ClientId(1)).await;
  57. create_room(&mut ship, ClientId(1), "room", "").await;
  58. for _ in 0..7usize {
  59. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(PlayerFeedMag {
  60. client: 0,
  61. target: 0,
  62. mag_id: 0x10000,
  63. item_id: 0x10001,
  64. })))).await.unwrap().for_each(drop);
  65. }
  66. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  67. assert_eq!(inventory_items.items.len(), 1);
  68. inventory_items.items[0].with_individual(|item| {
  69. match &item.item {
  70. item::ItemDetail::Mag(mag) => {
  71. println!("mag! {:?}", mag);
  72. assert!(mag.level() == 7);
  73. assert!(mag.def() == 5);
  74. assert!(mag.pow() == 2);
  75. assert!(mag.dex() == 0);
  76. assert!(mag.mind() == 0);
  77. }
  78. _ => panic!()
  79. }
  80. }).unwrap();
  81. }
  82. #[async_std::test]
  83. async fn test_mag_change_owner() {
  84. let mut entity_gateway = InMemoryGateway::new();
  85. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  86. let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  87. char1.char_class = CharacterClass::RAmarl;
  88. char1.section_id = SectionID::Redria;
  89. entity_gateway.save_character(&char1).await.unwrap();
  90. char2.char_class = CharacterClass::FOmarl;
  91. char2.section_id = SectionID::Whitill;
  92. entity_gateway.save_character(&char2).await.unwrap();
  93. let mag = entity_gateway.create_item(
  94. item::NewItemEntity {
  95. item: item::ItemDetail::Mag(
  96. item::mag::Mag::baby_mag(0)
  97. ),
  98. location: item::ItemLocation::Inventory {
  99. character_id: char1.id,
  100. }
  101. }).await.unwrap();
  102. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![mag])).await.unwrap();
  103. let mut ship = Box::new(ShipServerState::builder()
  104. .gateway(entity_gateway.clone())
  105. .build());
  106. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  107. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  108. join_lobby(&mut ship, ClientId(1)).await;
  109. join_lobby(&mut ship, ClientId(2)).await;
  110. create_room(&mut ship, ClientId(1), "room", "").await;
  111. join_room(&mut ship, ClientId(2), 0).await;
  112. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  113. client: 0,
  114. target: 0,
  115. unknown1: 0,
  116. map_area: 0,
  117. item_id: 0x10000,
  118. x: 0.0,
  119. y: 0.0,
  120. z: 0.0,
  121. })))).await.unwrap().for_each(drop);
  122. ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  123. client: 0,
  124. target: 0,
  125. item_id: 0x10000,
  126. map_area: 0,
  127. unknown: [0; 3]
  128. })))).await.unwrap().for_each(drop);
  129. let inventory_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  130. assert_eq!(inventory_items.items.len(), 1);
  131. inventory_items.items[0].with_individual(|item| {
  132. match &item.item {
  133. item::ItemDetail::Mag(mag) => {
  134. assert!(mag.class == CharacterClass::FOmarl);
  135. assert!(mag.id == SectionID::Whitill);
  136. }
  137. _ => panic!()
  138. }
  139. }).unwrap();
  140. }
  141. #[async_std::test]
  142. async fn test_mag_cell() {
  143. let mut entity_gateway = InMemoryGateway::new();
  144. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  145. let mag = entity_gateway.create_item(
  146. item::NewItemEntity {
  147. item: item::ItemDetail::Mag(
  148. item::mag::Mag::baby_mag(0)
  149. ),
  150. location: item::ItemLocation::Inventory {
  151. character_id: char1.id,
  152. }
  153. }).await.unwrap();
  154. for _ in 0..1000usize {
  155. let fed_tool = entity_gateway.create_item(
  156. item::NewItemEntity {
  157. item: item::ItemDetail::Tool (
  158. item::tool::Tool {
  159. tool: item::tool::ToolType::Monomate,
  160. wrapping: None,
  161. }
  162. ),
  163. location: item::ItemLocation::FedToMag {
  164. mag: mag.id,
  165. }
  166. }).await.unwrap();
  167. entity_gateway.feed_mag(&mag.id, &fed_tool.id).await.unwrap();
  168. }
  169. let mag_cell = entity_gateway.create_item(
  170. item::NewItemEntity {
  171. item: item::ItemDetail::Tool(
  172. item::tool::Tool {
  173. tool: item::tool::ToolType::CellOfMag502,
  174. wrapping: None,
  175. }
  176. ),
  177. location: item::ItemLocation::Inventory {
  178. character_id: char1.id,
  179. }
  180. }).await.unwrap();
  181. let equipped = item::EquippedEntity {
  182. weapon: None,
  183. armor: None,
  184. shield: None,
  185. unit: [None; 4],
  186. mag: Some(mag.id),
  187. };
  188. entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
  189. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![mag, mag_cell])).await.unwrap();
  190. let mut ship = Box::new(ShipServerState::builder()
  191. .gateway(entity_gateway.clone())
  192. .build());
  193. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  194. join_lobby(&mut ship, ClientId(1)).await;
  195. create_room(&mut ship, ClientId(1), "room", "").await;
  196. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  197. client: 0,
  198. target: 0,
  199. item_id: 0x10001,
  200. })))).await.unwrap().for_each(drop);
  201. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  202. inventory_items.items[0].with_individual(|item| {
  203. match &item.item {
  204. item::ItemDetail::Mag(mag) => {
  205. assert_eq!(mag.mag, item::mag::MagType::Soniti);
  206. }
  207. _ => panic!()
  208. }
  209. }).unwrap();
  210. }