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.

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