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.

1982 lines
76 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 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
3 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 std::collections::BTreeSet;
  2. use networking::serverstate::{ClientId, ServerState};
  3. use entity::gateway::{EntityGateway, InMemoryGateway};
  4. use entity::item;
  5. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  6. use libpso::packet::ship::*;
  7. use libpso::packet::messages::*;
  8. #[path = "common.rs"]
  9. mod common;
  10. use common::*;
  11. #[async_std::test]
  12. async fn test_bank_items_sent_in_character_login() {
  13. let mut entity_gateway = InMemoryGateway::default();
  14. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  15. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  16. let item = entity_gateway.create_item(
  17. item::NewItemEntity {
  18. item: item::ItemDetail::Weapon(
  19. item::weapon::Weapon {
  20. weapon: item::weapon::WeaponType::Vulcan,
  21. grind: 0,
  22. special: None,
  23. attrs: [None, None, None],
  24. tekked: true,
  25. }
  26. ),
  27. }).await.unwrap();
  28. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item]), &item::BankIdentifier::Character).await.unwrap();
  29. let mut ship = standard_ship(entity_gateway.clone());
  30. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  31. let packets = ship.handle(ClientId(1), RecvShipPacket::MenuSelect(MenuSelect {
  32. menu: BLOCK_MENU_ID,
  33. item: 1,
  34. })).await.unwrap();
  35. assert!(matches!(&packets[0], (_, SendShipPacket::FullCharacter(fc)) if fc.character.bank.items[0].data1[0..3] == [0x00, 0x08, 0x04] ));
  36. }
  37. #[async_std::test]
  38. async fn test_request_bank_items() {
  39. let mut entity_gateway = InMemoryGateway::default();
  40. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  41. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  42. let mut bank = Vec::new();
  43. for _ in 0..3 {
  44. bank.push(entity_gateway.create_item(
  45. item::NewItemEntity {
  46. item: item::ItemDetail::Weapon(
  47. item::weapon::Weapon {
  48. weapon: item::weapon::WeaponType::Vulcan,
  49. grind: 0,
  50. special: None,
  51. attrs: [None, None, None],
  52. tekked: true,
  53. }
  54. ),
  55. }).await.unwrap());
  56. }
  57. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap();
  58. let mut ship = standard_ship(entity_gateway.clone());
  59. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  60. join_lobby(&mut ship, ClientId(1)).await;
  61. create_room(&mut ship, ClientId(1), "room", "").await;
  62. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  63. client: 0,
  64. target: 0,
  65. unknown: 0,
  66. })))).await.unwrap();
  67. assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
  68. if bank_item_list.item_count == 3
  69. && bank_item_list.size == 0x18 * 3 + 0x14
  70. && bank_item_list.items[0].data1[0..3] == [0x00, 0x08, 0x04]
  71. && bank_item_list.items[1].data1[0..3] == [0x00, 0x08, 0x04]
  72. && bank_item_list.items[2].data1[0..3] == [0x00, 0x08, 0x04]
  73. ));
  74. }
  75. #[async_std::test]
  76. async fn test_request_stacked_bank_items() {
  77. let mut entity_gateway = InMemoryGateway::default();
  78. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  79. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  80. let mut monomates = Vec::new();
  81. for _ in 0..3usize {
  82. monomates.push(entity_gateway.create_item(
  83. item::NewItemEntity {
  84. item: item::ItemDetail::Tool (
  85. item::tool::Tool {
  86. tool: item::tool::ToolType::Monomate,
  87. }
  88. ),
  89. }).await.unwrap());
  90. }
  91. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap();
  92. let mut ship = standard_ship(entity_gateway.clone());
  93. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  94. join_lobby(&mut ship, ClientId(1)).await;
  95. create_room(&mut ship, ClientId(1), "room", "").await;
  96. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  97. client: 0,
  98. target: 0,
  99. unknown: 0,
  100. })))).await.unwrap();
  101. assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
  102. if bank_item_list.item_count == 1
  103. && bank_item_list.size == 0x18 + 0x14
  104. && bank_item_list.items[0].data1[0..3] == [0x03, 0x00, 0x00]
  105. && bank_item_list.items[0].amount == 3
  106. ));
  107. }
  108. #[async_std::test]
  109. async fn test_request_bank_items_sorted() {
  110. let mut entity_gateway = InMemoryGateway::default();
  111. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  112. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  113. let item1 = entity_gateway.create_item(
  114. item::NewItemEntity {
  115. item: item::ItemDetail::Weapon(
  116. item::weapon::Weapon {
  117. weapon: item::weapon::WeaponType::Vulcan,
  118. grind: 0,
  119. special: None,
  120. attrs: [None, None, None],
  121. tekked: true,
  122. }
  123. ),
  124. }).await.unwrap();
  125. let monomate = entity_gateway.create_item(
  126. item::NewItemEntity {
  127. item: item::ItemDetail::Tool (
  128. item::tool::Tool {
  129. tool: item::tool::ToolType::Monomate,
  130. }
  131. ),
  132. }).await.unwrap();
  133. let item2 = entity_gateway.create_item(
  134. item::NewItemEntity {
  135. item: item::ItemDetail::Weapon(
  136. item::weapon::Weapon {
  137. weapon: item::weapon::WeaponType::Calibur,
  138. grind: 0,
  139. special: None,
  140. attrs: [None, None, None],
  141. tekked: true,
  142. }
  143. ),
  144. }).await.unwrap();
  145. let bank = vec![item::BankItemEntity::Individual(item1), vec![monomate].into(), item2.into()];
  146. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap();
  147. let mut ship = standard_ship(entity_gateway.clone());
  148. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  149. join_lobby(&mut ship, ClientId(1)).await;
  150. create_room(&mut ship, ClientId(1), "room", "").await;
  151. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  152. client: 0,
  153. target: 0,
  154. unknown: 0,
  155. })))).await.unwrap();
  156. assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
  157. if bank_item_list.item_count == 3
  158. && bank_item_list.size == 0x18 * 3 + 0x14
  159. && bank_item_list.items[0].data1[0..3] == [0x00, 0x02, 0x04]
  160. && bank_item_list.items[1].data1[0..3] == [0x00, 0x08, 0x04]
  161. && bank_item_list.items[2].data1[0..3] == [0x03, 0x00, 0x00]
  162. ));
  163. }
  164. #[async_std::test]
  165. async fn test_deposit_individual_item() {
  166. let mut entity_gateway = InMemoryGateway::default();
  167. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  168. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  169. let item0 = entity_gateway.create_item(
  170. item::NewItemEntity {
  171. item: item::ItemDetail::Weapon(
  172. item::weapon::Weapon {
  173. weapon: item::weapon::WeaponType::Saber,
  174. grind: 0,
  175. special: None,
  176. attrs: [None, None, None],
  177. tekked: true,
  178. }
  179. ),
  180. }).await.unwrap();
  181. let item1 = entity_gateway.create_item(
  182. item::NewItemEntity {
  183. item: item::ItemDetail::Weapon(
  184. item::weapon::Weapon {
  185. weapon: item::weapon::WeaponType::Handgun,
  186. grind: 0,
  187. special: None,
  188. attrs: [None, None, None],
  189. tekked: true,
  190. }
  191. ),
  192. }).await.unwrap();
  193. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![item0, item1])).await.unwrap();
  194. let mut ship = standard_ship(entity_gateway.clone());
  195. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  196. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  197. join_lobby(&mut ship, ClientId(1)).await;
  198. join_lobby(&mut ship, ClientId(2)).await;
  199. create_room(&mut ship, ClientId(1), "room", "").await;
  200. join_room(&mut ship, ClientId(2), 0).await;
  201. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  202. client: 0,
  203. target: 0,
  204. unknown: 0,
  205. })))).await.unwrap();
  206. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  207. client: 0,
  208. target: 0,
  209. item_id: 0x10001,
  210. action: 0,
  211. item_amount: 0,
  212. meseta_amount: 0,
  213. unknown: 0,
  214. })))).await.unwrap();
  215. assert!(packets.len() == 2);
  216. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
  217. if player_no_longer_has_item.item_id == 0x10001
  218. && player_no_longer_has_item.amount == 0
  219. ));
  220. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  221. assert_eq!(inventory_items.items.len(), 1);
  222. inventory_items.items[0].with_individual(|item| {
  223. assert_eq!(item.id, item::ItemEntityId(1));
  224. }).unwrap();
  225. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  226. assert_eq!(bank_items.items.len(), 1);
  227. bank_items.items[0].with_individual(|item| {
  228. assert_eq!(item.id, item::ItemEntityId(2));
  229. }).unwrap();
  230. }
  231. #[async_std::test]
  232. async fn test_deposit_stacked_item() {
  233. let mut entity_gateway = InMemoryGateway::default();
  234. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  235. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  236. let mut monomates = Vec::new();
  237. for _ in 0..3usize {
  238. monomates.push(entity_gateway.create_item(
  239. item::NewItemEntity {
  240. item: item::ItemDetail::Tool(
  241. item::tool::Tool {
  242. tool: item::tool::ToolType::Monomate,
  243. }
  244. ),
  245. }).await.unwrap());
  246. }
  247. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap();
  248. let mut ship = standard_ship(entity_gateway.clone());
  249. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  250. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  251. join_lobby(&mut ship, ClientId(1)).await;
  252. join_lobby(&mut ship, ClientId(2)).await;
  253. create_room(&mut ship, ClientId(1), "room", "").await;
  254. join_room(&mut ship, ClientId(2), 0).await;
  255. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  256. client: 0,
  257. target: 0,
  258. unknown: 0,
  259. })))).await.unwrap();
  260. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  261. client: 0,
  262. target: 0,
  263. item_id: 0x10000,
  264. action: 0,
  265. item_amount: 3,
  266. meseta_amount: 0,
  267. unknown: 0,
  268. })))).await.unwrap();
  269. assert!(packets.len() == 2);
  270. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
  271. if player_no_longer_has_item.item_id == 0x10000
  272. && player_no_longer_has_item.amount == 3
  273. ));
  274. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  275. assert_eq!(bank_items.items.len(), 1);
  276. bank_items.items[0].with_stacked(|items| {
  277. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  278. vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3)]);
  279. }).unwrap();
  280. }
  281. #[async_std::test]
  282. async fn test_deposit_partial_stacked_item() {
  283. let mut entity_gateway = InMemoryGateway::default();
  284. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  285. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  286. let mut monomates = Vec::new();
  287. for _ in 0..3usize {
  288. monomates.push(entity_gateway.create_item(
  289. item::NewItemEntity {
  290. item: item::ItemDetail::Tool(
  291. item::tool::Tool {
  292. tool: item::tool::ToolType::Monomate,
  293. }
  294. ),
  295. }).await.unwrap());
  296. }
  297. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap();
  298. let mut ship = standard_ship(entity_gateway.clone());
  299. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  300. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  301. join_lobby(&mut ship, ClientId(1)).await;
  302. join_lobby(&mut ship, ClientId(2)).await;
  303. create_room(&mut ship, ClientId(1), "room", "").await;
  304. join_room(&mut ship, ClientId(2), 0).await;
  305. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  306. client: 0,
  307. target: 0,
  308. unknown: 0,
  309. })))).await.unwrap();
  310. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  311. client: 0,
  312. target: 0,
  313. item_id: 0x10000,
  314. action: 0,
  315. item_amount: 2,
  316. meseta_amount: 0,
  317. unknown: 0,
  318. })))).await.unwrap();
  319. assert!(packets.len() == 2);
  320. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
  321. if player_no_longer_has_item.item_id == 0x10000
  322. && player_no_longer_has_item.amount == 2
  323. ));
  324. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  325. assert_eq!(bank_items.items.len(), 1);
  326. bank_items.items[0].with_stacked(|items| {
  327. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  328. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  329. }).unwrap();
  330. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  331. assert_eq!(inventory_items.items.len(), 1);
  332. inventory_items.items[0].with_stacked(|items| {
  333. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  334. vec![item::ItemEntityId(3)]);
  335. }).unwrap();
  336. }
  337. #[async_std::test]
  338. async fn test_deposit_stacked_item_with_stack_already_in_bank() {
  339. let mut entity_gateway = InMemoryGateway::default();
  340. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  341. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  342. let mut bank_monomates = Vec::new();
  343. let mut inventory_monomates = Vec::new();
  344. for _ in 0..2usize {
  345. inventory_monomates.push(entity_gateway.create_item(
  346. item::NewItemEntity {
  347. item: item::ItemDetail::Tool(
  348. item::tool::Tool {
  349. tool: item::tool::ToolType::Monomate,
  350. }
  351. ),
  352. }).await.unwrap());
  353. bank_monomates.push(entity_gateway.create_item(
  354. item::NewItemEntity {
  355. item: item::ItemDetail::Tool(
  356. item::tool::Tool {
  357. tool: item::tool::ToolType::Monomate,
  358. }
  359. ),
  360. }).await.unwrap());
  361. }
  362. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap();
  363. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankIdentifier::Character).await.unwrap();
  364. let mut ship = standard_ship(entity_gateway.clone());
  365. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  366. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  367. join_lobby(&mut ship, ClientId(1)).await;
  368. join_lobby(&mut ship, ClientId(2)).await;
  369. create_room(&mut ship, ClientId(1), "room", "").await;
  370. join_room(&mut ship, ClientId(2), 0).await;
  371. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  372. client: 0,
  373. target: 0,
  374. unknown: 0,
  375. })))).await.unwrap();
  376. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  377. client: 0,
  378. target: 0,
  379. item_id: 0x10000,
  380. action: 0,
  381. item_amount: 2,
  382. meseta_amount: 0,
  383. unknown: 0,
  384. })))).await.unwrap();
  385. assert!(packets.len() == 2);
  386. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
  387. if player_no_longer_has_item.item_id == 0x10000
  388. && player_no_longer_has_item.amount == 2
  389. ));
  390. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  391. assert_eq!(bank_items.items.len(), 1);
  392. bank_items.items[0].with_stacked(|items| {
  393. assert_eq!(items.iter().map(|i| i.id).collect::<BTreeSet<_>>(),
  394. vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4)].into_iter().collect::<BTreeSet<_>>() );
  395. }).unwrap();
  396. }
  397. #[async_std::test]
  398. async fn test_deposit_stacked_item_with_full_stack_in_bank() {
  399. let mut entity_gateway = InMemoryGateway::default();
  400. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  401. let mut inventory_monomates = Vec::new();
  402. for _ in 0..2usize {
  403. inventory_monomates.push(entity_gateway.create_item(
  404. item::NewItemEntity {
  405. item: item::ItemDetail::Tool(
  406. item::tool::Tool {
  407. tool: item::tool::ToolType::Monomate,
  408. }
  409. ),
  410. }).await.unwrap());
  411. }
  412. let mut bank_monomates = Vec::new();
  413. for _ in 0..10 {
  414. bank_monomates.push(entity_gateway.create_item(
  415. item::NewItemEntity {
  416. item: item::ItemDetail::Tool(
  417. item::tool::Tool {
  418. tool: item::tool::ToolType::Monomate,
  419. }
  420. ),
  421. }).await.unwrap());
  422. }
  423. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap();
  424. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankIdentifier::Character).await.unwrap();
  425. let mut ship = standard_ship(entity_gateway.clone());
  426. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  427. join_lobby(&mut ship, ClientId(1)).await;
  428. create_room(&mut ship, ClientId(1), "room", "").await;
  429. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  430. client: 0,
  431. target: 0,
  432. unknown: 0,
  433. })))).await.unwrap();
  434. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  435. client: 0,
  436. target: 0,
  437. item_id: 0x10000,
  438. action: 0,
  439. item_amount: 2,
  440. meseta_amount: 0,
  441. unknown: 0,
  442. })))).await;
  443. assert!(packets.is_err());
  444. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  445. assert_eq!(bank_items.items.len(), 1);
  446. bank_items.items[0].with_stacked(|items| {
  447. assert_eq!(items.len(), 10);
  448. }).unwrap();
  449. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  450. assert_eq!(inventory_items.items.len(), 1);
  451. inventory_items.items[0].with_stacked(|items| {
  452. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  453. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  454. }).unwrap();
  455. }
  456. #[async_std::test]
  457. async fn test_deposit_individual_item_in_full_bank() {
  458. let mut entity_gateway = InMemoryGateway::default();
  459. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  460. let mut inventory = Vec::new();
  461. inventory.push(entity_gateway.create_item(
  462. item::NewItemEntity {
  463. item: item::ItemDetail::Weapon(
  464. item::weapon::Weapon {
  465. weapon: item::weapon::WeaponType::Vulcan,
  466. grind: 0,
  467. special: None,
  468. attrs: [None, None, None],
  469. tekked: true,
  470. }
  471. ),
  472. }).await.unwrap());
  473. let mut bank = Vec::new();
  474. for _ in 0..200usize {
  475. bank.push(entity_gateway.create_item(
  476. item::NewItemEntity {
  477. item: item::ItemDetail::Weapon(
  478. item::weapon::Weapon {
  479. weapon: item::weapon::WeaponType::Vulcan,
  480. grind: 0,
  481. special: None,
  482. attrs: [None, None, None],
  483. tekked: true,
  484. }
  485. ),
  486. }).await.unwrap());
  487. }
  488. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  489. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap();
  490. let mut ship = standard_ship(entity_gateway.clone());
  491. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  492. join_lobby(&mut ship, ClientId(1)).await;
  493. create_room(&mut ship, ClientId(1), "room", "").await;
  494. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  495. client: 0,
  496. target: 0,
  497. unknown: 0,
  498. })))).await.unwrap();
  499. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  500. client: 0,
  501. target: 0,
  502. item_id: 0x10000,
  503. action: 0,
  504. item_amount: 0,
  505. meseta_amount: 0,
  506. unknown: 0,
  507. })))).await;
  508. assert!(packets.is_err());
  509. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  510. assert_eq!(bank_items.items.len(), 200);
  511. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  512. assert_eq!(inventory_items.items.len(), 1);
  513. inventory_items.items[0].with_individual(|item| {
  514. assert_eq!(item.id, item::ItemEntityId(1));
  515. }).unwrap();
  516. }
  517. #[async_std::test]
  518. async fn test_deposit_stacked_item_in_full_bank() {
  519. let mut entity_gateway = InMemoryGateway::default();
  520. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  521. let mut monomates = Vec::new();
  522. for _ in 0..2usize {
  523. monomates.push(entity_gateway.create_item(
  524. item::NewItemEntity {
  525. item: item::ItemDetail::Tool(
  526. item::tool::Tool {
  527. tool: item::tool::ToolType::Monomate,
  528. }
  529. ),
  530. }).await.unwrap());
  531. }
  532. let mut full_bank = Vec::new();
  533. for _ in 0..200usize {
  534. full_bank.push(entity_gateway.create_item(
  535. item::NewItemEntity {
  536. item: item::ItemDetail::Weapon(
  537. item::weapon::Weapon {
  538. weapon: item::weapon::WeaponType::Vulcan,
  539. grind: 0,
  540. special: None,
  541. attrs: [None, None, None],
  542. tekked: true,
  543. }
  544. ),
  545. }).await.unwrap());
  546. }
  547. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap();
  548. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(full_bank), &item::BankIdentifier::Character).await.unwrap();
  549. let mut ship = standard_ship(entity_gateway.clone());
  550. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  551. join_lobby(&mut ship, ClientId(1)).await;
  552. create_room(&mut ship, ClientId(1), "room", "").await;
  553. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  554. client: 0,
  555. target: 0,
  556. unknown: 0,
  557. })))).await.unwrap();
  558. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  559. client: 0,
  560. target: 0,
  561. item_id: 0x10000,
  562. action: 0,
  563. item_amount: 2,
  564. meseta_amount: 0,
  565. unknown: 0,
  566. })))).await;
  567. assert!(packets.is_err());
  568. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  569. assert_eq!(bank_items.items.len(), 200);
  570. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  571. assert_eq!(inventory_items.items.len(), 1);
  572. inventory_items.items[0].with_stacked(|items| {
  573. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  574. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  575. }).unwrap();
  576. }
  577. #[async_std::test]
  578. async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() {
  579. let mut entity_gateway = InMemoryGateway::default();
  580. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  581. let mut monomates = Vec::new();
  582. for _ in 0..2usize {
  583. monomates.push(entity_gateway.create_item(
  584. item::NewItemEntity {
  585. item: item::ItemDetail::Tool(
  586. item::tool::Tool {
  587. tool: item::tool::ToolType::Monomate,
  588. }
  589. ),
  590. }).await.unwrap());
  591. }
  592. let mut bank_monomates = Vec::new();
  593. for _ in 0..2usize {
  594. bank_monomates.push(entity_gateway.create_item(
  595. item::NewItemEntity {
  596. item: item::ItemDetail::Tool(
  597. item::tool::Tool {
  598. tool: item::tool::ToolType::Monomate,
  599. }
  600. ),
  601. }).await.unwrap());
  602. }
  603. let mut almost_full_bank: Vec<item::BankItemEntity> = Vec::new();
  604. for _ in 0..199usize {
  605. almost_full_bank.push(entity_gateway.create_item(
  606. item::NewItemEntity {
  607. item: item::ItemDetail::Weapon(
  608. item::weapon::Weapon {
  609. weapon: item::weapon::WeaponType::Vulcan,
  610. grind: 0,
  611. special: None,
  612. attrs: [None, None, None],
  613. tekked: true,
  614. }
  615. ),
  616. }).await.unwrap().into());
  617. }
  618. almost_full_bank.push(bank_monomates.into());
  619. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap();
  620. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(almost_full_bank), &item::BankIdentifier::Character).await.unwrap();
  621. let mut ship = standard_ship(entity_gateway.clone());
  622. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  623. join_lobby(&mut ship, ClientId(1)).await;
  624. create_room(&mut ship, ClientId(1), "room", "").await;
  625. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  626. client: 0,
  627. target: 0,
  628. unknown: 0,
  629. })))).await.unwrap();
  630. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  631. client: 0,
  632. target: 0,
  633. item_id: 0x10000,
  634. action: 0,
  635. item_amount: 2,
  636. meseta_amount: 0,
  637. unknown: 0,
  638. })))).await.unwrap();
  639. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  640. assert_eq!(bank_items.items.len(), 200);
  641. bank_items.items[199].with_stacked(|items| {
  642. assert_eq!(items.len(), 4);
  643. }).unwrap();
  644. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  645. assert_eq!(inventory_items.items.len(), 0);
  646. }
  647. #[async_std::test]
  648. async fn test_deposit_meseta() {
  649. let mut entity_gateway = InMemoryGateway::default();
  650. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  651. entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap();
  652. let mut ship = standard_ship(entity_gateway.clone());
  653. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  654. join_lobby(&mut ship, ClientId(1)).await;
  655. create_room(&mut ship, ClientId(1), "room", "").await;
  656. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  657. client: 0,
  658. target: 0,
  659. unknown: 0,
  660. })))).await.unwrap();
  661. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  662. client: 0,
  663. target: 0,
  664. item_id: 0xFFFFFFFF,
  665. action: 0,
  666. item_amount: 0,
  667. meseta_amount: 23,
  668. unknown: 0,
  669. })))).await.unwrap();
  670. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  671. let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  672. assert!(c1_meseta.0 == 277);
  673. assert!(c1_bank_meseta.0 == 23);
  674. }
  675. #[async_std::test]
  676. async fn test_deposit_too_much_meseta() {
  677. let mut entity_gateway = InMemoryGateway::default();
  678. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  679. entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap();
  680. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(999980)).await.unwrap();
  681. let mut ship = standard_ship(entity_gateway.clone());
  682. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  683. join_lobby(&mut ship, ClientId(1)).await;
  684. create_room(&mut ship, ClientId(1), "room", "").await;
  685. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  686. client: 0,
  687. target: 0,
  688. unknown: 0,
  689. })))).await.unwrap();
  690. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  691. client: 0,
  692. target: 0,
  693. item_id: 0xFFFFFFFF,
  694. action: 0,
  695. item_amount: 0,
  696. meseta_amount: 23,
  697. unknown: 0,
  698. })))).await;
  699. assert!(packets.is_err());
  700. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  701. let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  702. assert!(c1_meseta.0 == 300);
  703. assert!(c1_bank_meseta.0 == 999980);
  704. }
  705. #[async_std::test]
  706. async fn test_deposit_meseta_when_bank_is_maxed() {
  707. let mut entity_gateway = InMemoryGateway::default();
  708. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  709. entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap();
  710. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(999999)).await.unwrap();
  711. let mut ship = standard_ship(entity_gateway.clone());
  712. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  713. join_lobby(&mut ship, ClientId(1)).await;
  714. create_room(&mut ship, ClientId(1), "room", "").await;
  715. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  716. client: 0,
  717. target: 0,
  718. unknown: 0,
  719. })))).await.unwrap();
  720. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  721. client: 0,
  722. target: 0,
  723. item_id: 0xFFFFFFFF,
  724. action: 0,
  725. item_amount: 0,
  726. meseta_amount: 23,
  727. unknown: 0,
  728. })))).await;
  729. assert!(packets.is_err());
  730. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  731. let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  732. assert!(c1_meseta.0 == 300);
  733. assert!(c1_bank_meseta.0 == 999999);
  734. }
  735. #[async_std::test]
  736. async fn test_withdraw_individual_item() {
  737. let mut entity_gateway = InMemoryGateway::default();
  738. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  739. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  740. let mut bank = Vec::new();
  741. bank.push(entity_gateway.create_item(
  742. item::NewItemEntity {
  743. item: item::ItemDetail::Weapon(
  744. item::weapon::Weapon {
  745. weapon: item::weapon::WeaponType::Saber,
  746. grind: 0,
  747. special: None,
  748. attrs: [None, None, None],
  749. tekked: true,
  750. }
  751. ),
  752. }).await.unwrap());
  753. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap();
  754. let mut ship = standard_ship(entity_gateway.clone());
  755. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  756. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  757. join_lobby(&mut ship, ClientId(1)).await;
  758. join_lobby(&mut ship, ClientId(2)).await;
  759. create_room(&mut ship, ClientId(1), "room", "").await;
  760. join_room(&mut ship, ClientId(2), 0).await;
  761. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  762. client: 0,
  763. target: 0,
  764. unknown: 0,
  765. })))).await.unwrap();
  766. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  767. client: 0,
  768. target: 0,
  769. item_id: 0x20000,
  770. action: 1,
  771. item_amount: 0,
  772. meseta_amount: 0,
  773. unknown: 0,
  774. })))).await.unwrap();
  775. assert!(packets.len() == 2);
  776. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
  777. if create_item.item_id == 0x20000
  778. ));
  779. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  780. assert_eq!(inventory_items.items.len(), 1);
  781. inventory_items.items[0].with_individual(|item| {
  782. assert_eq!(item.id, item::ItemEntityId(1));
  783. }).unwrap();
  784. }
  785. #[async_std::test]
  786. async fn test_withdraw_stacked_item() {
  787. let mut entity_gateway = InMemoryGateway::default();
  788. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  789. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  790. let mut monomates = Vec::new();
  791. for _ in 0..3usize {
  792. monomates.push(entity_gateway.create_item(
  793. item::NewItemEntity {
  794. item: item::ItemDetail::Tool(
  795. item::tool::Tool {
  796. tool: item::tool::ToolType::Monomate,
  797. }
  798. ),
  799. }).await.unwrap());
  800. }
  801. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap();
  802. let mut ship = standard_ship(entity_gateway.clone());
  803. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  804. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  805. join_lobby(&mut ship, ClientId(1)).await;
  806. join_lobby(&mut ship, ClientId(2)).await;
  807. create_room(&mut ship, ClientId(1), "room", "").await;
  808. join_room(&mut ship, ClientId(2), 0).await;
  809. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  810. client: 0,
  811. target: 0,
  812. unknown: 0,
  813. })))).await.unwrap();
  814. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  815. client: 0,
  816. target: 0,
  817. item_id: 0x20000,
  818. action: 1,
  819. item_amount: 3,
  820. meseta_amount: 0,
  821. unknown: 0,
  822. })))).await.unwrap();
  823. assert!(packets.len() == 2);
  824. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
  825. if create_item.item_id == 0x20000
  826. ));
  827. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  828. assert_eq!(inventory_items.items.len(), 1);
  829. inventory_items.items[0].with_stacked(|items| {
  830. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  831. vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3)]);
  832. }).unwrap();
  833. }
  834. #[async_std::test]
  835. async fn test_withdraw_partial_stacked_item() {
  836. let mut entity_gateway = InMemoryGateway::default();
  837. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  838. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  839. let mut monomates = Vec::new();
  840. for _ in 0..3usize {
  841. monomates.push(entity_gateway.create_item(
  842. item::NewItemEntity {
  843. item: item::ItemDetail::Tool(
  844. item::tool::Tool {
  845. tool: item::tool::ToolType::Monomate,
  846. }
  847. ),
  848. }).await.unwrap());
  849. }
  850. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap();
  851. let mut ship = standard_ship(entity_gateway.clone());
  852. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  853. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  854. join_lobby(&mut ship, ClientId(1)).await;
  855. join_lobby(&mut ship, ClientId(2)).await;
  856. create_room(&mut ship, ClientId(1), "room", "").await;
  857. join_room(&mut ship, ClientId(2), 0).await;
  858. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  859. client: 0,
  860. target: 0,
  861. unknown: 0,
  862. })))).await.unwrap();
  863. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  864. client: 0,
  865. target: 0,
  866. item_id: 0x20000,
  867. action: 1,
  868. item_amount: 2,
  869. meseta_amount: 0,
  870. unknown: 0,
  871. })))).await.unwrap();
  872. assert!(packets.len() == 2);
  873. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
  874. if create_item.item_id == 0x20001
  875. ));
  876. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  877. assert_eq!(bank_items.items.len(), 1);
  878. bank_items.items[0].with_stacked(|items| {
  879. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  880. vec![item::ItemEntityId(3)]);
  881. }).unwrap();
  882. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  883. assert_eq!(inventory_items.items.len(), 1);
  884. inventory_items.items[0].with_stacked(|items| {
  885. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  886. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  887. }).unwrap();
  888. }
  889. #[async_std::test]
  890. async fn test_withdraw_stacked_item_with_stack_already_in_inventory() {
  891. let mut entity_gateway = InMemoryGateway::default();
  892. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  893. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  894. let mut inventory_monomates = Vec::new();
  895. let mut bank_monomates = Vec::new();
  896. for _ in 0..2usize {
  897. inventory_monomates.push(entity_gateway.create_item(
  898. item::NewItemEntity {
  899. item: item::ItemDetail::Tool(
  900. item::tool::Tool {
  901. tool: item::tool::ToolType::Monomate,
  902. }
  903. ),
  904. }).await.unwrap());
  905. bank_monomates.push(entity_gateway.create_item(
  906. item::NewItemEntity {
  907. item: item::ItemDetail::Tool(
  908. item::tool::Tool {
  909. tool: item::tool::ToolType::Monomate,
  910. }
  911. ),
  912. }).await.unwrap());
  913. }
  914. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap();
  915. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankIdentifier::Character).await.unwrap();
  916. let mut ship = standard_ship(entity_gateway.clone());
  917. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  918. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  919. join_lobby(&mut ship, ClientId(1)).await;
  920. join_lobby(&mut ship, ClientId(2)).await;
  921. create_room(&mut ship, ClientId(1), "room", "").await;
  922. join_room(&mut ship, ClientId(2), 0).await;
  923. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  924. client: 0,
  925. target: 0,
  926. unknown: 0,
  927. })))).await.unwrap();
  928. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  929. client: 0,
  930. target: 0,
  931. item_id: 0x20000,
  932. action: 1,
  933. item_amount: 2,
  934. meseta_amount: 0,
  935. unknown: 0,
  936. })))).await.unwrap();
  937. assert!(packets.len() == 2);
  938. assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
  939. if create_item.item_id == 0x20000
  940. ));
  941. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  942. assert_eq!(bank_items.items.len(), 0);
  943. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  944. assert_eq!(inventory_items.items.len(), 1);
  945. inventory_items.items[0].with_stacked(|items| {
  946. assert_eq!(items.iter().map(|i| i.id).collect::<BTreeSet<_>>(),
  947. vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4)].into_iter().collect::<BTreeSet<_>>());
  948. }).unwrap();
  949. }
  950. #[async_std::test]
  951. async fn test_withdraw_stacked_item_with_full_stack_in_inventory() {
  952. let mut entity_gateway = InMemoryGateway::default();
  953. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  954. let mut bank_monomates = Vec::new();
  955. for _ in 0..2usize {
  956. bank_monomates.push(entity_gateway.create_item(
  957. item::NewItemEntity {
  958. item: item::ItemDetail::Tool(
  959. item::tool::Tool {
  960. tool: item::tool::ToolType::Monomate,
  961. }
  962. ),
  963. }).await.unwrap());
  964. }
  965. let mut inventory_monomates = Vec::new();
  966. for _ in 0..10usize {
  967. inventory_monomates.push(entity_gateway.create_item(
  968. item::NewItemEntity {
  969. item: item::ItemDetail::Tool(
  970. item::tool::Tool {
  971. tool: item::tool::ToolType::Monomate,
  972. }
  973. ),
  974. }).await.unwrap());
  975. }
  976. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap();
  977. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankIdentifier::Character).await.unwrap();
  978. let mut ship = standard_ship(entity_gateway.clone());
  979. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  980. join_lobby(&mut ship, ClientId(1)).await;
  981. create_room(&mut ship, ClientId(1), "room", "").await;
  982. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  983. client: 0,
  984. target: 0,
  985. unknown: 0,
  986. })))).await.unwrap();
  987. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  988. client: 0,
  989. target: 0,
  990. item_id: 0x20000,
  991. action: 1,
  992. item_amount: 2,
  993. meseta_amount: 0,
  994. unknown: 0,
  995. })))).await;
  996. assert!(packets.is_err());
  997. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  998. assert_eq!(bank_items.items.len(), 1);
  999. bank_items.items[0].with_stacked(|items| {
  1000. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  1001. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  1002. }).unwrap();
  1003. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  1004. assert_eq!(inventory_items.items.len(), 1);
  1005. inventory_items.items[0].with_stacked(|items| {
  1006. assert_eq!(items.len(), 10);
  1007. }).unwrap();
  1008. }
  1009. #[async_std::test]
  1010. async fn test_withdraw_individual_item_in_full_inventory() {
  1011. let mut entity_gateway = InMemoryGateway::default();
  1012. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1013. let mut bank = Vec::new();
  1014. bank.push(entity_gateway.create_item(
  1015. item::NewItemEntity {
  1016. item: item::ItemDetail::Weapon(
  1017. item::weapon::Weapon {
  1018. weapon: item::weapon::WeaponType::Vulcan,
  1019. grind: 0,
  1020. special: None,
  1021. attrs: [None, None, None],
  1022. tekked: true,
  1023. }
  1024. ),
  1025. }).await.unwrap());
  1026. let mut inventory = Vec::new();
  1027. for _ in 0..30usize {
  1028. inventory.push(entity_gateway.create_item(
  1029. item::NewItemEntity {
  1030. item: item::ItemDetail::Weapon(
  1031. item::weapon::Weapon {
  1032. weapon: item::weapon::WeaponType::Vulcan,
  1033. grind: 0,
  1034. special: None,
  1035. attrs: [None, None, None],
  1036. tekked: true,
  1037. }
  1038. ),
  1039. }).await.unwrap());
  1040. }
  1041. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  1042. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap();
  1043. let mut ship = standard_ship(entity_gateway.clone());
  1044. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1045. join_lobby(&mut ship, ClientId(1)).await;
  1046. create_room(&mut ship, ClientId(1), "room", "").await;
  1047. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1048. client: 0,
  1049. target: 0,
  1050. unknown: 0,
  1051. })))).await.unwrap();
  1052. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1053. client: 0,
  1054. target: 0,
  1055. item_id: 0x20000,
  1056. action: 1,
  1057. item_amount: 0,
  1058. meseta_amount: 0,
  1059. unknown: 0,
  1060. })))).await;
  1061. assert!(packets.is_err());
  1062. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1063. assert_eq!(bank_items.items.len(), 1);
  1064. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  1065. assert_eq!(inventory_items.items.len(), 30);
  1066. }
  1067. #[async_std::test]
  1068. async fn test_withdraw_stacked_item_in_full_inventory() {
  1069. let mut entity_gateway = InMemoryGateway::default();
  1070. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1071. let mut monomates = Vec::new();
  1072. for _ in 0..2usize {
  1073. monomates.push(entity_gateway.create_item(
  1074. item::NewItemEntity {
  1075. item: item::ItemDetail::Tool(
  1076. item::tool::Tool {
  1077. tool: item::tool::ToolType::Monomate,
  1078. }
  1079. ),
  1080. }).await.unwrap());
  1081. }
  1082. let mut inventory = Vec::new();
  1083. for _ in 0..30usize {
  1084. inventory.push(entity_gateway.create_item(
  1085. item::NewItemEntity {
  1086. item: item::ItemDetail::Weapon(
  1087. item::weapon::Weapon {
  1088. weapon: item::weapon::WeaponType::Vulcan,
  1089. grind: 0,
  1090. special: None,
  1091. attrs: [None, None, None],
  1092. tekked: true,
  1093. }
  1094. ),
  1095. }).await.unwrap());
  1096. }
  1097. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  1098. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap();
  1099. let mut ship = standard_ship(entity_gateway.clone());
  1100. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1101. join_lobby(&mut ship, ClientId(1)).await;
  1102. create_room(&mut ship, ClientId(1), "room", "").await;
  1103. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1104. client: 0,
  1105. target: 0,
  1106. unknown: 0,
  1107. })))).await.unwrap();
  1108. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1109. client: 0,
  1110. target: 0,
  1111. item_id: 0x20000,
  1112. action: 1,
  1113. item_amount: 2,
  1114. meseta_amount: 0,
  1115. unknown: 0,
  1116. })))).await;
  1117. assert!(packets.is_err());
  1118. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1119. assert_eq!(bank_items.items.len(), 1);
  1120. bank_items.items[0].with_stacked(|items| {
  1121. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  1122. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  1123. }).unwrap();
  1124. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  1125. assert_eq!(inventory_items.items.len(), 30);
  1126. }
  1127. #[async_std::test]
  1128. async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() {
  1129. let mut entity_gateway = InMemoryGateway::default();
  1130. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1131. let mut bank_item = Vec::new();
  1132. for _ in 0..2usize {
  1133. bank_item.push(entity_gateway.create_item(
  1134. item::NewItemEntity {
  1135. item: item::ItemDetail::Tool(
  1136. item::tool::Tool {
  1137. tool: item::tool::ToolType::Monomate,
  1138. }
  1139. ),
  1140. }).await.unwrap());
  1141. }
  1142. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_item]), &item::BankIdentifier::Character).await.unwrap();
  1143. let mut items = Vec::new();
  1144. for _i in 0..29usize {
  1145. items.push(entity_gateway.create_item(
  1146. item::NewItemEntity {
  1147. item: item::ItemDetail::Weapon(
  1148. item::weapon::Weapon {
  1149. weapon: item::weapon::WeaponType::Vulcan,
  1150. grind: 0,
  1151. special: None,
  1152. attrs: [None, None, None],
  1153. tekked: true,
  1154. }
  1155. ),
  1156. }).await.unwrap().into());
  1157. }
  1158. let mut item29 = Vec::new();
  1159. for _ in 0..2usize {
  1160. item29.push(entity_gateway.create_item(
  1161. item::NewItemEntity {
  1162. item: item::ItemDetail::Tool(
  1163. item::tool::Tool {
  1164. tool: item::tool::ToolType::Monomate,
  1165. }
  1166. ),
  1167. }).await.unwrap());
  1168. }
  1169. items.push(item::InventoryItemEntity::Stacked(item29));
  1170. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(items)).await.unwrap();
  1171. let mut ship = standard_ship(entity_gateway.clone());
  1172. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1173. join_lobby(&mut ship, ClientId(1)).await;
  1174. create_room(&mut ship, ClientId(1), "room", "").await;
  1175. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1176. client: 0,
  1177. target: 0,
  1178. unknown: 0,
  1179. })))).await.unwrap();
  1180. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1181. client: 0,
  1182. target: 0,
  1183. item_id: 0x20000,
  1184. action: 1,
  1185. item_amount: 2,
  1186. meseta_amount: 0,
  1187. unknown: 0,
  1188. })))).await.unwrap();
  1189. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1190. assert!(bank_items.items.len() == 0);
  1191. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  1192. assert!(inventory_items.items.len() == 30);
  1193. match &inventory_items.items[29] {
  1194. item::InventoryItemEntity::Stacked(items) => {
  1195. assert_eq!(items.len(), 4);
  1196. },
  1197. _ => panic!(),
  1198. }
  1199. }
  1200. #[async_std::test]
  1201. async fn test_withdraw_meseta() {
  1202. let mut entity_gateway = InMemoryGateway::default();
  1203. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1204. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap();
  1205. let mut ship = standard_ship(entity_gateway.clone());
  1206. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1207. join_lobby(&mut ship, ClientId(1)).await;
  1208. create_room(&mut ship, ClientId(1), "room", "").await;
  1209. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1210. client: 0,
  1211. target: 0,
  1212. unknown: 0,
  1213. })))).await.unwrap();
  1214. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1215. client: 0,
  1216. target: 0,
  1217. item_id: 0xFFFFFFFF,
  1218. action: 1,
  1219. item_amount: 0,
  1220. meseta_amount: 23,
  1221. unknown: 0,
  1222. })))).await.unwrap();
  1223. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  1224. let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1225. assert!(c1_meseta.0 == 23);
  1226. assert!(c1_bank_meseta.0 == 277);
  1227. }
  1228. #[async_std::test]
  1229. async fn test_withdraw_too_much_meseta() {
  1230. let mut entity_gateway = InMemoryGateway::default();
  1231. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1232. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999980)).await.unwrap();
  1233. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap();
  1234. let mut ship = standard_ship(entity_gateway.clone());
  1235. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1236. join_lobby(&mut ship, ClientId(1)).await;
  1237. create_room(&mut ship, ClientId(1), "room", "").await;
  1238. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1239. client: 0,
  1240. target: 0,
  1241. unknown: 0,
  1242. })))).await.unwrap();
  1243. let packet = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1244. client: 0,
  1245. target: 0,
  1246. item_id: 0xFFFFFFFF,
  1247. action: 1,
  1248. item_amount: 0,
  1249. meseta_amount: 23,
  1250. unknown: 0,
  1251. })))).await;
  1252. assert!(packet.is_err());
  1253. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  1254. let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1255. assert!(c1_meseta.0 == 999980);
  1256. assert!(c1_bank_meseta.0 == 300);
  1257. }
  1258. #[async_std::test]
  1259. async fn test_withdraw_meseta_inventory_is_maxed() {
  1260. let mut entity_gateway = InMemoryGateway::default();
  1261. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1262. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  1263. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap();
  1264. let mut ship = standard_ship(entity_gateway.clone());
  1265. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1266. join_lobby(&mut ship, ClientId(1)).await;
  1267. create_room(&mut ship, ClientId(1), "room", "").await;
  1268. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1269. client: 0,
  1270. target: 0,
  1271. unknown: 0,
  1272. })))).await.unwrap();
  1273. let packet = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1274. client: 0,
  1275. target: 0,
  1276. item_id: 0xFFFFFFFF,
  1277. action: 1,
  1278. item_amount: 0,
  1279. meseta_amount: 23,
  1280. unknown: 0,
  1281. })))).await;
  1282. assert!(packet.is_err());
  1283. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  1284. let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1285. assert!(c1_meseta.0 == 999999);
  1286. assert!(c1_bank_meseta.0 == 300);
  1287. }
  1288. #[async_std::test]
  1289. async fn test_withdraw_meseta_and_buy_a_few_monomates_with_it() {
  1290. let mut entity_gateway = InMemoryGateway::default();
  1291. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1292. entity_gateway.set_character_meseta(&char1.id, item::Meseta(100)).await.unwrap();
  1293. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap();
  1294. let mut ship = standard_ship(entity_gateway.clone());
  1295. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1296. join_lobby(&mut ship, ClientId(1)).await;
  1297. create_room(&mut ship, ClientId(1), "room", "").await;
  1298. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1299. client: 0,
  1300. target: 0,
  1301. unknown: 0,
  1302. })))).await.unwrap();
  1303. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1304. client: 0,
  1305. target: 0,
  1306. item_id: 0xFFFFFFFF,
  1307. action: 1,
  1308. item_amount: 0,
  1309. meseta_amount: 60,
  1310. unknown: 0,
  1311. })))).await.unwrap();
  1312. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
  1313. client: 255,
  1314. target: 255,
  1315. shop_type: 0,
  1316. })))).await.unwrap();
  1317. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
  1318. client: 255,
  1319. target: 255,
  1320. item_id: 0x10000,
  1321. shop_type: 0,
  1322. shop_index: 0,
  1323. amount: 3,
  1324. unknown1: 0,
  1325. })))).await.unwrap();
  1326. //let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  1327. //let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1328. //assert!(c1_meseta.0 == 23);
  1329. //assert!(c1_bank_meseta.0 == 277);
  1330. }
  1331. #[async_std::test]
  1332. async fn test_deposit_items_into_shared_banks() {
  1333. let mut entity_gateway = InMemoryGateway::default();
  1334. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1335. let item0 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Saber).as_new()).await.unwrap();
  1336. let item1 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Buster).as_new()).await.unwrap();
  1337. let item2 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Rifle).as_new()).await.unwrap();
  1338. let item3 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Handgun).as_new()).await.unwrap();
  1339. let item4 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Autogun).as_new()).await.unwrap();
  1340. let item5 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Calibur).as_new()).await.unwrap();
  1341. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![item0, item1, item2, item3, item4, item5])).await.unwrap();
  1342. let mut ship = standard_ship(entity_gateway.clone());
  1343. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1344. join_lobby(&mut ship, ClientId(1)).await;
  1345. create_room(&mut ship, ClientId(1), "room", "").await;
  1346. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1347. client: 0,
  1348. target: 0,
  1349. unknown: 0,
  1350. })))).await.unwrap();
  1351. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1352. client: 0,
  1353. target: 0,
  1354. item_id: 0x10000,
  1355. action: 0,
  1356. item_amount: 0,
  1357. meseta_amount: 0,
  1358. unknown: 0,
  1359. })))).await.unwrap();
  1360. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank asdf".into()))).await.unwrap();
  1361. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1362. client: 0,
  1363. target: 0,
  1364. unknown: 0,
  1365. })))).await.unwrap();
  1366. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1367. client: 0,
  1368. target: 0,
  1369. item_id: 0x10001,
  1370. action: 0,
  1371. item_amount: 0,
  1372. meseta_amount: 0,
  1373. unknown: 0,
  1374. })))).await.unwrap();
  1375. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1376. client: 0,
  1377. target: 0,
  1378. item_id: 0x10002,
  1379. action: 0,
  1380. item_amount: 0,
  1381. meseta_amount: 0,
  1382. unknown: 0,
  1383. })))).await.unwrap();
  1384. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank qwer".into()))).await.unwrap();
  1385. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1386. client: 0,
  1387. target: 0,
  1388. item_id: 0x10003,
  1389. action: 0,
  1390. item_amount: 0,
  1391. meseta_amount: 0,
  1392. unknown: 0,
  1393. })))).await.unwrap();
  1394. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/bank".into()))).await.unwrap();
  1395. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1396. client: 0,
  1397. target: 0,
  1398. item_id: 0x10004,
  1399. action: 0,
  1400. item_amount: 0,
  1401. meseta_amount: 0,
  1402. unknown: 0,
  1403. })))).await.unwrap();
  1404. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Shared(item::BankName("asdf".into()))).await.unwrap();
  1405. assert_eq!(bank_items.items.len(), 2);
  1406. bank_items.items[0].with_individual(|item| {
  1407. assert_eq!(item.id, item::ItemEntityId(2));
  1408. }).unwrap();
  1409. bank_items.items[1].with_individual(|item| {
  1410. assert_eq!(item.id, item::ItemEntityId(3));
  1411. }).unwrap();
  1412. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Shared(item::BankName("qwer".into()))).await.unwrap();
  1413. assert_eq!(bank_items.items.len(), 1);
  1414. bank_items.items[0].with_individual(|item| {
  1415. assert_eq!(item.id, item::ItemEntityId(4));
  1416. }).unwrap();
  1417. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1418. assert_eq!(bank_items.items.len(), 2);
  1419. bank_items.items[0].with_individual(|item| {
  1420. assert_eq!(item.id, item::ItemEntityId(1));
  1421. }).unwrap();
  1422. bank_items.items[1].with_individual(|item| {
  1423. assert_eq!(item.id, item::ItemEntityId(5));
  1424. }).unwrap();
  1425. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  1426. assert_eq!(inventory_items.items.len(), 1);
  1427. inventory_items.items[0].with_individual(|item| {
  1428. assert_eq!(item.id, item::ItemEntityId(6));
  1429. }).unwrap();
  1430. }
  1431. #[async_std::test]
  1432. async fn test_deposit_meseta_into_shared_banks() {
  1433. let mut entity_gateway = InMemoryGateway::default();
  1434. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1435. entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap();
  1436. let mut ship = standard_ship(entity_gateway.clone());
  1437. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1438. join_lobby(&mut ship, ClientId(1)).await;
  1439. create_room(&mut ship, ClientId(1), "room", "").await;
  1440. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1441. client: 0,
  1442. target: 0,
  1443. unknown: 0,
  1444. })))).await.unwrap();
  1445. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1446. client: 0,
  1447. target: 0,
  1448. item_id: 0xFFFFFFFF,
  1449. action: 0,
  1450. item_amount: 0,
  1451. meseta_amount: 23,
  1452. unknown: 0,
  1453. })))).await.unwrap();
  1454. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank asdf".into()))).await.unwrap();
  1455. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1456. client: 0,
  1457. target: 0,
  1458. unknown: 0,
  1459. })))).await.unwrap();
  1460. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1461. client: 0,
  1462. target: 0,
  1463. item_id: 0xFFFFFFFF,
  1464. action: 0,
  1465. item_amount: 0,
  1466. meseta_amount: 55,
  1467. unknown: 0,
  1468. })))).await.unwrap();
  1469. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank qwer".into()))).await.unwrap();
  1470. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1471. client: 0,
  1472. target: 0,
  1473. unknown: 0,
  1474. })))).await.unwrap();
  1475. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1476. client: 0,
  1477. target: 0,
  1478. item_id: 0xFFFFFFFF,
  1479. action: 0,
  1480. item_amount: 0,
  1481. meseta_amount: 32,
  1482. unknown: 0,
  1483. })))).await.unwrap();
  1484. let meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  1485. assert_eq!(meseta.0, 300-23-55-32);
  1486. let bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1487. assert_eq!(bank_meseta.0, 23);
  1488. let bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("asdf".into()))).await.unwrap();
  1489. assert_eq!(bank_meseta.0, 55);
  1490. let bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("qwer".into()))).await.unwrap();
  1491. assert_eq!(bank_meseta.0, 32);
  1492. }
  1493. #[async_std::test]
  1494. async fn test_withdraw_items_from_shared_banks() {
  1495. let mut entity_gateway = InMemoryGateway::default();
  1496. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1497. let item0 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Saber).as_new()).await.unwrap();
  1498. let item1 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Buster).as_new()).await.unwrap();
  1499. let item2 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Rifle).as_new()).await.unwrap();
  1500. let item3 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Handgun).as_new()).await.unwrap();
  1501. let item4 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Autogun).as_new()).await.unwrap();
  1502. let item5 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Calibur).as_new()).await.unwrap();
  1503. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item0, item1]), &item::BankIdentifier::Character).await.unwrap();
  1504. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item2, item3]), &item::BankIdentifier::Shared(item::BankName("asdf".into()))).await.unwrap();
  1505. entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item4, item5]), &item::BankIdentifier::Shared(item::BankName("qwer".into()))).await.unwrap();
  1506. let mut ship = standard_ship(entity_gateway.clone());
  1507. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1508. join_lobby(&mut ship, ClientId(1)).await;
  1509. create_room(&mut ship, ClientId(1), "room", "").await;
  1510. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1511. client: 0,
  1512. target: 0,
  1513. unknown: 0,
  1514. })))).await.unwrap();
  1515. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1516. client: 0,
  1517. target: 0,
  1518. item_id: 0x20000, // saber (1)
  1519. action: 1,
  1520. item_amount: 0,
  1521. meseta_amount: 0,
  1522. unknown: 0,
  1523. })))).await.unwrap();
  1524. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank asdf".into()))).await.unwrap();
  1525. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1526. client: 0,
  1527. target: 0,
  1528. unknown: 0,
  1529. })))).await.unwrap();
  1530. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1531. client: 0,
  1532. target: 0,
  1533. item_id: 0x810003, // handgun (4)
  1534. action: 1,
  1535. item_amount: 0,
  1536. meseta_amount: 0,
  1537. unknown: 0,
  1538. })))).await.unwrap();
  1539. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1540. client: 0,
  1541. target: 0,
  1542. item_id: 0x810004, // rifle (3)
  1543. action: 1,
  1544. item_amount: 0,
  1545. meseta_amount: 0,
  1546. unknown: 0,
  1547. })))).await.unwrap();
  1548. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank qwer".into()))).await.unwrap();
  1549. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1550. client: 0,
  1551. target: 0,
  1552. item_id: 0x810006, // autogun (5)
  1553. action: 1,
  1554. item_amount: 0,
  1555. meseta_amount: 0,
  1556. unknown: 0,
  1557. })))).await.unwrap();
  1558. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Shared(item::BankName("asdf".into()))).await.unwrap();
  1559. assert_eq!(bank_items.items.len(), 0);
  1560. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Shared(item::BankName("qwer".into()))).await.unwrap();
  1561. assert_eq!(bank_items.items.len(), 1);
  1562. bank_items.items[0].with_individual(|item| {
  1563. assert_eq!(item.id, item::ItemEntityId(6));
  1564. }).unwrap();
  1565. let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1566. assert_eq!(bank_items.items.len(), 1);
  1567. bank_items.items[0].with_individual(|item| {
  1568. assert_eq!(item.id, item::ItemEntityId(2));
  1569. }).unwrap();
  1570. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  1571. assert_eq!(inventory_items.items.len(), 4);
  1572. inventory_items.items[0].with_individual(|item| {
  1573. assert_eq!(item.id, item::ItemEntityId(1));
  1574. }).unwrap();
  1575. inventory_items.items[1].with_individual(|item| {
  1576. assert_eq!(item.id, item::ItemEntityId(4));
  1577. }).unwrap();
  1578. inventory_items.items[2].with_individual(|item| {
  1579. assert_eq!(item.id, item::ItemEntityId(3));
  1580. }).unwrap();
  1581. inventory_items.items[3].with_individual(|item| {
  1582. assert_eq!(item.id, item::ItemEntityId(5));
  1583. }).unwrap();
  1584. }
  1585. #[async_std::test]
  1586. async fn test_withdraw_meseta_from_shared_banks() {
  1587. let mut entity_gateway = InMemoryGateway::default();
  1588. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  1589. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap();
  1590. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("asdf".into())), item::Meseta(300)).await.unwrap();
  1591. entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("qwer".into())), item::Meseta(300)).await.unwrap();
  1592. let mut ship = standard_ship(entity_gateway.clone());
  1593. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  1594. join_lobby(&mut ship, ClientId(1)).await;
  1595. create_room(&mut ship, ClientId(1), "room", "").await;
  1596. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1597. client: 0,
  1598. target: 0,
  1599. unknown: 0,
  1600. })))).await.unwrap();
  1601. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1602. client: 0,
  1603. target: 0,
  1604. item_id: 0xFFFFFFFF,
  1605. action: 1,
  1606. item_amount: 0,
  1607. meseta_amount: 23,
  1608. unknown: 0,
  1609. })))).await.unwrap();
  1610. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank asdf".into()))).await.unwrap();
  1611. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1612. client: 0,
  1613. target: 0,
  1614. unknown: 0,
  1615. })))).await.unwrap();
  1616. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1617. client: 0,
  1618. target: 0,
  1619. item_id: 0xFFFFFFFF,
  1620. action: 1,
  1621. item_amount: 0,
  1622. meseta_amount: 55,
  1623. unknown: 0,
  1624. })))).await.unwrap();
  1625. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/sbank qwer".into()))).await.unwrap();
  1626. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1627. client: 0,
  1628. target: 0,
  1629. unknown: 0,
  1630. })))).await.unwrap();
  1631. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1632. client: 0,
  1633. target: 0,
  1634. item_id: 0xFFFFFFFF,
  1635. action: 1,
  1636. item_amount: 0,
  1637. meseta_amount: 32,
  1638. unknown: 0,
  1639. })))).await.unwrap();
  1640. ship.handle(ClientId(1), RecvShipPacket::PlayerChat(PlayerChat::new(0, "\tE/bank".into()))).await.unwrap();
  1641. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  1642. client: 0,
  1643. target: 0,
  1644. unknown: 0,
  1645. })))).await.unwrap();
  1646. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
  1647. client: 0,
  1648. target: 0,
  1649. item_id: 0xFFFFFFFF,
  1650. action: 1,
  1651. item_amount: 0,
  1652. meseta_amount: 5,
  1653. unknown: 0,
  1654. })))).await.unwrap();
  1655. let meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  1656. let bank_meseta1 = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Character).await.unwrap();
  1657. let bank_meseta2 = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("asdf".into()))).await.unwrap();
  1658. let bank_meseta3 = entity_gateway.get_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("qwer".into()))).await.unwrap();
  1659. assert_eq!(meseta.0, 23+55+32+5);
  1660. assert_eq!(bank_meseta1.0, 300-23-5);
  1661. assert_eq!(bank_meseta2.0, 300-55);
  1662. assert_eq!(bank_meseta3.0, 300-32);
  1663. }