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.

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