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.
 
 
 

148 lines
3.1 KiB

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