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.

289 lines
10 KiB

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::ship::items::{ClientItemId, ActiveItemEntityId, HeldItemType, FloorItemType};
  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_use_monomate() {
  13. let mut entity_gateway = InMemoryGateway::new();
  14. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  15. let mut p1_items = Vec::new();
  16. for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() {
  17. let mut item = Vec::new();
  18. for _ in 0..2usize {
  19. item.push(entity_gateway.create_item(
  20. item::NewItemEntity {
  21. item: item::ItemDetail::Tool(
  22. item::tool::Tool {
  23. tool: tool,
  24. wrapping: None,
  25. }
  26. ),
  27. location: item::ItemLocation::Inventory {
  28. character_id: char1.id,
  29. }
  30. }).await.unwrap());
  31. }
  32. p1_items.push(item::InventoryItemEntity::Stacked(item));
  33. }
  34. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap();
  35. let mut ship = Box::new(ShipServerState::builder()
  36. .gateway(entity_gateway.clone())
  37. .build());
  38. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  39. join_lobby(&mut ship, ClientId(1)).await;
  40. create_room(&mut ship, ClientId(1), "room", "").await;
  41. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  42. client: 0,
  43. target: 0,
  44. item_id: 0x10000,
  45. })))).await.unwrap().for_each(drop);
  46. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  47. assert_eq!(inventory_items.items.len(), 2);
  48. inventory_items.items[0].with_stacked(|items| {
  49. assert_eq!(items.len(), 1)
  50. }).unwrap();
  51. inventory_items.items[1].with_stacked(|items| {
  52. assert_eq!(items.len(), 2)
  53. }).unwrap();
  54. }
  55. #[async_std::test]
  56. async fn test_use_monomate_twice() {
  57. let mut entity_gateway = InMemoryGateway::new();
  58. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  59. let mut p1_items = Vec::new();
  60. for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() {
  61. let mut item = Vec::new();
  62. for _ in 0..3usize {
  63. item.push(entity_gateway.create_item(
  64. item::NewItemEntity {
  65. item: item::ItemDetail::Tool(
  66. item::tool::Tool {
  67. tool: tool,
  68. wrapping: None,
  69. }
  70. ),
  71. location: item::ItemLocation::Inventory {
  72. character_id: char1.id,
  73. }
  74. }).await.unwrap());
  75. }
  76. p1_items.push(item::InventoryItemEntity::Stacked(item));
  77. }
  78. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap();
  79. let mut ship = Box::new(ShipServerState::builder()
  80. .gateway(entity_gateway.clone())
  81. .build());
  82. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  83. join_lobby(&mut ship, ClientId(1)).await;
  84. create_room(&mut ship, ClientId(1), "room", "").await;
  85. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  86. client: 0,
  87. target: 0,
  88. item_id: 0x10000,
  89. })))).await.unwrap().for_each(drop);
  90. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  91. client: 0,
  92. target: 0,
  93. item_id: 0x10000,
  94. })))).await.unwrap().for_each(drop);
  95. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  96. assert_eq!(inventory_items.items.len(), 2);
  97. inventory_items.items[0].with_stacked(|items| {
  98. assert_eq!(items.len(), 1)
  99. }).unwrap();
  100. inventory_items.items[1].with_stacked(|items| {
  101. assert_eq!(items.len(), 3)
  102. }).unwrap();
  103. }
  104. #[async_std::test]
  105. async fn test_use_last_monomate() {
  106. let mut entity_gateway = InMemoryGateway::new();
  107. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  108. let mut p1_inv = Vec::new();
  109. for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() {
  110. p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item(
  111. item::NewItemEntity {
  112. item: item::ItemDetail::Tool(
  113. item::tool::Tool {
  114. tool: tool,
  115. wrapping: None,
  116. }
  117. ),
  118. location: item::ItemLocation::Inventory {
  119. character_id: char1.id,
  120. }
  121. }).await.unwrap()]));
  122. }
  123. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  124. let mut ship = Box::new(ShipServerState::builder()
  125. .gateway(entity_gateway.clone())
  126. .build());
  127. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  128. join_lobby(&mut ship, ClientId(1)).await;
  129. create_room(&mut ship, ClientId(1), "room", "").await;
  130. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  131. client: 0,
  132. target: 0,
  133. item_id: 0x10000,
  134. })))).await.unwrap().for_each(drop);
  135. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  136. assert_eq!(inventory_items.items.len(), 1);
  137. inventory_items.items[0].with_stacked(|items| {
  138. assert_eq!(items.len(), 1);
  139. assert_eq!(items[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monofluid));
  140. }).unwrap();
  141. }
  142. #[async_std::test]
  143. async fn test_use_nonstackable_tool() {
  144. let mut entity_gateway = InMemoryGateway::new();
  145. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  146. let mut p1_items = Vec::new();
  147. p1_items.push(entity_gateway.create_item(
  148. item::NewItemEntity {
  149. item: item::ItemDetail::Tool(
  150. item::tool::Tool {
  151. tool: item::tool::ToolType::MagicStoneIritista,
  152. wrapping: None,
  153. }
  154. ),
  155. location: item::ItemLocation::Inventory {
  156. character_id: char1.id,
  157. }
  158. }).await.unwrap());
  159. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap();
  160. let mut ship = Box::new(ShipServerState::builder()
  161. .gateway(entity_gateway.clone())
  162. .build());
  163. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  164. join_lobby(&mut ship, ClientId(1)).await;
  165. create_room(&mut ship, ClientId(1), "room", "").await;
  166. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  167. client: 0,
  168. target: 0,
  169. item_id: 0x10000,
  170. })))).await.unwrap().for_each(drop);
  171. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  172. assert_eq!(inventory_items.items.len(), 0);
  173. }
  174. #[async_std::test]
  175. async fn test_use_materials() {
  176. let mut entity_gateway = InMemoryGateway::new();
  177. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  178. let mut p1_inv = Vec::new();
  179. for tool in vec![item::tool::ToolType::PowerMaterial, item::tool::ToolType::LuckMaterial].into_iter() {
  180. let mut item = Vec::new();
  181. for _ in 0..5usize {
  182. item.push(entity_gateway.create_item(
  183. item::NewItemEntity {
  184. item: item::ItemDetail::Tool(
  185. item::tool::Tool {
  186. tool: tool,
  187. wrapping: None,
  188. }
  189. ),
  190. location: item::ItemLocation::Inventory {
  191. character_id: char1.id,
  192. }
  193. }).await.unwrap());
  194. }
  195. p1_inv.push(item::InventoryItemEntity::Stacked(item));
  196. }
  197. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  198. let mut ship = Box::new(ShipServerState::builder()
  199. .gateway(entity_gateway.clone())
  200. .build());
  201. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  202. join_lobby(&mut ship, ClientId(1)).await;
  203. create_room(&mut ship, ClientId(1), "room", "").await;
  204. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  205. client: 0,
  206. target: 0,
  207. item_id: 0x10000,
  208. })))).await.unwrap().for_each(drop);
  209. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  210. client: 0,
  211. target: 0,
  212. item_id: 0x10001,
  213. })))).await.unwrap().for_each(drop);
  214. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  215. client: 0,
  216. target: 0,
  217. item_id: 0x10001,
  218. })))).await.unwrap().for_each(drop);
  219. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  220. assert_eq!(inventory_items.items.len(), 2);
  221. inventory_items.items[0].with_stacked(|items| {
  222. assert_eq!(items.len(), 4)
  223. }).unwrap();
  224. inventory_items.items[1].with_stacked(|items| {
  225. assert_eq!(items.len(), 3)
  226. }).unwrap();
  227. let characters = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  228. let char = characters[0].as_ref().unwrap();
  229. assert!(char.materials.power == 1);
  230. assert!(char.materials.luck == 2);
  231. }
  232. #[async_std::test]
  233. pub async fn test_learn_new_tech() {}
  234. #[async_std::test]
  235. pub async fn test_new_fo_has_foie_1() {}
  236. #[async_std::test]
  237. pub async fn test_char_cannot_use_lower_level_tech() {}
  238. #[async_std::test]
  239. pub async fn test_char_cannot_learn_wrong_tech() {}
  240. #[async_std::test]
  241. pub async fn test_char_cannot_learn_high_level_tech() {}
  242. #[async_std::test]
  243. pub async fn test_android_cannot_learn_tech() {}