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.
 
 
 

168 lines
3.4 KiB

  1. //Imports
  2. const events = require('../misc/events');
  3. const mappings = {
  4. rune: [{
  5. materials: [{
  6. name: 'Essence',
  7. qualityName: ['Common Essence', 'Magic Essence', 'Rare Essence', 'Epic Essence', 'Legendary Essence'],
  8. chance: 100,
  9. quantity: 1
  10. }]
  11. }],
  12. slots: [{
  13. list: ['neck', 'finger', 'twoHanded', 'oneHanded', 'offHand'],
  14. materials: [{
  15. name: 'Iron Bar',
  16. chance: 100,
  17. quantity: 3,
  18. qualityMult: 1
  19. }]
  20. }, {
  21. list: ['trinket'],
  22. materials: [{
  23. name: 'Essence',
  24. qualityName: ['Common Essence', 'Magic Essence', 'Rare Essence', 'Epic Essence', 'Legendary Essence'],
  25. chance: 100,
  26. quantity: 1
  27. }]
  28. }, {
  29. list: ['tool'],
  30. materials: [{
  31. name: 'Cerulean Pearl',
  32. chance: 100,
  33. quantity: 1,
  34. quality: 3,
  35. qualityMult: 1
  36. }]
  37. }],
  38. types: [{
  39. list: ['Helmet', 'Belt', 'Legplates', 'Gauntlets', 'Steel Boots', 'Breastplate'],
  40. materials: [{
  41. name: 'Iron Bar',
  42. chance: 100,
  43. quantity: 3,
  44. qualityMult: 1
  45. }]
  46. }, {
  47. list: ['Cowl', 'Robe', 'Gloves', 'Sash', 'Pants', 'Boots'],
  48. materials: [{
  49. name: 'Cloth Scrap',
  50. chance: 100,
  51. quantity: 3,
  52. qualityMult: 1
  53. }]
  54. }, {
  55. list: ['Leather Cap', 'Leather Armor', 'Leather Gloves', 'Leather Belt', 'Leather Pants', 'Leather Boots', 'Facemask', 'Scalemail', 'Scale Gloves', 'Scaled Binding', 'Scale Leggings', 'Scale Boots'],
  56. materials: [{
  57. name: 'Leather Scrap',
  58. chance: 100,
  59. quantity: 3,
  60. qualityMult: 1
  61. }]
  62. }, {
  63. list: ['Fishing Rod'],
  64. materials: [{
  65. name: 'Cerulean Pearl',
  66. chance: 100,
  67. quantity: 1,
  68. qualityMult: 1
  69. }]
  70. }]
  71. };
  72. const materialItems = {
  73. 'Iron Bar': {
  74. sprite: [0, 0]
  75. },
  76. 'Cloth Scrap': {
  77. sprite: [0, 1]
  78. },
  79. 'Leather Scrap': {
  80. sprite: [0, 7]
  81. },
  82. 'Common Essence': {
  83. sprite: [0, 2]
  84. },
  85. 'Magic Essence': {
  86. sprite: [0, 3]
  87. },
  88. 'Rare Essence': {
  89. sprite: [0, 4]
  90. },
  91. 'Epic Essence': {
  92. sprite: [0, 5]
  93. },
  94. 'Legendary Essence': {
  95. sprite: [0, 6]
  96. },
  97. 'Cerulean Pearl': {
  98. sprite: [11, 9]
  99. }
  100. };
  101. module.exports = {
  102. init: function () {
  103. events.emit('onBeforeGetSalvagerMappings', {
  104. mappings
  105. });
  106. },
  107. salvage: function (item, maxRoll) {
  108. let result = [];
  109. let materials = [];
  110. let temp = mappings.slots.filter(m => m.list.indexOf(item.slot) > -1);
  111. temp = temp.concat(mappings.types.filter(m => m.list.indexOf(item.type) > -1));
  112. if (item.ability)
  113. temp = temp.concat(mappings.rune);
  114. temp.forEach(function (t) {
  115. let mats = t.materials;
  116. mats.forEach(function (m) {
  117. let exists = materials.find(mf => (mf.name === m.name));
  118. if (exists) {
  119. exists.chance = Math.max(exists.chance, m.chance);
  120. exists.quantity = Math.max(exists.quantity, m.quantity);
  121. exists.qualityMult = Math.max(exists.qualityMult, m.qualityMult);
  122. } else
  123. materials.push(extend({}, m));
  124. });
  125. });
  126. materials.forEach(function (m) {
  127. if ((!maxRoll) && (Math.random() * 100 > m.chance))
  128. return;
  129. let max = m.quantity;
  130. if (m.qualityMult)
  131. max *= (m.qualityMult * (item.quality + 1));
  132. let quantity = Math.ceil(random.norm(0, 1) * max) || 1;
  133. if (maxRoll)
  134. quantity = Math.ceil(max);
  135. let newItem = {
  136. name: m.name,
  137. quantity: quantity,
  138. quality: 0,
  139. material: true,
  140. sprite: null
  141. };
  142. if (m.qualityName) {
  143. newItem.quality = item.quality;
  144. newItem.name = m.qualityName[item.quality];
  145. } else if (m.has('quality'))
  146. newItem.quality = m.quality;
  147. newItem.sprite = materialItems[newItem.name].sprite;
  148. result.push(newItem);
  149. });
  150. return result;
  151. }
  152. };