Advertisement
SydneyMakers

Untitled

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