Advertisement
SydneyMakers

Untitled

Sep 15th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. //############################################################
  2. //Author: SydneyMakers & /u/PyroNyzen
  3. //reference variables
  4. var inventoryList = user.data.inventory.parts;
  5. var weaponList = user.data.characters[0].constructions.mainWeapon.parts;
  6. var shieldList = user.data.characters[0].constructions.shield.parts;
  7.  
  8. //set this to what will be scrapped unless it can upgrade an existing equipped item
  9. var scrapRank = 0;
  10.  
  11. // For convenience, store the part in a new variable
  12. var part = inventoryList[inventoryList.length-1];
  13.  
  14. var listLength = inventoryList.length - 1;
  15. var weaponListLength = weaponList.length - 1;
  16. var shieldListLength = shieldList.length - 1;
  17. //weapon addition
  18. var weaponConstruction = user.data.characters[0].constructions.mainWeapon;
  19. var shieldConstruction = user.data.characters[0].constructions.shield;
  20.  
  21. //Absolutes DO NOT MODIFY
  22. var replaceWeapon = false;
  23. var replaceShield = false;
  24. var weaponIndex = 0;
  25. var shieldIndex = 0;
  26.  
  27.  
  28. loop1:
  29. for(var i = 0; i < weaponListLength; i++) {
  30. if(part.type == weaponList[i].part.type) {
  31. //it exists, lets check if it is better than the current
  32. if(part.quality > weaponList[i].part.quality) {
  33. if(part.quality - weaponList[i].part.quality <= 2) {
  34. //its better so lets replace it
  35. replaceWeapon = true;
  36. weaponIndex = i;
  37. break loop1;
  38. }
  39. }
  40. else if(part.quality == weaponList[i].part.quality) {
  41. //both items match quality, lets check Mod value
  42. if(part.mod > weaponList[i].part.mod) {
  43. //The mod value is larger, so lets replace it
  44. replaceWeapon = true;
  45. weaponIndex = i;
  46. break loop1;
  47. }
  48. }
  49. }
  50. }
  51. //the replace script has been moved to shorten code
  52. if(replaceWeapon) {
  53. var xpos = weaponList[weaponIndex].x;
  54. var ypos = weaponList[weaponIndex].y;
  55. systemLog.push('Part <b class="rarity-' + weaponList[weaponIndex].part.quality + '-text"> ' + weaponList[weaponIndex].part.name + '</b> Was replaced with <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b>');
  56. Construction.removeFromSetup(weaponConstruction, weaponList[weaponIndex].part, weaponList[weaponIndex].x, weaponList[weaponIndex].y);
  57. Construction.addToSetup(weaponConstruction, part, xpos, ypos);
  58. userActions.saveConstruction;
  59. inventoryActions.scrapPart(inventoryList[listLength]);
  60. }
  61.  
  62.  
  63. loop2:
  64. for(var j = 0; j < shieldListLength; j++) {
  65. if(part.type == shieldList[j].part.type) {
  66. //it exists, lets check if it is better than the current
  67. if(part.quality > shieldList[j].part.quality) {
  68. if(part.quality - shieldList[j].part.quality <= 2) {
  69. //its better so lets replace it
  70. replaceShield = true;
  71. shieldIndex = j;
  72. break loop2;
  73. }
  74. }
  75. else if(part.quality == shieldList[j].part.quality) {
  76. if(part.mod > shieldList[j].part.mod) {
  77. replaceShield = true;
  78. shieldIndex = j;
  79. break loop2;
  80. }
  81. }
  82. }
  83. }
  84.  
  85. if(replaceShield) {
  86. var xpos = shieldList[shieldIndex].x;
  87. var ypos = shieldList[shieldIndex].y;
  88. systemLog.push('Part <b class="rarity-' + shieldList[shieldIndex].part.quality + '-text"> ' + shieldList[shieldIndex].part.name + '</b> Was replaced with <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b>');
  89. Construction.removeFromSetup(shieldConstruction, shieldList[shieldIndex].part, shieldList[shieldIndex].x, shieldList[shieldIndex].y);
  90. Construction.addToSetup(shieldConstruction, part, xpos, ypos);
  91. userActions.saveConstruction;
  92. inventoryActions.scrapPart(inventoryList[listLength]);
  93. }
  94.  
  95.  
  96.  
  97.  
  98. loop3:
  99. for(var k = 0; k < listLength; k++) {
  100. if(part.quality > scrapRank) {
  101. if(part.type == inventoryList[k].type) {
  102. // New item exists already
  103. if(part.quality > inventoryList[k].quality ) {
  104. //the new part has higher quality than the old part
  105. inventoryActions.scrapPart(inventoryList[k]);
  106. systemLog.push('Sold a <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> for ' + inventoryList[k].value + ' credits.');
  107.  
  108. break loop3;
  109. }
  110. else if(part.quality <= inventoryList[k].quality) {
  111. //the old part has higher quality than the new part
  112. inventoryActions.scrapPart(part);
  113. systemLog.push('Sold a <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  114. break loop3;
  115. }
  116. }
  117. else {
  118. //None exists, so we continue looping
  119. }
  120. }
  121. else
  122. {
  123. inventoryActions.scrapPart(part);
  124. systemLog.push('Sold a <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  125. //remove the Got item message
  126.  
  127. break loop3;
  128. }
  129. }
  130. var removeAnnoyingMessage = function(){
  131. if(systemLog[systemLog.length-1].includes("Got")){
  132. systemLog.pop();
  133. }
  134. }
  135. //the message is actually put there after this script so we use a timeout. May fail for obvious reasons.
  136. setTimeout(removeAnnoyingMessage, 100);
  137.  
  138. //ScrollFix
  139. $(".system-log-container").scrollTop($(".system-log-container")[0].scrollHeight);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement