2021-03-05 16:28:00 +00:00
|
|
|
const custom_url_base = location.href.split("#")[0];
|
|
|
|
const custom_url_tag = location.hash.slice(1);
|
|
|
|
|
2021-04-07 06:01:05 +00:00
|
|
|
const CUSTOM_BUILD_VERSION = "7.0.1";
|
2021-03-05 16:28:00 +00:00
|
|
|
|
|
|
|
function setTitle() {
|
2021-03-14 07:55:08 +00:00
|
|
|
let text = "WynnCustom version "+CUSTOM_BUILD_VERSION;
|
2021-03-05 16:28:00 +00:00
|
|
|
document.getElementById("header").classList.add("funnynumber");
|
|
|
|
document.getElementById("header").textContent = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTitle();
|
|
|
|
|
|
|
|
let player_custom_item;
|
2021-05-20 03:35:35 +00:00
|
|
|
let player_custom_ing;
|
2021-03-05 16:28:00 +00:00
|
|
|
let base_item; //the item that a user starts from, if any
|
|
|
|
let pos_range = [0.3,1.3];
|
|
|
|
let neg_range = [1.3,0.7];
|
|
|
|
|
|
|
|
|
|
|
|
let roll_range_ids = ["neg_roll_range-choice-min","neg_roll_range-choice-max","pos_roll_range-choice-min","pos_roll_range-choice-max"];
|
|
|
|
|
|
|
|
|
2021-04-02 22:07:15 +00:00
|
|
|
function init_customizer() {
|
2021-03-05 16:28:00 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
populateFields();
|
|
|
|
decodeCustom(custom_url_tag);
|
|
|
|
|
|
|
|
for (const id of rolledIDs) {
|
|
|
|
if (document.getElementById(id+"-choice-base")) {
|
|
|
|
let base_elem = document.getElementById(id+"-choice-base");
|
|
|
|
base_elem.addEventListener("focusout", (event) => {
|
|
|
|
base_to_range(id);
|
|
|
|
});
|
|
|
|
let min_elem = document.getElementById(id+"-choice-min");
|
|
|
|
min_elem.addEventListener("focusout", (event) => {
|
|
|
|
range_to_base(id,"min");
|
|
|
|
});
|
|
|
|
let max_elem = document.getElementById(id+"-choice-max");
|
|
|
|
max_elem.addEventListener("focusout", (event) => {
|
|
|
|
range_to_base(id,"max");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const id of roll_range_ids) {
|
|
|
|
document.getElementById(id).addEventListener("focusout", (event) => {
|
|
|
|
changeBaseValues();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.log("If you are seeing this while building, do not worry. Oherwise, panic! (jk contact ferricles)");
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a custom item based on data input into the fields.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function calculateCustom() {
|
|
|
|
try {
|
|
|
|
//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";
|
|
|
|
}
|
|
|
|
|
|
|
|
let statMap = new Map();
|
|
|
|
statMap.set("minRolls", new Map());
|
|
|
|
statMap.set("maxRolls", new Map());
|
|
|
|
let inputs = document.getElementsByTagName("input");
|
|
|
|
|
|
|
|
if (document.getElementById("fixID-choice").textContent === "yes") {//Fixed IDs
|
|
|
|
for (const input of inputs) {
|
|
|
|
if (input.id.includes("-min") || input.id.includes("-max")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let id = input.id.replace("-choice", "");
|
|
|
|
|
|
|
|
id = id.replace("-fixed", "");
|
|
|
|
id = id.replace("-min", "");
|
|
|
|
id = id.replace("-max", "");
|
|
|
|
|
|
|
|
if (input.classList.contains("number-input")) {
|
|
|
|
if (parseFloat(input.value)) {
|
|
|
|
if(rolledIDs.includes(id)) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.get("minRolls").set(id,Math.round(parseFloat(input.value)));
|
|
|
|
statMap.get("maxRolls").set(id,Math.round(parseFloat(input.value)));
|
2021-03-05 16:28:00 +00:00
|
|
|
} else {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, Math.round(parseFloat(input.value)));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (input.classList.contains("string-input")) {
|
|
|
|
if(rolledIDs.includes(id)) {
|
|
|
|
statMap.get("minRolls").set(id,input.value);
|
|
|
|
statMap.get("maxRolls").set(id,input.value);
|
|
|
|
} else {
|
|
|
|
statMap.set(id, input.value);
|
|
|
|
}
|
|
|
|
} else if (input.classList.contains("array-input")) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, input.value.split("-").map(x=>Math.round(parseFloat(x))));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(input.value === "" && input.placeholder && input.placeholder !== "") {
|
|
|
|
if (input.classList.contains("number-input") && parseFloat(input.placeholder)) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, Math.round(parseFloat(input.placeholder)));
|
2021-03-05 16:28:00 +00:00
|
|
|
} else if (input.classList.contains("string-input")) {
|
|
|
|
statMap.set(id, input.placeholder);
|
|
|
|
} else if (input.classList.contains("array-input")) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, input.placeholder.split("-").map(x=>Math.round(parseFloat(x))));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
statMap.set("fixID", true);
|
|
|
|
|
2021-04-12 21:30:16 +00:00
|
|
|
} else { //not fixed
|
2021-03-05 16:28:00 +00:00
|
|
|
for (const input of inputs) {
|
|
|
|
if (input.id.includes("-fixed")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let id = input.id.replace("-choice", "");
|
|
|
|
let rollMap = "";
|
2021-04-12 21:30:16 +00:00
|
|
|
let oppMap = "";
|
2021-03-05 16:28:00 +00:00
|
|
|
|
|
|
|
//If it's a minimum, it's -min
|
|
|
|
if(id.includes("-min")) {
|
|
|
|
rollMap = "minRolls";
|
|
|
|
}
|
|
|
|
//If it's a maximum, it's -max
|
|
|
|
else if(id.includes("-max")) {
|
|
|
|
rollMap = "maxRolls";
|
|
|
|
}
|
|
|
|
|
|
|
|
id = id.replace("-fixed", "");
|
|
|
|
id = id.replace("-min", "");
|
|
|
|
id = id.replace("-max", "");
|
|
|
|
|
|
|
|
if (input.classList.contains("number-input")) {
|
|
|
|
if (parseFloat(input.value)) {
|
|
|
|
if (rolledIDs.includes(id)) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.get(rollMap).set(id, Math.round(parseFloat(input.value)));
|
2021-03-05 16:28:00 +00:00
|
|
|
} else {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, Math.round(parseFloat(input.value)));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (input.classList.contains("string-input")) {
|
|
|
|
if(rolledIDs.includes(id)) {
|
|
|
|
statMap.get(rollMap).set(id, input.value);
|
|
|
|
} else {
|
|
|
|
statMap.set(id, input.value);
|
|
|
|
}
|
|
|
|
} else if (input.classList.contains("array-input")) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, input.value.split("-").map(x=>Math.round(parseFloat(x))));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(input.value === "" && input.placeholder && input.placeholder !== "") {
|
|
|
|
if (input.classList.contains("number-input")) {
|
|
|
|
if (rolledIDs.includes(id)) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.get(rollMap).set(id, Math.round(parseFloat(input.placeholder)));
|
2021-03-05 16:28:00 +00:00
|
|
|
} else {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, Math.round(parseFloat(input.placeholder)));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
} else if (input.classList.contains("string-input")){
|
|
|
|
if (rolledIDs.includes(id)) {
|
|
|
|
statMap.get(rollMap).set(id, input.placeholder);
|
|
|
|
} else {
|
|
|
|
statMap.set(id, input.placeholder);
|
|
|
|
}
|
|
|
|
} else if (input.classList.contains("array-input")) {
|
2021-03-08 22:50:47 +00:00
|
|
|
statMap.set(id, input.placeholder.split("-").map(x=>Math.round(parseFloat(x))));
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
player_custom_item = new Custom(statMap);
|
2021-03-08 22:50:47 +00:00
|
|
|
|
2021-03-14 07:55:08 +00:00
|
|
|
document.getElementById("right-container").classList.remove("sticky-box");
|
|
|
|
let custom_str = encodeCustom(player_custom_item.statMap, true);
|
2021-03-08 22:50:47 +00:00
|
|
|
location.hash = custom_str;
|
|
|
|
player_custom_item.setHash(custom_str);
|
2021-06-19 09:06:46 +00:00
|
|
|
//console.log(player_custom_item.statMap.get("hash"));
|
2021-03-08 22:50:47 +00:00
|
|
|
|
|
|
|
|
2021-03-05 16:28:00 +00:00
|
|
|
displayExpandedItem(player_custom_item.statMap, "custom-stats");
|
2021-03-08 22:50:47 +00:00
|
|
|
|
2021-06-19 09:06:46 +00:00
|
|
|
//console.log(player_custom_item.statMap);
|
2021-03-05 16:28:00 +00:00
|
|
|
|
|
|
|
}catch (error) {
|
|
|
|
//USE THE ERROR <p>S!
|
|
|
|
|
|
|
|
let msg = error.stack;
|
|
|
|
let lines = msg.split("\n");
|
|
|
|
let header = document.getElementById("header");
|
|
|
|
header.textContent = "";
|
|
|
|
for (const line of lines) {
|
|
|
|
let p = document.createElement("p");
|
|
|
|
p.classList.add("itemp");
|
|
|
|
p.textContent = line;
|
|
|
|
header.appendChild(p);
|
|
|
|
}
|
|
|
|
let p2 = document.createElement("p");
|
|
|
|
p2.textContent = "If you believe this is an error, contact hppeng on forums or discord.";
|
|
|
|
header.appendChild(p2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function decodeCustom(custom_url_tag) {
|
|
|
|
if (custom_url_tag) {
|
2021-03-14 07:55:08 +00:00
|
|
|
if (custom_url_tag.slice(0,3) === "CI-") {
|
|
|
|
custom_url_tag = custom_url_tag.substring(3);
|
|
|
|
location.hash = location.hash.substring(3);
|
|
|
|
}
|
2021-03-05 16:28:00 +00:00
|
|
|
let version = custom_url_tag.charAt(0);
|
2021-03-08 22:50:47 +00:00
|
|
|
let fixID = Boolean(parseInt(custom_url_tag.charAt(1),10));
|
|
|
|
let tag = custom_url_tag.substring(2);
|
|
|
|
let statMap = new Map();
|
|
|
|
statMap.set("minRolls", new Map());
|
|
|
|
statMap.set("maxRolls", new Map());
|
|
|
|
|
2021-03-05 16:28:00 +00:00
|
|
|
if (version === "1") {
|
|
|
|
//do the things
|
2021-03-08 23:14:47 +00:00
|
|
|
if (fixID) {
|
2021-03-14 07:55:08 +00:00
|
|
|
statMap.set("fixId", true);
|
2021-03-08 23:14:47 +00:00
|
|
|
toggleButton("fixID-choice");
|
|
|
|
toggleYN("fixID-choice");
|
|
|
|
toggleFixed(document.getElementById("fixID-choice"));
|
|
|
|
}
|
2021-03-08 22:50:47 +00:00
|
|
|
while (tag !== "") {
|
|
|
|
let id = ci_save_order[Base64.toInt(tag.slice(0,2))];
|
2021-06-19 09:06:46 +00:00
|
|
|
//console.log(tag.slice(0, 2) + ": " + id);
|
2021-03-08 22:50:47 +00:00
|
|
|
let len = Base64.toInt(tag.slice(2,4));
|
|
|
|
if (rolledIDs.includes(id)) {
|
2021-03-14 07:55:08 +00:00
|
|
|
let sign = parseInt(tag.slice(4,5),10);
|
|
|
|
let minRoll = Base64.toInt(tag.slice(5,5+len));
|
2021-03-08 22:50:47 +00:00
|
|
|
if (!fixID) {
|
2021-03-14 07:55:08 +00:00
|
|
|
let maxRoll = Base64.toInt(tag.slice(5+len,5+2*len));
|
|
|
|
if (sign > 1) {
|
|
|
|
maxRoll *= -1;
|
|
|
|
}
|
|
|
|
if (sign % 2 == 1) {
|
|
|
|
minRoll *= -1;
|
|
|
|
}
|
2021-03-08 22:50:47 +00:00
|
|
|
setValue(id+"-choice-min", minRoll);
|
|
|
|
setValue(id+"-choice-max", maxRoll);
|
|
|
|
statMap.get("minRolls").set(id,minRoll);
|
|
|
|
statMap.get("maxRolls").set(id,maxRoll);
|
2021-03-14 07:55:08 +00:00
|
|
|
tag = tag.slice(5+2*len);
|
2021-03-08 22:50:47 +00:00
|
|
|
} else {
|
2021-03-14 07:55:08 +00:00
|
|
|
if (sign != 0) {
|
|
|
|
minRoll *= -1;
|
|
|
|
}
|
2021-03-08 22:50:47 +00:00
|
|
|
setValue(id+"-choice-fixed", minRoll);
|
|
|
|
statMap.get("minRolls").set(id,minRoll);
|
|
|
|
statMap.get("maxRolls").set(id,minRoll);
|
2021-03-14 07:55:08 +00:00
|
|
|
tag = tag.slice(5+len);
|
2021-03-08 22:50:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let val;
|
2021-03-14 07:55:08 +00:00
|
|
|
//let elem = document.getElementById(id+"-choice");
|
|
|
|
if (nonRolled_strings.includes(id)) {
|
2021-03-08 22:50:47 +00:00
|
|
|
if (id === "tier") {
|
|
|
|
val = tiers[Base64.toInt(tag.charAt(2))];
|
|
|
|
len = -1;
|
|
|
|
} else if (id === "type") {
|
|
|
|
val = types[Base64.toInt(tag.charAt(2))];
|
|
|
|
len = -1;
|
2021-03-14 07:55:08 +00:00
|
|
|
} else if (id === "atkSpd") {
|
|
|
|
val = attackSpeeds[Base64.toInt(tag.charAt(2))];
|
|
|
|
len = -1;
|
|
|
|
} else if (id === "classReq") {
|
|
|
|
val = classes[Base64.toInt(tag.charAt(2))];
|
2021-03-08 22:50:47 +00:00
|
|
|
len = -1;
|
|
|
|
} else { //general case
|
2021-03-14 07:55:08 +00:00
|
|
|
val = tag.slice(4,4+len).replaceAll("%20"," ");
|
2021-03-08 22:50:47 +00:00
|
|
|
}
|
2021-03-14 07:55:08 +00:00
|
|
|
tag = tag.slice(4+len);
|
2021-03-08 22:50:47 +00:00
|
|
|
} else {
|
2021-03-14 07:55:08 +00:00
|
|
|
let sign = parseInt(tag.slice(4,5),10);
|
|
|
|
val = Base64.toInt(tag.slice(5,5+len));
|
|
|
|
if (sign == 1) {
|
|
|
|
val *= -1;
|
|
|
|
}
|
|
|
|
tag = tag.slice(5+len);
|
2021-03-08 22:50:47 +00:00
|
|
|
}
|
|
|
|
statMap.set(id, val);
|
|
|
|
setValue(id+"-choice", val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
statMap.set("hash",custom_url_tag);
|
2021-03-05 16:28:00 +00:00
|
|
|
calculateCustom();
|
2021-03-08 22:50:47 +00:00
|
|
|
player_custom_item.setHash(custom_url_tag);
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function populateFields() {
|
|
|
|
/*Ex
|
|
|
|
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 tier_list = document.getElementById("tier-list");
|
|
|
|
for (const tier of tiers) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = tier;
|
|
|
|
tier_list.appendChild(el);
|
|
|
|
}
|
|
|
|
let type_list = document.getElementById("type-list");
|
|
|
|
for (const type of types) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = type;
|
|
|
|
type_list.appendChild(el);
|
|
|
|
}
|
|
|
|
let atkSpd_list = document.getElementById("atkSpd-list");
|
|
|
|
for (const atkSpd of attackSpeeds) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = atkSpd;
|
|
|
|
atkSpd_list.appendChild(el);
|
|
|
|
}
|
|
|
|
let class_list = document.getElementById("class-list");
|
|
|
|
for (const className of classes) {
|
|
|
|
let el = document.createElement("option");
|
|
|
|
el.value = className;
|
|
|
|
class_list.appendChild(el);
|
|
|
|
}
|
|
|
|
let item_list = document.getElementById("base-list");
|
2021-03-14 07:55:08 +00:00
|
|
|
for (const name of itemMap.keys()) {
|
2021-03-05 16:28:00 +00:00
|
|
|
let el = document.createElement("option");
|
2021-03-14 07:55:08 +00:00
|
|
|
el.value = name;
|
2021-03-05 16:28:00 +00:00
|
|
|
item_list.appendChild(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 06:01:05 +00:00
|
|
|
|
2021-03-05 16:28:00 +00:00
|
|
|
|
|
|
|
/* Changes an element's text content from yes to no or vice versa
|
|
|
|
*/
|
|
|
|
function toggleYN(elemId) {
|
|
|
|
let elem = document.getElementById(elemId);
|
|
|
|
if (elem.textContent && elem.textContent === "no") {
|
|
|
|
elem.textContent = "yes";
|
|
|
|
} else if (elem.textContent === "yes") {
|
|
|
|
elem.textContent = "no";
|
|
|
|
} else {
|
|
|
|
elem.textContent = "no";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-08 23:14:47 +00:00
|
|
|
* @param fixed : a boolean for the state of the fixID button.
|
2021-03-05 16:28:00 +00:00
|
|
|
*/
|
|
|
|
function toggleFixed(fixed) {
|
|
|
|
for (const id of rolledIDs) {
|
|
|
|
let elem = document.getElementById(id);
|
|
|
|
if (elem) {
|
|
|
|
if (fixed.textContent === "yes") { //now fixed IDs -> go to 1 input
|
|
|
|
document.getElementById(id+"-choice-fixed-container").style = "";
|
|
|
|
document.getElementById(id+"-choice-container").style = "display:none";
|
|
|
|
} else { //now rollable -> go to 2 inputs
|
|
|
|
document.getElementById(id+"-choice-fixed-container").style = "display:none";
|
|
|
|
document.getElementById(id+"-choice-container").style = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Make a custom item
|
|
|
|
*
|
|
|
|
* @param {elem} : The elem with value item to base off of. A string input.
|
|
|
|
*/
|
|
|
|
function useBaseItem(elem) {
|
|
|
|
let itemName = getValue(elem);
|
|
|
|
let baseItem;
|
|
|
|
|
|
|
|
//Check items db.
|
|
|
|
for (const [name,itemObj] of itemMap) {
|
|
|
|
if (itemName === name) {
|
|
|
|
baseItem = expandItem(itemObj, []);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//If it starts with CR-, try creating a craft
|
|
|
|
if(!baseItem) {
|
2021-03-14 07:55:08 +00:00
|
|
|
baseItem = getCraftFromHash(itemName) ? getCraftFromHash(itemName) : (getCustomFromHash(itemName) ? getCustomFromHash(itemName) : null);
|
|
|
|
baseItem = baseItem.statMap;
|
2021-03-05 16:28:00 +00:00
|
|
|
console.log(baseItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
//If the item exists, go through stats and assign to values!
|
|
|
|
if(baseItem) {
|
|
|
|
resetFields();
|
|
|
|
|
|
|
|
//Rolled IDs
|
|
|
|
if (document.getElementById("fixID-choice").textContent === "yes") { //fixed IDs
|
|
|
|
for (const id of rolledIDs) { //use maxrolls
|
|
|
|
if (baseItem.get("maxRolls").get(id) && document.getElementById(id+"-choice-fixed")) {
|
|
|
|
setValue(id+"-choice-fixed", baseItem.get("maxRolls").get(id));
|
|
|
|
setValue(id+"-choice-min", baseItem.get("maxRolls").get(id));
|
|
|
|
setValue(id+"-choice-max", baseItem.get("maxRolls").get(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //use both
|
|
|
|
for (const id of rolledIDs) {
|
|
|
|
if (baseItem.get("maxRolls").get(id) && document.getElementById(id+"-choice-fixed")) {
|
|
|
|
setValue(id+"-choice-fixed", baseItem.get("maxRolls").get(id));
|
|
|
|
setValue(id+"-choice-min", baseItem.get("minRolls").get(id));
|
|
|
|
setValue(id+"-choice-max", baseItem.get("maxRolls").get(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Static IDs
|
|
|
|
for (const id of nonRolledIDs) {
|
|
|
|
if (baseItem.get(id) && document.getElementById(id+"-choice")) {
|
|
|
|
setValue(id+"-choice", baseItem.get(id));
|
|
|
|
}
|
|
|
|
}
|
2021-04-13 22:38:26 +00:00
|
|
|
//take care of displayName
|
|
|
|
if (baseItem.get("displayName")) {
|
|
|
|
setValue("name-choice", baseItem.get("displayName"));
|
|
|
|
}
|
|
|
|
|
2021-05-06 03:12:23 +00:00
|
|
|
//Take care of durability, duration, and charges.
|
2021-03-05 16:28:00 +00:00
|
|
|
if (baseItem.get("tier") === "Crafted") {
|
|
|
|
let specialIDs = ["duration", "durability"];
|
|
|
|
setValue("charges-choice", baseItem.get("charges"));
|
|
|
|
for (const id of specialIDs) {
|
|
|
|
setValue(id+"-choice", baseItem.get(id)[0]+"-"+baseItem.get(id)[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Don't do anything if nothing is met
|
|
|
|
calculateCustom();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the link
|
|
|
|
*/
|
2021-03-08 22:50:47 +00:00
|
|
|
function copyCustom() {
|
2021-03-05 16:28:00 +00:00
|
|
|
if (player_custom_item) {
|
|
|
|
copyTextToClipboard(custom_url_base+location.hash);
|
|
|
|
document.getElementById("copy-button").textContent = "Copied!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 22:49:17 +00:00
|
|
|
function copyHash() {
|
2021-03-08 22:50:47 +00:00
|
|
|
if (player_custom_item) {
|
2021-03-24 22:49:17 +00:00
|
|
|
let hash = player_custom_item.statMap.get("hash");
|
2021-03-08 22:50:47 +00:00
|
|
|
console.log(hash);
|
2021-03-24 22:49:17 +00:00
|
|
|
copyTextToClipboard(hash);
|
|
|
|
document.getElementById("copy-button-hash").textContent = "Copied!";
|
2021-03-08 22:50:47 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 16:28:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Reset all fields
|
|
|
|
*/
|
|
|
|
function resetFields() {
|
|
|
|
let inputs = document.getElementsByTagName('input');
|
|
|
|
for (const input of inputs) {
|
|
|
|
input.textContent = "";
|
|
|
|
input.value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
let elem = document.getElementById("fixID-choice")
|
|
|
|
if (elem.textContent === "yes") {
|
|
|
|
elem.textContent = "no";
|
|
|
|
elem.classList.remove("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Takes the base value for an id and attempts to autofill the corresponding min and maxes.
|
|
|
|
*
|
|
|
|
* @param {String} id - the id to do the math for (ex: hprPct)
|
|
|
|
*/
|
|
|
|
function base_to_range(id) {
|
|
|
|
let base = parseFloat(getValue(id+"-choice-base"));
|
|
|
|
if(base) {
|
|
|
|
//This version allows overriding of min and max.
|
2021-04-12 21:30:16 +00:00
|
|
|
if (reversedIDs.includes(id)) {
|
|
|
|
if (base < 0) {
|
|
|
|
setValue(id+"-choice-min", Math.min(Math.round(neg_range[1]*base),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-min", Math.max(Math.round(pos_range[1]*base),1));
|
|
|
|
}
|
|
|
|
if (base < 0) {
|
|
|
|
setValue(id+"-choice-max", Math.min(Math.round(neg_range[0]*base),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-max", Math.max(Math.round(pos_range[0]*base),1));
|
|
|
|
}
|
2021-03-05 16:28:00 +00:00
|
|
|
} else {
|
2021-04-12 21:30:16 +00:00
|
|
|
if (base < 0) {
|
|
|
|
setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]*base),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]*base),1));
|
|
|
|
}
|
|
|
|
if (base < 0) {
|
|
|
|
setValue(id+"-choice-max", Math.min(Math.round(neg_range[1]*base),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-max", Math.max(Math.round(pos_range[1]*base),1));
|
|
|
|
}
|
2021-03-05 16:28:00 +00:00
|
|
|
}
|
2021-04-12 21:30:16 +00:00
|
|
|
|
|
|
|
|
2021-03-05 16:28:00 +00:00
|
|
|
/* No overiding min/max version
|
|
|
|
if (!getValue(id+"-choice-min")) {
|
|
|
|
if (base < 0) {
|
|
|
|
setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]*base),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]*base),1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!getValue(id+"-choice-max")) {
|
|
|
|
if (base < 0) {
|
|
|
|
setValue(id+"-choice-max", Math.min(Math.round(neg_range[1]*base),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-max", Math.max(Math.round(pos_range[1]*base),1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Takes min/max value(s) and attempts to autofill the corresponding base and min/max
|
|
|
|
*
|
|
|
|
* @param {String} id - the id to do the math for (ex: hprPct)
|
|
|
|
* @param {String} mode - the tabbed value (min or max)
|
|
|
|
*/
|
|
|
|
function range_to_base(id, mode) {
|
|
|
|
let value;
|
|
|
|
try {
|
|
|
|
value = parseFloat(getValue(id+"-choice-"+mode));
|
|
|
|
} catch (error) {
|
|
|
|
console.log("Error in range_to_base.");
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode === "min") { //base and max
|
|
|
|
if (value && !getValue(id+"-choice-base")) {
|
|
|
|
if (value < 0) {
|
|
|
|
setValue(id+"-choice-base", Math.min(Math.round(1/neg_range[0]*value),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-base", Math.max(Math.round(1/pos_range[0]*value),1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value && !getValue(id+"-choice-max")) {
|
|
|
|
if (value < 0) {
|
|
|
|
setValue(id+"-choice-max", Math.min(Math.round(neg_range[1]/neg_range[0]*value),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-max", Math.max(Math.round(pos_range[1]/pos_range[0]*value),1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (mode === "max") { //min and base
|
|
|
|
if (value && !getValue(id+"-choice-base")) {
|
|
|
|
if (value < 0) {
|
|
|
|
setValue(id+"-choice-base", Math.min(Math.round(1/neg_range[1]*value),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-base", Math.max(Math.round(1/pos_range[1]*value),1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value && !getValue(id+"-choice-min")) {
|
|
|
|
if (value < 0) {
|
|
|
|
setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]/neg_range[1]*value),-1));
|
|
|
|
} else {
|
|
|
|
setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]/pos_range[1]*value),1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Uses the base value input fields and changes the base values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function changeBaseValues() {
|
|
|
|
for (const id of roll_range_ids) {
|
|
|
|
if (getValue(id)) {
|
|
|
|
if (id.includes("neg")) {
|
|
|
|
if (id.includes("min")) {
|
|
|
|
neg_range[0] = parseFloat(getValue(id));
|
|
|
|
} else {
|
|
|
|
neg_range[1] = parseFloat(getValue(id));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (id.includes("min")) {
|
|
|
|
pos_range[0] = parseFloat(getValue(id));
|
|
|
|
} else {
|
|
|
|
pos_range[1] = parseFloat(getValue(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const identification of rolledIDs) {
|
|
|
|
if (document.getElementById(identification)) {
|
|
|
|
base_to_range(identification);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetBaseValues() {
|
|
|
|
pos_range = [0.3,1.3];
|
|
|
|
neg_range = [1.3,0.7];
|
|
|
|
for (const id of roll_range_ids) {
|
|
|
|
setValue(id,"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 22:07:15 +00:00
|
|
|
function _init_customizer() {
|
|
|
|
load_ing_init(init_customizer);
|
|
|
|
}
|
|
|
|
|
2021-04-21 05:28:16 +00:00
|
|
|
/** Saves the current user's item as a JSON file.
|
|
|
|
* Starts a JSON download.
|
|
|
|
*/
|
|
|
|
function saveAsJSON() {
|
|
|
|
let CI = {};
|
|
|
|
for (const [id, val] of player_custom_item.statMap) {
|
2021-05-01 14:19:33 +00:00
|
|
|
let skipIds = ["minRolls", "maxRolls", "skillpoints", "reqs", "custom", "crafted", "restrict", "hash",
|
|
|
|
"nDam_", "tDam_", "eDam_", "wDam_", "fDam_", "aDam_",
|
|
|
|
"powders", "durability", "duration" ]
|
2021-04-30 01:30:59 +00:00
|
|
|
if (skipIds.includes(id)) {
|
2021-04-21 05:28:16 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
val ? CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = val : "" ;
|
|
|
|
}
|
|
|
|
}
|
2021-06-19 09:06:46 +00:00
|
|
|
let is_fixid = true;
|
2021-04-21 05:28:16 +00:00
|
|
|
if (player_custom_item.statMap.get("minRolls")) {
|
2021-06-19 09:06:46 +00:00
|
|
|
for (let [id, min] of player_custom_item.statMap.get("minRolls")) {
|
|
|
|
let max = player_custom_item.statMap.get("maxRolls").get(id);
|
2021-04-21 05:28:16 +00:00
|
|
|
if (min && max) {
|
2021-06-19 09:06:46 +00:00
|
|
|
let tmp = Math.min(min, max);
|
|
|
|
max = Math.max(min, max);
|
|
|
|
min = tmp;
|
|
|
|
if (min != max) {
|
|
|
|
is_fixid = false;
|
|
|
|
}
|
|
|
|
// console.log(reversetranslations);
|
2021-04-30 01:30:59 +00:00
|
|
|
let base = full_range_to_base(min, max);
|
|
|
|
if (base === null) {
|
|
|
|
CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = [min,max];
|
|
|
|
} else if (base) {
|
|
|
|
CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = base;
|
|
|
|
}
|
2021-06-19 09:06:46 +00:00
|
|
|
else {
|
|
|
|
console.log("CONVERSION ERROR: " + id);
|
|
|
|
}
|
2021-04-21 05:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-19 09:06:46 +00:00
|
|
|
CI["identified"] = is_fixid
|
2021-04-21 05:28:16 +00:00
|
|
|
|
2021-06-19 09:06:46 +00:00
|
|
|
console.log(JSON.stringify(CI, null, 0));
|
2021-04-21 05:28:16 +00:00
|
|
|
//yuck
|
2021-04-30 01:30:59 +00:00
|
|
|
copyTextToClipboard(JSON.stringify(CI, null, 0));
|
|
|
|
document.getElementById("json-button").textContent = "Copied!";
|
|
|
|
// let filename = player_custom_item.statMap.get("displayName");
|
|
|
|
// var element = document.createElement('a');
|
|
|
|
// element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(CI, null, 0)));
|
|
|
|
// element.setAttribute('download', filename + ".json");
|
|
|
|
|
|
|
|
// element.style.display = 'none';
|
|
|
|
// document.body.appendChild(element);
|
|
|
|
// element.click();
|
|
|
|
// document.body.removeChild(element);
|
2021-04-21 05:28:16 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 01:30:59 +00:00
|
|
|
/**Helper function
|
|
|
|
* Takes min, max, attempts to get the correct base. Returns null if no possible base or no base found.
|
|
|
|
*/
|
|
|
|
function full_range_to_base(min, max) {
|
|
|
|
//checks against the range
|
|
|
|
function checkBase(b, min, max) {
|
|
|
|
if ( b > 0 ) {
|
|
|
|
if (Math.round(pos_range[0] * b) == min && Math.round(pos_range[1] * b ) == max) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Math.round(neg_range[0] * b) == min && Math.round(neg_range[1] * b ) == max) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (min && max && min/max < 0) {
|
|
|
|
return null;
|
|
|
|
} else if (min == max) {
|
|
|
|
//0 shouldn't save but this is for -1 and 1
|
|
|
|
return min;
|
|
|
|
} else {
|
|
|
|
//both should be same sign - now do math
|
|
|
|
if (min < 0) {
|
2021-06-19 09:06:46 +00:00
|
|
|
let minPossible = (max - 0.5) / neg_range[1];
|
|
|
|
let maxPossible = (max + 0.5) / neg_range[1];
|
|
|
|
for (let i = Math.floor(minPossible); i < Math.ceil(maxPossible); i++) {
|
|
|
|
if (checkBase(i, min, max)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2021-04-30 01:30:59 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
let minPossible = (max - 0.5) / pos_range[1];
|
|
|
|
let maxPossible = (max + 0.5) / pos_range[1];
|
|
|
|
for (let i = Math.floor(minPossible); i < Math.ceil(maxPossible); i++) {
|
|
|
|
if (checkBase(i, min, max)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 22:07:15 +00:00
|
|
|
load_init(_init_customizer);
|