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.

576 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
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 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
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 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. entity_gateway.save_character(&char1).await.unwrap();
  92. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).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 c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  114. assert!(c1_meseta.0 < 999999);
  115. //let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
  116. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  117. assert_eq!(p1_items.items.len(), 1);
  118. }
  119. #[async_std::test]
  120. async fn test_player_buys_from_tool_shop() {
  121. let mut entity_gateway = InMemoryGateway::default();
  122. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  123. char1.exp = 80000000;
  124. entity_gateway.save_character(&char1).await.unwrap();
  125. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  126. let mut ship = Box::new(ShipServerState::builder()
  127. .gateway(entity_gateway.clone())
  128. .build());
  129. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  130. join_lobby(&mut ship, ClientId(1)).await;
  131. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  132. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  133. client: 255,
  134. target: 255,
  135. shop_type: 0,
  136. })))).await.unwrap().for_each(drop);
  137. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  138. client: 255,
  139. target: 255,
  140. item_id: 0x10000,
  141. shop_type: 0,
  142. shop_index: 0,
  143. amount: 1,
  144. unknown1: 0,
  145. })))).await.unwrap().for_each(drop);
  146. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  147. assert!(c1_meseta.0 < 999999);
  148. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  149. assert_eq!(p1_items.items.len(), 1);
  150. }
  151. #[async_std::test]
  152. async fn test_player_buys_multiple_from_tool_shop() {
  153. let mut entity_gateway = InMemoryGateway::default();
  154. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  155. char1.exp = 80000000;
  156. entity_gateway.save_character(&char1).await.unwrap();
  157. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  158. let mut ship = Box::new(ShipServerState::builder()
  159. .gateway(entity_gateway.clone())
  160. .build());
  161. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  162. join_lobby(&mut ship, ClientId(1)).await;
  163. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  164. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  165. client: 255,
  166. target: 255,
  167. shop_type: 0,
  168. })))).await.unwrap().for_each(drop);
  169. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  170. client: 255,
  171. target: 255,
  172. item_id: 0x10000,
  173. shop_type: 0,
  174. shop_index: 0,
  175. amount: 5,
  176. unknown1: 0,
  177. })))).await.unwrap().for_each(drop);
  178. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  179. assert!(c1_meseta.0 < 999999);
  180. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  181. assert_eq!(p1_items.items.len(), 1);
  182. p1_items.items[0].with_stacked(|item| {
  183. assert_eq!(item.len(), 5);
  184. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  185. }).unwrap();
  186. }
  187. #[async_std::test]
  188. async fn test_player_buys_from_armor_shop() {
  189. let mut entity_gateway = InMemoryGateway::default();
  190. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  191. char1.exp = 80000000;
  192. entity_gateway.save_character(&char1).await.unwrap();
  193. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  194. let mut ship = Box::new(ShipServerState::builder()
  195. .gateway(entity_gateway.clone())
  196. .build());
  197. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  198. join_lobby(&mut ship, ClientId(1)).await;
  199. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  200. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  201. client: 255,
  202. target: 255,
  203. shop_type: 2
  204. })))).await.unwrap().for_each(drop);
  205. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  206. client: 255,
  207. target: 255,
  208. item_id: 0x10000,
  209. shop_type: 2,
  210. shop_index: 0,
  211. amount: 1,
  212. unknown1: 0,
  213. })))).await.unwrap().for_each(drop);
  214. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  215. assert!(c1_meseta.0 < 999999);
  216. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  217. assert_eq!(p1_items.items.len(), 1);
  218. }
  219. #[async_std::test]
  220. async fn test_player_sells_to_shop() {
  221. }
  222. #[async_std::test]
  223. async fn test_other_clients_see_purchase() {
  224. let mut entity_gateway = InMemoryGateway::default();
  225. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  226. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  227. char1.exp = 80000000;
  228. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  229. entity_gateway.save_character(&char1).await.unwrap();
  230. let mut ship = Box::new(ShipServerState::builder()
  231. .gateway(entity_gateway.clone())
  232. .build());
  233. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  234. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  235. join_lobby(&mut ship, ClientId(1)).await;
  236. join_lobby(&mut ship, ClientId(2)).await;
  237. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  238. join_room(&mut ship, ClientId(2), 0).await;
  239. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  240. client: 255,
  241. target: 255,
  242. shop_type: 1
  243. })))).await.unwrap().for_each(drop);
  244. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  245. client: 255,
  246. target: 255,
  247. item_id: 0x10000,
  248. shop_type: 1,
  249. shop_index: 0,
  250. amount: 1,
  251. unknown1: 0,
  252. })))).await.unwrap().collect::<Vec<_>>();
  253. assert_eq!(packets.len(), 1);
  254. assert_eq!(packets[0].0, ClientId(2));
  255. match &packets[0].1 {
  256. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  257. _ => panic!(""),
  258. }
  259. }
  260. #[async_std::test]
  261. async fn test_other_clients_see_stacked_purchase() {
  262. let mut entity_gateway = InMemoryGateway::default();
  263. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  264. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  265. char1.exp = 80000000;
  266. entity_gateway.save_character(&char1).await.unwrap();
  267. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  268. entity_gateway.create_item(
  269. item::NewItemEntity {
  270. item: item::ItemDetail::Tool(
  271. item::tool::Tool {
  272. tool: item::tool::ToolType::Monomate
  273. }
  274. ),
  275. }).await.unwrap();
  276. let mut ship = Box::new(ShipServerState::builder()
  277. .gateway(entity_gateway.clone())
  278. .build());
  279. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  280. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  281. join_lobby(&mut ship, ClientId(1)).await;
  282. join_lobby(&mut ship, ClientId(2)).await;
  283. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  284. join_room(&mut ship, ClientId(2), 0).await;
  285. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  286. client: 255,
  287. target: 255,
  288. shop_type: 1
  289. })))).await.unwrap().for_each(drop);
  290. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  291. client: 255,
  292. target: 255,
  293. item_id: 0x10000,
  294. shop_type: 1,
  295. shop_index: 0,
  296. amount: 1,
  297. unknown1: 0,
  298. })))).await.unwrap().collect::<Vec<_>>();
  299. assert_eq!(packets.len(), 1);
  300. assert_eq!(packets[0].0, ClientId(2));
  301. match &packets[0].1 {
  302. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  303. _ => panic!(""),
  304. }
  305. }
  306. #[async_std::test]
  307. async fn test_buying_item_without_enough_mseseta() {
  308. let mut entity_gateway = InMemoryGateway::default();
  309. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  310. let mut ship = Box::new(ShipServerState::builder()
  311. .gateway(entity_gateway.clone())
  312. .build());
  313. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  314. join_lobby(&mut ship, ClientId(1)).await;
  315. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  316. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  317. client: 255,
  318. target: 255,
  319. shop_type: 1
  320. })))).await.unwrap().for_each(drop);
  321. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  322. client: 255,
  323. target: 255,
  324. item_id: 0x10000,
  325. shop_type: 1,
  326. shop_index: 0,
  327. amount: 1,
  328. unknown1: 0,
  329. })))).await;
  330. assert!(packets.is_err());
  331. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  332. assert_eq!(c1_meseta.0, 0);
  333. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  334. assert_eq!(p1_items.items.len(), 0);
  335. }
  336. #[async_std::test]
  337. async fn test_player_double_buys_from_tool_shop() {
  338. let mut entity_gateway = InMemoryGateway::default();
  339. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  340. char1.exp = 80000000;
  341. entity_gateway.save_character(&char1).await.unwrap();
  342. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  343. let mut ship = Box::new(ShipServerState::builder()
  344. .gateway(entity_gateway.clone())
  345. .build());
  346. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  347. join_lobby(&mut ship, ClientId(1)).await;
  348. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  349. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  350. client: 255,
  351. target: 255,
  352. shop_type: 0,
  353. })))).await.unwrap().for_each(drop);
  354. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  355. client: 255,
  356. target: 255,
  357. item_id: 0x10000,
  358. shop_type: 0,
  359. shop_index: 0,
  360. amount: 3,
  361. unknown1: 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: 0x10001,
  367. shop_type: 0,
  368. shop_index: 1,
  369. amount: 2,
  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: 0x10002,
  376. shop_type: 0,
  377. shop_index: 0,
  378. amount: 4,
  379. unknown1: 0,
  380. })))).await.unwrap().for_each(drop);
  381. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  382. assert!(c1_meseta.0 < 999999);
  383. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  384. assert_eq!(p1_items.items.len(), 2);
  385. p1_items.items[0].with_stacked(|item| {
  386. assert_eq!(item.len(), 7);
  387. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  388. }).unwrap();
  389. p1_items.items[1].with_stacked(|item| {
  390. assert_eq!(item.len(), 2);
  391. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Dimate));
  392. }).unwrap();
  393. }
  394. #[async_std::test]
  395. async fn test_techs_disappear_from_shop_when_bought() {
  396. let mut entity_gateway = InMemoryGateway::default();
  397. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  398. char1.exp = 80000000;
  399. entity_gateway.save_character(&char1).await.unwrap();
  400. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  401. let mut ship = Box::new(ShipServerState::builder()
  402. .gateway(entity_gateway.clone())
  403. .build());
  404. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  405. join_lobby(&mut ship, ClientId(1)).await;
  406. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  407. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  408. client: 255,
  409. target: 255,
  410. shop_type: 0,
  411. })))).await.unwrap().collect::<Vec<_>>();
  412. let first_tech = match &packets[0].1 {
  413. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  414. shop_list.items.iter()
  415. .enumerate()
  416. .filter(|(_, item)| {
  417. item.item_bytes[0] == 3 && item.item_bytes[1] == 2
  418. })
  419. .nth(0).unwrap().0
  420. },
  421. _ => panic!(""),
  422. };
  423. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  424. client: 255,
  425. target: 255,
  426. item_id: 0x10000,
  427. shop_type: 0,
  428. shop_index: first_tech as u8,
  429. amount: 1,
  430. unknown1: 0,
  431. })))).await.unwrap().for_each(drop);
  432. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  433. client: 255,
  434. target: 255,
  435. item_id: 0x10001,
  436. shop_type: 0,
  437. shop_index: first_tech as u8,
  438. amount: 1,
  439. unknown1: 0,
  440. })))).await.unwrap().for_each(drop);
  441. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  442. p1_items.items[0].with_individual(|item1| {
  443. p1_items.items[1].with_individual(|item2| {
  444. assert_ne!(item1, item2);
  445. }).unwrap();
  446. }).unwrap();
  447. }
  448. // TOOD: this is not deterministic and can randomly fail
  449. #[async_std::test]
  450. async fn test_units_disappear_from_shop_when_bought() {
  451. let mut entity_gateway = InMemoryGateway::default();
  452. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  453. char1.exp = 80000000;
  454. entity_gateway.save_character(&char1).await.unwrap();
  455. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  456. let mut ship = Box::new(ShipServerState::builder()
  457. .gateway(entity_gateway.clone())
  458. .build());
  459. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  460. join_lobby(&mut ship, ClientId(1)).await;
  461. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  462. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  463. client: 255,
  464. target: 255,
  465. shop_type: 2,
  466. })))).await.unwrap().collect::<Vec<_>>();
  467. let first_unit = match &packets[0].1 {
  468. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  469. shop_list.items.iter()
  470. .enumerate()
  471. .filter(|(_, item)| {
  472. item.item_bytes[0] == 1 && item.item_bytes[1] == 3
  473. })
  474. .nth(0).unwrap().0
  475. },
  476. _ => panic!(""),
  477. };
  478. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  479. client: 255,
  480. target: 255,
  481. item_id: 0x10000,
  482. shop_type: 2,
  483. shop_index: first_unit as u8,
  484. amount: 1,
  485. unknown1: 0,
  486. })))).await.unwrap().for_each(drop);
  487. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  488. client: 255,
  489. target: 255,
  490. item_id: 0x10001,
  491. shop_type: 2,
  492. shop_index: first_unit as u8,
  493. amount: 1,
  494. unknown1: 0,
  495. })))).await.unwrap().for_each(drop);
  496. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  497. p1_items.items[0].with_individual(|item1| {
  498. p1_items.items[1].with_individual(|item2| {
  499. assert_ne!(item1, item2);
  500. }).unwrap();
  501. }).unwrap();
  502. }