Advertisement
SydneyMakers

Untitled

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