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.

586 lines
22 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
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
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
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::ship::room::Difficulty;
  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_player_opens_weapon_shop() {
  13. let mut entity_gateway = InMemoryGateway::new();
  14. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  15. char1.exp = 80000000;
  16. entity_gateway.save_character(&char1).await.unwrap();
  17. let mut ship = Box::new(ShipServerState::builder()
  18. .gateway(entity_gateway.clone())
  19. .build());
  20. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  21. join_lobby(&mut ship, ClientId(1)).await;
  22. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  23. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  24. client: 255,
  25. target: 255,
  26. shop_type: 1
  27. })))).await.unwrap().collect::<Vec<_>>();
  28. assert_eq!(packets.len(), 1);
  29. match &packets[0].1 {
  30. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  31. assert_eq!(shop_list.items.len(), 16)
  32. }
  33. _ => panic!("")
  34. }
  35. }
  36. #[async_std::test]
  37. async fn test_player_opens_tool_shop() {
  38. let mut entity_gateway = InMemoryGateway::new();
  39. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  40. char1.exp = 80000000;
  41. entity_gateway.save_character(&char1).await.unwrap();
  42. let mut ship = Box::new(ShipServerState::builder()
  43. .gateway(entity_gateway.clone())
  44. .build());
  45. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  46. join_lobby(&mut ship, ClientId(1)).await;
  47. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  48. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  49. client: 255,
  50. target: 255,
  51. shop_type: 0
  52. })))).await.unwrap().collect::<Vec<_>>();
  53. assert_eq!(packets.len(), 1);
  54. match &packets[0].1 {
  55. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  56. assert_eq!(shop_list.items.len(), 18)
  57. }
  58. _ => panic!("")
  59. }
  60. }
  61. #[async_std::test]
  62. async fn test_player_opens_armor_shop() {
  63. let mut entity_gateway = InMemoryGateway::new();
  64. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  65. char1.exp = 80000000;
  66. entity_gateway.save_character(&char1).await.unwrap();
  67. let mut ship = Box::new(ShipServerState::builder()
  68. .gateway(entity_gateway.clone())
  69. .build());
  70. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  71. join_lobby(&mut ship, ClientId(1)).await;
  72. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  73. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  74. client: 255,
  75. target: 255,
  76. shop_type: 2
  77. })))).await.unwrap().collect::<Vec<_>>();
  78. assert_eq!(packets.len(), 1);
  79. match &packets[0].1 {
  80. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  81. assert_eq!(shop_list.items.len(), 21)
  82. }
  83. _ => panic!("")
  84. }
  85. }
  86. #[async_std::test]
  87. async fn test_player_buys_from_weapon_shop() {
  88. let mut entity_gateway = InMemoryGateway::new();
  89. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  90. char1.exp = 80000000;
  91. char1.meseta = 999999;
  92. entity_gateway.save_character(&char1).await.unwrap();
  93. let mut ship = Box::new(ShipServerState::builder()
  94. .gateway(entity_gateway.clone())
  95. .build());
  96. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  97. join_lobby(&mut ship, ClientId(1)).await;
  98. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  99. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  100. client: 255,
  101. target: 255,
  102. shop_type: 1
  103. })))).await.unwrap().for_each(drop);
  104. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  105. client: 255,
  106. target: 255,
  107. item_id: 0x10000,
  108. shop_type: 1,
  109. shop_index: 0,
  110. amount: 1,
  111. unknown1: 0,
  112. })))).await.unwrap().for_each(drop);
  113. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  114. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  115. assert!(c1.meseta < 999999);
  116. //let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
  117. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  118. assert_eq!(p1_items.items.len(), 1);
  119. }
  120. #[async_std::test]
  121. async fn test_player_buys_from_tool_shop() {
  122. let mut entity_gateway = InMemoryGateway::new();
  123. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  124. char1.exp = 80000000;
  125. char1.meseta = 999999;
  126. entity_gateway.save_character(&char1).await.unwrap();
  127. let mut ship = Box::new(ShipServerState::builder()
  128. .gateway(entity_gateway.clone())
  129. .build());
  130. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  131. join_lobby(&mut ship, ClientId(1)).await;
  132. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  133. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  134. client: 255,
  135. target: 255,
  136. shop_type: 0,
  137. })))).await.unwrap().for_each(drop);
  138. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  139. client: 255,
  140. target: 255,
  141. item_id: 0x10000,
  142. shop_type: 0,
  143. shop_index: 0,
  144. amount: 1,
  145. unknown1: 0,
  146. })))).await.unwrap().for_each(drop);
  147. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  148. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  149. assert!(c1.meseta < 999999);
  150. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  151. assert_eq!(p1_items.items.len(), 1);
  152. }
  153. #[async_std::test]
  154. async fn test_player_buys_multiple_from_tool_shop() {
  155. let mut entity_gateway = InMemoryGateway::new();
  156. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  157. char1.exp = 80000000;
  158. char1.meseta = 999999;
  159. entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  166. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  167. client: 255,
  168. target: 255,
  169. shop_type: 0,
  170. })))).await.unwrap().for_each(drop);
  171. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  172. client: 255,
  173. target: 255,
  174. item_id: 0x10000,
  175. shop_type: 0,
  176. shop_index: 0,
  177. amount: 5,
  178. unknown1: 0,
  179. })))).await.unwrap().for_each(drop);
  180. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  181. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  182. assert!(c1.meseta < 999999);
  183. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  184. assert_eq!(p1_items.items.len(), 1);
  185. p1_items.items[0].with_stacked(|item| {
  186. assert_eq!(item.len(), 5);
  187. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  188. }).unwrap();
  189. }
  190. #[async_std::test]
  191. async fn test_player_buys_from_armor_shop() {
  192. let mut entity_gateway = InMemoryGateway::new();
  193. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  194. char1.exp = 80000000;
  195. char1.meseta = 999999;
  196. entity_gateway.save_character(&char1).await.unwrap();
  197. let mut ship = Box::new(ShipServerState::builder()
  198. .gateway(entity_gateway.clone())
  199. .build());
  200. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  201. join_lobby(&mut ship, ClientId(1)).await;
  202. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  203. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  204. client: 255,
  205. target: 255,
  206. shop_type: 2
  207. })))).await.unwrap().for_each(drop);
  208. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  209. client: 255,
  210. target: 255,
  211. item_id: 0x10000,
  212. shop_type: 2,
  213. shop_index: 0,
  214. amount: 1,
  215. unknown1: 0,
  216. })))).await.unwrap().for_each(drop);
  217. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  218. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  219. assert!(c1.meseta < 999999);
  220. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  221. assert_eq!(p1_items.items.len(), 1);
  222. }
  223. #[async_std::test]
  224. async fn test_player_sells_to_shop() {
  225. }
  226. #[async_std::test]
  227. async fn test_other_clients_see_purchase() {
  228. let mut entity_gateway = InMemoryGateway::new();
  229. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  230. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  231. char1.exp = 80000000;
  232. char1.meseta = 999999;
  233. entity_gateway.save_character(&char1).await.unwrap();
  234. let mut ship = Box::new(ShipServerState::builder()
  235. .gateway(entity_gateway.clone())
  236. .build());
  237. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  238. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  239. join_lobby(&mut ship, ClientId(1)).await;
  240. join_lobby(&mut ship, ClientId(2)).await;
  241. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  242. join_room(&mut ship, ClientId(2), 0).await;
  243. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  244. client: 255,
  245. target: 255,
  246. shop_type: 1
  247. })))).await.unwrap().for_each(drop);
  248. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  249. client: 255,
  250. target: 255,
  251. item_id: 0x10000,
  252. shop_type: 1,
  253. shop_index: 0,
  254. amount: 1,
  255. unknown1: 0,
  256. })))).await.unwrap().collect::<Vec<_>>();
  257. assert_eq!(packets.len(), 1);
  258. assert_eq!(packets[0].0, ClientId(2));
  259. match &packets[0].1 {
  260. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  261. _ => panic!(""),
  262. }
  263. }
  264. #[async_std::test]
  265. async fn test_other_clients_see_stacked_purchase() {
  266. let mut entity_gateway = InMemoryGateway::new();
  267. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  268. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  269. char1.exp = 80000000;
  270. char1.meseta = 999999;
  271. entity_gateway.save_character(&char1).await.unwrap();
  272. entity_gateway.create_item(
  273. item::NewItemEntity {
  274. item: item::ItemDetail::Tool(
  275. item::tool::Tool {
  276. tool: item::tool::ToolType::Monomate,
  277. wrapping: None,
  278. }
  279. ),
  280. location: item::ItemLocation::Inventory {
  281. character_id: char1.id,
  282. }
  283. }).await.unwrap();
  284. let mut ship = Box::new(ShipServerState::builder()
  285. .gateway(entity_gateway.clone())
  286. .build());
  287. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  288. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  289. join_lobby(&mut ship, ClientId(1)).await;
  290. join_lobby(&mut ship, ClientId(2)).await;
  291. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  292. join_room(&mut ship, ClientId(2), 0).await;
  293. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  294. client: 255,
  295. target: 255,
  296. shop_type: 1
  297. })))).await.unwrap().for_each(drop);
  298. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  299. client: 255,
  300. target: 255,
  301. item_id: 0x10000,
  302. shop_type: 1,
  303. shop_index: 0,
  304. amount: 1,
  305. unknown1: 0,
  306. })))).await.unwrap().collect::<Vec<_>>();
  307. assert_eq!(packets.len(), 1);
  308. assert_eq!(packets[0].0, ClientId(2));
  309. match &packets[0].1 {
  310. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  311. _ => panic!(""),
  312. }
  313. }
  314. #[async_std::test]
  315. async fn test_buying_item_without_enough_mseseta() {
  316. let mut entity_gateway = InMemoryGateway::new();
  317. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  318. let mut ship = Box::new(ShipServerState::builder()
  319. .gateway(entity_gateway.clone())
  320. .build());
  321. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  322. join_lobby(&mut ship, ClientId(1)).await;
  323. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  324. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  325. client: 255,
  326. target: 255,
  327. shop_type: 1
  328. })))).await.unwrap().for_each(drop);
  329. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  330. client: 255,
  331. target: 255,
  332. item_id: 0x10000,
  333. shop_type: 1,
  334. shop_index: 0,
  335. amount: 1,
  336. unknown1: 0,
  337. })))).await;
  338. assert!(packets.is_err());
  339. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  340. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  341. assert_eq!(c1.meseta, 0);
  342. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  343. assert_eq!(p1_items.items.len(), 0);
  344. }
  345. #[async_std::test]
  346. async fn test_player_double_buys_from_tool_shop() {
  347. let mut entity_gateway = InMemoryGateway::new();
  348. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  349. char1.exp = 80000000;
  350. char1.meseta = 999999;
  351. entity_gateway.save_character(&char1).await.unwrap();
  352. let mut ship = Box::new(ShipServerState::builder()
  353. .gateway(entity_gateway.clone())
  354. .build());
  355. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  356. join_lobby(&mut ship, ClientId(1)).await;
  357. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  358. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  359. client: 255,
  360. target: 255,
  361. shop_type: 0,
  362. })))).await.unwrap().for_each(drop);
  363. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  364. client: 255,
  365. target: 255,
  366. item_id: 0x10000,
  367. shop_type: 0,
  368. shop_index: 0,
  369. amount: 3,
  370. unknown1: 0,
  371. })))).await.unwrap().for_each(drop);
  372. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  373. client: 255,
  374. target: 255,
  375. item_id: 0x10001,
  376. shop_type: 0,
  377. shop_index: 1,
  378. amount: 2,
  379. unknown1: 0,
  380. })))).await.unwrap().for_each(drop);
  381. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  382. client: 255,
  383. target: 255,
  384. item_id: 0x10002,
  385. shop_type: 0,
  386. shop_index: 0,
  387. amount: 4,
  388. unknown1: 0,
  389. })))).await.unwrap().for_each(drop);
  390. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  391. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  392. assert!(c1.meseta < 999999);
  393. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  394. assert_eq!(p1_items.items.len(), 2);
  395. p1_items.items[0].with_stacked(|item| {
  396. assert_eq!(item.len(), 7);
  397. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  398. }).unwrap();
  399. p1_items.items[1].with_stacked(|item| {
  400. assert_eq!(item.len(), 2);
  401. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Dimate));
  402. }).unwrap();
  403. }
  404. #[async_std::test]
  405. async fn test_techs_disappear_from_shop_when_bought() {
  406. let mut entity_gateway = InMemoryGateway::new();
  407. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  408. char1.exp = 80000000;
  409. char1.meseta = 999999;
  410. entity_gateway.save_character(&char1).await.unwrap();
  411. let mut ship = Box::new(ShipServerState::builder()
  412. .gateway(entity_gateway.clone())
  413. .build());
  414. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  415. join_lobby(&mut ship, ClientId(1)).await;
  416. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  417. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  418. client: 255,
  419. target: 255,
  420. shop_type: 0,
  421. })))).await.unwrap().collect::<Vec<_>>();
  422. let first_tech = match &packets[0].1 {
  423. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  424. shop_list.items.iter()
  425. .enumerate()
  426. .filter(|(_, item)| {
  427. item.item_bytes[0] == 3 && item.item_bytes[1] == 2
  428. })
  429. .nth(0).unwrap().0
  430. },
  431. _ => panic!(""),
  432. };
  433. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  434. client: 255,
  435. target: 255,
  436. item_id: 0x10000,
  437. shop_type: 0,
  438. shop_index: first_tech as u8,
  439. amount: 1,
  440. unknown1: 0,
  441. })))).await.unwrap().for_each(drop);
  442. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  443. client: 255,
  444. target: 255,
  445. item_id: 0x10001,
  446. shop_type: 0,
  447. shop_index: first_tech as u8,
  448. amount: 1,
  449. unknown1: 0,
  450. })))).await.unwrap().for_each(drop);
  451. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  452. p1_items.items[0].with_individual(|item1| {
  453. p1_items.items[1].with_individual(|item2| {
  454. assert_ne!(item1, item2);
  455. }).unwrap();
  456. }).unwrap();
  457. }
  458. // TOOD: this is not deterministic and can randomly fail
  459. #[async_std::test]
  460. async fn test_units_disappear_from_shop_when_bought() {
  461. let mut entity_gateway = InMemoryGateway::new();
  462. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  463. char1.exp = 80000000;
  464. char1.meseta = 999999;
  465. entity_gateway.save_character(&char1).await.unwrap();
  466. let mut ship = Box::new(ShipServerState::builder()
  467. .gateway(entity_gateway.clone())
  468. .build());
  469. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  470. join_lobby(&mut ship, ClientId(1)).await;
  471. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  472. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  473. client: 255,
  474. target: 255,
  475. shop_type: 2,
  476. })))).await.unwrap().collect::<Vec<_>>();
  477. let first_unit = match &packets[0].1 {
  478. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  479. shop_list.items.iter()
  480. .enumerate()
  481. .filter(|(_, item)| {
  482. item.item_bytes[0] == 1 && item.item_bytes[1] == 3
  483. })
  484. .nth(0).unwrap().0
  485. },
  486. _ => panic!(""),
  487. };
  488. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  489. client: 255,
  490. target: 255,
  491. item_id: 0x10000,
  492. shop_type: 2,
  493. shop_index: first_unit as u8,
  494. amount: 1,
  495. unknown1: 0,
  496. })))).await.unwrap().for_each(drop);
  497. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  498. client: 255,
  499. target: 255,
  500. item_id: 0x10001,
  501. shop_type: 2,
  502. shop_index: first_unit as u8,
  503. amount: 1,
  504. unknown1: 0,
  505. })))).await.unwrap().for_each(drop);
  506. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  507. p1_items.items[0].with_individual(|item1| {
  508. p1_items.items[1].with_individual(|item2| {
  509. assert_ne!(item1, item2);
  510. }).unwrap();
  511. }).unwrap();
  512. }