|
|
|
const fs = require('fs');
|
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
console.log("Hello!")
|
|
|
|
|
|
|
|
finalData=[]
|
|
|
|
firstLoad=true
|
|
|
|
|
|
|
|
itemCache={}
|
|
|
|
retainerIDs=[1572880,16,2359328,131092,9,0,13,1048586,2162700]
|
|
|
|
retainerInventories=[[],[],[],[],[],[],[],[],[]]
|
|
|
|
|
|
|
|
lastDisplayString=""
|
|
|
|
|
|
|
|
function getRetainerIndex(id){
|
|
|
|
switch(id){
|
|
|
|
case 65576:{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case 1769474:{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case 196652:{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
case 655362:{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
case 65568:{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
case 65540:{
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
case 327684:{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
case 3276807:{
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
case 393254:{
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
default:{
|
|
|
|
console.log("No retainer found with ID "+id+"!")
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getItemData(item){
|
|
|
|
if (Number.isInteger(item.id)){
|
|
|
|
if ((item.id in itemCache)){
|
|
|
|
item.name=itemCache[item.id].Name
|
|
|
|
item.icon=itemCache[item.id].Icon
|
|
|
|
} else {
|
|
|
|
if (fs.existsSync("cache/"+item.id)){
|
|
|
|
data=JSON.parse(fs.readFileSync("cache/"+item.id))
|
|
|
|
console.log("Loaded Item "+item.id+" ("+data.Name+") from Cache")
|
|
|
|
itemCache[item.id]=data
|
|
|
|
getItemData(item)
|
|
|
|
} else {
|
|
|
|
await axios.get("https://xivapi.com/Item/"+item.id)
|
|
|
|
.then((data)=>{
|
|
|
|
itemCache[item.id]=data.data
|
|
|
|
fs.writeFileSync("cache/"+item.id,JSON.stringify(data.data))
|
|
|
|
console.log("Added Item "+item.id+" ("+data.data.Name+") to Cache")
|
|
|
|
})
|
|
|
|
.catch((err)=>{
|
|
|
|
itemCache[item.id]={}
|
|
|
|
console.log(item.id+" is not a valid Item ID!")})
|
|
|
|
await sleep(250)
|
|
|
|
getItemData(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update(){
|
|
|
|
changed=false
|
|
|
|
fs.readFile("C:\\Users\\sigon\\Documents\\memory",
|
|
|
|
async(err,data)=>{
|
|
|
|
var fileContents = data.toString().split("\n");
|
|
|
|
if (fileContents.length>=387){
|
|
|
|
for (i=0;i<fileContents.length;i++){
|
|
|
|
line=fileContents[i]
|
|
|
|
item=line.split(" ")
|
|
|
|
if (i==385){
|
|
|
|
ind=getRetainerIndex(Number(item[0]));
|
|
|
|
//140 + 70
|
|
|
|
retainerInventories[ind]=finalData.slice(210,385)
|
|
|
|
}
|
|
|
|
if (i==386){
|
|
|
|
//Target Item Slot Amt. (4294967295 means invalid amt)
|
|
|
|
//387 should be item ID.
|
|
|
|
if (fileContents[387].split(" ")[0]!=0){
|
|
|
|
var tempLine=fileContents[387].split(" ")[0]
|
|
|
|
var tempLineAmt=fileContents[386].split(" ")[0]
|
|
|
|
var itemObj={id:Number(tempLine)}
|
|
|
|
await getItemData(itemObj)
|
|
|
|
var fileData=fs.readFileSync("goalamt.txt")
|
|
|
|
if (fileData!=0){
|
|
|
|
tempString=itemObj.name+": "+tempLineAmt+"/"+fileData+" ("+Math.min(100,Math.floor(tempLineAmt/Number(fileData)*100))+"%)"
|
|
|
|
if (lastDisplayString!=tempString){
|
|
|
|
fs.writeFile("amt",tempString,()=>{})
|
|
|
|
lastDisplayString=tempString
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lastDisplayString!=" "){
|
|
|
|
fs.writeFile("amt"," ",()=>{})
|
|
|
|
lastDisplayString=" "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lastDisplayString!=" "){
|
|
|
|
fs.writeFile("amt"," ",()=>{})
|
|
|
|
lastDisplayString=" "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemID=item[1]
|
|
|
|
itemAmt=item[0]
|
|
|
|
hq=(item[2]!==undefined)?item[2].replace("\r",""):""
|
|
|
|
itemHQ=hq==="0"?false:true
|
|
|
|
newItem={"id":Number(itemID),"amt":Number(itemAmt),"hq":itemHQ}
|
|
|
|
//console.log(itemID+" x"+itemAmt+" "+(itemHQ))
|
|
|
|
if(firstLoad){
|
|
|
|
await getItemData(newItem)
|
|
|
|
finalData=[...finalData,newItem]
|
|
|
|
}else
|
|
|
|
if (finalData[i]!==undefined&&(Number.isInteger(finalData[i].id)^Number.isInteger(itemID))){
|
|
|
|
if (finalData[i].id!=Number(itemID)||finalData[i].amt!==Number(itemAmt)||finalData[i].hq!==Boolean(itemHQ)){
|
|
|
|
await getItemData(newItem)
|
|
|
|
console.log(JSON.stringify(finalData[i])+" !== "+JSON.stringify(newItem))
|
|
|
|
finalData[i]=newItem
|
|
|
|
changed=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed){
|
|
|
|
console.log("Changes occurred...")
|
|
|
|
finalArr=[finalData.slice(0,210)]
|
|
|
|
for (inventory of retainerInventories){
|
|
|
|
finalArr=[...finalArr,[...inventory]]
|
|
|
|
}
|
|
|
|
axios.post("http://projectdivar.com/inventoryData",finalArr)
|
|
|
|
.catch((err)=>{})
|
|
|
|
}
|
|
|
|
firstLoad=false
|
|
|
|
}
|
|
|
|
setTimeout(update,1000)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
update()
|