Skip to content

Instantly share code, notes, and snippets.

@bitexploder
Created March 6, 2024 20:52
Show Gist options
  • Save bitexploder/e7235d3130815451f7cb2995d117162b to your computer and use it in GitHub Desktop.
Save bitexploder/e7235d3130815451f7cb2995d117162b to your computer and use it in GitHub Desktop.
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers');
const Database = require('wow-classic-items')
const items = new Database.Items()
const professions = new Database.Professions()
const zones = new Database.Zones()
const classes = new Database.Classes()
/* const waylaidSuppliesItems = [
"Brilliant Smallfish",
"Heavy Linen Bandage",
"Light Leather",
"Rough Stone",
"Spiced Wolf Meat",
"Copper Bar",
"Herb Baked Egg",
"Peacebloom",
"Silverleaf",
"Brown Linen Pants",
"Copper Shortsword",
"Handstitched Leather Belt",
"Lesser Magic Wand",
"Minor Wizard Oil",
"Rough Copper Bomb",
"Brown Linen Robe",
"Embossed Leather Vest",
"Healing Potion",
"Minor Healing Potion",
"Rough Boomstick",
"Runed Copper Pants",
"Bronze Bar",
"Goblin Deviled Clams",
"Medium Leather",
"Smoked Bear Meat",
"Swiftthistle",
"Bruiseweed",
"Heavy Wool Bandage",
"Silver Bar",
"Smoked Sagefish",
"Dark Leather Cloak",
"Lesser Mana Potion",
"Rough Bronze Boots",
"Gray Woolen Shirt",
"Minor Mana Oil",
"Small Bronze Bomb",
"Thick Leather",
"Elixir of Firepower",
"Ornate Spyglass",
"Runed Silver Rod",
"Hillman's Shoulders",
"Pearl-clasped Cloak",
"Silver Skeleton Key"
]; */
const waylaidSuppliesItems = {
"Brilliant Smallfish": { amount: 20, repAmount: 300 },
"Heavy Linen Bandage": { amount: 10, repAmount: 300 },
"Light Leather": { amount: 14, repAmount: 300 },
"Rough Stone": { amount: 10, repAmount: 300 },
"Spiced Wolf Meat": { amount: 20, repAmount: 300 },
"Copper Bar": { amount: 20, repAmount: 300 },
"Herb Baked Egg": { amount: 20, repAmount: 300 },
"Peacebloom": { amount: 20, repAmount: 300 },
"Silverleaf": { amount: 20, repAmount: 300 },
"Brown Linen Pants": { amount: 6, repAmount: 450 },
"Copper Shortsword": { amount: 6, repAmount: 450 },
"Handstitched Leather Belt": { amount: 5, repAmount: 450 },
"Lesser Magic Wand": { amount: 2, repAmount: 450 },
"Minor Wizard Oil": { amount: 2, repAmount: 450 },
"Rough Copper Bomb": { amount: 12, repAmount: 450 },
"Brown Linen Robe": { amount: 4, repAmount: 450 },
"Embossed Leather Vest": { amount: 3, repAmount: 450 },
"Healing Potion": { amount: 10, repAmount: 450 },
"Minor Healing Potion": { amount: 20, repAmount: 450 },
"Rough Boomstick": { amount: 3, repAmount: 450 },
"Runed Copper Pants": { amount: 3, repAmount: 450 },
"Bronze Bar": { amount: 12, repAmount: 500 },
"Goblin Deviled Clams": { amount: 8, repAmount: 500 },
"Medium Leather": { amount: 12, repAmount: 500 },
"Smoked Bear Meat": { amount: 20, repAmount: 500 },
"Swiftthistle": { amount: 20, repAmount: 500 },
"Bruiseweed": { amount: 20, repAmount: 500 },
"Heavy Wool Bandage": { amount: 15, repAmount: 500 },
"Silver Bar": { amount: 6, repAmount: 500 },
"Smoked Sagefish": { amount: 15, repAmount: 500 },
"Dark Leather Cloak": { amount: 2, repAmount: 650 },
"Lesser Mana Potion": { amount: 20, repAmount: 650 },
"Rough Bronze Boots": { amount: 3, repAmount: 650 },
"Gray Woolen Shirt": { amount: 4, repAmount: 650 },
"Minor Mana Oil": { amount: 2, repAmount: 650 },
"Small Bronze Bomb": { amount: 12, repAmount: 650 },
"Thick Leather": { amount: 10, repAmount: 650 },
"Elixir of Firepower": { amount: 15, repAmount: 800 },
"Ornate Spyglass": { amount: 2, repAmount: 800 },
"Runed Silver Rod": { amount: 1, repAmount: 800 },
"Hillman's Shoulders": { amount: 2, repAmount: 800 },
"Pearl-clasped Cloak": { amount: 3, repAmount: 800 },
"Silver Skeleton Key": { amount: 14, repAmount: 800 },
};
// Parse the command line arguments
const argv = yargs(hideBin(process.argv)).options({
'itemId': {
alias: 'id',
describe: 'Wow Item Id',
type: 'number', // Explicitly telling yargs that this argument is expected to be a number
demandOption: false // This flag is optional
},
'age': {
alias: 'a',
describe: 'Your age',
type: 'number', // Explicitly telling yargs that this argument is expected to be a number
demandOption: false // This flag is optional
}
}).argv;
function getItemById(items, itemId) {
var filtered = items.filter(item => item.itemId === itemId)
// console.log(filtered)
if(filtered.length == 1) {
return filtered[0]
} else {
return {}
}
}
function getReagentsForItem(item) {
if(!item.hasOwnProperty('createdBy')) {
return []
}
if(item.createdBy.length == 1) {
var cb = item.createdBy[0]
//console.log(cb)
var reagents = cb.reagents.map(item =>
({
itemId: item.itemId,
amount: item.amount
})
)
return reagents
} else {
console.log("hmmm")
return []
}
}
function filterItemsByIds(items, itemIds) {
return items.filter(item => itemIds.includes(item.itemId))
}
function filterItemsByName(items, names) {
return items.filter(item => names.includes(item.name))
}
if(argv.itemId) {
var item = getItemById(items, argv.itemId);
//console.log(item)
//console.log(item.createdBy)
//console.log('---- getReagentItemIds')
var reagents = getReagentsForItem(item)
} else if (argv.itemName) {
// do stuff
} else {
// console.log(reagents)
//console.log(itemIds)
//var reagentsItems = filterItemsByIds(items, itemIds);
//console.log(`Stuff: ${reagentsItems}`);
var itemNamesTest = ["Copper Shortsword", "Heavy Linen Bandage"];
//var someItems = filterItemsByName(items, itemNamesTest);
var someItems = filterItemsByName(items, Object.keys(waylaidSuppliesItems));
// console.log(someItems)
var cnt = 0;
var csvFile = "";
csvFile += "Item,Amount, Rep,Total Reagent Amounts\n"
for(item of someItems) {
var itemAmount = waylaidSuppliesItems[item.name].amount;
var repReward = waylaidSuppliesItems[item.name].repAmount;
var supplyRow = `"${item.name}",${itemAmount},${repReward},`;
//console.log(item)
//console.log(item.createdBy)
//console.log(`Item: ${item.name}`)
//console.log(` ${waylaidSuppliesItems[item.name].amount}`)
var reagents = getReagentsForItem(item);
supplyRow += `"`;
for (reagent of reagents) {
var reagentItem = getItemById(items, reagent.itemId)
var totalReagentAmt = waylaidSuppliesItems[item.name].amount * reagent.amount
var reagentStr = `${reagentItem.name} x ${totalReagentAmt}, `
supplyRow += reagentStr;
//console.log(reagentStr)
}
supplyRow += `"`
if(reagents.length == 0) {
// console.log(" No reagents")
}
csvFile += supplyRow + "\n";
cnt += 1;
}
console.log(csvFile);
console.log(cnt)
const fs = require('fs');
fs.writeFileSync('/mnt/c/Users/Jeremy/Desktop/waylaid-supplies.csv', csvFile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment