Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //############################################################
- //Author: SydneyMakers /u/PyroNyzen
- //Version 6.16
- /* 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 weaponList = user.data.characters[0].constructions.mainWeapon.parts;
- var shieldList = user.data.characters[0].constructions.shield.parts;
- var part = inventoryList[inventoryList.length-1];
- var listLength = inventoryList.length - 1;
- var weaponListLength = weaponList.length - 1;
- var shieldListLength = shieldList.length - 1;
- var weaponConstruction = user.data.characters[0].constructions.mainWeapon;
- var shieldConstruction = user.data.characters[0].constructions.shield;
- var replaceWeapon = false;
- var replaceShield = false;
- var weaponIndex = 0;
- var shieldIndex = 0;
- /* END GLOBAL VARIABLES*/
- loop1:
- for(var i = 0; i < weaponListLength; i++) {
- if(part.type == weaponList[i].part.type) {
- //it exists, lets check if it is better than the current
- if(part.quality > weaponList[i].part.quality) {
- for(var j = 0; j < weaponList.length; j++) {
- //check if the aprt can be equipped ± 2 quality
- if(part.quality - weaponList[j].part.quality <= 2) {
- //its better and valid so lets replace it
- replaceWeapon = true;
- weaponIndex = j;
- }
- else {
- replaceWeapon = false;
- break loop1;
- }
- }
- }
- else if(part.quality == weaponList[i].part.quality) {
- //both items match quality, lets check Mod value
- if(part.mod > weaponList[i].part.mod) {
- //The mod value is larger, so lets replace it
- replaceWeapon = true;
- weaponIndex = i;
- break loop1;
- }
- }
- }
- }
- //the replace script has been moved to shorten code
- if(replaceWeapon) {
- var xpos = weaponList[weaponIndex].x;
- var ypos = weaponList[weaponIndex].y;
- var oldWeapon = weaponList[weaponIndex].part;
- 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>');
- Construction.removeFromSetup(weaponConstruction, weaponList[weaponIndex].part, weaponList[weaponIndex].x, weaponList[weaponIndex].y);
- Construction.addToSetup(weaponConstruction, part, xpos, ypos);
- userActions.saveConstruction();
- for(var i = 0; i < listLength; i++) {
- if(oldWeapon == inventoryList[i]) {
- inventoryActions.scrapPart(inventoryList[i]);
- break;
- }
- }
- }
- loop2:
- for(var j = 0; j < shieldListLength; j++) {
- if(part.type == shieldList[j].part.type) {
- //it exists, lets check if it is better than the current
- if(part.quality > shieldList[j].part.quality) {
- for(var i = 0; i < shieldList.length; i++) {
- //check if the aprt can be equipped ± 2 quality
- if(part.quality - shieldList[i].part.quality <= 2) {
- //its better and valid so lets replace it
- replaceShield = true;
- shieldIndex = j;
- }
- else {
- replaceShield = false;
- break loop2;
- }
- }
- }
- else if(part.quality == shieldList[j].part.quality) {
- if(part.mod > shieldList[j].part.mod) {
- //an existing quality is already there so we know it can be equipped
- replaceShield = true;
- shieldIndex = j;
- break loop2;
- }
- }
- }
- }
- if(replaceShield) {
- var xpos = shieldList[shieldIndex].x;
- var ypos = shieldList[shieldIndex].y;
- var oldShield = shieldList[shieldIndex].part;
- 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>');
- Construction.removeFromSetup(shieldConstruction, shieldList[shieldIndex].part, xpos, ypos);
- Construction.addToSetup(shieldConstruction, part, xpos, ypos);
- userActions.saveConstruction();
- for(var i = 0; i < listLength; i++) {
- if(oldShield == inventoryList[i]) {
- inventoryActions.scrapPart(inventoryList[i]);
- break;
- }
- }
- }
- var replaceNewPart = false;
- var replaceCurrentPart = false;
- var replaceNewPartIndex = 0;
- var replaceCurrentPartIndex = 0;
- loop3:
- 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);
- break loop3;
- }
- if( (part.quality == 7) && (part.type == inventoryList[k].type) ) {
- //New item is an 8 rank, lets scrap the old one since it cannot be crafted.
- //re-iterating just to be safe
- replaceCurrentPart = false;
- replaceNewPart = false;
- systemLog.push('Rank 8 Encountered: Scrapped Existing <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> for ' + inventoryList[k].value + ' credits.');
- inventoryActions.scrapPart(inventoryList[k]);
- break loop3;
- }
- else if( (inventoryList[k].quality == 7) && (part.type == inventoryList[k].type) ) {
- //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('Rank 8 Encountered: Scrapped New <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- inventoryActions.scrapPart(part);
- break loop3;
- }
- 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) ) {
- //New part has equal mod, equal type, higher quality.
- replaceCurrentPart = true;
- replaceNewPart = false;
- replaceCurrentPartIndex = k;
- break loop3;
- }
- 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) ) {
- //New part has equal mod, equal type, lower quality but is within threshold
- replaceCurrentPart = false;
- replaceNewPart = true;
- replaceNewPartIndex = k;
- break loop3;
- }
- 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) ) {
- systemLog.push('Sold <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- inventoryActions.scrapPart(part);
- replaceCurrentPart = false;
- replaceNewPart = false;
- break loop3;
- }
- 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();
- }
- 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement