Skip to content

Instantly share code, notes, and snippets.

@JamesDonnelly
Last active March 22, 2017 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesDonnelly/d0d3a108d99742bb48ca89b812007cd3 to your computer and use it in GitHub Desktop.
Save JamesDonnelly/d0d3a108d99742bb48ca89b812007cd3 to your computer and use it in GitHub Desktop.
const config = {
method: 'GET',
mode: 'cors'
}
fetch(
"https://api.xivdb.com/achievement?columns=help_en,icon,id,name,points,requirement_1,requirement_2,type",
config
)
.then(response => response.json())
.then(achievements => {
getWeights(achievements);
})
.catch(e => console.error(e));
function getWeights(achievements) {
let result = {};
achievements.forEach(a => {
result[a.id] = {
cumulative: getCumulative(a),
description: a.help_en,
icon: a.icon,
name: a.name,
points: a.points,
weight: getWeight(a)
}
})
console.info(result);
}
function getWeight(achievement) {
switch (achievement.type) {
case 4: // affix n materia to the same piece of gear
case 10: // level your companion chocobo to rank n
case 12: // participate in n matches in The Fold
case 13: // triumph in n matches in The Fold
case 17: // participate in n Frontline matches
case 19: // triumph in n Frontline matches
return achievement.requirement_1;
case 1: // do n things
case 3: // achieve n levels as class
case 11: // achieve PVP rank n with a specific Grand Company
case 15: // achieve rank n with a specific Beast Tribe
case 18: // guide a specific Grand Company to n Frontline victories
case 21: // obtain n minions
return achievement.requirement_2;
case 0: // complete specific Legacy thing (some stil relevant)
case 5: // complete all n of these requirement_2 - 9 things
case 6: // complete a specific quest
case 7: // complete all specific hunting log entries
case 8: // discover every location within...
case 9: // complete any of these requirement_2 - 9 quests (?)
case 14: // complete a specific Trial
case 20: // attune to all aether currents in a specific area
case 23: // complete all Verminion challenges
case 24: // obtain a variety of anima weapon
return 1;
case 2: // complete n other achievements
return 0; // the other achievements have their own weights and this is automatic
case 16: // there is no type 16
case 22: // there is no type 22
default:
return null;
}
}
function getCumulative(achievement) {
// The following are all cumulative.
if (achievement.type == 3
|| achievement.type == 4
|| achievement.type == 10
|| achievement.type == 12
|| achievement.type == 13
|| achievement.type == 17
|| achievement.type == 19)
return true;
// The following are not cumulative.
if (achievement.type == 2
|| achievement.type == 5
|| achievement.type == 6
|| achievement.type == 7
|| achievement.type == 8
|| achievement.type == 9
|| achievement.type == 14
|| achievement.type == 20
|| achievement.type == 23
|| achievement.type == 24)
return false;
// The rest are cumulative if their requirement_1 property contains any of the following values.
const requirement_1_cumulative_keys = [
"0","1","2","3","4","5","6","7","8","11",
"12","13","14","15","16","17","18","19","20","21",
"22","138","139","140","141","142","143","144","145","146",
"147","148","149","162","163","164","165","166","167","168",
"169","170","179","180","181","182","183","184","185","186",
"187","188","189","190","191","192","193","194","195","196",
"197","198","199","200","201","202","203","204","205","206",
"207","208","209","210","211","212","213","214","215","216",
"217","218","219","238","239","240","244","251","266","267",
"268","277","278","284","285","286","290","291","292","294",
"348","352","353","354","355","356","357","358","362","363",
"364","365","366","369","370","371","372","373","374","423",
"433","444","460","461","462","463","464","465","466","467",
"468","469","470","471","472","473","474","498","499","500",
"501","511","512","532","539","540","544","545","546","548",
"549","567"
];
return requirement_1_cumulative_keys.indexOf("" + achievement.requirement_1) !== -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment