Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //############################################################
- //Author: SydneyMakers /u/PyroNyzen
- //Version 5
- //reference 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;
- //set this to what will be scrapped unless it can upgrade an existing equipped item
- var scrapRank = 3;
- // For convenience, store the part in a new variable
- var part = inventoryList[inventoryList.length-1];
- var listLength = inventoryList.length - 1;
- var weaponListLength = weaponList.length - 1;
- var shieldListLength = shieldList.length - 1;
- //weapon addition
- var weaponConstruction = user.data.characters[0].constructions.mainWeapon;
- var shieldConstruction = user.data.characters[0].constructions.shield;
- //Absolutes DO NOT MODIFY
- var replaceWeapon = false;
- var replaceShield = false;
- var weaponIndex = 0;
- var shieldIndex = 0;
- 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;
- }
- }
- }
- loop3:
- for(var k = 0; k < listLength; k++) {
- if(part.quality > scrapRank) {
- if(part.type == inventoryList[k].type) {
- // New item exists already
- if(part.quality > inventoryList[k].quality ) {
- //the new part has higher quality than the old part
- inventoryActions.scrapPart(inventoryList[k]);
- systemLog.push('Sold a <b class="rarity-' + inventoryList[k].quality + '-text"> ' + inventoryList[k].name + '</b> for ' + inventoryList[k].value + ' credits.');
- break loop3;
- }
- else if(part.quality <= inventoryList[k].quality) {
- //the old part has higher quality than the new part
- inventoryActions.scrapPart(part);
- systemLog.push('Sold a <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- break loop3;
- }
- }
- else {
- //None exists, so we continue looping
- }
- }
- else
- {
- inventoryActions.scrapPart(part);
- systemLog.push('Sold a <b class="rarity-' + part.quality + '-text"> ' + part.name + '</b> for ' + part.value + ' credits.');
- //remove the Got item message
- break loop3;
- }
- }
- 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