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
6.8 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
  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. 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. slot: 0,
  23. equipped: true,
  24. }
  25. }).await.unwrap();
  26. for _ in 0..7 {
  27. entity_gateway.create_item(
  28. item::NewItemEntity {
  29. item: item::ItemDetail::Tool(
  30. item::tool::Tool {
  31. tool: item::tool::ToolType::Monomate,
  32. }
  33. ),
  34. location: item::ItemLocation::Inventory {
  35. character_id: char1.id,
  36. slot: 1,
  37. equipped: false,
  38. }
  39. }).await.unwrap();
  40. }
  41. let mut ship = ShipServerState::builder()
  42. .gateway(entity_gateway.clone())
  43. .build();
  44. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  45. join_lobby(&mut ship, ClientId(1)).await;
  46. create_room(&mut ship, ClientId(1), "room", "").await;
  47. for _ in 0..7 {
  48. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(PlayerFeedMag {
  49. client: 0,
  50. target: 0,
  51. mag_id: 0x10000,
  52. item_id: 0x10001,
  53. })))).await.unwrap().for_each(drop);
  54. }
  55. let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap();
  56. let mag = p1_items.get(0).unwrap();
  57. match &mag.item {
  58. item::ItemDetail::Mag(mag) => {
  59. assert!(mag.level() == 7);
  60. assert!(mag.def() == 5);
  61. assert!(mag.pow() == 2);
  62. assert!(mag.dex() == 0);
  63. assert!(mag.mind() == 0);
  64. }
  65. _ => panic!()
  66. }
  67. }
  68. #[async_std::test]
  69. async fn test_mag_change_owner() {
  70. let mut entity_gateway = InMemoryGateway::new();
  71. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  72. let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  73. char1.char_class = CharacterClass::RAmarl;
  74. char1.section_id = SectionID::Redria;
  75. entity_gateway.save_character(&char1).await.unwrap();
  76. char2.char_class = CharacterClass::FOmarl;
  77. char2.section_id = SectionID::Whitill;
  78. entity_gateway.save_character(&char2).await.unwrap();
  79. entity_gateway.create_item(
  80. item::NewItemEntity {
  81. item: item::ItemDetail::Mag(
  82. item::mag::Mag::baby_mag(0)
  83. ),
  84. location: item::ItemLocation::Inventory {
  85. character_id: char1.id,
  86. slot: 0,
  87. equipped: true,
  88. }
  89. }).await.unwrap();
  90. let mut ship = ShipServerState::builder()
  91. .gateway(entity_gateway.clone())
  92. .build();
  93. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  94. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  95. join_lobby(&mut ship, ClientId(1)).await;
  96. join_lobby(&mut ship, ClientId(2)).await;
  97. create_room(&mut ship, ClientId(1), "room", "").await;
  98. join_room(&mut ship, ClientId(2), 0).await;
  99. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  100. client: 0,
  101. target: 0,
  102. unknown1: 0,
  103. map_area: 0,
  104. item_id: 0x10000,
  105. x: 0.0,
  106. y: 0.0,
  107. z: 0.0,
  108. })))).await.unwrap().for_each(drop);
  109. ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  110. client: 0,
  111. target: 0,
  112. item_id: 0x10000,
  113. map_area: 0,
  114. unknown: [0; 3]
  115. })))).await.unwrap().for_each(drop);
  116. let p2_items = entity_gateway.get_items_by_character(&char2).await.unwrap();
  117. let mag = p2_items.get(0).unwrap();
  118. match &mag.item {
  119. item::ItemDetail::Mag(mag) => {
  120. assert!(mag.class == CharacterClass::FOmarl);
  121. assert!(mag.id == SectionID::Whitill);
  122. },
  123. _ => panic!()
  124. }
  125. }
  126. #[async_std::test]
  127. async fn test_mag_cell() {
  128. let mut entity_gateway = InMemoryGateway::new();
  129. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").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. location: item::ItemLocation::Inventory {
  136. character_id: char1.id,
  137. slot: 0,
  138. equipped: true,
  139. }
  140. }).await.unwrap();
  141. for _ in 0..1000 {
  142. let fed_tool = entity_gateway.create_item(
  143. item::NewItemEntity {
  144. item: item::ItemDetail::Tool (
  145. item::tool::Tool {
  146. tool: item::tool::ToolType::Monomate,
  147. }
  148. ),
  149. location: item::ItemLocation::FedToMag {
  150. mag: mag.id,
  151. }
  152. }).await.unwrap();
  153. entity_gateway.feed_mag(&mag.id, &fed_tool.id).await.unwrap();
  154. }
  155. entity_gateway.create_item(
  156. item::NewItemEntity {
  157. item: item::ItemDetail::Tool(
  158. item::tool::Tool {
  159. tool: item::tool::ToolType::CellOfMag502,
  160. }
  161. ),
  162. location: item::ItemLocation::Inventory {
  163. character_id: char1.id,
  164. slot: 1,
  165. equipped: false,
  166. }
  167. }).await.unwrap();
  168. let mut ship = 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 p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap();
  180. let mag = p1_items.get(0).unwrap();
  181. match &mag.item {
  182. item::ItemDetail::Mag(mag) => {
  183. assert!(mag.mag == item::mag::MagType::Soniti);
  184. }
  185. _ => panic!()
  186. }
  187. }