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.

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