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.

220 lines
8.1 KiB

  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::entity::item;
  4. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  5. use elseware::ship::items::{ClientItemId};
  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::new();
  14. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  15. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  16. 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. location: item::ItemLocation::Bank {
  28. character_id: char1.id,
  29. name: item::BankName("".to_string())
  30. }
  31. }).await;
  32. let mut ship = ShipServerState::new(entity_gateway.clone());
  33. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  34. let packets = ship.handle(ClientId(1), &RecvShipPacket::MenuSelect(MenuSelect {
  35. menu: BLOCK_MENU_ID,
  36. item: 1,
  37. })).await.unwrap().collect::<Vec<_>>();
  38. assert!(matches!(&packets[0], (_, SendShipPacket::FullCharacter(fc)) if fc.character.bank.items[0].data1[0..3] == [0x00, 0x08, 0x04] ));
  39. }
  40. #[async_std::test]
  41. async fn test_request_bank_items() {
  42. let mut entity_gateway = InMemoryGateway::new();
  43. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  44. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  45. for _ in 0..3 {
  46. entity_gateway.create_item(
  47. item::NewItemEntity {
  48. item: item::ItemDetail::Weapon(
  49. item::weapon::Weapon {
  50. weapon: item::weapon::WeaponType::Vulcan,
  51. grind: 0,
  52. special: None,
  53. attrs: [None, None, None],
  54. tekked: true,
  55. }
  56. ),
  57. location: item::ItemLocation::Bank {
  58. character_id: char1.id,
  59. name: item::BankName("".to_string())
  60. }
  61. }).await;
  62. }
  63. let mut ship = ShipServerState::new(entity_gateway.clone());
  64. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  65. join_lobby(&mut ship, ClientId(1)).await;
  66. create_room(&mut ship, ClientId(1), "room", "").await;
  67. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  68. client: 0,
  69. target: 0,
  70. unknown: 0,
  71. })))).await.unwrap().collect::<Vec<_>>();
  72. assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
  73. if bank_item_list.item_count == 3
  74. && bank_item_list.size == 0x18 * 3 + 0x14
  75. && bank_item_list.items[0].data1[0..3] == [0x00, 0x08, 0x04]
  76. && bank_item_list.items[1].data1[0..3] == [0x00, 0x08, 0x04]
  77. && bank_item_list.items[2].data1[0..3] == [0x00, 0x08, 0x04]
  78. ));
  79. }
  80. #[async_std::test]
  81. async fn test_request_stacked_bank_items() {
  82. let mut entity_gateway = InMemoryGateway::new();
  83. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  84. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  85. for _ in 0..3 {
  86. entity_gateway.create_item(
  87. item::NewItemEntity {
  88. item: item::ItemDetail::Tool (
  89. item::tool::Tool {
  90. tool: item::tool::ToolType::Monomate,
  91. }
  92. ),
  93. location: item::ItemLocation::Bank {
  94. character_id: char1.id,
  95. name: item::BankName("".to_string())
  96. }
  97. }).await;
  98. }
  99. let mut ship = ShipServerState::new(entity_gateway.clone());
  100. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  101. join_lobby(&mut ship, ClientId(1)).await;
  102. create_room(&mut ship, ClientId(1), "room", "").await;
  103. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  104. client: 0,
  105. target: 0,
  106. unknown: 0,
  107. })))).await.unwrap().collect::<Vec<_>>();
  108. assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
  109. if bank_item_list.item_count == 1
  110. && bank_item_list.size == 0x18 + 0x14
  111. && bank_item_list.items[0].data1[0..3] == [0x03, 0x00, 0x00]
  112. && bank_item_list.items[0].amount == 3
  113. ));
  114. }
  115. #[async_std::test]
  116. async fn test_request_bank_items_sorted() {
  117. let mut entity_gateway = InMemoryGateway::new();
  118. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  119. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  120. entity_gateway.create_item(
  121. item::NewItemEntity {
  122. item: item::ItemDetail::Weapon(
  123. item::weapon::Weapon {
  124. weapon: item::weapon::WeaponType::Vulcan,
  125. grind: 0,
  126. special: None,
  127. attrs: [None, None, None],
  128. tekked: true,
  129. }
  130. ),
  131. location: item::ItemLocation::Bank {
  132. character_id: char1.id,
  133. name: item::BankName("".to_string())
  134. }
  135. }).await;
  136. entity_gateway.create_item(
  137. item::NewItemEntity {
  138. item: item::ItemDetail::Tool (
  139. item::tool::Tool {
  140. tool: item::tool::ToolType::Monomate,
  141. }
  142. ),
  143. location: item::ItemLocation::Bank {
  144. character_id: char1.id,
  145. name: item::BankName("".to_string())
  146. }
  147. }).await;
  148. entity_gateway.create_item(
  149. item::NewItemEntity {
  150. item: item::ItemDetail::Weapon(
  151. item::weapon::Weapon {
  152. weapon: item::weapon::WeaponType::Calibur,
  153. grind: 0,
  154. special: None,
  155. attrs: [None, None, None],
  156. tekked: true,
  157. }
  158. ),
  159. location: item::ItemLocation::Bank {
  160. character_id: char1.id,
  161. name: item::BankName("".to_string())
  162. }
  163. }).await;
  164. let mut ship = ShipServerState::new(entity_gateway.clone());
  165. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  166. join_lobby(&mut ship, ClientId(1)).await;
  167. create_room(&mut ship, ClientId(1), "room", "").await;
  168. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
  169. client: 0,
  170. target: 0,
  171. unknown: 0,
  172. })))).await.unwrap().collect::<Vec<_>>();
  173. println!("{:?}", packets);
  174. assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
  175. if bank_item_list.item_count == 3
  176. && bank_item_list.size == 0x18 * 3 + 0x14
  177. && bank_item_list.items[0].data1[0..3] == [0x00, 0x02, 0x04]
  178. && bank_item_list.items[1].data1[0..3] == [0x00, 0x08, 0x04]
  179. && bank_item_list.items[2].data1[0..3] == [0x03, 0x00, 0x00]
  180. ));
  181. }
  182. //test_deposit_individual_item
  183. //test_deposit_stacked_item
  184. //test_deposit_stacked_item_with_stack_already_in_bank
  185. //test_deposit_stacked_item_when_full_stack_in_bank
  186. //test_deposit_individual_item_in_full_bank
  187. //test_deposit_stacked_item_in_full_bank
  188. //test_deposit_meseta
  189. //test_deposit_too_much_meseta
  190. //test_deposit_when_bank_has_max_meseta