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.

582 lines
21 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
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::default();
  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::default();
  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::default();
  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::default();
  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::default();
  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::default();
  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::default();
  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::default();
  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::default();
  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. }
  278. ),
  279. }).await.unwrap();
  280. let mut ship = Box::new(ShipServerState::builder()
  281. .gateway(entity_gateway.clone())
  282. .build());
  283. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  284. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  285. join_lobby(&mut ship, ClientId(1)).await;
  286. join_lobby(&mut ship, ClientId(2)).await;
  287. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  288. join_room(&mut ship, ClientId(2), 0).await;
  289. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  290. client: 255,
  291. target: 255,
  292. shop_type: 1
  293. })))).await.unwrap().for_each(drop);
  294. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  295. client: 255,
  296. target: 255,
  297. item_id: 0x10000,
  298. shop_type: 1,
  299. shop_index: 0,
  300. amount: 1,
  301. unknown1: 0,
  302. })))).await.unwrap().collect::<Vec<_>>();
  303. assert_eq!(packets.len(), 1);
  304. assert_eq!(packets[0].0, ClientId(2));
  305. match &packets[0].1 {
  306. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  307. _ => panic!(""),
  308. }
  309. }
  310. #[async_std::test]
  311. async fn test_buying_item_without_enough_mseseta() {
  312. let mut entity_gateway = InMemoryGateway::default();
  313. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  314. let mut ship = Box::new(ShipServerState::builder()
  315. .gateway(entity_gateway.clone())
  316. .build());
  317. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  318. join_lobby(&mut ship, ClientId(1)).await;
  319. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  320. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  321. client: 255,
  322. target: 255,
  323. shop_type: 1
  324. })))).await.unwrap().for_each(drop);
  325. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  326. client: 255,
  327. target: 255,
  328. item_id: 0x10000,
  329. shop_type: 1,
  330. shop_index: 0,
  331. amount: 1,
  332. unknown1: 0,
  333. })))).await;
  334. assert!(packets.is_err());
  335. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  336. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  337. assert_eq!(c1.meseta, 0);
  338. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  339. assert_eq!(p1_items.items.len(), 0);
  340. }
  341. #[async_std::test]
  342. async fn test_player_double_buys_from_tool_shop() {
  343. let mut entity_gateway = InMemoryGateway::default();
  344. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  345. char1.exp = 80000000;
  346. char1.meseta = 999999;
  347. entity_gateway.save_character(&char1).await.unwrap();
  348. let mut ship = Box::new(ShipServerState::builder()
  349. .gateway(entity_gateway.clone())
  350. .build());
  351. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  352. join_lobby(&mut ship, ClientId(1)).await;
  353. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  354. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  355. client: 255,
  356. target: 255,
  357. shop_type: 0,
  358. })))).await.unwrap().for_each(drop);
  359. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  360. client: 255,
  361. target: 255,
  362. item_id: 0x10000,
  363. shop_type: 0,
  364. shop_index: 0,
  365. amount: 3,
  366. unknown1: 0,
  367. })))).await.unwrap().for_each(drop);
  368. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  369. client: 255,
  370. target: 255,
  371. item_id: 0x10001,
  372. shop_type: 0,
  373. shop_index: 1,
  374. amount: 2,
  375. unknown1: 0,
  376. })))).await.unwrap().for_each(drop);
  377. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  378. client: 255,
  379. target: 255,
  380. item_id: 0x10002,
  381. shop_type: 0,
  382. shop_index: 0,
  383. amount: 4,
  384. unknown1: 0,
  385. })))).await.unwrap().for_each(drop);
  386. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  387. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  388. assert!(c1.meseta < 999999);
  389. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  390. assert_eq!(p1_items.items.len(), 2);
  391. p1_items.items[0].with_stacked(|item| {
  392. assert_eq!(item.len(), 7);
  393. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  394. }).unwrap();
  395. p1_items.items[1].with_stacked(|item| {
  396. assert_eq!(item.len(), 2);
  397. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Dimate));
  398. }).unwrap();
  399. }
  400. #[async_std::test]
  401. async fn test_techs_disappear_from_shop_when_bought() {
  402. let mut entity_gateway = InMemoryGateway::default();
  403. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  404. char1.exp = 80000000;
  405. char1.meseta = 999999;
  406. entity_gateway.save_character(&char1).await.unwrap();
  407. let mut ship = Box::new(ShipServerState::builder()
  408. .gateway(entity_gateway.clone())
  409. .build());
  410. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  411. join_lobby(&mut ship, ClientId(1)).await;
  412. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  413. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  414. client: 255,
  415. target: 255,
  416. shop_type: 0,
  417. })))).await.unwrap().collect::<Vec<_>>();
  418. let first_tech = match &packets[0].1 {
  419. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  420. shop_list.items.iter()
  421. .enumerate()
  422. .filter(|(_, item)| {
  423. item.item_bytes[0] == 3 && item.item_bytes[1] == 2
  424. })
  425. .nth(0).unwrap().0
  426. },
  427. _ => panic!(""),
  428. };
  429. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  430. client: 255,
  431. target: 255,
  432. item_id: 0x10000,
  433. shop_type: 0,
  434. shop_index: first_tech as u8,
  435. amount: 1,
  436. unknown1: 0,
  437. })))).await.unwrap().for_each(drop);
  438. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  439. client: 255,
  440. target: 255,
  441. item_id: 0x10001,
  442. shop_type: 0,
  443. shop_index: first_tech as u8,
  444. amount: 1,
  445. unknown1: 0,
  446. })))).await.unwrap().for_each(drop);
  447. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  448. p1_items.items[0].with_individual(|item1| {
  449. p1_items.items[1].with_individual(|item2| {
  450. assert_ne!(item1, item2);
  451. }).unwrap();
  452. }).unwrap();
  453. }
  454. // TOOD: this is not deterministic and can randomly fail
  455. #[async_std::test]
  456. async fn test_units_disappear_from_shop_when_bought() {
  457. let mut entity_gateway = InMemoryGateway::default();
  458. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  459. char1.exp = 80000000;
  460. char1.meseta = 999999;
  461. entity_gateway.save_character(&char1).await.unwrap();
  462. let mut ship = Box::new(ShipServerState::builder()
  463. .gateway(entity_gateway.clone())
  464. .build());
  465. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  466. join_lobby(&mut ship, ClientId(1)).await;
  467. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  468. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  469. client: 255,
  470. target: 255,
  471. shop_type: 2,
  472. })))).await.unwrap().collect::<Vec<_>>();
  473. let first_unit = match &packets[0].1 {
  474. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  475. shop_list.items.iter()
  476. .enumerate()
  477. .filter(|(_, item)| {
  478. item.item_bytes[0] == 1 && item.item_bytes[1] == 3
  479. })
  480. .nth(0).unwrap().0
  481. },
  482. _ => panic!(""),
  483. };
  484. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  485. client: 255,
  486. target: 255,
  487. item_id: 0x10000,
  488. shop_type: 2,
  489. shop_index: first_unit as u8,
  490. amount: 1,
  491. unknown1: 0,
  492. })))).await.unwrap().for_each(drop);
  493. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  494. client: 255,
  495. target: 255,
  496. item_id: 0x10001,
  497. shop_type: 2,
  498. shop_index: first_unit as u8,
  499. amount: 1,
  500. unknown1: 0,
  501. })))).await.unwrap().for_each(drop);
  502. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  503. p1_items.items[0].with_individual(|item1| {
  504. p1_items.items[1].with_individual(|item2| {
  505. assert_ne!(item1, item2);
  506. }).unwrap();
  507. }).unwrap();
  508. }