Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //############################################################
- //Author: SydneyMakers /u/PyroNyzen
- //Version 10.2
- /* TODO:
- * Add in mainWeapon crafting functionality
- * Very hard considering the following example returning success but no item
- Crafting.createCombinedPart(user, user.data.inventory.parts[0], user.data.characters[0].constructions.mainWeapon.parts[1].part);
- */
- var checkCraftable = function (item1, item2) {
- 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) ){
- return true;
- }
- }
- var combineToConstruction = function( construction, posx, posy, shieldItem, inventoryItem) {
- Construction.removeFromSetup(construction, shieldItem, posx, posy);
- userActions.saveConstruction();
- var shieldID = shieldItem.id;
- var shieldItem = inventoryLib.getPartById(shieldID);
- 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>');
- craftingActions.setPrimary(shieldItem, true);
- craftingActions.setConsumed(inventoryItem, true);
- craftingActions.combine();
- craftingActions.update();
- Construction.addToSetup(construction, shieldItem, posx, posy);
- userActions.saveConstruction();
- }
- var shieldConstruction = user.data.characters[0].constructions.shield;
- var weaponConstruction = user.data.characters[0].constructions.mainWeapon;
- var shieldLength = user.data.characters[0].constructions.shield.parts.length - 1;
- var shieldList = user.data.characters[0].constructions.shield.parts;
- //long-winded method INCOMPLETE
- /*
- */
- /* User-Customisable Variables */
- //set this to what will be scrapped unless it can upgrade an existing equipped item
- var scrapRank = 3;
- // This value is the quality threshold below the current item that will be combined
- var starDifference = 1; // for a starDifference of 1, a 7* item will only combine with 6* or 7* items
- /* End User-Customisable Variables*/
- /* GLOBAL VARIABLES */
- var inventoryList = user.data.inventory.parts;
- var part = inventoryList[inventoryList.length-1];
- var listLength = inventoryList.length - 1;
- /* END GLOBAL VARIABLES*/
- var checkEquipped = true;
- var replaceNewPart = false;
- var replaceCurrentPart = false;
- var replaceNewPartIndex = 0;
- var replaceCurrentPartIndex = 0;
- inventoryLoop:
- for(var k = 0; k < listLength; k++) {
- if(part.quality < scrapRank) {
- // Item is below quality threshold so it's being scrapped
- systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- inventoryActions.scrapPart(part);
- checkEquipped = false;
- break inventoryLoop;
- }
- if(part.type == inventoryList[k].type) {
- if((part.mod > inventoryList[k].mod)) {
- systemLog.push('Mod <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> too low.');
- systemLog.push('Part <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> kept.');
- inventoryActions.scrapPart(inventoryList[k]);
- checkEquipped = false;
- break inventoryLoop;
- }
- else if((part.mod < inventoryList[k].mod)) {
- systemLog.push('Mod <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> too low.');
- systemLog.push('Part <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> kept.');
- inventoryActions.scrapPart(part);
- checkEquipped = false;
- break inventoryLoop;
- }
- if( (part.quality > crafting.limits.rarity)) {
- //New item is an uncraftable rank, lets scrap the old one since it cannot be crafted.
- //re-iterating the booleans just to be safe.
- replaceCurrentPart = false;
- replaceNewPart = false;
- systemLog.push('Uncraftable Encountered: Scrapped Existing <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> for ' + inventoryList[k].value + ' credits.');
- inventoryActions.scrapPart(inventoryList[k]);
- checkEquipped = false;
- break inventoryLoop;
- }
- else if( (inventoryList[k].quality > crafting.limits.rarity)) {
- //Current item is an 8 rank, and it exists, so lets scrap the new item
- //re-iterating just to be safe
- replaceNewPart = false;
- replaceCurrentPart = false;
- systemLog.push('Uncraftable Encountered: Scrapped New <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- inventoryActions.scrapPart(part);
- checkEquipped = false;
- break inventoryLoop;
- }
- else if( ( ( part.plus + inventoryList[k].plus ) < ( (part.quality + 1) * 5 ) ) && (part.quality >= inventoryList[k].quality) && (part.mod == inventoryList[k].mod) ) {
- //New part has equal mod, equal type, higher quality.
- replaceCurrentPart = true;
- replaceNewPart = false;
- replaceCurrentPartIndex = k;
- checkEquipped = false;
- break inventoryLoop;
- }
- 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) ) {
- //New part has equal mod, equal type, lower quality but is within threshold
- replaceCurrentPart = false;
- replaceNewPart = true;
- replaceNewPartIndex = k;
- checkEquipped = false;
- break inventoryLoop;
- }
- 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) ) {
- systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- inventoryActions.scrapPart(part);
- replaceCurrentPart = false;
- replaceNewPart = false;
- checkEquipped = false;
- break inventoryLoop;
- }
- else {
- //None exists, so we continue looping
- }
- }
- }
- if(replaceCurrentPart) {
- var oldQualityPart = inventoryList[replaceCurrentPartIndex];
- systemLog.push('<b class="rarity-' + part.quality + '-text"> ' + part.name + ' +' + ( part.plus) + '</b> <- <b class="rarity-' + oldQualityPart.quality + '-text">' + oldQualityPart.name + ' +' + ( oldQualityPart.plus) + '</b>');
- craftingActions.setPrimary(part, true);
- craftingActions.setConsumed(inventoryList[replaceCurrentPartIndex], true);
- craftingActions.combine();
- craftingActions.update();
- }
- if(replaceNewPart) {
- 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>');
- craftingActions.setPrimary(inventoryList[replaceNewPartIndex], true);
- craftingActions.setConsumed(part, true);
- craftingActions.combine();
- craftingActions.update();
- }
- if(checkEquipped) {
- loop1:
- for(var a = 0; a < listLength; a++) {
- for(var b = 0; b < shieldLength; b++) {
- if(checkCraftable(shieldList[b].part, part)) {
- combineToConstruction(shieldConstruction, shieldList[b].x, shieldList[b].y, shieldList[b].part, part);
- break loop1;
- }
- }
- }
- }
- var removeAnnoyingMessage = function(){
- if(systemLog[systemLog.length-1].includes("Got")){
- systemLog.pop();
- }
- }
- //the message is actually put there after this script so we use a timeout. May fail for obvious reasons.
- setTimeout(removeAnnoyingMessage, 100);
- //ScrollFix
- $(".system-log-container").scrollTop($(".system-log-container")[0].scrollHeight);
- //Global error handler
- window.onerror = function(msg, url, line, col, error) {
- // Note that col & error are new to the HTML 5 spec and may not be
- // supported in every browser. It worked for me in Chrome.
- var extra = !col ? '' : '\ncolumn: ' + col;
- extra += !error ? '' : '\nerror: ' + error;
- // You can view the information in an alert to see things working like this:
- systemLog.push("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
- // TODO: Report this error via ajax so you can keep track
- // of what pages have JS issues
- var suppressErrorAlert = true;
- // If you return true, then error alerts (like in older versions of
- // Internet Explorer) will be suppressed.
- return suppressErrorAlert;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement