2021-01-19 17:32:27 +00:00
|
|
|
/*
|
|
|
|
* TESTING SECTION
|
|
|
|
*/
|
|
|
|
|
2021-01-30 08:50:25 +00:00
|
|
|
const ing_url_base = location.href.split("#")[0];
|
|
|
|
const ing_url_tag = location.hash.slice(1);
|
2021-04-02 17:44:54 +00:00
|
|
|
// console.log(ing_url_base);
|
|
|
|
// console.log(ing_url_tag);
|
2021-01-19 17:32:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-02 22:29:38 +00:00
|
|
|
const ING_BUILD_VERSION = "7.0.1";
|
2021-01-19 17:32:27 +00:00
|
|
|
/*
|
|
|
|
* END testing section
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
Make material tier do something
|
|
|
|
Double powders
|
|
|
|
Integrate to normal builder
|
|
|
|
*/
|
|
|
|
let player_craft;
|
|
|
|
|
2022-05-12 08:48:59 +00:00
|
|
|
// function setTitle() {
|
|
|
|
// document.getElementById("header").textContent = "WynnCrafter version "+ING_BUILD_VERSION+" (ingredient db version "+ING_DB_VERSION+")";
|
|
|
|
// document.getElementById("header").classList.add("funnynumber");
|
|
|
|
// }
|
2021-01-30 08:50:25 +00:00
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
|
|
|
|
|
2021-01-29 02:31:31 +00:00
|
|
|
|
2021-04-02 22:07:15 +00:00
|
|
|
function init_crafter() {
|
2021-01-19 17:32:27 +00:00
|
|
|
//no ing
|
2021-01-28 00:52:34 +00:00
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
console.log("all ingredients");
|
2021-03-04 14:47:08 +00:00
|
|
|
console.log(ingMap);
|
2021-04-02 17:44:54 +00:00
|
|
|
console.log("all recipes");
|
|
|
|
console.log(recipeMap);
|
2021-01-30 08:50:25 +00:00
|
|
|
/*console.log(ingList);
|
2021-01-28 00:52:34 +00:00
|
|
|
console.log(recipeList);
|
2021-01-29 02:31:31 +00:00
|
|
|
console.log(ingIDMap);
|
2021-01-30 08:50:25 +00:00
|
|
|
console.log(recipeIDMap);*/
|
|
|
|
try {
|
|
|
|
document.getElementById("recipe-choice").addEventListener("change", (event) => {
|
|
|
|
updateMaterials();
|
|
|
|
});
|
|
|
|
document.getElementById("level-choice").addEventListener("change", (event) => {
|
|
|
|
updateMaterials();
|
|
|
|
});
|
|
|
|
|
|
|
|
populateFields();
|
|
|
|
decodeCraft(ing_url_tag);
|
2021-02-25 06:03:44 +00:00
|
|
|
} catch (error) {
|
2021-01-30 08:50:25 +00:00
|
|
|
console.log("If you are seeing this while building, do not worry. Oherwise, panic! (jk contact ferricles)");
|
2021-02-25 06:03:44 +00:00
|
|
|
console.log(error);
|
2021-01-30 08:50:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 22:11:57 +00:00
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
}
|
|
|
|
function updateMaterials() {
|
|
|
|
let recipeName = getValue("recipe-choice") ? getValue("recipe-choice") : "Potion";
|
|
|
|
let levelRange = getValue("level-choice") ? getValue("level-choice") : "103-105";
|
|
|
|
let recipe = expandRecipe(recipeMap.get(recipeName + "-" + levelRange));
|
|
|
|
if (recipe !== undefined) {
|
|
|
|
try{
|
|
|
|
document.getElementById("mat-1").textContent = recipe.get("materials")[0].get("item").split(" ").slice(1).join(" ") + " Tier:";
|
|
|
|
document.getElementById("mat-2").textContent = recipe.get("materials")[1].get("item").split(" ").slice(1).join(" ") + " Tier:";
|
|
|
|
} catch (error){
|
2021-01-28 00:52:34 +00:00
|
|
|
//e e e
|
2021-01-19 17:32:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("mat-1").textContent = "Material 1 Tier:";
|
|
|
|
document.getElementById("mat-2").textContent = "Material 2 Tier:";
|
|
|
|
}
|
|
|
|
}
|
2021-01-21 18:30:22 +00:00
|
|
|
function toggleAtkSpd(buttonId) {
|
|
|
|
let buttons = ["slow-atk-button", "normal-atk-button", "fast-atk-button"];
|
|
|
|
let elem = document.getElementById(buttonId);
|
|
|
|
if (elem.classList.contains("toggleOn")) {
|
|
|
|
elem.classList.remove("toggleOn");
|
|
|
|
} else {
|
|
|
|
for (const button of buttons) {
|
|
|
|
document.getElementById(button).classList.remove("toggleOn");
|
|
|
|
}
|
|
|
|
elem.classList.add("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 17:32:27 +00:00
|
|
|
|
|
|
|
function calculateCraft() {
|
|
|
|
//Make things display.
|
|
|
|
for (let i of document.getElementsByClassName("hide-container-block")) {
|
|
|
|
i.style.display = "block";
|
|
|
|
}
|
|
|
|
for (let i of document.getElementsByClassName("hide-container-grid")) {
|
|
|
|
i.style.display = "grid";
|
|
|
|
}
|
|
|
|
//define the fields that will go into crafting the craft.
|
|
|
|
let recipe = getValue("recipe-choice") === "" ? "Potion" : getValue("recipe-choice");
|
|
|
|
let levelrange = getValue("level-choice") === "" ? "103-105" : getValue("level-choice");
|
|
|
|
recipe = expandRecipe(recipeMap.get(recipe+"-"+levelrange));
|
|
|
|
let mat_tiers = [];
|
|
|
|
for (i = 1; i < 3; i++) {
|
|
|
|
for(j = 1; j < 4; j++) {
|
|
|
|
let elem = document.getElementById("mat-" + i + "-" + j);
|
|
|
|
if(elem.classList.contains("toggleOn")) {
|
|
|
|
mat_tiers.push(j); //Tier is 1, 2, or 3.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 19:53:41 +00:00
|
|
|
if (mat_tiers.length < i) { //default to t3
|
2021-01-19 17:32:27 +00:00
|
|
|
mat_tiers.push(3);
|
|
|
|
document.getElementById("mat-"+i+"-3").classList.add("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let ingreds = [];
|
|
|
|
for (i = 1; i < 7; i++) {
|
2022-05-12 08:48:59 +00:00
|
|
|
console.log("ing-choice-"+i);
|
|
|
|
// console.log(getValue("ing-choice-"+i));
|
2021-01-19 17:32:27 +00:00
|
|
|
getValue("ing-choice-" + i) === "" ? ingreds.push(expandIngredient(ingMap.get("No Ingredient"))) : ingreds.push(expandIngredient(ingMap.get(getValue("ing-choice-" + i))));
|
|
|
|
}
|
2021-01-21 18:30:22 +00:00
|
|
|
let atkSpd = "NORMAL"; //default attack speed will be normal.
|
|
|
|
for (const b of ["slow-atk-button", "normal-atk-button", "fast-atk-button"]) {
|
|
|
|
button = document.getElementById(b);
|
|
|
|
if (button.classList.contains("toggleOn")) {
|
|
|
|
atkSpd = b.split("-")[0].toUpperCase();
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 17:32:27 +00:00
|
|
|
//create the craft
|
2021-01-28 00:52:34 +00:00
|
|
|
player_craft = new Craft(recipe,mat_tiers,ingreds,atkSpd,"");
|
|
|
|
|
2021-01-30 11:06:16 +00:00
|
|
|
let craft_str = encodeCraft(player_craft);
|
|
|
|
location.hash = craft_str;
|
|
|
|
player_craft.setHash(craft_str);
|
2021-01-19 17:32:27 +00:00
|
|
|
console.log(player_craft);
|
|
|
|
/*console.log(recipe)
|
|
|
|
console.log(levelrange)
|
|
|
|
console.log(mat_tiers)
|
|
|
|
console.log(ingreds)*/
|
2022-05-12 08:48:59 +00:00
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
document.getElementById("mat-1").textContent = recipe.get("materials")[0].get("item").split(" ").slice(1).join(" ") + " Tier:";
|
|
|
|
document.getElementById("mat-2").textContent = recipe.get("materials")[1].get("item").split(" ").slice(1).join(" ") + " Tier:";
|
|
|
|
|
2021-01-20 05:59:17 +00:00
|
|
|
//Display Recipe Stats
|
2022-05-12 08:48:59 +00:00
|
|
|
displaysq2RecipeStats(player_craft, "recipe-stats");
|
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
//Display Craft Stats
|
2022-05-12 08:48:59 +00:00
|
|
|
// displayCraftStats(player_craft, "craft-stats");
|
|
|
|
let mock_item = player_craft.statMap;
|
|
|
|
displaysq2ExpandedItem(mock_item, "craft-stats");
|
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
//Display Ingredients' Stats
|
|
|
|
for (let i = 1; i < 7; i++) {
|
2022-05-12 08:48:59 +00:00
|
|
|
displaysq2ExpandedIngredient(player_craft.ingreds[i-1] , "ing-"+i+"-stats");
|
2021-01-19 17:32:27 +00:00
|
|
|
}
|
2021-01-20 05:59:17 +00:00
|
|
|
//Display Warnings - only ingred type warnings for now
|
|
|
|
let warning_elem = document.getElementById("craft-warnings");
|
|
|
|
warning_elem.textContent = ""; //refresh warnings
|
|
|
|
warning_elem.classList.add("warning");
|
|
|
|
let type = player_craft["recipe"].get("skill");
|
|
|
|
for (const ingred of player_craft["ingreds"]) {
|
|
|
|
if (!(ingred.get("skills").includes(type))) {
|
|
|
|
let p = document.createElement("p");
|
|
|
|
p.textContent = "WARNING: " + ingred.get("name") + " cannot be used for " + type.charAt(0) + type.substring(1).toLowerCase() +"!";
|
|
|
|
warning_elem.appendChild(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 00:52:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-30 08:50:25 +00:00
|
|
|
function decodeCraft(ing_url_tag) {
|
|
|
|
if (ing_url_tag) {
|
2021-03-14 07:55:08 +00:00
|
|
|
if (ing_url_tag.slice(0,3) === "CR-") {
|
|
|
|
ing_url_tag = ing_url_tag.substring(3);
|
|
|
|
location.hash = location.hash.substring(3);
|
|
|
|
}
|
2021-01-30 08:50:25 +00:00
|
|
|
console.log(ing_url_tag);
|
|
|
|
let version = ing_url_tag.charAt(0);
|
|
|
|
let tag = ing_url_tag.substring(1);
|
2021-01-28 00:52:34 +00:00
|
|
|
if (version === "1") {
|
|
|
|
ingreds = [];
|
|
|
|
for (let i = 0; i < 6; i ++ ) {
|
2021-01-29 02:31:31 +00:00
|
|
|
setValue("ing-choice-"+(i+1), ingIDMap.get(Base64.toInt(tag.substring(2*i,2*i+2))));
|
2021-01-30 08:50:25 +00:00
|
|
|
//console.log(Base64.toInt(tag.substring(2*i,2*i+2)));
|
2021-01-28 00:52:34 +00:00
|
|
|
}
|
2021-01-29 02:31:31 +00:00
|
|
|
recipe = recipeIDMap.get(Base64.toInt(tag.substring(12,14)));
|
2021-01-30 08:50:25 +00:00
|
|
|
//console.log(Base64.toInt(tag.substring(12,14)));
|
2021-01-28 00:52:34 +00:00
|
|
|
recipesName = recipe.split("-");
|
|
|
|
setValue("recipe-choice",recipesName[0]);
|
|
|
|
setValue("level-choice",recipesName[1]+"-"+recipesName[2]);
|
|
|
|
tierNum = Base64.toInt(tag.substring(14,15));
|
|
|
|
mat_tiers = [];
|
|
|
|
mat_tiers.push(tierNum % 3 == 0 ? 3 : tierNum % 3);
|
|
|
|
mat_tiers.push(Math.floor((tierNum-0.5) / 3)+1); //Trying to prevent round-off error, don't yell at me
|
|
|
|
toggleMaterial("mat-1-"+mat_tiers[0]);
|
|
|
|
toggleMaterial("mat-2-"+mat_tiers[1]);
|
|
|
|
atkSpd = Base64.toInt(tag.substring(15));
|
|
|
|
let atkSpdButtons = ["slow-atk-button", "normal-atk-button", "fast-atk-button"];
|
|
|
|
toggleAtkSpd(atkSpdButtons[atkSpd]);
|
|
|
|
|
|
|
|
calculateCraft();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 17:32:27 +00:00
|
|
|
function populateFields() {
|
|
|
|
let recipe_list = document.getElementById("recipe-choices");
|
|
|
|
for (const recipe of recipeTypes) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = recipe.charAt(0) + recipe.substring(1).toLowerCase();
|
|
|
|
recipe_list.appendChild(el);
|
|
|
|
}
|
|
|
|
let level_list = document.getElementById("level-choices");
|
|
|
|
for (const range of levelTypes) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = range;
|
|
|
|
level_list.appendChild(el);
|
|
|
|
}
|
|
|
|
for (i = 1; i < 7; i++) {
|
|
|
|
let ing_list = document.getElementById("ing-choices-"+i);
|
|
|
|
for (const ing of ingList) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = ing;
|
|
|
|
ing_list.appendChild(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy the link
|
|
|
|
*/
|
|
|
|
function copyRecipe(){
|
|
|
|
if (player_craft) {
|
2021-01-30 08:50:25 +00:00
|
|
|
copyTextToClipboard(ing_url_base+location.hash);
|
2021-01-19 17:32:27 +00:00
|
|
|
document.getElementById("copy-button").textContent = "Copied!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the link AND a display of all ingredients
|
|
|
|
*/
|
|
|
|
function shareRecipe(){
|
|
|
|
if (player_craft) {
|
2021-01-30 08:50:25 +00:00
|
|
|
let copyString = ing_url_base+location.hash + "\n";
|
2021-01-29 02:31:31 +00:00
|
|
|
let name = player_craft.recipe.get("name").split("-");
|
2021-01-28 00:52:34 +00:00
|
|
|
copyString += " > " + name[0] + " " + "Lv. " + name[1] + "-" + name[2] + " (" + player_craft.mat_tiers[0] + "\u272B, " + player_craft.mat_tiers[1] + "\u272B)\n";
|
2021-01-29 02:31:31 +00:00
|
|
|
let names = [
|
2021-03-04 14:47:08 +00:00
|
|
|
player_craft.ingreds[0].get("displayName"),
|
|
|
|
player_craft.ingreds[1].get("displayName"),
|
|
|
|
player_craft.ingreds[2].get("displayName"),
|
|
|
|
player_craft.ingreds[3].get("displayName"),
|
|
|
|
player_craft.ingreds[4].get("displayName"),
|
|
|
|
player_craft.ingreds[5].get("displayName")
|
2021-01-29 02:31:31 +00:00
|
|
|
];
|
|
|
|
//fancy justify code that doesn't work properly b/c most font isn't monospaced
|
|
|
|
let buffer1 = Math.max(names[0].length,names[2].length,names[4].length);
|
|
|
|
let buffer2 = Math.max(names[1].length,names[3].length,names[5].length);
|
|
|
|
for (let i in names) {
|
|
|
|
let name = names[i];
|
|
|
|
let spaces;
|
|
|
|
if (i % 2 == 0) { //buffer 1
|
|
|
|
spaces = buffer1 - name.length;
|
|
|
|
} else { //buffer 2
|
|
|
|
spaces = buffer2 - name.length;
|
|
|
|
}
|
|
|
|
for (let j = 0; j < spaces; j ++) {
|
|
|
|
if (j % 2 == 0) {
|
|
|
|
names[i]+=" ";
|
|
|
|
} else {
|
|
|
|
names[i] = " "+names[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
copyString += " > [" + names[0] + " | " + names[1] + "\n";
|
|
|
|
copyString += " > " + names[2] + " | " + names[3] + "\n";
|
|
|
|
copyString += " > " + names[4] + " | " + names[5] + "]";
|
2021-01-28 00:52:34 +00:00
|
|
|
copyTextToClipboard(copyString);
|
2021-01-19 17:32:27 +00:00
|
|
|
document.getElementById("share-button").textContent = "Copied!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Toggles the entire material's buttons
|
|
|
|
*/
|
|
|
|
function toggleMaterial(buttonId) {
|
|
|
|
let elem = document.getElementById(buttonId);
|
|
|
|
let mat = buttonId.split("-")[1]
|
|
|
|
if (!elem.classList.contains("toggleOn")) { //we turned on that button, now toggle the others off
|
|
|
|
toggleButton(buttonId);
|
|
|
|
for (i = 1; i < 4; i++) {
|
|
|
|
if ("mat-" + mat + "-" + i !== buttonId) {
|
|
|
|
document.getElementById("mat-" + mat + "-" + i).classList.remove("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //we turned off a button: do nothing
|
|
|
|
toggleButton(buttonId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset all fields
|
|
|
|
*/
|
|
|
|
function resetFields() {
|
|
|
|
for (let i = 1; i < 3; i ++) {
|
|
|
|
for (let j = 1; j < 4; j++) {
|
|
|
|
document.getElementById("mat-"+i+"-"+j).classList.remove("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let i = 1; i < 7; i++) {
|
|
|
|
setValue("ing-choice-"+i, "");
|
|
|
|
}
|
|
|
|
setValue("recipe-choice", "");
|
|
|
|
setValue("level-choice", "");
|
|
|
|
location.hash = "";
|
|
|
|
calculateCraft();
|
|
|
|
}
|
|
|
|
|
2021-04-02 22:07:15 +00:00
|
|
|
load_ing_init(init_crafter);
|