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.

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