Advertisement
SydneyMakers

Untitled

Oct 7th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //############################################################
  2. //Author: SydneyMakers /u/PyroNyzen
  3. //Version 8.3
  4.  
  5. /*  TODO:
  6. * Add in Auto "dequip -> combine -> requip" functionality
  7. *   Very hard considering the following example returning success but no item
  8. Crafting.createCombinedPart(user, user.data.characters[0].constructions.shield.parts[2].part , user.data.inventory.parts[17]);
  9. userActions.saveConstruction();
  10. *
  11. */
  12. /* User-Customisable Variables */
  13. //set this to what will be scrapped unless it can upgrade an existing equipped item
  14. var scrapRank = 3;
  15. // This value is the quality threshold below the current item that will be combined
  16. var starDifference = 1; // for a starDifference of 1, a 7* item will only combine with 6* or 7* items
  17. /* End User-Customisable Variables*/
  18. /* GLOBAL VARIABLES */
  19. var inventoryList = user.data.inventory.parts;
  20. var part = inventoryList[inventoryList.length-1];
  21.  
  22. var listLength = inventoryList.length - 1;
  23.  
  24. /* END GLOBAL VARIABLES*/
  25.  
  26. var replaceNewPart = false;
  27. var replaceCurrentPart = false;
  28. var replaceNewPartIndex = 0;
  29. var replaceCurrentPartIndex = 0;
  30.  
  31. loop3:
  32. for(var k = 0; k < listLength; k++) {
  33.     if(part.quality < scrapRank) {
  34.         // Item is below quality threshold so it's being scrapped
  35.         systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  36.         inventoryActions.scrapPart(part);
  37.         break loop3;
  38.     }
  39.         if(part.mod > inventoryList[k].mod) {
  40.         systemLog.push('Mod <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> too low.');
  41.         inventoryActions.scrapPart(inventoryList[k]);
  42.         break loop3;
  43.     }
  44.     else if(part.mod < inventoryList[k].mod) {
  45.         systemLog.push('Mod <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> too low.');
  46.         inventoryActions.scrapPart(part);
  47.         break loop3;
  48.     }
  49.     if( (part.quality > crafting.limits.rarity) && (part.type == inventoryList[k].type) ) {
  50.         //New item is an 8 rank, lets scrap the old one since it cannot be crafted.
  51.         //re-iterating just to be safe
  52.         replaceCurrentPart = false;
  53.         replaceNewPart = false;
  54.         systemLog.push('Uncraftable Encountered: Scrapped Existing <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> for ' + inventoryList[k].value + ' credits.');
  55.         inventoryActions.scrapPart(inventoryList[k]);
  56.         break loop3;
  57.     }
  58.     else if( (inventoryList[k].quality > crafting.limits.rarity) && (part.type == inventoryList[k].type) ) {
  59.         //Current item is an 8 rank, and it exists, so lets scrap the new item
  60.         //re-iterating just to be safe
  61.         replaceNewPart = false;
  62.         replaceCurrentPart = false;
  63.         systemLog.push('Uncraftable Encountered: Scrapped New <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  64.         inventoryActions.scrapPart(part);
  65.         break loop3;
  66.     }
  67.     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) ) {
  68.         //New part has equal mod, equal type, higher quality.
  69.         replaceCurrentPart = true;
  70.         replaceNewPart = false;
  71.         replaceCurrentPartIndex = k;
  72.         break loop3;
  73.     }
  74.     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) ) {
  75.         //New part has equal mod, equal type, lower quality but is within threshold
  76.         replaceCurrentPart = false;
  77.         replaceNewPart = true;
  78.         replaceNewPartIndex = k;
  79.         break loop3;
  80.     }
  81.     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) ) {
  82.         systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  83.         inventoryActions.scrapPart(part);
  84.         replaceCurrentPart = false;
  85.         replaceNewPart = false;
  86.         break loop3;
  87.     }
  88.     else {
  89.         //None exists, so we continue looping
  90.     }  
  91. }
  92. if(replaceCurrentPart) {
  93.     var oldQualityPart = inventoryList[replaceCurrentPartIndex];
  94.     systemLog.push('<b class="rarity-' + part.quality + '-text"> ' + part.name + ' +' + ( part.plus) + '</b> <- <b class="rarity-' + oldQualityPart.quality + '-text">' + oldQualityPart.name +  ' +' + ( oldQualityPart.plus) + '</b>');
  95.     craftingActions.setPrimary(part, true);
  96.     craftingActions.setConsumed(inventoryList[replaceCurrentPartIndex], true);
  97.     craftingActions.combine();
  98.     craftingActions.update();
  99. }
  100.  
  101. if(replaceNewPart) {
  102.     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>');
  103.     craftingActions.setPrimary(inventoryList[replaceNewPartIndex], true);
  104.     craftingActions.setConsumed(part, true);
  105.     craftingActions.combine();
  106.     craftingActions.update();
  107. }
  108.  
  109.  
  110. var removeAnnoyingMessage = function(){
  111.     if(systemLog[systemLog.length-1].includes("Got")){
  112.         systemLog.pop();
  113.     }
  114. }
  115.         //the message is actually put there after this script so we use a timeout. May fail for obvious reasons.
  116. setTimeout(removeAnnoyingMessage, 100);
  117.  
  118. //ScrollFix
  119. $(".system-log-container").scrollTop($(".system-log-container")[0].scrollHeight);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement