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