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.

271 lines
9.7 KiB

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. /* TODO:
  2. 4. test unsealing item:
  3. - client item id does not change
  4. - unsealed item no longer has kill counter
  5. 5. test reject unsealing item if not enough kills (can this even happen?)
  6. */
  7. use elseware::common::serverstate::{ClientId, ServerState};
  8. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  9. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  10. use elseware::entity::character::SectionID;
  11. use elseware::ship::room::Difficulty;
  12. use elseware::ship::monster::MonsterType;
  13. use elseware::entity::item;
  14. use libpso::packet::ship::*;
  15. use libpso::packet::messages::*;
  16. #[path = "common.rs"]
  17. mod common;
  18. use common::*;
  19. #[async_std::test]
  20. async fn test_sjs_drops_with_kill_counter() {
  21. let mut entity_gateway = InMemoryGateway::default();
  22. let (_user1, mut char1) = new_user_character_with_sid(&mut entity_gateway, "a1", "a", SectionID::Skyly).await;
  23. char1.exp = 80000000;
  24. entity_gateway.save_character(&char1).await.unwrap();
  25. let mut ship = Box::new(ShipServerState::builder()
  26. .gateway(entity_gateway.clone())
  27. .build());
  28. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  29. join_lobby(&mut ship, ClientId(1)).await;
  30. create_ep2_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  31. let room = ship.blocks.0[0].rooms[0].as_mut().unwrap();
  32. room.toggle_redbox_mode(); // enable redbox mode
  33. let gigue_id = room.maps.get_enemy_id_by_monster_type(MonsterType::GiGue).unwrap();
  34. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem {
  35. client: 0,
  36. target: 0,
  37. map_area: 9, // seaside
  38. pt_index: 55, // gigue ? (taken from ingame logs)
  39. enemy_id: gigue_id,
  40. x: 0.0,
  41. y: 0.0,
  42. z: 0.0,
  43. })))).await.unwrap().collect::<Vec<_>>(); // this should return 1 packet (ItemDrop)?
  44. assert!(packets.len() == 1);
  45. match &packets[0].1 {
  46. SendShipPacket::Message(Message {msg: GameMessage::ItemDrop(item_drop)}) => {
  47. assert_eq!(item_drop.item_bytes[10], 0x80)
  48. }
  49. _ => panic!("SJS didn't drop with the expected value! attr[2] should be 0x80 (128) for 0 kills")
  50. }
  51. }
  52. #[async_std::test]
  53. async fn test_other_weapons_drop_without_kill_counter() {
  54. let mut entity_gateway = InMemoryGateway::default();
  55. let (_user1, mut char1) = new_user_character_with_sid(&mut entity_gateway, "a1", "a", SectionID::Skyly).await;
  56. char1.exp = 80000000;
  57. entity_gateway.save_character(&char1).await.unwrap();
  58. let mut ship = Box::new(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_ep2_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
  64. let room = ship.blocks.0[0].rooms[0].as_mut().unwrap();
  65. room.toggle_redbox_mode(); // enable redbox mode
  66. let enemy_id = room.maps.get_enemy_id_by_monster_type(MonsterType::Hildebear).unwrap();
  67. let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem {
  68. client: 0,
  69. target: 0,
  70. map_area: 1, // temple alpha
  71. pt_index: 0, // TODO: this is going to break if pt_index ever gets properly used
  72. enemy_id: enemy_id,
  73. x: 0.0,
  74. y: 0.0,
  75. z: 0.0,
  76. })))).await.unwrap().collect::<Vec<_>>();
  77. assert!(packets.len() == 1);
  78. match &packets[0].1 {
  79. SendShipPacket::Message(Message {msg: GameMessage::ItemDrop(item_drop)}) => {
  80. assert_ne!(item_drop.item_bytes[10], 0x80)
  81. }
  82. _ => panic!("Weapon didn't drop with the expected value! attr[2] should be less than 0x80 (128) because it shouldn't have a kill counter!")
  83. }
  84. }
  85. #[async_std::test]
  86. async fn test_all_equipped_kill_counters_increase_per_kill() {
  87. let mut entity_gateway = InMemoryGateway::default();
  88. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  89. let mut ship = Box::new(ShipServerState::builder()
  90. .gateway(entity_gateway.clone())
  91. .build());
  92. let mut p1_inv = Vec::new();
  93. p1_inv.push(entity_gateway.create_item(
  94. item::NewItemEntity {
  95. item: item::ItemDetail::Weapon(
  96. item::weapon::Weapon {
  97. weapon: item::weapon::WeaponType::SealedJSword,
  98. grind: 0,
  99. special: None,
  100. attrs: [None,
  101. None,
  102. None,],
  103. tekked: true,
  104. kills: Some(0),
  105. }
  106. ),
  107. }).await.unwrap());
  108. p1_inv.push(entity_gateway.create_item(
  109. item::NewItemEntity {
  110. item: item::ItemDetail::Unit(
  111. item::unit::Unit {
  112. unit: item::unit::UnitType::Limiter,
  113. modifier: None,
  114. kills: Some(0),
  115. }
  116. ),
  117. }).await.unwrap());
  118. let equipped = item::EquippedEntity {
  119. weapon: Some(p1_inv[0].id),
  120. armor: None,
  121. shield: None,
  122. unit: [Some(p1_inv[1].id), None, None, None],
  123. mag: None,
  124. };
  125. entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
  126. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  127. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  128. join_lobby(&mut ship, ClientId(1)).await;
  129. create_room(&mut ship, ClientId(1), "room", "").await;
  130. let enemy_id = {
  131. let room = ship.blocks.0[0].rooms[0].as_ref().unwrap();
  132. let enemy_id = (0..).filter_map(|i| {
  133. room.maps.enemy_by_id(i).ok().and_then(|enemy| {
  134. if enemy.monster == MonsterType::Booma {
  135. Some(i)
  136. }
  137. else {
  138. None
  139. }
  140. })
  141. }).next().unwrap();
  142. enemy_id
  143. };
  144. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::KillMonster(KillMonster{
  145. client: enemy_id as u8,
  146. target: 16,
  147. map_area: 1,
  148. data: [8,0],
  149. })))).await.unwrap().for_each(drop);
  150. let equipped_items = entity_gateway.get_character_equips(&char1.id).await.unwrap();
  151. let inventory = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  152. let w = inventory.items.iter().find(|x| x.individual().unwrap().id == equipped_items.weapon.unwrap()).unwrap().individual().unwrap();
  153. let u = inventory.items.iter().find(|x| x.individual().unwrap().id == equipped_items.unit[0].unwrap()).unwrap().individual().unwrap();
  154. assert!(w.item.as_client_bytes()[11] == u.item.as_client_bytes()[11]);
  155. }
  156. #[async_std::test]
  157. async fn test_non_equipped_kill_counter_does_not_increase() {
  158. let mut entity_gateway = InMemoryGateway::default();
  159. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  160. let mut ship = Box::new(ShipServerState::builder()
  161. .gateway(entity_gateway.clone())
  162. .build());
  163. let mut p1_inv = Vec::new();
  164. p1_inv.push(entity_gateway.create_item(
  165. item::NewItemEntity {
  166. item: item::ItemDetail::Weapon(
  167. item::weapon::Weapon {
  168. weapon: item::weapon::WeaponType::SealedJSword,
  169. grind: 0,
  170. special: None,
  171. attrs: [None,
  172. None,
  173. None,],
  174. tekked: true,
  175. kills: Some(0),
  176. }
  177. ),
  178. }).await.unwrap());
  179. p1_inv.push(entity_gateway.create_item(
  180. item::NewItemEntity {
  181. item: item::ItemDetail::Unit(
  182. item::unit::Unit {
  183. unit: item::unit::UnitType::Limiter,
  184. modifier: None,
  185. kills: Some(0),
  186. }
  187. ),
  188. }).await.unwrap());
  189. let equipped = item::EquippedEntity {
  190. weapon: Some(p1_inv[0].id),
  191. armor: None,
  192. shield: None,
  193. unit: [None; 4],
  194. mag: None,
  195. };
  196. entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
  197. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  198. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  199. join_lobby(&mut ship, ClientId(1)).await;
  200. create_room(&mut ship, ClientId(1), "room", "").await;
  201. let enemy_id = {
  202. let room = ship.blocks.0[0].rooms[0].as_ref().unwrap();
  203. let enemy_id = (0..).filter_map(|i| {
  204. room.maps.enemy_by_id(i).ok().and_then(|enemy| {
  205. if enemy.monster == MonsterType::Booma {
  206. Some(i)
  207. }
  208. else {
  209. None
  210. }
  211. })
  212. }).next().unwrap();
  213. enemy_id
  214. };
  215. ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::KillMonster(KillMonster{
  216. client: enemy_id as u8,
  217. target: 16,
  218. map_area: 1,
  219. data: [8,0],
  220. })))).await.unwrap().for_each(drop);
  221. let equipped_items = entity_gateway.get_character_equips(&char1.id).await.unwrap();
  222. let inventory = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  223. let w = inventory.items.iter().find(|x| x.individual().unwrap().id == equipped_items.weapon.unwrap()).unwrap().individual().unwrap();
  224. let u = inventory.items.iter().find(|x| x.individual().unwrap().id == item::ItemEntityId(2)).unwrap().individual().unwrap();
  225. assert!(w.item.as_client_bytes()[11] == 1);
  226. assert!(u.item.as_client_bytes()[11] == 0);
  227. }