Advertisement
SydneyMakers

Untitled

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