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.

1122 lines
40 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
3 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
3 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
3 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
3 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
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
4 years ago
4 years ago
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
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
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use entity::item;
  4. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  5. use maps::room::Difficulty;
  6. use items::state::ItemStateError;
  7. use shops::StandardItemShops;
  8. use libpso::packet::ship::*;
  9. use libpso::packet::messages::*;
  10. #[path = "common.rs"]
  11. mod common;
  12. use common::*;
  13. #[async_std::test]
  14. async fn test_player_opens_weapon_shop() {
  15. let mut entity_gateway = InMemoryGateway::default();
  16. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  17. char1.exp = 80000000;
  18. entity_gateway.save_character(&char1).await.unwrap();
  19. let mut ship = standard_ship_buildable(entity_gateway.clone())
  20. .item_shops(StandardItemShops::default())
  21. .build();
  22. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  23. join_lobby(&mut ship, ClientId(1)).await;
  24. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  25. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  26. client: 255,
  27. target: 255,
  28. shop_type: 1
  29. })))).await.unwrap();
  30. assert_eq!(packets.len(), 1);
  31. match &packets[0].1 {
  32. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  33. assert_eq!(shop_list.items.len(), 16)
  34. }
  35. _ => panic!("")
  36. }
  37. }
  38. #[async_std::test]
  39. async fn test_player_opens_tool_shop() {
  40. let mut entity_gateway = InMemoryGateway::default();
  41. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  42. char1.exp = 80000000;
  43. entity_gateway.save_character(&char1).await.unwrap();
  44. let mut ship = standard_ship_buildable(entity_gateway.clone())
  45. .item_shops(StandardItemShops::default())
  46. .build();
  47. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  48. join_lobby(&mut ship, ClientId(1)).await;
  49. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  50. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  51. client: 255,
  52. target: 255,
  53. shop_type: 0
  54. })))).await.unwrap();
  55. assert_eq!(packets.len(), 1);
  56. match &packets[0].1 {
  57. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  58. assert_eq!(shop_list.items.len(), 18)
  59. }
  60. _ => panic!("")
  61. }
  62. }
  63. #[async_std::test]
  64. async fn test_player_opens_armor_shop() {
  65. let mut entity_gateway = InMemoryGateway::default();
  66. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  67. char1.exp = 80000000;
  68. entity_gateway.save_character(&char1).await.unwrap();
  69. let mut ship = standard_ship_buildable(entity_gateway.clone())
  70. .item_shops(StandardItemShops::default())
  71. .build();
  72. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  73. join_lobby(&mut ship, ClientId(1)).await;
  74. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  75. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  76. client: 255,
  77. target: 255,
  78. shop_type: 2
  79. })))).await.unwrap();
  80. assert_eq!(packets.len(), 1);
  81. match &packets[0].1 {
  82. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  83. assert_eq!(shop_list.items.len(), 21)
  84. }
  85. _ => panic!("")
  86. }
  87. }
  88. #[async_std::test]
  89. async fn test_player_buys_from_weapon_shop() {
  90. let mut entity_gateway = InMemoryGateway::default();
  91. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  92. char1.exp = 80000000;
  93. entity_gateway.save_character(&char1).await.unwrap();
  94. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  95. let mut ship = standard_ship_buildable(entity_gateway.clone())
  96. .item_shops(StandardItemShops::default())
  97. .build();
  98. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  99. join_lobby(&mut ship, ClientId(1)).await;
  100. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  101. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  102. client: 255,
  103. target: 255,
  104. shop_type: 1
  105. })))).await.unwrap();
  106. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  107. client: 255,
  108. target: 255,
  109. item_id: 0x10000,
  110. shop_type: 1,
  111. shop_index: 0,
  112. amount: 1,
  113. unknown1: 0,
  114. })))).await.unwrap();
  115. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  116. assert!(c1_meseta.0 < 999999);
  117. //let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
  118. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  119. assert_eq!(p1_items.items.len(), 1);
  120. }
  121. #[async_std::test]
  122. async fn test_player_buys_from_tool_shop() {
  123. let mut entity_gateway = InMemoryGateway::default();
  124. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  125. char1.exp = 80000000;
  126. entity_gateway.save_character(&char1).await.unwrap();
  127. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  128. let mut ship = standard_ship_buildable(entity_gateway.clone())
  129. .item_shops(StandardItemShops::default())
  130. .build();
  131. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  132. join_lobby(&mut ship, ClientId(1)).await;
  133. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  134. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  135. client: 255,
  136. target: 255,
  137. shop_type: 0,
  138. })))).await.unwrap();
  139. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  140. client: 255,
  141. target: 255,
  142. item_id: 0x10000,
  143. shop_type: 0,
  144. shop_index: 0,
  145. amount: 1,
  146. unknown1: 0,
  147. })))).await.unwrap();
  148. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  149. assert!(c1_meseta.0 < 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", 1).await;
  157. char1.exp = 80000000;
  158. entity_gateway.save_character(&char1).await.unwrap();
  159. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  160. let mut ship = standard_ship_buildable(entity_gateway.clone())
  161. .item_shops(StandardItemShops::default())
  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();
  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();
  180. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  181. assert_eq!(c1_meseta.0, 999749);
  182. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  183. assert_eq!(p1_items.items.len(), 1);
  184. p1_items.items[0].with_stacked(|item| {
  185. assert_eq!(item.len(), 5);
  186. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  187. }).unwrap();
  188. }
  189. #[async_std::test]
  190. async fn test_player_buys_from_armor_shop() {
  191. let mut entity_gateway = InMemoryGateway::default();
  192. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  193. char1.exp = 80000000;
  194. entity_gateway.save_character(&char1).await.unwrap();
  195. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  196. let mut ship = standard_ship_buildable(entity_gateway.clone())
  197. .item_shops(StandardItemShops::default())
  198. .build();
  199. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  200. join_lobby(&mut ship, ClientId(1)).await;
  201. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  202. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  203. client: 255,
  204. target: 255,
  205. shop_type: 2
  206. })))).await.unwrap();
  207. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  208. client: 255,
  209. target: 255,
  210. item_id: 0x10000,
  211. shop_type: 2,
  212. shop_index: 0,
  213. amount: 1,
  214. unknown1: 0,
  215. })))).await.unwrap();
  216. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  217. assert!(c1_meseta.0 < 999999);
  218. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  219. assert_eq!(p1_items.items.len(), 1);
  220. }
  221. #[async_std::test]
  222. async fn test_player_sells_3_attr_weapon_to_shop() {
  223. let mut entity_gateway = InMemoryGateway::default();
  224. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  225. let mut p1_inv = Vec::new();
  226. p1_inv.push(entity_gateway.create_item(
  227. item::NewItemEntity {
  228. item: item::ItemDetail::Weapon(
  229. item::weapon::Weapon {
  230. weapon: item::weapon::WeaponType::Vulcan,
  231. grind: 5,
  232. special: Some(item::weapon::WeaponSpecial::Charge),
  233. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  234. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  235. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  236. tekked: true,
  237. }
  238. ),
  239. }).await.unwrap());
  240. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  241. let mut ship = standard_ship(entity_gateway.clone());
  242. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  243. join_lobby(&mut ship, ClientId(1)).await;
  244. create_room(&mut ship, ClientId(1), "room", "").await;
  245. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  246. client: 0,
  247. target: 0,
  248. item_id: 0x10000,
  249. amount: 1,
  250. })))).await.unwrap();
  251. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  252. assert_eq!(c1_meseta.0, 4406);
  253. }
  254. #[async_std::test]
  255. async fn test_other_clients_see_purchase() {
  256. let mut entity_gateway = InMemoryGateway::default();
  257. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  258. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  259. char1.exp = 80000000;
  260. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  261. entity_gateway.save_character(&char1).await.unwrap();
  262. let mut ship = standard_ship_buildable(entity_gateway.clone())
  263. .item_shops(StandardItemShops::default())
  264. .build();
  265. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  266. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  267. join_lobby(&mut ship, ClientId(1)).await;
  268. join_lobby(&mut ship, ClientId(2)).await;
  269. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  270. join_room(&mut ship, ClientId(2), 0).await;
  271. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  272. client: 255,
  273. target: 255,
  274. shop_type: 1
  275. })))).await.unwrap();
  276. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  277. client: 255,
  278. target: 255,
  279. item_id: 0x10000,
  280. shop_type: 1,
  281. shop_index: 0,
  282. amount: 1,
  283. unknown1: 0,
  284. })))).await.unwrap();
  285. assert_eq!(packets.len(), 1);
  286. assert_eq!(packets[0].0, ClientId(2));
  287. match &packets[0].1 {
  288. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  289. _ => panic!(""),
  290. }
  291. }
  292. #[async_std::test]
  293. async fn test_other_clients_see_stacked_purchase() {
  294. let mut entity_gateway = InMemoryGateway::default();
  295. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  296. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  297. char1.exp = 80000000;
  298. entity_gateway.save_character(&char1).await.unwrap();
  299. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  300. entity_gateway.create_item(
  301. item::NewItemEntity {
  302. item: item::ItemDetail::Tool(
  303. item::tool::Tool {
  304. tool: item::tool::ToolType::Monomate
  305. }
  306. ),
  307. }).await.unwrap();
  308. let mut ship = standard_ship_buildable(entity_gateway.clone())
  309. .item_shops(StandardItemShops::default())
  310. .build();
  311. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  312. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  313. join_lobby(&mut ship, ClientId(1)).await;
  314. join_lobby(&mut ship, ClientId(2)).await;
  315. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  316. join_room(&mut ship, ClientId(2), 0).await;
  317. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  318. client: 255,
  319. target: 255,
  320. shop_type: 1
  321. })))).await.unwrap();
  322. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  323. client: 255,
  324. target: 255,
  325. item_id: 0x10000,
  326. shop_type: 1,
  327. shop_index: 0,
  328. amount: 1,
  329. unknown1: 0,
  330. })))).await.unwrap();
  331. assert_eq!(packets.len(), 1);
  332. assert_eq!(packets[0].0, ClientId(2));
  333. match &packets[0].1 {
  334. SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
  335. _ => panic!(""),
  336. }
  337. }
  338. #[async_std::test]
  339. async fn test_buying_item_without_enough_mseseta() {
  340. let mut entity_gateway = InMemoryGateway::default();
  341. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  342. let mut ship = standard_ship(entity_gateway.clone());
  343. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  344. join_lobby(&mut ship, ClientId(1)).await;
  345. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
  346. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  347. client: 255,
  348. target: 255,
  349. shop_type: 1
  350. })))).await.unwrap();
  351. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  352. client: 255,
  353. target: 255,
  354. item_id: 0x10000,
  355. shop_type: 1,
  356. shop_index: 0,
  357. amount: 1,
  358. unknown1: 0,
  359. })))).await;
  360. assert!(packets.is_err());
  361. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  362. assert_eq!(c1_meseta.0, 0);
  363. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  364. assert_eq!(p1_items.items.len(), 0);
  365. }
  366. #[async_std::test]
  367. async fn test_player_double_buys_from_tool_shop() {
  368. let mut entity_gateway = InMemoryGateway::default();
  369. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  370. char1.exp = 80000000;
  371. entity_gateway.save_character(&char1).await.unwrap();
  372. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  373. let mut ship = standard_ship_buildable(entity_gateway.clone())
  374. .item_shops(StandardItemShops::default())
  375. .build();
  376. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  377. join_lobby(&mut ship, ClientId(1)).await;
  378. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  379. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  380. client: 255,
  381. target: 255,
  382. shop_type: 0,
  383. })))).await.unwrap();
  384. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  385. client: 255,
  386. target: 255,
  387. item_id: 0x10000,
  388. shop_type: 0,
  389. shop_index: 0,
  390. amount: 3,
  391. unknown1: 0,
  392. })))).await.unwrap();
  393. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  394. client: 255,
  395. target: 255,
  396. item_id: 0x10001,
  397. shop_type: 0,
  398. shop_index: 1,
  399. amount: 2,
  400. unknown1: 0,
  401. })))).await.unwrap();
  402. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  403. client: 255,
  404. target: 255,
  405. item_id: 0x10002,
  406. shop_type: 0,
  407. shop_index: 0,
  408. amount: 4,
  409. unknown1: 0,
  410. })))).await.unwrap();
  411. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  412. assert!(c1_meseta.0 < 999999);
  413. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  414. assert_eq!(p1_items.items.len(), 2);
  415. p1_items.items[0].with_stacked(|item| {
  416. assert_eq!(item.len(), 7);
  417. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  418. }).unwrap();
  419. p1_items.items[1].with_stacked(|item| {
  420. assert_eq!(item.len(), 2);
  421. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Dimate));
  422. }).unwrap();
  423. }
  424. #[async_std::test]
  425. async fn test_techs_disappear_from_shop_when_bought() {
  426. let mut entity_gateway = InMemoryGateway::default();
  427. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  428. char1.exp = 80000000;
  429. entity_gateway.save_character(&char1).await.unwrap();
  430. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  431. let mut ship = standard_ship_buildable(entity_gateway.clone())
  432. .item_shops(StandardItemShops::default())
  433. .build();
  434. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  435. join_lobby(&mut ship, ClientId(1)).await;
  436. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  437. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  438. client: 255,
  439. target: 255,
  440. shop_type: 0,
  441. })))).await.unwrap();
  442. let first_tech = match &packets[0].1 {
  443. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  444. shop_list.items.iter()
  445. .enumerate()
  446. .filter(|(_, item)| {
  447. item.item_bytes[0] == 3 && item.item_bytes[1] == 2
  448. })
  449. .nth(0).unwrap().0
  450. },
  451. _ => panic!(""),
  452. };
  453. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  454. client: 255,
  455. target: 255,
  456. item_id: 0x10000,
  457. shop_type: 0,
  458. shop_index: first_tech as u8,
  459. amount: 1,
  460. unknown1: 0,
  461. })))).await.unwrap();
  462. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  463. client: 255,
  464. target: 255,
  465. item_id: 0x10001,
  466. shop_type: 0,
  467. shop_index: first_tech as u8,
  468. amount: 1,
  469. unknown1: 0,
  470. })))).await.unwrap();
  471. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  472. p1_items.items[0].with_individual(|item1| {
  473. p1_items.items[1].with_individual(|item2| {
  474. assert_ne!(item1, item2);
  475. }).unwrap();
  476. }).unwrap();
  477. }
  478. // TOOD: this is not deterministic and can randomly fail
  479. #[async_std::test]
  480. async fn test_units_disappear_from_shop_when_bought() {
  481. let mut entity_gateway = InMemoryGateway::default();
  482. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  483. char1.exp = 80000000;
  484. entity_gateway.save_character(&char1).await.unwrap();
  485. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  486. let mut ship = standard_ship_buildable(entity_gateway.clone())
  487. .item_shops(StandardItemShops::default())
  488. .build();
  489. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  490. join_lobby(&mut ship, ClientId(1)).await;
  491. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  492. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  493. client: 255,
  494. target: 255,
  495. shop_type: 2,
  496. })))).await.unwrap();
  497. let first_unit = match &packets[0].1 {
  498. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  499. shop_list.items.iter()
  500. .enumerate()
  501. .filter(|(_, item)| {
  502. item.item_bytes[0] == 1 && item.item_bytes[1] == 3
  503. })
  504. .nth(0).unwrap().0
  505. },
  506. _ => panic!(""),
  507. };
  508. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  509. client: 255,
  510. target: 255,
  511. item_id: 0x10000,
  512. shop_type: 2,
  513. shop_index: first_unit as u8,
  514. amount: 1,
  515. unknown1: 0,
  516. })))).await.unwrap();
  517. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  518. client: 255,
  519. target: 255,
  520. item_id: 0x10001,
  521. shop_type: 2,
  522. shop_index: first_unit as u8,
  523. amount: 1,
  524. unknown1: 0,
  525. })))).await.unwrap();
  526. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  527. p1_items.items[0].with_individual(|item1| {
  528. p1_items.items[1].with_individual(|item2| {
  529. assert_ne!(item1, item2);
  530. }).unwrap();
  531. }).unwrap();
  532. }
  533. #[async_std::test]
  534. async fn test_player_sells_untekked_weapon() {
  535. let mut entity_gateway = InMemoryGateway::default();
  536. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  537. let mut p1_inv = Vec::new();
  538. p1_inv.push(entity_gateway.create_item(
  539. item::NewItemEntity {
  540. item: item::ItemDetail::Weapon(
  541. item::weapon::Weapon {
  542. weapon: item::weapon::WeaponType::Vulcan,
  543. grind: 5,
  544. special: Some(item::weapon::WeaponSpecial::Charge),
  545. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  546. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  547. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  548. tekked: false,
  549. }
  550. ),
  551. }).await.unwrap());
  552. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  553. let mut ship = standard_ship(entity_gateway.clone());
  554. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  555. join_lobby(&mut ship, ClientId(1)).await;
  556. create_room(&mut ship, ClientId(1), "room", "").await;
  557. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  558. client: 0,
  559. target: 0,
  560. item_id: 0x10000,
  561. amount: 1,
  562. })))).await.unwrap();
  563. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  564. assert_eq!(c1_meseta.0, 1);
  565. }
  566. #[async_std::test]
  567. async fn test_player_sells_rare_item() {
  568. let mut entity_gateway = InMemoryGateway::default();
  569. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  570. let mut p1_inv = Vec::new();
  571. p1_inv.push(entity_gateway.create_item(
  572. item::NewItemEntity {
  573. item: item::ItemDetail::Weapon(
  574. item::weapon::Weapon {
  575. weapon: item::weapon::WeaponType::DarkFlow,
  576. grind: 5,
  577. special: None,
  578. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  579. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  580. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  581. tekked: true,
  582. }
  583. ),
  584. }).await.unwrap());
  585. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  586. let mut ship = standard_ship(entity_gateway.clone());
  587. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  588. join_lobby(&mut ship, ClientId(1)).await;
  589. create_room(&mut ship, ClientId(1), "room", "").await;
  590. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  591. client: 0,
  592. target: 0,
  593. item_id: 0x10000,
  594. amount: 1,
  595. })))).await.unwrap();
  596. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  597. assert_eq!(c1_meseta.0, 10);
  598. }
  599. #[async_std::test]
  600. async fn test_player_sells_partial_photon_drop_stack() {
  601. let mut entity_gateway = InMemoryGateway::default();
  602. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  603. let mut p1_inv = Vec::new();
  604. let mut photon_drops = Vec::new();
  605. for _ in 0..7usize {
  606. photon_drops.push(entity_gateway.create_item(
  607. item::NewItemEntity {
  608. item: item::ItemDetail::Tool(
  609. item::tool::Tool {
  610. tool: item::tool::ToolType::PhotonDrop,
  611. }
  612. ),
  613. }).await.unwrap());
  614. }
  615. p1_inv.push(item::InventoryItemEntity::Stacked(photon_drops));
  616. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  617. let mut ship = standard_ship(entity_gateway.clone());
  618. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  619. join_lobby(&mut ship, ClientId(1)).await;
  620. create_room(&mut ship, ClientId(1), "room", "").await;
  621. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  622. client: 0,
  623. target: 0,
  624. item_id: 0x10000,
  625. amount: 3,
  626. })))).await.unwrap();
  627. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  628. assert_eq!(c1_meseta.0, 3000);
  629. }
  630. #[async_std::test]
  631. async fn test_player_sells_basic_frame() {
  632. let mut entity_gateway = InMemoryGateway::default();
  633. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  634. let mut p1_inv = Vec::new();
  635. p1_inv.push(entity_gateway.create_item(
  636. item::NewItemEntity {
  637. item: item::ItemDetail::Armor(
  638. item::armor::Armor {
  639. armor: item::armor::ArmorType::Frame,
  640. dfp: 0,
  641. evp: 0,
  642. slots: 0,
  643. }
  644. ),
  645. }).await.unwrap());
  646. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  647. let mut ship = standard_ship(entity_gateway.clone());
  648. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  649. join_lobby(&mut ship, ClientId(1)).await;
  650. create_room(&mut ship, ClientId(1), "room", "").await;
  651. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  652. client: 0,
  653. target: 0,
  654. item_id: 0x10000,
  655. amount: 1,
  656. })))).await.unwrap();
  657. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  658. assert_eq!(c1_meseta.0, 24);
  659. }
  660. #[async_std::test]
  661. async fn test_player_sells_max_frame() {
  662. let mut entity_gateway = InMemoryGateway::default();
  663. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  664. let mut p1_inv = Vec::new();
  665. p1_inv.push(entity_gateway.create_item(
  666. item::NewItemEntity {
  667. item: item::ItemDetail::Armor(
  668. item::armor::Armor {
  669. armor: item::armor::ArmorType::Frame,
  670. dfp: 2,
  671. evp: 2,
  672. slots: 4,
  673. }
  674. ),
  675. }).await.unwrap());
  676. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  677. let mut ship = standard_ship(entity_gateway.clone());
  678. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  679. join_lobby(&mut ship, ClientId(1)).await;
  680. create_room(&mut ship, ClientId(1), "room", "").await;
  681. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  682. client: 0,
  683. target: 0,
  684. item_id: 0x10000,
  685. amount: 1,
  686. })))).await.unwrap();
  687. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  688. assert_eq!(c1_meseta.0, 74);
  689. }
  690. #[async_std::test]
  691. async fn test_player_sells_basic_barrier() {
  692. let mut entity_gateway = InMemoryGateway::default();
  693. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  694. let mut p1_inv = Vec::new();
  695. p1_inv.push(entity_gateway.create_item(
  696. item::NewItemEntity {
  697. item: item::ItemDetail::Shield(
  698. item::shield::Shield {
  699. shield: item::shield::ShieldType::Barrier,
  700. dfp: 0,
  701. evp: 0,
  702. }
  703. ),
  704. }).await.unwrap());
  705. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  706. let mut ship = standard_ship(entity_gateway.clone());
  707. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  708. join_lobby(&mut ship, ClientId(1)).await;
  709. create_room(&mut ship, ClientId(1), "room", "").await;
  710. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  711. client: 0,
  712. target: 0,
  713. item_id: 0x10000,
  714. amount: 1,
  715. })))).await.unwrap();
  716. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  717. assert_eq!(c1_meseta.0, 69);
  718. }
  719. #[async_std::test]
  720. async fn test_player_sells_max_barrier() {
  721. let mut entity_gateway = InMemoryGateway::default();
  722. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  723. let mut p1_inv = Vec::new();
  724. p1_inv.push(entity_gateway.create_item(
  725. item::NewItemEntity {
  726. item: item::ItemDetail::Shield(
  727. item::shield::Shield {
  728. shield: item::shield::ShieldType::Barrier,
  729. dfp: 5,
  730. evp: 5,
  731. }
  732. ),
  733. }).await.unwrap());
  734. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  735. let mut ship = standard_ship(entity_gateway.clone());
  736. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  737. join_lobby(&mut ship, ClientId(1)).await;
  738. create_room(&mut ship, ClientId(1), "room", "").await;
  739. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  740. client: 0,
  741. target: 0,
  742. item_id: 0x10000,
  743. amount: 1,
  744. })))).await.unwrap();
  745. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  746. assert_eq!(c1_meseta.0, 122);
  747. }
  748. #[async_std::test]
  749. async fn test_player_sells_1_star_minusminus_unit() {
  750. let mut entity_gateway = InMemoryGateway::default();
  751. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  752. let mut p1_inv = Vec::new();
  753. p1_inv.push(entity_gateway.create_item(
  754. item::NewItemEntity {
  755. item: item::ItemDetail::Unit(
  756. item::unit::Unit {
  757. unit: item::unit::UnitType::PriestMind,
  758. modifier: Some(item::unit::UnitModifier::MinusMinus),
  759. }
  760. ),
  761. }).await.unwrap());
  762. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  763. let mut ship = standard_ship(entity_gateway.clone());
  764. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  765. join_lobby(&mut ship, ClientId(1)).await;
  766. create_room(&mut ship, ClientId(1), "room", "").await;
  767. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  768. client: 0,
  769. target: 0,
  770. item_id: 0x10000,
  771. amount: 1,
  772. })))).await.unwrap();
  773. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  774. assert_eq!(c1_meseta.0, 125);
  775. }
  776. #[async_std::test]
  777. async fn test_player_sells_5_star_plusplus_unit() {
  778. let mut entity_gateway = InMemoryGateway::default();
  779. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  780. let mut p1_inv = Vec::new();
  781. p1_inv.push(entity_gateway.create_item(
  782. item::NewItemEntity {
  783. item: item::ItemDetail::Unit(
  784. item::unit::Unit {
  785. unit: item::unit::UnitType::GeneralHp,
  786. modifier: Some(item::unit::UnitModifier::PlusPlus),
  787. }
  788. ),
  789. }).await.unwrap());
  790. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  791. let mut ship = standard_ship(entity_gateway.clone());
  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();
  801. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  802. assert_eq!(c1_meseta.0, 625);
  803. }
  804. #[async_std::test]
  805. async fn test_player_sells_rare_frame() {
  806. let mut entity_gateway = InMemoryGateway::default();
  807. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  808. let mut p1_inv = Vec::new();
  809. p1_inv.push(entity_gateway.create_item(
  810. item::NewItemEntity {
  811. item: item::ItemDetail::Armor(
  812. item::armor::Armor {
  813. armor: item::armor::ArmorType::StinkFrame,
  814. dfp: 10,
  815. evp: 20,
  816. slots: 3,
  817. }
  818. ),
  819. }).await.unwrap());
  820. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  821. let mut ship = standard_ship(entity_gateway.clone());
  822. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  823. join_lobby(&mut ship, ClientId(1)).await;
  824. create_room(&mut ship, ClientId(1), "room", "").await;
  825. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  826. client: 0,
  827. target: 0,
  828. item_id: 0x10000,
  829. amount: 1,
  830. })))).await.unwrap();
  831. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  832. assert_eq!(c1_meseta.0, 10);
  833. }
  834. #[async_std::test]
  835. async fn test_player_sells_rare_barrier() {
  836. let mut entity_gateway = InMemoryGateway::default();
  837. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  838. let mut p1_inv = Vec::new();
  839. p1_inv.push(entity_gateway.create_item(
  840. item::NewItemEntity {
  841. item: item::ItemDetail::Shield(
  842. item::shield::Shield {
  843. shield: item::shield::ShieldType::RedRing,
  844. dfp: 10,
  845. evp: 20,
  846. }
  847. ),
  848. }).await.unwrap());
  849. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  850. let mut ship = standard_ship(entity_gateway.clone());
  851. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  852. join_lobby(&mut ship, ClientId(1)).await;
  853. create_room(&mut ship, ClientId(1), "room", "").await;
  854. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  855. client: 0,
  856. target: 0,
  857. item_id: 0x10000,
  858. amount: 1,
  859. })))).await.unwrap();
  860. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  861. assert_eq!(c1_meseta.0, 10);
  862. }
  863. #[async_std::test]
  864. async fn test_player_sells_rare_unit() {
  865. let mut entity_gateway = InMemoryGateway::default();
  866. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  867. let mut p1_inv = Vec::new();
  868. p1_inv.push(entity_gateway.create_item(
  869. item::NewItemEntity {
  870. item: item::ItemDetail::Unit(
  871. item::unit::Unit {
  872. unit: item::unit::UnitType::V101,
  873. modifier: None,
  874. }
  875. ),
  876. }).await.unwrap());
  877. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  878. let mut ship = standard_ship(entity_gateway.clone());
  879. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  880. join_lobby(&mut ship, ClientId(1)).await;
  881. create_room(&mut ship, ClientId(1), "room", "").await;
  882. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  883. client: 0,
  884. target: 0,
  885. item_id: 0x10000,
  886. amount: 1,
  887. })))).await.unwrap();
  888. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  889. assert_eq!(c1_meseta.0, 10);
  890. }
  891. #[async_std::test]
  892. async fn test_player_cant_sell_if_meseta_would_go_over_max() {
  893. let mut entity_gateway = InMemoryGateway::default();
  894. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  895. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999995)).await.unwrap();
  896. let mut p1_inv = Vec::new();
  897. p1_inv.push(entity_gateway.create_item(
  898. item::NewItemEntity {
  899. item: item::ItemDetail::Unit(
  900. item::unit::Unit {
  901. unit: item::unit::UnitType::V101,
  902. modifier: None,
  903. }
  904. ),
  905. }).await.unwrap());
  906. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  907. let mut ship = standard_ship(entity_gateway.clone());
  908. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  909. join_lobby(&mut ship, ClientId(1)).await;
  910. create_room(&mut ship, ClientId(1), "room", "").await;
  911. let ack = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  912. client: 0,
  913. target: 0,
  914. item_id: 0x10000,
  915. amount: 1,
  916. })))).await.err().unwrap();
  917. //assert_eq!(ack, ShipError::ItemStateError(ItemStateError::FullOfMeseta));
  918. assert!(matches!(ack.downcast::<ItemStateError>().unwrap(), ItemStateError::FullOfMeseta));
  919. //assert!(matches!(ack.downcast::<ShipError>().unwrap(), ShipError::ItemStateError(ItemStateError::FullOfMeseta)));
  920. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  921. assert_eq!(c1_meseta.0, 999995);
  922. }