Advertisement
SydneyMakers

Untitled

Oct 10th, 2016
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //############################################################
  2. //Author: SydneyMakers /u/PyroNyzen
  3. //Version 10.2
  4.  
  5. /*  TODO:
  6. * Add in mainWeapon crafting functionality
  7. *   Very hard considering the following example returning success but no item
  8. Crafting.createCombinedPart(user, user.data.inventory.parts[0], user.data.characters[0].constructions.mainWeapon.parts[1].part);
  9. */
  10. var checkCraftable = function (item1, item2) {
  11.     if( /* Combined plus ranking*/( ( item1.plus + item2.plus ) <  ((item1.quality+1)*5)  ) && /* Type Match */ (item1.type == item2.type  == ("shieldGenerator" || "stock" || "shortScope" || "longScope") ) && /* Mod match*/ (item1.mod == item2.mod) ){
  12.         return true;
  13.     }
  14. }
  15.  
  16. var combineToConstruction = function( construction, posx, posy, shieldItem, inventoryItem) {
  17.     Construction.removeFromSetup(construction, shieldItem, posx, posy);
  18.     userActions.saveConstruction();
  19.     var shieldID = shieldItem.id;
  20.     var shieldItem = inventoryLib.getPartById(shieldID);
  21.     systemLog.push('Equipped <b class="rarity-' + shieldItem.quality + '-text"> ' + shieldItem.name + ' +' + shieldItem.plus + '</b> consumed: <b class="rarity-' + inventoryItem.quality + '-text">' + inventoryItem.name +  ' +' + inventoryItem.plus + '</b>');
  22.     craftingActions.setPrimary(shieldItem, true);
  23.     craftingActions.setConsumed(inventoryItem, true);
  24.     craftingActions.combine();
  25.     craftingActions.update();
  26.     Construction.addToSetup(construction, shieldItem, posx, posy);
  27.     userActions.saveConstruction();
  28. }
  29.  
  30.  
  31. var shieldConstruction = user.data.characters[0].constructions.shield;
  32. var weaponConstruction = user.data.characters[0].constructions.mainWeapon;
  33.  
  34. var shieldLength = user.data.characters[0].constructions.shield.parts.length - 1;
  35. var shieldList = user.data.characters[0].constructions.shield.parts;
  36.  
  37.  
  38. //long-winded method INCOMPLETE
  39. /*
  40. */
  41. /* User-Customisable Variables */
  42. //set this to what will be scrapped unless it can upgrade an existing equipped item
  43. var scrapRank = 3;
  44. // This value is the quality threshold below the current item that will be combined
  45. var starDifference = 1; // for a starDifference of 1, a 7* item will only combine with 6* or 7* items
  46. /* End User-Customisable Variables*/
  47. /* GLOBAL VARIABLES */
  48. var inventoryList = user.data.inventory.parts;
  49. var part = inventoryList[inventoryList.length-1];
  50.  
  51. var listLength = inventoryList.length - 1;
  52.  
  53. /* END GLOBAL VARIABLES*/
  54. var checkEquipped = true;
  55. var replaceNewPart = false;
  56. var replaceCurrentPart = false;
  57. var replaceNewPartIndex = 0;
  58. var replaceCurrentPartIndex = 0;
  59.  
  60. inventoryLoop:
  61. for(var k = 0; k < listLength; k++) {
  62.     if(part.quality < scrapRank) {
  63.         // Item is below quality threshold so it's being scrapped
  64.         systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  65.         inventoryActions.scrapPart(part);
  66.         checkEquipped = false;
  67.         break inventoryLoop;
  68.     }
  69.     if(part.type == inventoryList[k].type) {
  70.         if((part.mod > inventoryList[k].mod)) {
  71.             systemLog.push('Mod <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> too low.');
  72.             systemLog.push('Part <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> kept.');
  73.             inventoryActions.scrapPart(inventoryList[k]);
  74.             checkEquipped = false;
  75.             break inventoryLoop;
  76.         }
  77.         else if((part.mod < inventoryList[k].mod)) {
  78.             systemLog.push('Mod <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> too low.');
  79.             systemLog.push('Part <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> kept.');
  80.             inventoryActions.scrapPart(part);
  81.             checkEquipped = false;
  82.             break inventoryLoop;
  83.         }
  84.         if( (part.quality > crafting.limits.rarity)) {
  85.         //New item is an uncraftable rank, lets scrap the old one since it cannot be crafted.
  86.         //re-iterating the booleans just to be safe.
  87.             replaceCurrentPart = false;
  88.             replaceNewPart = false;
  89.             systemLog.push('Uncraftable Encountered: Scrapped Existing <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> for ' + inventoryList[k].value + ' credits.');
  90.             inventoryActions.scrapPart(inventoryList[k]);
  91.             checkEquipped = false;
  92.             break inventoryLoop;
  93.         }
  94.         else if( (inventoryList[k].quality > crafting.limits.rarity)) {
  95.         //Current item is an 8 rank, and it exists, so lets scrap the new item
  96.         //re-iterating just to be safe
  97.             replaceNewPart = false;
  98.             replaceCurrentPart = false;
  99.             systemLog.push('Uncraftable Encountered: Scrapped New <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  100.             inventoryActions.scrapPart(part);
  101.             checkEquipped = false;
  102.             break inventoryLoop;
  103.         }
  104.         else if( ( ( part.plus + inventoryList[k].plus ) < ( (part.quality + 1) * 5 ) ) && (part.quality >= inventoryList[k].quality) && (part.mod == inventoryList[k].mod) ) {
  105.         //New part has equal mod, equal type, higher quality.
  106.             replaceCurrentPart = true;
  107.             replaceNewPart = false;
  108.             replaceCurrentPartIndex = k;
  109.             checkEquipped = false;
  110.             break inventoryLoop;
  111.         }
  112.         else if(( ( part.plus + inventoryList[k].plus ) < ( (inventoryList[k].quality + 1) * 5 ) )  && (part.quality < inventoryList[k].quality) && (part.mod == inventoryList[k].mod) && (inventoryList[k].quality - part.quality <= starDifference) ) {
  113.         //New part has equal mod, equal type, lower quality but is within threshold
  114.             replaceCurrentPart = false;
  115.             replaceNewPart = true;
  116.             replaceNewPartIndex = k;
  117.             checkEquipped = false;
  118.             break inventoryLoop;
  119.         }
  120.         else if(( ( part.plus + inventoryList[k].plus ) < ( (inventoryList[k].quality + 1) * 5 ) ) && (part.quality < inventoryList[k].quality) && (part.mod == inventoryList[k].mod) && (inventoryList[k].quality - part.quality > starDifference) ) {
  121.             systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
  122.             inventoryActions.scrapPart(part);
  123.             replaceCurrentPart = false;
  124.             replaceNewPart = false;
  125.             checkEquipped = false;
  126.             break inventoryLoop;
  127.         }
  128.         else {
  129.         //None exists, so we continue looping
  130.         }  
  131.     }
  132. }
  133.  
  134. if(replaceCurrentPart) {
  135.     var oldQualityPart = inventoryList[replaceCurrentPartIndex];
  136.     systemLog.push('<b class="rarity-' + part.quality + '-text"> ' + part.name + ' +' + ( part.plus) + '</b> <- <b class="rarity-' + oldQualityPart.quality + '-text">' + oldQualityPart.name +  ' +' + ( oldQualityPart.plus) + '</b>');
  137.     craftingActions.setPrimary(part, true);
  138.     craftingActions.setConsumed(inventoryList[replaceCurrentPartIndex], true);
  139.     craftingActions.combine();
  140.     craftingActions.update();
  141. }
  142.  
  143. if(replaceNewPart) {
  144.     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>');
  145.     craftingActions.setPrimary(inventoryList[replaceNewPartIndex], true);
  146.     craftingActions.setConsumed(part, true);
  147.     craftingActions.combine();
  148.     craftingActions.update();
  149. }
  150. if(checkEquipped) {
  151.     loop1:
  152.     for(var a = 0; a < listLength; a++) {
  153.         for(var b = 0; b < shieldLength; b++) {
  154.             if(checkCraftable(shieldList[b].part, part)) {
  155.                 combineToConstruction(shieldConstruction, shieldList[b].x, shieldList[b].y, shieldList[b].part, part);
  156.                 break loop1;
  157.             }
  158.         }
  159.     }
  160. }
  161.  
  162. var removeAnnoyingMessage = function(){
  163.     if(systemLog[systemLog.length-1].includes("Got")){
  164.         systemLog.pop();
  165.     }
  166. }
  167.  
  168.         //the message is actually put there after this script so we use a timeout. May fail for obvious reasons.
  169. setTimeout(removeAnnoyingMessage, 100);
  170.  
  171.  
  172.  
  173. //ScrollFix
  174. $(".system-log-container").scrollTop($(".system-log-container")[0].scrollHeight);
  175.  
  176. //Global error handler
  177. window.onerror = function(msg, url, line, col, error) {
  178.    // Note that col & error are new to the HTML 5 spec and may not be
  179.    // supported in every browser.  It worked for me in Chrome.
  180.    var extra = !col ? '' : '\ncolumn: ' + col;
  181.    extra += !error ? '' : '\nerror: ' + error;
  182.  
  183.    // You can view the information in an alert to see things working like this:
  184.    systemLog.push("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
  185.  
  186.    // TODO: Report this error via ajax so you can keep track
  187.    //       of what pages have JS issues
  188.  
  189.    var suppressErrorAlert = true;
  190.    // If you return true, then error alerts (like in older versions of
  191.    // Internet Explorer) will be suppressed.
  192.    return suppressErrorAlert;
  193. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement