Advertisement
SydneyMakers

Untitled

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