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.

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