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.

289 lines
10 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. // unwrap presents
  11. #[async_std::test]
  12. async fn test_unwrap_weapon() {
  13. let mut entity_gateway = InMemoryGateway::new();
  14. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  15. let wrapped_item = entity_gateway.create_item(
  16. item::NewItemEntity {
  17. item: item::ItemDetail::Weapon(item::weapon::Weapon {
  18. weapon: item::weapon::WeaponType::Saber,
  19. special: Some(item::weapon::WeaponSpecial::Burning),
  20. grind: 5,
  21. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Machine, value: 20}),
  22. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 30}),
  23. None],
  24. tekked: false,
  25. wrapping: Some(item::WrappingPaper::RedGreen),
  26. }),
  27. location: item::ItemLocation::Inventory{
  28. character_id: char1.id,
  29. }
  30. }).await.unwrap();
  31. assert!(wrapped_item.item.as_client_bytes() == [0x00,0x01,0x00,0x05,0xDA,0x05,0x03,0x14,0x05,0x1E,0x00,0x00,0x00,0x00,0x00,0x00]);
  32. let mut inventory = Vec::<item::ItemEntity>::new();
  33. inventory.push(wrapped_item.into());
  34. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  35. let mut ship = Box::new(ShipServerState::builder()
  36. .gateway(entity_gateway.clone())
  37. .build());
  38. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  39. join_lobby(&mut ship, ClientId(1)).await;
  40. create_room(&mut ship, ClientId(1), "room", "").await;
  41. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  42. client: 0,
  43. target: 0,
  44. item_id: 0x10000,
  45. })))).await.unwrap().for_each(drop);
  46. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  47. inventory_items.items[0].with_individual(|item| {
  48. match &item.item {
  49. item::ItemDetail::Weapon(weapon) => {
  50. assert!(weapon.as_bytes() == [0x00, 0x01, 0x00, 0x05, 0x9A, 0x00, 0x03, 0x14, 0x05, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
  51. },
  52. _ => panic!(),
  53. }
  54. }).unwrap();
  55. }
  56. #[async_std::test]
  57. async fn test_unwrap_armor() {
  58. let mut entity_gateway = InMemoryGateway::new();
  59. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  60. let wrapped_item = entity_gateway.create_item(
  61. item::NewItemEntity {
  62. item: item::ItemDetail::Armor(item::armor::Armor {
  63. armor: item::armor::ArmorType::PerfectFrame,
  64. dfp: 3u8,
  65. evp: 2u8,
  66. slots: 4u8,
  67. wrapping: Some(item::WrappingPaper::RedGreen), // 5
  68. }),
  69. location: item::ItemLocation::Inventory{
  70. character_id: char1.id,
  71. }
  72. }).await.unwrap();
  73. // slots should be untouched when wrapped regardless of wrapping paper colour
  74. assert!(wrapped_item.item.as_client_bytes() == [0x01,0x01,0x10,0x00,0x40,0x04,0x03,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
  75. let mut inventory = Vec::<item::ItemEntity>::new();
  76. inventory.push(wrapped_item.into());
  77. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  78. let mut ship = Box::new(ShipServerState::builder()
  79. .gateway(entity_gateway.clone())
  80. .build());
  81. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  82. join_lobby(&mut ship, ClientId(1)).await;
  83. create_room(&mut ship, ClientId(1), "room", "").await;
  84. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  85. client: 0,
  86. target: 0,
  87. item_id: 0x10000,
  88. })))).await.unwrap().for_each(drop);
  89. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  90. inventory_items.items[0].with_individual(|item| {
  91. match &item.item {
  92. item::ItemDetail::Armor(armor) => {
  93. assert!(armor.as_bytes() == [0x01,0x01,0x10,0x00,0x00,0x04,0x03,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
  94. },
  95. _ => panic!(),
  96. }
  97. }).unwrap();
  98. }
  99. #[async_std::test]
  100. async fn test_unwrap_shield() {
  101. let mut entity_gateway = InMemoryGateway::new();
  102. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  103. let wrapped_item = entity_gateway.create_item(
  104. item::NewItemEntity {
  105. item: item::ItemDetail::Shield(item::shield::Shield {
  106. shield: item::shield::ShieldType::CoreShield,
  107. dfp: 2u8,
  108. evp: 3u8,
  109. wrapping: Some(item::WrappingPaper::RedGreen), // 5
  110. }),
  111. location: item::ItemLocation::Inventory{
  112. character_id: char1.id,
  113. }
  114. }).await.unwrap();
  115. assert!(wrapped_item.item.as_client_bytes() == [0x01,0x02,0x02,0x00,0x40,0x05,0x02,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
  116. let mut inventory = Vec::<item::ItemEntity>::new();
  117. inventory.push(wrapped_item.into());
  118. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  119. let mut ship = Box::new(ShipServerState::builder()
  120. .gateway(entity_gateway.clone())
  121. .build());
  122. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  123. join_lobby(&mut ship, ClientId(1)).await;
  124. create_room(&mut ship, ClientId(1), "room", "").await;
  125. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  126. client: 0,
  127. target: 0,
  128. item_id: 0x10000,
  129. })))).await.unwrap().for_each(drop);
  130. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  131. inventory_items.items[0].with_individual(|item| {
  132. match &item.item {
  133. item::ItemDetail::Shield(shield) => {
  134. assert!(shield.as_bytes() == [0x01,0x02,0x02,0x00,0x00,0x00,0x02,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
  135. },
  136. _ => panic!(),
  137. }
  138. }).unwrap();
  139. }
  140. #[async_std::test]
  141. async fn test_unwrap_unit() {
  142. let mut entity_gateway = InMemoryGateway::new();
  143. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  144. let wrapped_item = entity_gateway.create_item(
  145. item::NewItemEntity {
  146. item: item::ItemDetail::Unit(item::unit::Unit {
  147. unit: item::unit::UnitType::KnightPower,
  148. modifier: Some(item::unit::UnitModifier::MinusMinus),
  149. wrapping: Some(item::WrappingPaper::RedGreen), // 5
  150. }),
  151. location: item::ItemLocation::Inventory{
  152. character_id: char1.id,
  153. }
  154. }).await.unwrap();
  155. assert!(wrapped_item.item.as_client_bytes() == [0x01,0x03,0x00,0x00,0x40,0x05,0xFE,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
  156. let mut inventory = Vec::<item::ItemEntity>::new();
  157. inventory.push(wrapped_item.into());
  158. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  159. let mut ship = Box::new(ShipServerState::builder()
  160. .gateway(entity_gateway.clone())
  161. .build());
  162. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  163. join_lobby(&mut ship, ClientId(1)).await;
  164. create_room(&mut ship, ClientId(1), "room", "").await;
  165. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  166. client: 0,
  167. target: 0,
  168. item_id: 0x10000,
  169. })))).await.unwrap().for_each(drop);
  170. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  171. inventory_items.items[0].with_individual(|item| {
  172. match &item.item {
  173. item::ItemDetail::Unit(unit) => {
  174. assert!(unit.as_bytes() == [0x01,0x03,0x00,0x00,0x00,0x00,0xFE,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
  175. },
  176. _ => panic!(),
  177. }
  178. }).unwrap();
  179. }
  180. // mag cells are covered in test_mags.rs
  181. #[async_std::test]
  182. async fn test_unwrap_mag() {
  183. let mut entity_gateway = InMemoryGateway::new();
  184. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  185. let wrapped_item = entity_gateway.create_item(
  186. item::NewItemEntity {
  187. item: item::ItemDetail::Mag(item::mag::Mag::wrapped_baby_mag(12)), //turquoise
  188. location: item::ItemLocation::Inventory{
  189. character_id: char1.id,
  190. }
  191. }).await.unwrap();
  192. assert!(wrapped_item.item.as_client_bytes() == [0x02,0x00,0x00,0x00,0xF4,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x40,0x0C]); // item maker is wrong?
  193. let mut inventory = Vec::<item::ItemEntity>::new();
  194. inventory.push(wrapped_item.into());
  195. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap();
  196. let mut ship = Box::new(ShipServerState::builder()
  197. .gateway(entity_gateway.clone())
  198. .build());
  199. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  200. join_lobby(&mut ship, ClientId(1)).await;
  201. create_room(&mut ship, ClientId(1), "room", "").await;
  202. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
  203. client: 0,
  204. target: 0,
  205. item_id: 0x10000,
  206. })))).await.unwrap().for_each(drop);
  207. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  208. inventory_items.items[0].with_individual(|item| {
  209. match &item.item {
  210. item::ItemDetail::Mag(mag) => {
  211. assert!(mag.as_bytes() == [0x02,0x00,0x00,0x00,0xF4,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x0C]);
  212. },
  213. _ => panic!(),
  214. }
  215. }).unwrap();
  216. }
  217. // TODO: implement wrapping packet (message 0xD6) (gallons shop quest)
  218. // wrap presents
  219. #[async_std::test]
  220. async fn test_wrap_weapon() {}
  221. #[async_std::test]
  222. async fn test_wrap_armor() {}
  223. #[async_std::test]
  224. async fn test_wrap_shield() {}
  225. #[async_std::test]
  226. async fn test_wrap_unit() {}
  227. // mag cells are covered in test_mags.rs
  228. #[async_std::test]
  229. async fn test_wrap_mag() {}
  230. // item combinations?