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.

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