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.
 
 
 

160 lines
3.3 KiB

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