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.

1168 lines
42 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
4 years ago
4 years ago
4 years ago
4 years ago
3 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_eq!(c1.meseta, 999749);
  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_3_attr_weapon_to_shop() {
  225. let mut entity_gateway = InMemoryGateway::default();
  226. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  227. let mut p1_inv = Vec::new();
  228. p1_inv.push(entity_gateway.create_item(
  229. item::NewItemEntity {
  230. item: item::ItemDetail::Weapon(
  231. item::weapon::Weapon {
  232. weapon: item::weapon::WeaponType::Vulcan,
  233. grind: 5,
  234. special: Some(item::weapon::WeaponSpecial::Charge),
  235. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  236. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  237. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  238. tekked: true,
  239. }
  240. ),
  241. location: item::ItemLocation::Inventory {
  242. character_id: char1.id,
  243. }
  244. }).await.unwrap());
  245. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  246. let mut ship = Box::new(ShipServerState::builder()
  247. .gateway(entity_gateway.clone())
  248. .build());
  249. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  250. join_lobby(&mut ship, ClientId(1)).await;
  251. create_room(&mut ship, ClientId(1), "room", "").await;
  252. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  253. client: 0,
  254. target: 0,
  255. item_id: 0x10000,
  256. amount: 1,
  257. })))).await.unwrap().for_each(drop);
  258. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  259. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  260. assert_eq!(c1.meseta, 4406);
  261. }
  262. #[async_std::test]
  263. async fn test_other_clients_see_purchase() {
  264. let mut entity_gateway = InMemoryGateway::default();
  265. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  266. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  267. char1.exp = 80000000;
  268. char1.meseta = 999999;
  269. entity_gateway.save_character(&char1).await.unwrap();
  270. let mut ship = Box::new(ShipServerState::builder()
  271. .gateway(entity_gateway.clone())
  272. .build());
  273. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  274. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  275. join_lobby(&mut ship, ClientId(1)).await;
  276. join_lobby(&mut ship, ClientId(2)).await;
  277. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  278. join_room(&mut ship, ClientId(2), 0).await;
  279. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  280. client: 255,
  281. target: 255,
  282. shop_type: 1
  283. })))).await.unwrap().for_each(drop);
  284. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  285. client: 255,
  286. target: 255,
  287. item_id: 0x10000,
  288. shop_type: 1,
  289. shop_index: 0,
  290. amount: 1,
  291. unknown1: 0,
  292. })))).await.unwrap().collect::<Vec<_>>();
  293. assert_eq!(packets.len(), 1);
  294. assert_eq!(packets[0].0, ClientId(2));
  295. match &packets[0].1 {
  296. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  297. _ => panic!(""),
  298. }
  299. }
  300. #[async_std::test]
  301. async fn test_other_clients_see_stacked_purchase() {
  302. let mut entity_gateway = InMemoryGateway::default();
  303. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  304. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  305. char1.exp = 80000000;
  306. char1.meseta = 999999;
  307. entity_gateway.save_character(&char1).await.unwrap();
  308. entity_gateway.create_item(
  309. item::NewItemEntity {
  310. item: item::ItemDetail::Tool(
  311. item::tool::Tool {
  312. tool: item::tool::ToolType::Monomate
  313. }
  314. ),
  315. location: item::ItemLocation::Inventory {
  316. character_id: char1.id,
  317. }
  318. }).await.unwrap();
  319. let mut ship = Box::new(ShipServerState::builder()
  320. .gateway(entity_gateway.clone())
  321. .build());
  322. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  323. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  324. join_lobby(&mut ship, ClientId(1)).await;
  325. join_lobby(&mut ship, ClientId(2)).await;
  326. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  327. join_room(&mut ship, ClientId(2), 0).await;
  328. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  329. client: 255,
  330. target: 255,
  331. shop_type: 1
  332. })))).await.unwrap().for_each(drop);
  333. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  334. client: 255,
  335. target: 255,
  336. item_id: 0x10000,
  337. shop_type: 1,
  338. shop_index: 0,
  339. amount: 1,
  340. unknown1: 0,
  341. })))).await.unwrap().collect::<Vec<_>>();
  342. assert_eq!(packets.len(), 1);
  343. assert_eq!(packets[0].0, ClientId(2));
  344. match &packets[0].1 {
  345. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  346. _ => panic!(""),
  347. }
  348. }
  349. #[async_std::test]
  350. async fn test_buying_item_without_enough_mseseta() {
  351. let mut entity_gateway = InMemoryGateway::default();
  352. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  353. let mut ship = Box::new(ShipServerState::builder()
  354. .gateway(entity_gateway.clone())
  355. .build());
  356. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  357. join_lobby(&mut ship, ClientId(1)).await;
  358. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  359. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  360. client: 255,
  361. target: 255,
  362. shop_type: 1
  363. })))).await.unwrap().for_each(drop);
  364. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  365. client: 255,
  366. target: 255,
  367. item_id: 0x10000,
  368. shop_type: 1,
  369. shop_index: 0,
  370. amount: 1,
  371. unknown1: 0,
  372. })))).await;
  373. assert!(packets.is_err());
  374. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  375. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  376. assert_eq!(c1.meseta, 0);
  377. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  378. assert_eq!(p1_items.items.len(), 0);
  379. }
  380. #[async_std::test]
  381. async fn test_player_double_buys_from_tool_shop() {
  382. let mut entity_gateway = InMemoryGateway::default();
  383. let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  384. char1.exp = 80000000;
  385. char1.meseta = 999999;
  386. entity_gateway.save_character(&char1).await.unwrap();
  387. let mut ship = Box::new(ShipServerState::builder()
  388. .gateway(entity_gateway.clone())
  389. .build());
  390. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  391. join_lobby(&mut ship, ClientId(1)).await;
  392. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  393. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  394. client: 255,
  395. target: 255,
  396. shop_type: 0,
  397. })))).await.unwrap().for_each(drop);
  398. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  399. client: 255,
  400. target: 255,
  401. item_id: 0x10000,
  402. shop_type: 0,
  403. shop_index: 0,
  404. amount: 3,
  405. unknown1: 0,
  406. })))).await.unwrap().for_each(drop);
  407. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  408. client: 255,
  409. target: 255,
  410. item_id: 0x10001,
  411. shop_type: 0,
  412. shop_index: 1,
  413. amount: 2,
  414. unknown1: 0,
  415. })))).await.unwrap().for_each(drop);
  416. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  417. client: 255,
  418. target: 255,
  419. item_id: 0x10002,
  420. shop_type: 0,
  421. shop_index: 0,
  422. amount: 4,
  423. unknown1: 0,
  424. })))).await.unwrap().for_each(drop);
  425. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  426. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  427. assert!(c1.meseta < 999999);
  428. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  429. assert_eq!(p1_items.items.len(), 2);
  430. p1_items.items[0].with_stacked(|item| {
  431. assert_eq!(item.len(), 7);
  432. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  433. }).unwrap();
  434. p1_items.items[1].with_stacked(|item| {
  435. assert_eq!(item.len(), 2);
  436. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Dimate));
  437. }).unwrap();
  438. }
  439. #[async_std::test]
  440. async fn test_techs_disappear_from_shop_when_bought() {
  441. let mut entity_gateway = InMemoryGateway::default();
  442. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  443. char1.exp = 80000000;
  444. char1.meseta = 999999;
  445. entity_gateway.save_character(&char1).await.unwrap();
  446. let mut ship = Box::new(ShipServerState::builder()
  447. .gateway(entity_gateway.clone())
  448. .build());
  449. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  450. join_lobby(&mut ship, ClientId(1)).await;
  451. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  452. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  453. client: 255,
  454. target: 255,
  455. shop_type: 0,
  456. })))).await.unwrap().collect::<Vec<_>>();
  457. let first_tech = match &packets[0].1 {
  458. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  459. shop_list.items.iter()
  460. .enumerate()
  461. .filter(|(_, item)| {
  462. item.item_bytes[0] == 3 && item.item_bytes[1] == 2
  463. })
  464. .nth(0).unwrap().0
  465. },
  466. _ => panic!(""),
  467. };
  468. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  469. client: 255,
  470. target: 255,
  471. item_id: 0x10000,
  472. shop_type: 0,
  473. shop_index: first_tech as u8,
  474. amount: 1,
  475. unknown1: 0,
  476. })))).await.unwrap().for_each(drop);
  477. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  478. client: 255,
  479. target: 255,
  480. item_id: 0x10001,
  481. shop_type: 0,
  482. shop_index: first_tech as u8,
  483. amount: 1,
  484. unknown1: 0,
  485. })))).await.unwrap().for_each(drop);
  486. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  487. p1_items.items[0].with_individual(|item1| {
  488. p1_items.items[1].with_individual(|item2| {
  489. assert_ne!(item1, item2);
  490. }).unwrap();
  491. }).unwrap();
  492. }
  493. // TOOD: this is not deterministic and can randomly fail
  494. #[async_std::test]
  495. async fn test_units_disappear_from_shop_when_bought() {
  496. let mut entity_gateway = InMemoryGateway::default();
  497. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  498. char1.exp = 80000000;
  499. char1.meseta = 999999;
  500. entity_gateway.save_character(&char1).await.unwrap();
  501. let mut ship = Box::new(ShipServerState::builder()
  502. .gateway(entity_gateway.clone())
  503. .build());
  504. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  505. join_lobby(&mut ship, ClientId(1)).await;
  506. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  507. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  508. client: 255,
  509. target: 255,
  510. shop_type: 2,
  511. })))).await.unwrap().collect::<Vec<_>>();
  512. let first_unit = match &packets[0].1 {
  513. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  514. shop_list.items.iter()
  515. .enumerate()
  516. .filter(|(_, item)| {
  517. item.item_bytes[0] == 1 && item.item_bytes[1] == 3
  518. })
  519. .nth(0).unwrap().0
  520. },
  521. _ => panic!(""),
  522. };
  523. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  524. client: 255,
  525. target: 255,
  526. item_id: 0x10000,
  527. shop_type: 2,
  528. shop_index: first_unit as u8,
  529. amount: 1,
  530. unknown1: 0,
  531. })))).await.unwrap().for_each(drop);
  532. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  533. client: 255,
  534. target: 255,
  535. item_id: 0x10001,
  536. shop_type: 2,
  537. shop_index: first_unit as u8,
  538. amount: 1,
  539. unknown1: 0,
  540. })))).await.unwrap().for_each(drop);
  541. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  542. p1_items.items[0].with_individual(|item1| {
  543. p1_items.items[1].with_individual(|item2| {
  544. assert_ne!(item1, item2);
  545. }).unwrap();
  546. }).unwrap();
  547. }
  548. #[async_std::test]
  549. async fn test_player_sells_untekked_weapon() {
  550. let mut entity_gateway = InMemoryGateway::default();
  551. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  552. let mut p1_inv = Vec::new();
  553. p1_inv.push(entity_gateway.create_item(
  554. item::NewItemEntity {
  555. item: item::ItemDetail::Weapon(
  556. item::weapon::Weapon {
  557. weapon: item::weapon::WeaponType::Vulcan,
  558. grind: 5,
  559. special: Some(item::weapon::WeaponSpecial::Charge),
  560. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  561. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  562. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  563. tekked: false,
  564. }
  565. ),
  566. location: item::ItemLocation::Inventory {
  567. character_id: char1.id,
  568. }
  569. }).await.unwrap());
  570. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  571. let mut ship = Box::new(ShipServerState::builder()
  572. .gateway(entity_gateway.clone())
  573. .build());
  574. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  575. join_lobby(&mut ship, ClientId(1)).await;
  576. create_room(&mut ship, ClientId(1), "room", "").await;
  577. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  578. client: 0,
  579. target: 0,
  580. item_id: 0x10000,
  581. amount: 1,
  582. })))).await.unwrap().for_each(drop);
  583. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  584. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  585. assert_eq!(c1.meseta, 1);
  586. }
  587. #[async_std::test]
  588. async fn test_player_sells_rare_item() {
  589. let mut entity_gateway = InMemoryGateway::default();
  590. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  591. let mut p1_inv = Vec::new();
  592. p1_inv.push(entity_gateway.create_item(
  593. item::NewItemEntity {
  594. item: item::ItemDetail::Weapon(
  595. item::weapon::Weapon {
  596. weapon: item::weapon::WeaponType::DarkFlow,
  597. grind: 5,
  598. special: None,
  599. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  600. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  601. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  602. tekked: true,
  603. }
  604. ),
  605. location: item::ItemLocation::Inventory {
  606. character_id: char1.id,
  607. }
  608. }).await.unwrap());
  609. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  610. let mut ship = Box::new(ShipServerState::builder()
  611. .gateway(entity_gateway.clone())
  612. .build());
  613. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  614. join_lobby(&mut ship, ClientId(1)).await;
  615. create_room(&mut ship, ClientId(1), "room", "").await;
  616. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  617. client: 0,
  618. target: 0,
  619. item_id: 0x10000,
  620. amount: 1,
  621. })))).await.unwrap().for_each(drop);
  622. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  623. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  624. assert_eq!(c1.meseta, 10);
  625. }
  626. #[async_std::test]
  627. async fn test_player_sells_partial_photon_drop_stack() {
  628. let mut entity_gateway = InMemoryGateway::default();
  629. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  630. let mut p1_inv = Vec::new();
  631. let mut photon_drops = Vec::new();
  632. for _ in 0..7usize {
  633. photon_drops.push(entity_gateway.create_item(
  634. item::NewItemEntity {
  635. item: item::ItemDetail::Tool(
  636. item::tool::Tool {
  637. tool: item::tool::ToolType::PhotonDrop,
  638. }
  639. ),
  640. location: item::ItemLocation::Inventory {
  641. character_id: char1.id,
  642. }
  643. }).await.unwrap());
  644. }
  645. p1_inv.push(item::InventoryItemEntity::Stacked(photon_drops));
  646. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  647. let mut ship = Box::new(ShipServerState::builder()
  648. .gateway(entity_gateway.clone())
  649. .build());
  650. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  651. join_lobby(&mut ship, ClientId(1)).await;
  652. create_room(&mut ship, ClientId(1), "room", "").await;
  653. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  654. client: 0,
  655. target: 0,
  656. item_id: 0x10000,
  657. amount: 3,
  658. })))).await.unwrap().for_each(drop);
  659. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  660. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  661. assert_eq!(c1.meseta, 3000);
  662. }
  663. #[async_std::test]
  664. async fn test_player_sells_basic_frame() {
  665. let mut entity_gateway = InMemoryGateway::default();
  666. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  667. let mut p1_inv = Vec::new();
  668. p1_inv.push(entity_gateway.create_item(
  669. item::NewItemEntity {
  670. item: item::ItemDetail::Armor(
  671. item::armor::Armor {
  672. armor: item::armor::ArmorType::Frame,
  673. dfp: 0,
  674. evp: 0,
  675. slots: 0,
  676. }
  677. ),
  678. location: item::ItemLocation::Inventory {
  679. character_id: char1.id,
  680. }
  681. }).await.unwrap());
  682. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  683. let mut ship = Box::new(ShipServerState::builder()
  684. .gateway(entity_gateway.clone())
  685. .build());
  686. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  687. join_lobby(&mut ship, ClientId(1)).await;
  688. create_room(&mut ship, ClientId(1), "room", "").await;
  689. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  690. client: 0,
  691. target: 0,
  692. item_id: 0x10000,
  693. amount: 1,
  694. })))).await.unwrap().for_each(drop);
  695. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  696. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  697. assert_eq!(c1.meseta, 24);
  698. }
  699. #[async_std::test]
  700. async fn test_player_sells_max_frame() {
  701. let mut entity_gateway = InMemoryGateway::default();
  702. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  703. let mut p1_inv = Vec::new();
  704. p1_inv.push(entity_gateway.create_item(
  705. item::NewItemEntity {
  706. item: item::ItemDetail::Armor(
  707. item::armor::Armor {
  708. armor: item::armor::ArmorType::Frame,
  709. dfp: 2,
  710. evp: 2,
  711. slots: 4,
  712. }
  713. ),
  714. location: item::ItemLocation::Inventory {
  715. character_id: char1.id,
  716. }
  717. }).await.unwrap());
  718. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  719. let mut ship = Box::new(ShipServerState::builder()
  720. .gateway(entity_gateway.clone())
  721. .build());
  722. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  723. join_lobby(&mut ship, ClientId(1)).await;
  724. create_room(&mut ship, ClientId(1), "room", "").await;
  725. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  726. client: 0,
  727. target: 0,
  728. item_id: 0x10000,
  729. amount: 1,
  730. })))).await.unwrap().for_each(drop);
  731. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  732. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  733. assert_eq!(c1.meseta, 74);
  734. }
  735. #[async_std::test]
  736. async fn test_player_sells_basic_barrier() {
  737. let mut entity_gateway = InMemoryGateway::default();
  738. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  739. let mut p1_inv = Vec::new();
  740. p1_inv.push(entity_gateway.create_item(
  741. item::NewItemEntity {
  742. item: item::ItemDetail::Shield(
  743. item::shield::Shield {
  744. shield: item::shield::ShieldType::Barrier,
  745. dfp: 0,
  746. evp: 0,
  747. }
  748. ),
  749. location: item::ItemLocation::Inventory {
  750. character_id: char1.id,
  751. }
  752. }).await.unwrap());
  753. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  754. let mut ship = Box::new(ShipServerState::builder()
  755. .gateway(entity_gateway.clone())
  756. .build());
  757. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  758. join_lobby(&mut ship, ClientId(1)).await;
  759. create_room(&mut ship, ClientId(1), "room", "").await;
  760. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  761. client: 0,
  762. target: 0,
  763. item_id: 0x10000,
  764. amount: 1,
  765. })))).await.unwrap().for_each(drop);
  766. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  767. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  768. assert_eq!(c1.meseta, 69);
  769. }
  770. #[async_std::test]
  771. async fn test_player_sells_max_barrier() {
  772. let mut entity_gateway = InMemoryGateway::default();
  773. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  774. let mut p1_inv = Vec::new();
  775. p1_inv.push(entity_gateway.create_item(
  776. item::NewItemEntity {
  777. item: item::ItemDetail::Shield(
  778. item::shield::Shield {
  779. shield: item::shield::ShieldType::Barrier,
  780. dfp: 5,
  781. evp: 5,
  782. }
  783. ),
  784. location: item::ItemLocation::Inventory {
  785. character_id: char1.id,
  786. }
  787. }).await.unwrap());
  788. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  789. let mut ship = Box::new(ShipServerState::builder()
  790. .gateway(entity_gateway.clone())
  791. .build());
  792. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  793. join_lobby(&mut ship, ClientId(1)).await;
  794. create_room(&mut ship, ClientId(1), "room", "").await;
  795. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  796. client: 0,
  797. target: 0,
  798. item_id: 0x10000,
  799. amount: 1,
  800. })))).await.unwrap().for_each(drop);
  801. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  802. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  803. assert_eq!(c1.meseta, 122);
  804. }
  805. #[async_std::test]
  806. async fn test_player_sells_1_star_minusminus_unit() {
  807. let mut entity_gateway = InMemoryGateway::default();
  808. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  809. let mut p1_inv = Vec::new();
  810. p1_inv.push(entity_gateway.create_item(
  811. item::NewItemEntity {
  812. item: item::ItemDetail::Unit(
  813. item::unit::Unit {
  814. unit: item::unit::UnitType::PriestMind,
  815. modifier: Some(item::unit::UnitModifier::MinusMinus),
  816. }
  817. ),
  818. location: item::ItemLocation::Inventory {
  819. character_id: char1.id,
  820. }
  821. }).await.unwrap());
  822. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  823. let mut ship = Box::new(ShipServerState::builder()
  824. .gateway(entity_gateway.clone())
  825. .build());
  826. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  827. join_lobby(&mut ship, ClientId(1)).await;
  828. create_room(&mut ship, ClientId(1), "room", "").await;
  829. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  830. client: 0,
  831. target: 0,
  832. item_id: 0x10000,
  833. amount: 1,
  834. })))).await.unwrap().for_each(drop);
  835. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  836. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  837. assert_eq!(c1.meseta, 125);
  838. }
  839. #[async_std::test]
  840. async fn test_player_sells_5_star_plusplus_unit() {
  841. let mut entity_gateway = InMemoryGateway::default();
  842. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  843. let mut p1_inv = Vec::new();
  844. p1_inv.push(entity_gateway.create_item(
  845. item::NewItemEntity {
  846. item: item::ItemDetail::Unit(
  847. item::unit::Unit {
  848. unit: item::unit::UnitType::GeneralHp,
  849. modifier: Some(item::unit::UnitModifier::PlusPlus),
  850. }
  851. ),
  852. location: item::ItemLocation::Inventory {
  853. character_id: char1.id,
  854. }
  855. }).await.unwrap());
  856. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  857. let mut ship = Box::new(ShipServerState::builder()
  858. .gateway(entity_gateway.clone())
  859. .build());
  860. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  861. join_lobby(&mut ship, ClientId(1)).await;
  862. create_room(&mut ship, ClientId(1), "room", "").await;
  863. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  864. client: 0,
  865. target: 0,
  866. item_id: 0x10000,
  867. amount: 1,
  868. })))).await.unwrap().for_each(drop);
  869. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  870. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  871. assert_eq!(c1.meseta, 625);
  872. }
  873. #[async_std::test]
  874. async fn test_player_sells_rare_frame() {
  875. let mut entity_gateway = InMemoryGateway::default();
  876. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  877. let mut p1_inv = Vec::new();
  878. p1_inv.push(entity_gateway.create_item(
  879. item::NewItemEntity {
  880. item: item::ItemDetail::Armor(
  881. item::armor::Armor {
  882. armor: item::armor::ArmorType::StinkFrame,
  883. dfp: 10,
  884. evp: 20,
  885. slots: 3,
  886. }
  887. ),
  888. location: item::ItemLocation::Inventory {
  889. character_id: char1.id,
  890. }
  891. }).await.unwrap());
  892. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  893. let mut ship = Box::new(ShipServerState::builder()
  894. .gateway(entity_gateway.clone())
  895. .build());
  896. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  897. join_lobby(&mut ship, ClientId(1)).await;
  898. create_room(&mut ship, ClientId(1), "room", "").await;
  899. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  900. client: 0,
  901. target: 0,
  902. item_id: 0x10000,
  903. amount: 1,
  904. })))).await.unwrap().for_each(drop);
  905. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  906. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  907. assert_eq!(c1.meseta, 10);
  908. }
  909. #[async_std::test]
  910. async fn test_player_sells_rare_barrier() {
  911. let mut entity_gateway = InMemoryGateway::default();
  912. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  913. let mut p1_inv = Vec::new();
  914. p1_inv.push(entity_gateway.create_item(
  915. item::NewItemEntity {
  916. item: item::ItemDetail::Shield(
  917. item::shield::Shield {
  918. shield: item::shield::ShieldType::RedRing,
  919. dfp: 10,
  920. evp: 20,
  921. }
  922. ),
  923. location: item::ItemLocation::Inventory {
  924. character_id: char1.id,
  925. }
  926. }).await.unwrap());
  927. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  928. let mut ship = Box::new(ShipServerState::builder()
  929. .gateway(entity_gateway.clone())
  930. .build());
  931. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  932. join_lobby(&mut ship, ClientId(1)).await;
  933. create_room(&mut ship, ClientId(1), "room", "").await;
  934. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  935. client: 0,
  936. target: 0,
  937. item_id: 0x10000,
  938. amount: 1,
  939. })))).await.unwrap().for_each(drop);
  940. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  941. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  942. assert_eq!(c1.meseta, 10);
  943. }
  944. #[async_std::test]
  945. async fn test_player_sells_rare_unit() {
  946. let mut entity_gateway = InMemoryGateway::default();
  947. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  948. let mut p1_inv = Vec::new();
  949. p1_inv.push(entity_gateway.create_item(
  950. item::NewItemEntity {
  951. item: item::ItemDetail::Unit(
  952. item::unit::Unit {
  953. unit: item::unit::UnitType::V101,
  954. modifier: None,
  955. }
  956. ),
  957. location: item::ItemLocation::Inventory {
  958. character_id: char1.id,
  959. }
  960. }).await.unwrap());
  961. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  962. let mut ship = Box::new(ShipServerState::builder()
  963. .gateway(entity_gateway.clone())
  964. .build());
  965. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  966. join_lobby(&mut ship, ClientId(1)).await;
  967. create_room(&mut ship, ClientId(1), "room", "").await;
  968. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  969. client: 0,
  970. target: 0,
  971. item_id: 0x10000,
  972. amount: 1,
  973. })))).await.unwrap().for_each(drop);
  974. let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  975. let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
  976. assert_eq!(c1.meseta, 10);
  977. }