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.

1150 lines
41 KiB

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