@@ -26,6 +26,7 @@ const CraftData = require('../staticFiles/rustlabsCraftData.json');
26
26
const ResearchData = require ( '../staticFiles/rustlabsResearchData.json' ) ;
27
27
const RecycleData = require ( '../staticFiles/rustlabsRecycleData.json' ) ;
28
28
const DurabilityData = require ( '../staticFiles/rustlabsDurabilityData.json' ) ;
29
+ const SmeltingData = require ( '../staticFiles/rustlabsSmeltingData.json' ) ;
29
30
30
31
const IGNORED_RECYCLE_ITEMS = [
31
32
'-946369541' /* Low Grade Fuel */
@@ -43,6 +44,7 @@ class RustLabs {
43
44
this . _researchData = ResearchData ;
44
45
this . _recycleData = RecycleData ;
45
46
this . _durabilityData = DurabilityData ;
47
+ this . _smeltingData = SmeltingData ;
46
48
47
49
this . _items = new Items ( ) ;
48
50
@@ -88,6 +90,7 @@ class RustLabs {
88
90
get researchData ( ) { return this . _researchData ; }
89
91
get recycleData ( ) { return this . _recycleData ; }
90
92
get durabilityData ( ) { return this . _durabilityData ; }
93
+ get smeltingData ( ) { return this . _smeltingData ; }
91
94
get items ( ) { return this . _items ; }
92
95
get durabilityGroups ( ) { return this . _durabilityGroups }
93
96
get durabilityWhich ( ) { return this . _durabilityWhich ; }
@@ -240,7 +243,7 @@ class RustLabs {
240
243
241
244
/**
242
245
* Get craft details of an item.
243
- * @param {string } name The name of the item.
246
+ * @param {string } id The id of the item.
244
247
* @return {array|null } null if something went wrong, otherwise [id, itemDetails, craftDetails]
245
248
*/
246
249
getCraftDetailsById ( id ) {
@@ -276,7 +279,7 @@ class RustLabs {
276
279
277
280
/**
278
281
* Get research details of an item.
279
- * @param {string } name The name of the item.
282
+ * @param {string } id The id of the item.
280
283
* @return {array|null } null if something went wrong, otherwise [id, itemDetails, researchDetails]
281
284
*/
282
285
getResearchDetailsById ( id ) {
@@ -312,7 +315,7 @@ class RustLabs {
312
315
313
316
/**
314
317
* Get recycle details of an item.
315
- * @param {string } name The name of the item.
318
+ * @param {string } id The id of the item.
316
319
* @return {array|null } null if something went wrong, otherwise [id, itemDetails, recycleDetails]
317
320
*/
318
321
getRecycleDetailsById ( id ) {
@@ -485,6 +488,66 @@ class RustLabs {
485
488
486
489
return [ 'items' , id , this . items . items [ id ] , content ] ;
487
490
}
491
+
492
+
493
+ /***********************************************************************************
494
+ * Smelting functions
495
+ **********************************************************************************/
496
+
497
+ /**
498
+ * Check to see if itemId is part of smelting details data.
499
+ * @param {string } itemId The itemId of the item.
500
+ * @return {boolean } true if exist, otherwise false.
501
+ */
502
+ hasSmeltingDetails ( itemId ) {
503
+ return this . smeltingData . hasOwnProperty ( itemId ) ;
504
+ }
505
+
506
+ /**
507
+ * Get smelting details of an item.
508
+ * @param {string } name The name of the item.
509
+ * @return {array|null } null if something went wrong, otherwise [id, itemDetails, smeltingDetails]
510
+ */
511
+ getSmeltingDetailsByName ( name ) {
512
+ if ( typeof ( name ) !== 'string' ) return null ;
513
+ const id = this . items . getClosestItemIdByName ( name ) ;
514
+ if ( ! id ) return null ;
515
+ return this . getSmeltingDetailsById ( id ) ;
516
+ }
517
+
518
+ /**
519
+ * Get smelting details of an item.
520
+ * @param {string } id The id of the item.
521
+ * @return {array|null } null if something went wrong, otherwise [id, itemDetails, smeltingDetails]
522
+ */
523
+ getSmeltingDetailsById ( id ) {
524
+ if ( ! this . hasSmeltingDetails ( id ) ) return null ;
525
+ return [ id , this . items . items [ id ] , this . smeltingData [ id ] ] ;
526
+ }
527
+
528
+ /**
529
+ * Get smelting details by the from parameter item.
530
+ * @param {string } id The id of the from parameter item.
531
+ * @return {array|null } null if something went wrong, otherwise Object of smelting details of the
532
+ * from parameter item.
533
+ */
534
+ getSmeltingDetailsFromParameterById ( id ) {
535
+ if ( ! this . items . hasOwnProperty ( id ) ) return null ;
536
+ const fromParameterSmeltingDetails = new Object ( ) ;
537
+ for ( const [ smeltingTool , smeltingDetails ] of Object . entries ( this . smeltingData ) ) {
538
+ for ( const details of smeltingDetails ) {
539
+ if ( details . fromId === id ) {
540
+ if ( ! fromParameterSmeltingDetails . hasOwnProperty ( smeltingTool ) ) {
541
+ fromParameterSmeltingDetails [ smeltingTool ] = [ ] ;
542
+ }
543
+
544
+ fromParameterSmeltingDetails [ smeltingTool ] . push ( details ) ;
545
+ }
546
+ }
547
+ }
548
+
549
+ return fromParameterSmeltingDetails ;
550
+ }
488
551
}
489
552
490
553
module . exports = RustLabs ;
0 commit comments