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.

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