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.

1156 lines
42 KiB

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
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
3 years ago
  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::entity::item;
  4. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  5. use elseware::ship::room::Difficulty;
  6. use elseware::ship::items::state::ItemStateError;
  7. use libpso::packet::ship::*;
  8. use libpso::packet::messages::*;
  9. #[path = "common.rs"]
  10. mod common;
  11. use common::*;
  12. #[async_std::test]
  13. async fn test_player_opens_weapon_shop() {
  14. let mut entity_gateway = InMemoryGateway::default();
  15. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  16. char1.exp = 80000000;
  17. entity_gateway.save_character(&char1).await.unwrap();
  18. let mut ship = Box::new(ShipServerState::builder()
  19. .gateway(entity_gateway.clone())
  20. .build());
  21. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  22. join_lobby(&mut ship, ClientId(1)).await;
  23. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  24. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  25. client: 255,
  26. target: 255,
  27. shop_type: 1
  28. })))).await.unwrap().collect::<Vec<_>>();
  29. assert_eq!(packets.len(), 1);
  30. match &packets[0].1 {
  31. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  32. assert_eq!(shop_list.items.len(), 16)
  33. }
  34. _ => panic!("")
  35. }
  36. }
  37. #[async_std::test]
  38. async fn test_player_opens_tool_shop() {
  39. let mut entity_gateway = InMemoryGateway::default();
  40. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  41. char1.exp = 80000000;
  42. entity_gateway.save_character(&char1).await.unwrap();
  43. let mut ship = Box::new(ShipServerState::builder()
  44. .gateway(entity_gateway.clone())
  45. .build());
  46. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  47. join_lobby(&mut ship, ClientId(1)).await;
  48. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  49. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  50. client: 255,
  51. target: 255,
  52. shop_type: 0
  53. })))).await.unwrap().collect::<Vec<_>>();
  54. assert_eq!(packets.len(), 1);
  55. match &packets[0].1 {
  56. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  57. assert_eq!(shop_list.items.len(), 18)
  58. }
  59. _ => panic!("")
  60. }
  61. }
  62. #[async_std::test]
  63. async fn test_player_opens_armor_shop() {
  64. let mut entity_gateway = InMemoryGateway::default();
  65. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  66. char1.exp = 80000000;
  67. entity_gateway.save_character(&char1).await.unwrap();
  68. let mut ship = Box::new(ShipServerState::builder()
  69. .gateway(entity_gateway.clone())
  70. .build());
  71. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  72. join_lobby(&mut ship, ClientId(1)).await;
  73. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  74. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  75. client: 255,
  76. target: 255,
  77. shop_type: 2
  78. })))).await.unwrap().collect::<Vec<_>>();
  79. assert_eq!(packets.len(), 1);
  80. match &packets[0].1 {
  81. SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
  82. assert_eq!(shop_list.items.len(), 21)
  83. }
  84. _ => panic!("")
  85. }
  86. }
  87. #[async_std::test]
  88. async fn test_player_buys_from_weapon_shop() {
  89. let mut entity_gateway = InMemoryGateway::default();
  90. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  91. char1.exp = 80000000;
  92. entity_gateway.save_character(&char1).await.unwrap();
  93. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  94. let mut ship = Box::new(ShipServerState::builder()
  95. .gateway(entity_gateway.clone())
  96. .build());
  97. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  98. join_lobby(&mut ship, ClientId(1)).await;
  99. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  100. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  101. client: 255,
  102. target: 255,
  103. shop_type: 1
  104. })))).await.unwrap().for_each(drop);
  105. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  106. client: 255,
  107. target: 255,
  108. item_id: 0x10000,
  109. shop_type: 1,
  110. shop_index: 0,
  111. amount: 1,
  112. unknown1: 0,
  113. })))).await.unwrap().for_each(drop);
  114. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  115. assert!(c1_meseta.0 < 999999);
  116. //let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
  117. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  118. assert_eq!(p1_items.items.len(), 1);
  119. }
  120. #[async_std::test]
  121. async fn test_player_buys_from_tool_shop() {
  122. let mut entity_gateway = InMemoryGateway::default();
  123. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  124. char1.exp = 80000000;
  125. entity_gateway.save_character(&char1).await.unwrap();
  126. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  127. let mut ship = Box::new(ShipServerState::builder()
  128. .gateway(entity_gateway.clone())
  129. .build());
  130. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  131. join_lobby(&mut ship, ClientId(1)).await;
  132. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  133. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  134. client: 255,
  135. target: 255,
  136. shop_type: 0,
  137. })))).await.unwrap().for_each(drop);
  138. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  139. client: 255,
  140. target: 255,
  141. item_id: 0x10000,
  142. shop_type: 0,
  143. shop_index: 0,
  144. amount: 1,
  145. unknown1: 0,
  146. })))).await.unwrap().for_each(drop);
  147. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  148. assert!(c1_meseta.0 < 999999);
  149. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  150. assert_eq!(p1_items.items.len(), 1);
  151. }
  152. #[async_std::test]
  153. async fn test_player_buys_multiple_from_tool_shop() {
  154. let mut entity_gateway = InMemoryGateway::default();
  155. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  156. char1.exp = 80000000;
  157. entity_gateway.save_character(&char1).await.unwrap();
  158. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  159. let mut ship = Box::new(ShipServerState::builder()
  160. .gateway(entity_gateway.clone())
  161. .build());
  162. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  163. join_lobby(&mut ship, ClientId(1)).await;
  164. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  165. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  166. client: 255,
  167. target: 255,
  168. shop_type: 0,
  169. })))).await.unwrap().for_each(drop);
  170. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  171. client: 255,
  172. target: 255,
  173. item_id: 0x10000,
  174. shop_type: 0,
  175. shop_index: 0,
  176. amount: 5,
  177. unknown1: 0,
  178. })))).await.unwrap().for_each(drop);
  179. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  180. assert_eq!(c1_meseta.0, 999749);
  181. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  182. assert_eq!(p1_items.items.len(), 1);
  183. p1_items.items[0].with_stacked(|item| {
  184. assert_eq!(item.len(), 5);
  185. assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  186. }).unwrap();
  187. }
  188. #[async_std::test]
  189. async fn test_player_buys_from_armor_shop() {
  190. let mut entity_gateway = InMemoryGateway::default();
  191. let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  192. char1.exp = 80000000;
  193. entity_gateway.save_character(&char1).await.unwrap();
  194. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  195. let mut ship = Box::new(ShipServerState::builder()
  196. .gateway(entity_gateway.clone())
  197. .build());
  198. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  199. join_lobby(&mut ship, ClientId(1)).await;
  200. create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  201. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  202. client: 255,
  203. target: 255,
  204. shop_type: 2
  205. })))).await.unwrap().for_each(drop);
  206. ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  207. client: 255,
  208. target: 255,
  209. item_id: 0x10000,
  210. shop_type: 2,
  211. shop_index: 0,
  212. amount: 1,
  213. unknown1: 0,
  214. })))).await.unwrap().for_each(drop);
  215. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  216. assert!(c1_meseta.0 < 999999);
  217. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  218. assert_eq!(p1_items.items.len(), 1);
  219. }
  220. #[async_std::test]
  221. async fn test_player_sells_3_attr_weapon_to_shop() {
  222. let mut entity_gateway = InMemoryGateway::default();
  223. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  224. let mut p1_inv = Vec::new();
  225. p1_inv.push(entity_gateway.create_item(
  226. item::NewItemEntity {
  227. item: item::ItemDetail::Weapon(
  228. item::weapon::Weapon {
  229. weapon: item::weapon::WeaponType::Vulcan,
  230. grind: 5,
  231. special: Some(item::weapon::WeaponSpecial::Charge),
  232. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  233. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  234. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  235. tekked: true,
  236. kills: None,
  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. kills: None,
  554. }
  555. ),
  556. }).await.unwrap());
  557. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  558. let mut ship = Box::new(ShipServerState::builder()
  559. .gateway(entity_gateway.clone())
  560. .build());
  561. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  562. join_lobby(&mut ship, ClientId(1)).await;
  563. create_room(&mut ship, ClientId(1), "room", "").await;
  564. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  565. client: 0,
  566. target: 0,
  567. item_id: 0x10000,
  568. amount: 1,
  569. })))).await.unwrap().for_each(drop);
  570. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  571. assert_eq!(c1_meseta.0, 1);
  572. }
  573. #[async_std::test]
  574. async fn test_player_sells_rare_item() {
  575. let mut entity_gateway = InMemoryGateway::default();
  576. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  577. let mut p1_inv = Vec::new();
  578. p1_inv.push(entity_gateway.create_item(
  579. item::NewItemEntity {
  580. item: item::ItemDetail::Weapon(
  581. item::weapon::Weapon {
  582. weapon: item::weapon::WeaponType::DarkFlow,
  583. grind: 5,
  584. special: None,
  585. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  586. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  587. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  588. tekked: true,
  589. kills: None,
  590. }
  591. ),
  592. }).await.unwrap());
  593. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  594. let mut ship = Box::new(ShipServerState::builder()
  595. .gateway(entity_gateway.clone())
  596. .build());
  597. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  598. join_lobby(&mut ship, ClientId(1)).await;
  599. create_room(&mut ship, ClientId(1), "room", "").await;
  600. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  601. client: 0,
  602. target: 0,
  603. item_id: 0x10000,
  604. amount: 1,
  605. })))).await.unwrap().for_each(drop);
  606. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  607. assert_eq!(c1_meseta.0, 10);
  608. }
  609. #[async_std::test]
  610. async fn test_player_sells_partial_photon_drop_stack() {
  611. let mut entity_gateway = InMemoryGateway::default();
  612. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  613. let mut p1_inv = Vec::new();
  614. let mut photon_drops = Vec::new();
  615. for _ in 0..7usize {
  616. photon_drops.push(entity_gateway.create_item(
  617. item::NewItemEntity {
  618. item: item::ItemDetail::Tool(
  619. item::tool::Tool {
  620. tool: item::tool::ToolType::PhotonDrop,
  621. }
  622. ),
  623. }).await.unwrap());
  624. }
  625. p1_inv.push(item::InventoryItemEntity::Stacked(photon_drops));
  626. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  627. let mut ship = Box::new(ShipServerState::builder()
  628. .gateway(entity_gateway.clone())
  629. .build());
  630. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  631. join_lobby(&mut ship, ClientId(1)).await;
  632. create_room(&mut ship, ClientId(1), "room", "").await;
  633. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  634. client: 0,
  635. target: 0,
  636. item_id: 0x10000,
  637. amount: 3,
  638. })))).await.unwrap().for_each(drop);
  639. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  640. assert_eq!(c1_meseta.0, 3000);
  641. }
  642. #[async_std::test]
  643. async fn test_player_sells_basic_frame() {
  644. let mut entity_gateway = InMemoryGateway::default();
  645. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  646. let mut p1_inv = Vec::new();
  647. p1_inv.push(entity_gateway.create_item(
  648. item::NewItemEntity {
  649. item: item::ItemDetail::Armor(
  650. item::armor::Armor {
  651. armor: item::armor::ArmorType::Frame,
  652. dfp: 0,
  653. evp: 0,
  654. slots: 0,
  655. }
  656. ),
  657. }).await.unwrap());
  658. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  659. let mut ship = Box::new(ShipServerState::builder()
  660. .gateway(entity_gateway.clone())
  661. .build());
  662. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  663. join_lobby(&mut ship, ClientId(1)).await;
  664. create_room(&mut ship, ClientId(1), "room", "").await;
  665. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  666. client: 0,
  667. target: 0,
  668. item_id: 0x10000,
  669. amount: 1,
  670. })))).await.unwrap().for_each(drop);
  671. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  672. assert_eq!(c1_meseta.0, 24);
  673. }
  674. #[async_std::test]
  675. async fn test_player_sells_max_frame() {
  676. let mut entity_gateway = InMemoryGateway::default();
  677. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  678. let mut p1_inv = Vec::new();
  679. p1_inv.push(entity_gateway.create_item(
  680. item::NewItemEntity {
  681. item: item::ItemDetail::Armor(
  682. item::armor::Armor {
  683. armor: item::armor::ArmorType::Frame,
  684. dfp: 2,
  685. evp: 2,
  686. slots: 4,
  687. }
  688. ),
  689. }).await.unwrap());
  690. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  691. let mut ship = Box::new(ShipServerState::builder()
  692. .gateway(entity_gateway.clone())
  693. .build());
  694. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  695. join_lobby(&mut ship, ClientId(1)).await;
  696. create_room(&mut ship, ClientId(1), "room", "").await;
  697. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  698. client: 0,
  699. target: 0,
  700. item_id: 0x10000,
  701. amount: 1,
  702. })))).await.unwrap().for_each(drop);
  703. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  704. assert_eq!(c1_meseta.0, 74);
  705. }
  706. #[async_std::test]
  707. async fn test_player_sells_basic_barrier() {
  708. let mut entity_gateway = InMemoryGateway::default();
  709. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  710. let mut p1_inv = Vec::new();
  711. p1_inv.push(entity_gateway.create_item(
  712. item::NewItemEntity {
  713. item: item::ItemDetail::Shield(
  714. item::shield::Shield {
  715. shield: item::shield::ShieldType::Barrier,
  716. dfp: 0,
  717. evp: 0,
  718. }
  719. ),
  720. }).await.unwrap());
  721. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  722. let mut ship = Box::new(ShipServerState::builder()
  723. .gateway(entity_gateway.clone())
  724. .build());
  725. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  726. join_lobby(&mut ship, ClientId(1)).await;
  727. create_room(&mut ship, ClientId(1), "room", "").await;
  728. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  729. client: 0,
  730. target: 0,
  731. item_id: 0x10000,
  732. amount: 1,
  733. })))).await.unwrap().for_each(drop);
  734. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  735. assert_eq!(c1_meseta.0, 69);
  736. }
  737. #[async_std::test]
  738. async fn test_player_sells_max_barrier() {
  739. let mut entity_gateway = InMemoryGateway::default();
  740. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  741. let mut p1_inv = Vec::new();
  742. p1_inv.push(entity_gateway.create_item(
  743. item::NewItemEntity {
  744. item: item::ItemDetail::Shield(
  745. item::shield::Shield {
  746. shield: item::shield::ShieldType::Barrier,
  747. dfp: 5,
  748. evp: 5,
  749. }
  750. ),
  751. }).await.unwrap());
  752. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  753. let mut ship = Box::new(ShipServerState::builder()
  754. .gateway(entity_gateway.clone())
  755. .build());
  756. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  757. join_lobby(&mut ship, ClientId(1)).await;
  758. create_room(&mut ship, ClientId(1), "room", "").await;
  759. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  760. client: 0,
  761. target: 0,
  762. item_id: 0x10000,
  763. amount: 1,
  764. })))).await.unwrap().for_each(drop);
  765. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  766. assert_eq!(c1_meseta.0, 122);
  767. }
  768. #[async_std::test]
  769. async fn test_player_sells_1_star_minusminus_unit() {
  770. let mut entity_gateway = InMemoryGateway::default();
  771. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  772. let mut p1_inv = Vec::new();
  773. p1_inv.push(entity_gateway.create_item(
  774. item::NewItemEntity {
  775. item: item::ItemDetail::Unit(
  776. item::unit::Unit {
  777. unit: item::unit::UnitType::PriestMind,
  778. modifier: Some(item::unit::UnitModifier::MinusMinus),
  779. kills: None,
  780. }
  781. ),
  782. }).await.unwrap());
  783. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  784. let mut ship = Box::new(ShipServerState::builder()
  785. .gateway(entity_gateway.clone())
  786. .build());
  787. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  788. join_lobby(&mut ship, ClientId(1)).await;
  789. create_room(&mut ship, ClientId(1), "room", "").await;
  790. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  791. client: 0,
  792. target: 0,
  793. item_id: 0x10000,
  794. amount: 1,
  795. })))).await.unwrap().for_each(drop);
  796. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  797. assert_eq!(c1_meseta.0, 125);
  798. }
  799. #[async_std::test]
  800. async fn test_player_sells_5_star_plusplus_unit() {
  801. let mut entity_gateway = InMemoryGateway::default();
  802. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  803. let mut p1_inv = Vec::new();
  804. p1_inv.push(entity_gateway.create_item(
  805. item::NewItemEntity {
  806. item: item::ItemDetail::Unit(
  807. item::unit::Unit {
  808. unit: item::unit::UnitType::GeneralHp,
  809. modifier: Some(item::unit::UnitModifier::PlusPlus),
  810. kills: None,
  811. }
  812. ),
  813. }).await.unwrap());
  814. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  815. let mut ship = Box::new(ShipServerState::builder()
  816. .gateway(entity_gateway.clone())
  817. .build());
  818. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  819. join_lobby(&mut ship, ClientId(1)).await;
  820. create_room(&mut ship, ClientId(1), "room", "").await;
  821. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  822. client: 0,
  823. target: 0,
  824. item_id: 0x10000,
  825. amount: 1,
  826. })))).await.unwrap().for_each(drop);
  827. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  828. assert_eq!(c1_meseta.0, 625);
  829. }
  830. #[async_std::test]
  831. async fn test_player_sells_rare_frame() {
  832. let mut entity_gateway = InMemoryGateway::default();
  833. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  834. let mut p1_inv = Vec::new();
  835. p1_inv.push(entity_gateway.create_item(
  836. item::NewItemEntity {
  837. item: item::ItemDetail::Armor(
  838. item::armor::Armor {
  839. armor: item::armor::ArmorType::StinkFrame,
  840. dfp: 10,
  841. evp: 20,
  842. slots: 3,
  843. }
  844. ),
  845. }).await.unwrap());
  846. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  847. let mut ship = Box::new(ShipServerState::builder()
  848. .gateway(entity_gateway.clone())
  849. .build());
  850. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  851. join_lobby(&mut ship, ClientId(1)).await;
  852. create_room(&mut ship, ClientId(1), "room", "").await;
  853. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  854. client: 0,
  855. target: 0,
  856. item_id: 0x10000,
  857. amount: 1,
  858. })))).await.unwrap().for_each(drop);
  859. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  860. assert_eq!(c1_meseta.0, 10);
  861. }
  862. #[async_std::test]
  863. async fn test_player_sells_rare_barrier() {
  864. let mut entity_gateway = InMemoryGateway::default();
  865. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  866. let mut p1_inv = Vec::new();
  867. p1_inv.push(entity_gateway.create_item(
  868. item::NewItemEntity {
  869. item: item::ItemDetail::Shield(
  870. item::shield::Shield {
  871. shield: item::shield::ShieldType::RedRing,
  872. dfp: 10,
  873. evp: 20,
  874. }
  875. ),
  876. }).await.unwrap());
  877. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  878. let mut ship = Box::new(ShipServerState::builder()
  879. .gateway(entity_gateway.clone())
  880. .build());
  881. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  882. join_lobby(&mut ship, ClientId(1)).await;
  883. create_room(&mut ship, ClientId(1), "room", "").await;
  884. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  885. client: 0,
  886. target: 0,
  887. item_id: 0x10000,
  888. amount: 1,
  889. })))).await.unwrap().for_each(drop);
  890. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  891. assert_eq!(c1_meseta.0, 10);
  892. }
  893. #[async_std::test]
  894. async fn test_player_sells_rare_unit() {
  895. let mut entity_gateway = InMemoryGateway::default();
  896. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  897. let mut p1_inv = Vec::new();
  898. p1_inv.push(entity_gateway.create_item(
  899. item::NewItemEntity {
  900. item: item::ItemDetail::Unit(
  901. item::unit::Unit {
  902. unit: item::unit::UnitType::V101,
  903. modifier: None,
  904. kills: None,
  905. }
  906. ),
  907. }).await.unwrap());
  908. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  909. let mut ship = Box::new(ShipServerState::builder()
  910. .gateway(entity_gateway.clone())
  911. .build());
  912. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  913. join_lobby(&mut ship, ClientId(1)).await;
  914. create_room(&mut ship, ClientId(1), "room", "").await;
  915. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  916. client: 0,
  917. target: 0,
  918. item_id: 0x10000,
  919. amount: 1,
  920. })))).await.unwrap().for_each(drop);
  921. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  922. assert_eq!(c1_meseta.0, 10);
  923. }
  924. #[async_std::test]
  925. async fn test_player_cant_sell_if_meseta_would_go_over_max() {
  926. let mut entity_gateway = InMemoryGateway::default();
  927. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  928. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999995)).await.unwrap();
  929. let mut p1_inv = Vec::new();
  930. p1_inv.push(entity_gateway.create_item(
  931. item::NewItemEntity {
  932. item: item::ItemDetail::Unit(
  933. item::unit::Unit {
  934. unit: item::unit::UnitType::V101,
  935. modifier: None,
  936. kills: None,
  937. }
  938. ),
  939. }).await.unwrap());
  940. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  941. let mut ship = Box::new(ShipServerState::builder()
  942. .gateway(entity_gateway.clone())
  943. .build());
  944. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  945. join_lobby(&mut ship, ClientId(1)).await;
  946. create_room(&mut ship, ClientId(1), "room", "").await;
  947. let ack = ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
  948. client: 0,
  949. target: 0,
  950. item_id: 0x10000,
  951. amount: 1,
  952. })))).await.err().unwrap();
  953. assert!(matches!(ack.downcast::<ItemStateError>().unwrap(), ItemStateError::FullOfMeseta));
  954. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  955. assert_eq!(c1_meseta.0, 999995);
  956. }