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.

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