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.

218 lines
6.7 KiB

  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::ship::ship::{ShipServerState, RecvShipPacket};
  4. use elseware::entity::item;
  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_equip_unit_from_equip_menu() {
  12. let mut entity_gateway = InMemoryGateway::new();
  13. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  14. entity_gateway.create_item(
  15. item::NewItemEntity {
  16. item: item::ItemDetail::Armor(
  17. item::armor::Armor{
  18. armor: item::armor::ArmorType::Frame,
  19. dfp: 0,
  20. evp: 0,
  21. slots: 4,
  22. modifiers: Vec::new(),
  23. }),
  24. location: item::ItemLocation::Inventory {
  25. character_id: char1.id,
  26. slot: 0,
  27. equipped: true,
  28. }
  29. }).await;
  30. entity_gateway.create_item(
  31. item::NewItemEntity {
  32. item: item::ItemDetail::Unit(
  33. item::unit::Unit{
  34. unit: item::unit::UnitType::KnightPower,
  35. modifier: None,
  36. armor_slot: 0,
  37. }),
  38. location: item::ItemLocation::Inventory {
  39. character_id: char1.id,
  40. slot: 1,
  41. equipped: false,
  42. }
  43. }).await.unwrap();
  44. entity_gateway.create_item(
  45. item::NewItemEntity {
  46. item: item::ItemDetail::Unit(
  47. item::unit::Unit{
  48. unit: item::unit::UnitType::KnightPower,
  49. modifier: Some(item::unit::UnitModifier::Plus),
  50. armor_slot: 0,
  51. }),
  52. location: item::ItemLocation::Inventory {
  53. character_id: char1.id,
  54. slot: 2,
  55. equipped: false,
  56. }
  57. }).await.unwrap();
  58. let mut ship = ShipServerState::builder()
  59. .gateway(entity_gateway.clone())
  60. .build();
  61. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  62. join_lobby(&mut ship, ClientId(1)).await;
  63. create_room(&mut ship, ClientId(1), "room", "").await;
  64. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerEquipItem(PlayerEquipItem {
  65. client: 0,
  66. target: 0,
  67. item_id: 0x10001,
  68. sub_menu: 9,
  69. unknown1: 0,
  70. })))).await.unwrap().for_each(drop);
  71. // case when someone tries to send invalid submenu? submenu is 9-12 in normal gameplay
  72. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerEquipItem(PlayerEquipItem {
  73. client: 0,
  74. target: 0,
  75. item_id: 0x10002,
  76. sub_menu: 14,
  77. unknown1: 0,
  78. })))).await.unwrap().for_each(drop);
  79. let items = entity_gateway.get_items_by_character(&char1).await;
  80. let (unit1, unit2) = (&items[1], &items[2]);
  81. let unit1_equipped = match unit1.location {
  82. item::ItemLocation::Inventory{equipped, ..} => equipped,
  83. _ => false,
  84. };
  85. let unit2_equipped = match unit2.location {
  86. item::ItemLocation::Inventory{equipped, ..} => equipped,
  87. _ => false,
  88. };
  89. assert!({
  90. match unit1.item {
  91. item::ItemDetail::Unit(u) => {
  92. if u.armor_slot == 0 && unit1_equipped {
  93. true
  94. } else {
  95. false
  96. }
  97. },
  98. _ => false,
  99. }
  100. });
  101. assert!({
  102. match unit2.item {
  103. item::ItemDetail::Unit(u) => {
  104. if u.armor_slot == 1 && unit2_equipped {
  105. true
  106. } else {
  107. false
  108. }
  109. },
  110. _ => false,
  111. }
  112. });
  113. }
  114. #[async_std::test]
  115. async fn test_unequip_armor_with_units() {
  116. let mut entity_gateway = InMemoryGateway::new();
  117. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  118. entity_gateway.create_item(
  119. item::NewItemEntity {
  120. item: item::ItemDetail::Armor(
  121. item::armor::Armor{
  122. armor: item::armor::ArmorType::Frame,
  123. dfp: 0,
  124. evp: 0,
  125. slots: 4,
  126. modifiers: Vec::new(),
  127. }),
  128. location: item::ItemLocation::Inventory {
  129. character_id: char1.id,
  130. slot: 0,
  131. equipped: true,
  132. }
  133. }).await;
  134. entity_gateway.create_item(
  135. item::NewItemEntity {
  136. item: item::ItemDetail::Unit(
  137. item::unit::Unit{
  138. unit: item::unit::UnitType::KnightPower,
  139. modifier: None,
  140. armor_slot: 0,
  141. }),
  142. location: item::ItemLocation::Inventory {
  143. character_id: char1.id,
  144. slot: 1,
  145. equipped: true,
  146. }
  147. }).await.unwrap();
  148. entity_gateway.create_item(
  149. item::NewItemEntity {
  150. item: item::ItemDetail::Unit(
  151. item::unit::Unit{
  152. unit: item::unit::UnitType::KnightPower,
  153. modifier: Some(item::unit::UnitModifier::Plus),
  154. armor_slot: 1,
  155. }),
  156. location: item::ItemLocation::Inventory {
  157. character_id: char1.id,
  158. slot: 2,
  159. equipped: true,
  160. }
  161. }).await.unwrap();
  162. let mut ship = ShipServerState::builder()
  163. .gateway(entity_gateway.clone())
  164. .build();
  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. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUnequipItem(PlayerUnequipItem {
  169. client: 0,
  170. target: 0,
  171. item_id: 0x10000,
  172. unknown1: 0,
  173. })))).await.unwrap().for_each(drop);
  174. let items = entity_gateway.get_items_by_character(&char1).await;
  175. let (armor, unit1, unit2) = (&items[0], &items[1], &items[2]);
  176. let armor_equipped = match armor.location {
  177. item::ItemLocation::Inventory{equipped, ..} => equipped,
  178. _ => true,
  179. };
  180. let unit1_equipped = match unit1.location {
  181. item::ItemLocation::Inventory{equipped, ..} => equipped,
  182. _ => true,
  183. };
  184. let unit2_equipped = match unit2.location {
  185. item::ItemLocation::Inventory{equipped, ..} => equipped,
  186. _ => true,
  187. };
  188. assert!(armor_equipped == false);
  189. assert!(unit1_equipped == false);
  190. assert!(unit2_equipped == false);
  191. }