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.

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