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.

684 lines
24 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
3 years ago
  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use entity::item;
  4. use libpso::item::weapon;
  5. use ship_server::RecvShipPacket;
  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_pick_up_individual_item() {
  13. let mut entity_gateway = InMemoryGateway::default();
  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. let mut p1_inv = Vec::new();
  17. p1_inv.push(entity_gateway.create_item(
  18. ItemBuilder::weapon(weapon::WeaponType::Handgun)
  19. .as_new()
  20. ).await.unwrap());
  21. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  22. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::<item::InventoryItemEntity>::new())).await.unwrap();
  23. let mut ship = standard_ship(entity_gateway.clone());
  24. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  25. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  26. join_lobby(&mut ship, ClientId(1)).await;
  27. join_lobby(&mut ship, ClientId(2)).await;
  28. create_room(&mut ship, ClientId(1), "room", "").await;
  29. join_room(&mut ship, ClientId(2), 0).await;
  30. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  31. assert_eq!(p1_items.items.len(), 1);
  32. let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  33. assert_eq!(p2_items.items.len(), 0);
  34. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  35. client: 0,
  36. target: 0,
  37. unknown1: 0,
  38. map_area: 0,
  39. item_id: 0x10000,
  40. x: 0.0,
  41. y: 0.0,
  42. z: 0.0,
  43. })))).await.unwrap();
  44. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  45. assert_eq!(p1_items.items.len(), 0);
  46. let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  47. assert_eq!(p2_items.items.len(), 0);
  48. ship.handle(ClientId(2), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  49. client: 0,
  50. target: 0,
  51. item_id: 0x10000,
  52. map_area: 0,
  53. unknown: [0; 3]
  54. })))).await.unwrap();
  55. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  56. assert_eq!(p1_items.items.len(), 0);
  57. let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  58. assert_eq!(p2_items.items.len(), 1);
  59. }
  60. #[async_std::test]
  61. async fn test_pick_up_item_stack_of_items_already_in_inventory() {
  62. let mut entity_gateway = InMemoryGateway::default();
  63. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  64. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  65. let mut p1_monomate = Vec::new();
  66. p1_monomate.push(entity_gateway.create_item(
  67. ItemBuilder::tool(item::tool::ToolType::Monomate)
  68. .as_new()
  69. ).await.unwrap());
  70. let mut p2_items = Vec::new();
  71. for (_slot, tool) in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter().enumerate() {
  72. let mut item = Vec::new();
  73. for _ in 0..5usize {
  74. item.push(entity_gateway.create_item(
  75. ItemBuilder::tool(tool)
  76. .as_new()
  77. ).await.unwrap());
  78. }
  79. p2_items.push(item);
  80. }
  81. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![p1_monomate])).await.unwrap();
  82. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_items)).await.unwrap();
  83. let mut ship = standard_ship(entity_gateway.clone());
  84. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  85. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  86. join_lobby(&mut ship, ClientId(1)).await;
  87. join_lobby(&mut ship, ClientId(2)).await;
  88. create_room(&mut ship, ClientId(1), "room", "").await;
  89. join_room(&mut ship, ClientId(2), 0).await;
  90. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  91. client: 0,
  92. target: 0,
  93. unknown1: 0,
  94. map_area: 0,
  95. item_id: 0x210000,
  96. x: 0.0,
  97. y: 0.0,
  98. z: 0.0,
  99. })))).await.unwrap();
  100. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  101. client: 0,
  102. target: 0,
  103. item_id: 0x210000,
  104. map_area: 0,
  105. unknown: [0; 3]
  106. })))).await.unwrap();
  107. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  108. assert_eq!(inventory_items.items.len(), 1);
  109. inventory_items.items[0].with_stacked(|items| {
  110. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  111. vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5), item::ItemEntityId(6)]);
  112. assert!(items.iter().all(|item| item.item.item_type() == item::ItemType::Tool(item::tool::ToolType::Monomate)));
  113. }).unwrap();
  114. }
  115. #[async_std::test]
  116. async fn test_pick_up_item_stack_of_items_not_already_held() {
  117. let mut entity_gateway = InMemoryGateway::default();
  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. let mut p2_monomate = Vec::new();
  121. p2_monomate.push(entity_gateway.create_item(
  122. ItemBuilder::tool(item::tool::ToolType::Monomate)
  123. .as_new()
  124. ).await.unwrap());
  125. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomate])).await.unwrap();
  126. let mut ship = standard_ship(entity_gateway.clone());
  127. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  128. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  129. join_lobby(&mut ship, ClientId(1)).await;
  130. join_lobby(&mut ship, ClientId(2)).await;
  131. create_room(&mut ship, ClientId(1), "room", "").await;
  132. join_room(&mut ship, ClientId(2), 0).await;
  133. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  134. client: 0,
  135. target: 0,
  136. unknown1: 0,
  137. map_area: 0,
  138. item_id: 0x210000,
  139. x: 0.0,
  140. y: 0.0,
  141. z: 0.0,
  142. })))).await.unwrap();
  143. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  144. client: 0,
  145. target: 0,
  146. item_id: 0x210000,
  147. map_area: 0,
  148. unknown: [0; 3]
  149. })))).await.unwrap();
  150. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  151. assert_eq!(inventory_items.items.len(), 1);
  152. inventory_items.items[0].with_stacked(|items| {
  153. assert_eq!(items.len(), 1);
  154. assert_eq!(items[0].id, item::ItemEntityId(1));
  155. assert_eq!(items[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
  156. }).unwrap();
  157. }
  158. #[async_std::test]
  159. async fn test_pick_up_meseta_when_inventory_full() {
  160. let mut entity_gateway = InMemoryGateway::default();
  161. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  162. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  163. let mut p1_items = Vec::new();
  164. for _ in 0..30usize {
  165. p1_items.push(entity_gateway.create_item(
  166. ItemBuilder::weapon(weapon::WeaponType::Saber)
  167. .as_new()
  168. ).await.unwrap());
  169. }
  170. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap();
  171. entity_gateway.set_character_meseta(&char2.id, item::Meseta(300)).await.unwrap();
  172. let mut ship = standard_ship(entity_gateway.clone());
  173. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  174. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  175. join_lobby(&mut ship, ClientId(1)).await;
  176. join_lobby(&mut ship, ClientId(2)).await;
  177. create_room(&mut ship, ClientId(1), "room", "").await;
  178. join_room(&mut ship, ClientId(2), 0).await;
  179. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
  180. client: 0,
  181. target: 0,
  182. item_id: 0xFFFFFFFF,
  183. map_area: 0,
  184. room: 0,
  185. x: 0.0,
  186. z: 0.0,
  187. amount: 23,
  188. })))).await.unwrap();
  189. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
  190. client: 0,
  191. target: 0,
  192. item_id: 0xFFFFFFFF,
  193. amount: 23,
  194. })))).await.unwrap();
  195. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  196. client: 0,
  197. target: 0,
  198. item_id: 0x00810001,
  199. map_area: 0,
  200. unknown: [0; 3]
  201. })))).await.unwrap();
  202. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  203. assert_eq!(inventory_items.items.len(), 30);
  204. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  205. let c2_meseta = entity_gateway.get_character_meseta(&char2.id).await.unwrap();
  206. assert!(c1_meseta.0 == 23);
  207. assert!(c2_meseta.0 == 277);
  208. }
  209. #[async_std::test]
  210. async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
  211. let mut entity_gateway = InMemoryGateway::default();
  212. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  213. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  214. let mut p1_inv = Vec::new();
  215. for _slot in 0..29usize {
  216. p1_inv.push(entity_gateway.create_item(
  217. ItemBuilder::weapon(weapon::WeaponType::Saber)
  218. .as_new()
  219. ).await.unwrap().into());
  220. }
  221. p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item(
  222. ItemBuilder::tool(item::tool::ToolType::Monomate)
  223. .as_new()
  224. ).await.unwrap()]));
  225. let mut p2_monomates = Vec::new();
  226. p2_monomates.push(entity_gateway.create_item(
  227. ItemBuilder::tool(item::tool::ToolType::Monomate)
  228. .as_new()
  229. ).await.unwrap());
  230. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  231. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap();
  232. let mut ship = standard_ship(entity_gateway.clone());
  233. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  234. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  235. join_lobby(&mut ship, ClientId(1)).await;
  236. join_lobby(&mut ship, ClientId(2)).await;
  237. create_room(&mut ship, ClientId(1), "room", "").await;
  238. join_room(&mut ship, ClientId(2), 0).await;
  239. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  240. client: 0,
  241. target: 0,
  242. unknown1: 0,
  243. map_area: 0,
  244. item_id: 0x210000,
  245. x: 0.0,
  246. y: 0.0,
  247. z: 0.0,
  248. })))).await.unwrap();
  249. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  250. client: 0,
  251. target: 0,
  252. item_id: 0x210000,
  253. map_area: 0,
  254. unknown: [0; 3]
  255. })))).await.unwrap();
  256. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  257. assert_eq!(inventory_items.items.len(), 30);
  258. inventory_items.items[29].with_stacked(|items| {
  259. assert_eq!(items.len(), 2);
  260. }).unwrap();
  261. }
  262. #[async_std::test]
  263. async fn test_can_not_pick_up_item_when_inventory_full() {
  264. let mut entity_gateway = InMemoryGateway::default();
  265. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  266. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  267. let mut p1_inv = Vec::new();
  268. for _slot in 0..30usize {
  269. p1_inv.push(entity_gateway.create_item(
  270. ItemBuilder::weapon(weapon::WeaponType::Saber)
  271. .as_new()
  272. ).await.unwrap());
  273. }
  274. let mut p2_inv = Vec::new();
  275. p2_inv.push(entity_gateway.create_item(
  276. ItemBuilder::weapon(weapon::WeaponType::Handgun)
  277. .as_new()
  278. ).await.unwrap());
  279. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
  280. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap();
  281. let mut ship = standard_ship(entity_gateway.clone());
  282. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  283. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  284. join_lobby(&mut ship, ClientId(1)).await;
  285. join_lobby(&mut ship, ClientId(2)).await;
  286. create_room(&mut ship, ClientId(1), "room", "").await;
  287. join_room(&mut ship, ClientId(2), 0).await;
  288. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  289. client: 0,
  290. target: 0,
  291. unknown1: 0,
  292. map_area: 0,
  293. item_id: 0x210000,
  294. x: 0.0,
  295. y: 0.0,
  296. z: 0.0,
  297. })))).await.unwrap();
  298. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  299. client: 0,
  300. target: 0,
  301. item_id: 0x210000,
  302. map_area: 0,
  303. unknown: [0; 3]
  304. })))).await.unwrap();
  305. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  306. assert_eq!(p1_items.items.len(), 30);
  307. let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  308. assert_eq!(p2_items.items.len(), 0);
  309. ship.handle(ClientId(2), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  310. client: 0,
  311. target: 0,
  312. item_id: 0x210000,
  313. map_area: 0,
  314. unknown: [0; 3]
  315. })))).await.unwrap();
  316. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  317. assert_eq!(p1_items.items.len(), 30);
  318. let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  319. assert_eq!(p2_items.items.len(), 1);
  320. }
  321. #[async_std::test]
  322. async fn test_can_not_drop_more_meseta_than_is_held() {
  323. let mut entity_gateway = InMemoryGateway::default();
  324. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  325. entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap();
  326. let mut ship = standard_ship(entity_gateway.clone());
  327. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  328. join_lobby(&mut ship, ClientId(1)).await;
  329. create_room(&mut ship, ClientId(1), "room", "").await;
  330. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
  331. client: 0,
  332. target: 0,
  333. item_id: 0xFFFFFFFF,
  334. map_area: 0,
  335. room: 0,
  336. x: 0.0,
  337. z: 0.0,
  338. amount: 301,
  339. })))).await.unwrap();
  340. let split_attempt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
  341. client: 0,
  342. target: 0,
  343. item_id: 0xFFFFFFFF,
  344. amount: 301,
  345. })))).await;
  346. assert!(split_attempt.is_err());
  347. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  348. assert!(c1_meseta.0 == 300);
  349. }
  350. #[async_std::test]
  351. async fn test_pick_up_stack_that_would_exceed_stack_limit() {
  352. let mut entity_gateway = InMemoryGateway::default();
  353. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  354. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  355. let mut p1_monomates = Vec::new();
  356. for _ in 0..6usize {
  357. p1_monomates.push(entity_gateway.create_item(
  358. ItemBuilder::tool(item::tool::ToolType::Monomate)
  359. .as_new()
  360. ).await.unwrap());
  361. }
  362. let mut p2_monomates = Vec::new();
  363. for _ in 0..6usize {
  364. p2_monomates.push(entity_gateway.create_item(
  365. ItemBuilder::tool(item::tool::ToolType::Monomate)
  366. .as_new()
  367. ).await.unwrap());
  368. }
  369. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![p1_monomates])).await.unwrap();
  370. entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap();
  371. let mut ship = standard_ship(entity_gateway.clone());
  372. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  373. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  374. join_lobby(&mut ship, ClientId(1)).await;
  375. join_lobby(&mut ship, ClientId(2)).await;
  376. create_room(&mut ship, ClientId(1), "room", "").await;
  377. join_room(&mut ship, ClientId(2), 0).await;
  378. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
  379. client: 0,
  380. target: 0,
  381. unknown1: 0,
  382. map_area: 0,
  383. item_id: 0x210000,
  384. x: 0.0,
  385. y: 0.0,
  386. z: 0.0,
  387. })))).await.unwrap();
  388. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  389. client: 0,
  390. target: 0,
  391. item_id: 0x210000,
  392. map_area: 0,
  393. unknown: [0; 3]
  394. })))).await.unwrap();
  395. assert!(packets.len() == 0);
  396. let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  397. assert_eq!(p1_items.items.len(), 1);
  398. p1_items.items[0].with_stacked(|items| {
  399. assert_eq!(items.len(), 6);
  400. }).unwrap();
  401. let p2_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  402. assert_eq!(p2_items.items.len(), 0);
  403. }
  404. #[async_std::test]
  405. async fn test_can_not_pick_up_meseta_when_full() {
  406. let mut entity_gateway = InMemoryGateway::default();
  407. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  408. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  409. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap();
  410. entity_gateway.set_character_meseta(&char2.id, item::Meseta(300)).await.unwrap();
  411. let mut ship = standard_ship(entity_gateway.clone());
  412. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  413. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  414. join_lobby(&mut ship, ClientId(1)).await;
  415. join_lobby(&mut ship, ClientId(2)).await;
  416. create_room(&mut ship, ClientId(1), "room", "").await;
  417. join_room(&mut ship, ClientId(2), 0).await;
  418. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
  419. client: 0,
  420. target: 0,
  421. item_id: 0xFFFFFFFF,
  422. map_area: 0,
  423. room: 0,
  424. x: 0.0,
  425. z: 0.0,
  426. amount: 23,
  427. })))).await.unwrap();
  428. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
  429. client: 0,
  430. target: 0,
  431. item_id: 0xFFFFFFFF,
  432. amount: 23,
  433. })))).await.unwrap();
  434. let packets = ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  435. client: 0,
  436. target: 0,
  437. item_id: 0x00810001,
  438. map_area: 0,
  439. unknown: [0; 3]
  440. })))).await.unwrap();
  441. assert!(packets.len() == 0);
  442. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  443. let c2_meseta = entity_gateway.get_character_meseta(&char2.id).await.unwrap();
  444. assert!(c1_meseta.0 == 999999);
  445. assert!(c2_meseta.0 == 277);
  446. }
  447. #[async_std::test]
  448. async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
  449. let mut entity_gateway = InMemoryGateway::default();
  450. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  451. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  452. entity_gateway.set_character_meseta(&char1.id, item::Meseta(999998)).await.unwrap();
  453. entity_gateway.set_character_meseta(&char2.id, item::Meseta(300)).await.unwrap();
  454. let mut ship = standard_ship(entity_gateway.clone());
  455. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  456. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  457. join_lobby(&mut ship, ClientId(1)).await;
  458. join_lobby(&mut ship, ClientId(2)).await;
  459. create_room(&mut ship, ClientId(1), "room", "").await;
  460. join_room(&mut ship, ClientId(2), 0).await;
  461. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
  462. client: 0,
  463. target: 0,
  464. item_id: 0xFFFFFFFF,
  465. map_area: 0,
  466. room: 0,
  467. x: 0.0,
  468. z: 0.0,
  469. amount: 23,
  470. })))).await.unwrap();
  471. ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
  472. client: 0,
  473. target: 0,
  474. item_id: 0xFFFFFFFF,
  475. amount: 23,
  476. })))).await.unwrap();
  477. ship.handle(ClientId(1), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  478. client: 0,
  479. target: 0,
  480. item_id: 0x00810001,
  481. map_area: 0,
  482. unknown: [0; 3]
  483. })))).await.unwrap();
  484. let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
  485. let c2_meseta = entity_gateway.get_character_meseta(&char2.id).await.unwrap();
  486. assert!(c1_meseta.0 == 999999);
  487. assert!(c2_meseta.0 == 277);
  488. }
  489. #[async_std::test]
  490. async fn test_player_drops_partial_stack_and_other_player_picks_it_up() {
  491. let mut entity_gateway = InMemoryGateway::default();
  492. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  493. let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  494. let mut monomates = Vec::new();
  495. for _ in 0..5usize {
  496. monomates.push(entity_gateway.create_item(
  497. ItemBuilder::tool(item::tool::ToolType::Monomate)
  498. .as_new()
  499. ).await.unwrap());
  500. }
  501. entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap();
  502. let mut ship = standard_ship(entity_gateway.clone());
  503. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  504. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  505. join_lobby(&mut ship, ClientId(1)).await;
  506. join_lobby(&mut ship, ClientId(2)).await;
  507. create_room(&mut ship, ClientId(1), "room", "").await;
  508. join_room(&mut ship, ClientId(2), 0).await;
  509. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::DropCoordinates(DropCoordinates {
  510. client: 0,
  511. target: 0,
  512. item_id: 0x10000,
  513. map_area: 0,
  514. room: 0,
  515. x: 0.0,
  516. z: 0.0,
  517. amount: 2,
  518. })))).await.unwrap();
  519. ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::PlayerNoLongerHasItem(PlayerNoLongerHasItem {
  520. client: 0,
  521. target: 0,
  522. item_id: 0x10000,
  523. amount: 2,
  524. })))).await.unwrap();
  525. ship.handle(ClientId(2), RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
  526. client: 0,
  527. target: 0,
  528. item_id: 0x10001,
  529. map_area: 0,
  530. unknown: [0; 3]
  531. })))).await.unwrap();
  532. let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
  533. assert_eq!(inventory_items.items.len(), 1);
  534. inventory_items.items[0].with_stacked(|items| {
  535. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  536. vec![item::ItemEntityId(3), item::ItemEntityId(4), item::ItemEntityId(5)]);
  537. }).unwrap();
  538. let inventory_items = entity_gateway.get_character_inventory(&char2.id).await.unwrap();
  539. assert_eq!(inventory_items.items.len(), 1);
  540. inventory_items.items[0].with_stacked(|items| {
  541. assert_eq!(items.iter().map(|i| i.id).collect::<Vec<_>>(),
  542. vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
  543. }).unwrap();
  544. }
  545. /*
  546. #[async_std::test]
  547. async fn test_try_and_pick_up_individual_item_twice() {
  548. panic!()
  549. }
  550. #[async_std::test]
  551. async fn test_try_and_pick_up_stacked_item_twice() {
  552. panic!()
  553. }
  554. #[async_std::test]
  555. async fn test_try_and_pick_up_meseta_twice() {
  556. panic!()
  557. }
  558. */