SydneyMakers

Untitled

Sep 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //############################################################
  2. //Author: SydneyMakers /u/PyroNyzen
  3. /* ATTRIBUTIONS:
  4. removeAnnoyingMessage() provided by Grote
  5.  
  6. */
  7. //Version 6.7
  8.  
  9. /* User-Customisable Variables */
  10. //set this to what will be scrapped unless it can upgrade an existing equipped item
  11. var scrapRank = 1;
  12. // This value is the quality threshold below the current item that will be combined
  13. var starDifference = 1; // for a starDifference of 1, a 7* item will only combine with 6* or 7* items
  14. /* End User-Customisable Variables*/
  15.  
  16. /* GLOBAL VARIABLES */
  17. var inventoryList = user.data.inventory.parts;
  18. var weaponList = user.data.characters[0].constructions.mainWeapon.parts;
  19. var shieldList = user.data.characters[0].constructions.shield.parts;
  20. var part = inventoryList[inventoryList.length-1];
  21.  
  22. var listLength = inventoryList.length - 1;
  23. var weaponListLength = weaponList.length - 1;
  24. var shieldListLength = shieldList.length - 1;
  25.  
  26. var weaponConstruction = user.data.characters[0].constructions.mainWeapon;
  27. var shieldConstruction = user.data.characters[0].constructions.shield;
  28.  
  29. var replaceWeapon = false;
  30. var replaceShield = false;
  31. var weaponIndex = 0;
  32. var shieldIndex = 0;
  33. /* END GLOBAL VARIABLES*/
  34.  
  35. loop1:
  36. for(var i = 0; i < weaponListLength; i++) {
  37.     if(part.type == weaponList[i].part.type) {
  38.         //it exists, lets check if it is better than the current
  39.         if(part.quality > weaponList[i].part.quality) {
  40.             for(var j = 0; j < weaponList.length; j++) {
  41.                 //check if the aprt can be equipped ± 2 quality
  42.                 if(part.quality - weaponList[j].part.quality <= 2) {
  43.                     //its better and valid so lets replace it
  44.                     replaceWeapon = true;
  45.                     weaponIndex = j;
  46.                    
  47.                 }
  48.                 else {
  49.                     replaceWeapon = false;
  50.                     break loop1;
  51.                 }
  52.             }
  53.         }
  54.         else if(part.quality == weaponList[i].part.quality) {
  55.             //both items match quality, lets check Mod value
  56.             if(part.mod > weaponList[i].part.mod) {
  57.                 //The mod value is larger, so lets replace it
  58.                 replaceWeapon = true;
  59.                 weaponIndex = i;
  60.                 break loop1;
  61.             }
  62.         }
  63.     }
  64. }
  65. //the replace script has been moved to shorten code
  66. if(replaceWeapon) {
  67.     var xpos = weaponList[weaponIndex].x;
  68.     var ypos = weaponList[weaponIndex].y;
  69.     var oldWeapon = weaponList[weaponIndex].part;
  70.     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>');
  71.     Construction.removeFromSetup(weaponConstruction, weaponList[weaponIndex].part, weaponList[weaponIndex].x, weaponList[weaponIndex].y);
  72.     Construction.addToSetup(weaponConstruction, part, xpos, ypos);
  73.     userActions.saveConstruction();
  74.     for(var i = 0; i < listLength; i++) {
  75.         if(oldWeapon == inventoryList[i]) {
  76.             inventoryActions.scrapPart(inventoryList[i]);
  77.             break;
  78.         }
  79.     }
  80. }
  81.  
  82.  
  83. loop2:
  84. for(var j = 0; j < shieldListLength; j++) {
  85.     if(part.type == shieldList[j].part.type) {
  86.         //it exists, lets check if it is better than the current
  87.         if(part.quality > shieldList[j].part.quality) {
  88.             for(var i = 0; i < shieldList.length; i++) {
  89.                 //check if the aprt can be equipped ± 2 quality
  90.                 if(part.quality - shieldList[i].part.quality <= 2) {
  91.                     //its better and valid so lets replace it
  92.                     replaceShield = true;
  93.                     shieldIndex = j;
  94.                 }
  95.                 else {
  96.                     replaceShield = false;
  97.                     break loop2;
  98.                 }
  99.             }
  100.         }
  101.         else if(part.quality == shieldList[j].part.quality) {
  102.             if(part.mod > shieldList[j].part.mod) {
  103.                 //an existing quality is already there so we know it can be equipped
  104.                 replaceShield = true;
  105.                 shieldIndex = j;
  106.                 break loop2;
  107.             }
  108.         }
  109.     }
  110. }
  111.  
  112. if(replaceShield) {
  113.     var xpos = shieldList[shieldIndex].x;
  114.     var ypos = shieldList[shieldIndex].y;
  115.     var oldShield = shieldList[shieldIndex].part;
  116.     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>');
  117.     Construction.removeFromSetup(shieldConstruction, shieldList[shieldIndex].part, xpos, ypos);
  118.     Construction.addToSetup(shieldConstruction, part, xpos, ypos);
  119.     userActions.saveConstruction();
  120.     for(var i = 0; i < listLength; i++) {
  121.         if(oldShield == inventoryList[i]) {
  122.             inventoryActions.scrapPart(inventoryList[i]);
  123.             break;
  124.         }
  125.     }
  126. }
  127.  
  128.  
  129.  
  130. var replaceNewPart = false;
  131. var replaceCurrentPart = false;
  132. var replaceNewPartIndex = 0;
  133. var replaceCurrentPartIndex = 0;
  134.  
  135. loop3:
  136. for(var k = 0; k < listLength; k++) {
  137.     if(part.quality < scrapRank) {
  138.         systemLog.push('Sold a <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  139.         inventoryActions.scrapPart(part);
  140.         break loop3;
  141.     }
  142.     if( ( ( part.plus + inventoryList[k].plus ) < ( (part.quality + 1) * 5 ) ) && (part.type == inventoryList[k].type) && (part.quality >= inventoryList[k].quality) && (part.mod == inventoryList[k].mod) ) {
  143.         //New part has equal mod, equal type, higher quality.
  144.         replaceCurrentPart = true;
  145.         replaceNewPart = false;
  146.         replaceCurrentPartIndex = k;
  147.         break loop3;
  148.     }
  149.     else if(( ( part.plus + inventoryList[k].plus ) < ( (inventoryList[k].quality + 1) * 5 ) ) && (part.type == inventoryList[k].type) & (part.quality < inventoryList[k].quality) && (part.mod == inventoryList[k].mod) && (inventoryList[k].quality - part.quality <= starDifference) ) {
  150.         //New part has equal mod, equal type, lower quality but is within threshold
  151.         replaceCurrentPart = false;
  152.         replaceNewPart = true;
  153.         replaceNewPartIndex = k;
  154.         break loop3;
  155.     }
  156.     else {
  157.         //None exists, so we continue looping
  158.     }  
  159. }
  160.  
  161. if(replaceCurrentPart) {
  162.     var oldQualityPart = inventoryList[replaceCurrentPartIndex];
  163.     craftingActions.update();
  164.     craftingActions.setPrimary(part, true);
  165.     craftingActions.setConsumed(inventoryList[replaceCurrentPartIndex], true);
  166.     craftingActions.combine();
  167.     craftingActions.update();
  168.     systemLog.push('Combined <b class="rarity-' + part.quality + '-text"> ' + part.name + ' ' + ( inventoryList[replaceNewPartIndex].plus + 1 ) + '</b> <- <b class="rarity-' + oldQualityPart.quality + '-text">' + oldQualityPart.name + '</b>');
  169. }
  170.  
  171. if(replaceNewPart) {
  172.     craftingActions.update();
  173.     craftingActions.setPrimary(inventoryList[replaceNewPartIndex], true);
  174.     craftingActions.setConsumed(part, true);
  175.     craftingActions.combine();
  176.     craftingActions.update();
  177.     systemLog.push('Combined <b class="rarity-' + inventoryList[replaceNewPartIndex].quality + '-text"> ' + inventoryList[replaceNewPartIndex].name + ' ' + ( inventoryList[replaceNewPartIndex].plus + 1 ) + '</b> <- <b class="rarity-' + part.quality + '-text">' + part.name + '</b>');
  178. }
  179.  
  180.  
  181. var removeAnnoyingMessage = function(){
  182.     if(systemLog[systemLog.length-1].includes("Got")){
  183.         systemLog.pop();
  184.     }
  185. }
  186.         //the message is actually put there after this script so we use a timeout. May fail for obvious reasons.
  187. setTimeout(removeAnnoyingMessage, 100);
  188.  
  189. //ScrollFix
  190. $(".system-log-container").scrollTop($(".system-log-container")[0].scrollHeight);
Add Comment
Please, Sign In to add comment