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.

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