Last active
April 6, 2017 13:18
-
-
Save wein3967/73430a38fdd4007577e1 to your computer and use it in GitHub Desktop.
This is a DIM specific script that is run from the Chrome developer tools console in an active DIM tab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a DIM specific script that can be run in the Developer Console in Chrome on a DIM tab. | |
// it writes out a csv string with stats and perks for armor, ghosts, and artifacts. | |
// FUNCTIONS | |
function isArmor(myItem) { | |
return (myItem.type === "Helmet" || | |
myItem.type === "Gauntlets" || | |
myItem.type === "Chest" || | |
myItem.type === "Leg" || | |
myItem.type === "ClassItem") && | |
myItem.name.indexOf("Engram") == -1; // Filtering out various Engrams | |
}; | |
function isArtifact(myItem) { | |
return myItem.type === "Artifact"; | |
}; | |
function isGhost(myItem) { | |
return myItem.type === "Ghost"; | |
}; | |
function isRealPerk(myItem) { // Omitting "perks" I don't really care about | |
return myItem !== "Upgrade Defense" && | |
myItem !== "Ascend" && | |
myItem !== "Infuse" && | |
myItem !== "Increase Intellect" && | |
myItem !== "Increase Discipline" && | |
myItem !== "Increase Strength" && | |
myItem !== "Twist Fate" && | |
myItem !== "The Life Exotic" && | |
myItem !== "Reforge Artifact" && // These are sometimes added by Bungie to Vault items | |
myItem !== "Reforge Shell" && // These are sometimes added by Bungie to Vault items | |
myItem.indexOf("Chroma") == -1; | |
}; | |
function statSplit(intVal, discVal, strVal) { | |
var statStr = ""; | |
if (intVal > 0) { statStr = statStr + "I" }; | |
if (discVal > 0) { statStr = statStr + "D" }; | |
if (strVal > 0) { statStr = statStr + "S" }; | |
return statStr; | |
}; | |
function findStat(statName, statArray) { // Make sure I get the stat I want (single stats exist) | |
for (k = 0; k < statArray.length; k++) { | |
if (statArray[k].name === statName) { | |
return k; | |
break; | |
}; | |
}; | |
}; | |
function setDummyStats(statArray) { | |
var completeStats = []; | |
for (m = 0; m < statArray.length; m++) { | |
if (!!statArray[m] == false) { | |
var dummyStat = { base: 0, bonus: 0, scaled: 0 }; | |
statArray[m] = dummyStat; | |
}; | |
completeStats[m] = statArray[m]; | |
}; | |
return completeStats | |
}; | |
function getItemString(item) { | |
var descriptionString = item.id + ',' + | |
',' + // Placeholder for my Keep/Trash column | |
item.locked + ',' + | |
item.classTypeName + ',' + | |
item.tier + ',' + | |
item.year + ',' + | |
item.sort + ',' + | |
item.type + ',' + | |
item.name + ','; | |
if (item.primStat == undefined) { // Handles the few pieces of armor that have no light value (e.g. SRL Legs) | |
descriptionString = descriptionString + '0,'; | |
} else { | |
descriptionString = descriptionString + item.primStat.value + ','; | |
}; | |
if (item.stats == undefined) { // Handles the items of armor that have no stats (e.g. Year 1 class items) | |
descriptionString = descriptionString + 'None,0,0,0,0,0,0,0,0'; | |
} else { | |
//Set up stat references | |
var intObj = item.stats[findStat("Intellect", item.stats)]; | |
var disObj = item.stats[findStat("Discipline", item.stats)]; | |
var strObj = item.stats[findStat("Strength", item.stats)]; | |
var dummyStats = setDummyStats([intObj, disObj, strObj]); | |
intObj = dummyStats[0]; | |
disObj = dummyStats[1]; | |
strObj = dummyStats[2]; | |
descriptionString = descriptionString + | |
statSplit(intObj.base, disObj.base, strObj.base) + ',' + | |
(!!item.quality ? item.quality.min: 0) + ',' + | |
item.percentComplete + ',' + | |
// Base stats | |
(!!intObj ? intObj.base: 0) + ',' + | |
(!!disObj ? disObj.base: 0) + ',' + | |
(!!strObj ? strObj.base: 0) + ',' + | |
Math.max(intObj.bonus, disObj.bonus, strObj.bonus) + ',' + | |
// Scaled stats | |
(!!intObj.scaled ? intObj.scaled.min:0) + ',' + | |
(!!disObj.scaled ? disObj.scaled.min:0) + ',' + | |
(!!strObj.scaled ? strObj.scaled.min:0); | |
}; | |
return descriptionString; | |
}; | |
function getPerkList(testObject) { | |
if (!!testObject.talentGrid) { // Handles the items of armor that have no perks (e.g. Year 1 class items) | |
var perkList = []; | |
var color = "None"; | |
for (j = 0; j < testObject.talentGrid.nodes.length; j++) { | |
if (testObject.talentGrid.nodes[j].hidden == false) { // Ignore hidden perks | |
perkList.push(testObject.talentGrid.nodes[j].name); | |
}; | |
}; | |
color = getColor(perkList); | |
perkList = perkList.filter(isRealPerk); | |
perkList.unshift(color); // Add color to the front of the perkList | |
return perkList; | |
} else { | |
return "None,None"; | |
}; | |
}; | |
function getColor(perks) { | |
var chromaColor = "None"; | |
for (k = 0; k < perks.length; k++) { | |
if (perks[k].indexOf("Chroma") !== -1 && perks[k] !== "Deactivate Chroma") { | |
chromaColor = perks[k].split(" ")[0]; | |
}; | |
}; | |
return chromaColor; | |
}; | |
///////////////////////////////////////////////////////////////////// | |
// MAIN CODE | |
var stuff = angular.element(document.body).injector().get('dimStoreService').getStores(); | |
var guardian1_Items = (stuff.length >= 2) ? stuff[0].items : []; | |
var guardian2_Items = (stuff.length >= 3) ? stuff[1].items : []; | |
var guardian3_Items = (stuff.length >= 4) ? stuff[2].items : []; | |
var vaultItems = stuff[stuff.length - 1].items; | |
var allItems = guardian1_Items.concat(guardian2_Items, guardian3_Items, vaultItems); | |
var allFilteredItems = allItems.filter(isArmor); //Filter for only armor | |
allFilteredItems = allFilteredItems.concat(allItems.filter(isGhost), allItems.filter(isArtifact)); | |
var descString = "IndexID,Status,IsLocked,Class,Tier,Year,Armor,Type,Name,Light,StatSplit,Quality,XPcomplete,IntellectB,DisciplineB,StrengthB,BonusB,IntellectS,DisciplineS,StrengthS,Color,Perks" + '\n'; | |
for (i = 0; i < allFilteredItems.length; i++) { | |
descString = descString + | |
getItemString(allFilteredItems[i]) + ',' + | |
getPerkList(allFilteredItems[i]) + | |
'\n'; | |
}; | |
descString; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment