2021-03-05 16:28:00 +00:00
/ *
* TESTING SECTION
* /
const custom _url _base = location . href . split ( "#" ) [ 0 ] ;
const custom _url _tag = location . hash . slice ( 1 ) ;
console . log ( custom _url _base ) ;
console . log ( custom _url _tag ) ;
2021-04-01 04:38:07 +00:00
const CUSTOM _BUILD _VERSION = "7" ;
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 ( ) ;
/ *
* END testing section
* /
let player _custom _item ;
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 ] ;
2021-03-08 22:50:47 +00:00
2021-03-05 16:28:00 +00:00
let roll _range _ids = [ "neg_roll_range-choice-min" , "neg_roll_range-choice-max" , "pos_roll_range-choice-min" , "pos_roll_range-choice-max" ] ;
function init ( ) {
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 ) ;
}
}
/ * * C r e a t e a c u s t o m i t e m b a s e d o n d a t a i n p u t i n t o t h e f i e l d s .
*
* /
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 ) ;
} else { //rolled IDs!
for ( const input of inputs ) {
if ( input . id . includes ( "-fixed" ) ) {
continue ;
}
//FIXs
let id = input . id . replace ( "-choice" , "" ) ;
let rollMap = "" ;
//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 ;
2021-03-14 07:55:08 +00:00
custom _str = encodeCustom ( player _custom _item . statMap , true ) ;
2021-03-08 22:50:47 +00:00
player _custom _item . setHash ( custom _str ) ;
console . log ( player _custom _item . statMap . get ( "hash" ) ) ;
2021-03-05 16:28:00 +00:00
displayExpandedItem ( player _custom _item . statMap , "custom-stats" ) ;
2021-03-08 22:50:47 +00:00
2021-03-14 07:55:08 +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 ) ;
}
}
2021-03-08 22:50:47 +00:00
/ * *
* @ param { Map } custom - the statMap of the CI
* @ param { boolean } verbose - if we want lore and majorIds to display
* /
function encodeCustom ( custom , verbose ) {
if ( custom ) {
2021-03-14 07:55:08 +00:00
if ( custom . statMap ) {
custom = custom . statMap ;
}
2021-03-08 22:50:47 +00:00
let hash = "1" ;
//version 1
if ( custom . has ( "fixID" ) && custom . get ( "fixID" ) ) {
hash += "1" ;
} else {
hash += "0" ;
}
for ( const i in ci _save _order ) {
let id = ci _save _order [ i ] ;
if ( rolledIDs . includes ( id ) ) {
let val _min = custom . get ( "minRolls" ) . has ( id ) ? custom . get ( "minRolls" ) . get ( id ) : 0 ;
let val _max = custom . get ( "maxRolls" ) . has ( id ) ? custom . get ( "maxRolls" ) . get ( id ) : 0 ;
2021-03-14 07:55:08 +00:00
let sign = ( Boolean ( val _min / Math . abs ( val _min ) < 0 ) | 0 ) + 2 * ( Boolean ( val _max / Math . abs ( val _max ) < 0 ) | 0 ) // 0 - both pos 1 - min neg max pos 2 - min pos max neg (how?) 3 - min neg max neg
//console.log(id + ": " + sign);
2021-03-08 22:50:47 +00:00
let min _len = Math . max ( 1 , Math . ceil ( log ( 64 , Math . abs ( val _min ) ) ) ) ;
let max _len = Math . max ( 1 , Math . ceil ( log ( 64 , Math . abs ( val _max ) ) ) ) ;
let len = Math . max ( min _len , max _len ) ;
2021-03-14 07:55:08 +00:00
val _min = Math . abs ( val _min ) ;
val _max = Math . abs ( val _max ) ;
2021-03-08 22:50:47 +00:00
if ( val _min != 0 || val _max != 0 ) {
//hash += Base64.fromIntN(i,2) + Base64.fromIntN(val_min,Math.max(1,Math.ceil(log(64,Math.abs(val_min))))) + ":" + Base64.fromIntN(val_max,Math.max(1,Math.ceil(log(64,Math.abs(val_min))))) + "_";
if ( custom . get ( "fixID" ) ) {
2021-03-14 07:55:08 +00:00
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( len , 2 ) + sign + Base64 . fromIntN ( val _min , len ) ;
2021-03-08 22:50:47 +00:00
} else {
2021-03-14 07:55:08 +00:00
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( len , 2 ) + sign + Base64 . fromIntN ( val _min , len ) + Base64 . fromIntN ( val _max , len ) ;
2021-03-08 22:50:47 +00:00
}
}
} else {
let damages = [ "nDam" , "eDam" , "tDam" , "wDam" , "fDam" , "aDam" , "nDam_" , "eDam_" , "tDam_" , "wDam_" , "fDam_" , "aDam_" ] ;
let val = custom . get ( id ) ;
2021-03-14 07:55:08 +00:00
2021-03-08 22:50:47 +00:00
if ( typeof ( val ) === "string" && val !== "" ) {
2021-03-14 07:55:08 +00:00
if ( ( damages . includes ( id ) && val === "0-0" ) || ( ! verbose && [ "lore" , "majorIds" , "quest" , "materials" , "drop" , "set" ] . includes ( id ) ) ) { continue ; }
2021-03-08 22:50:47 +00:00
if ( id === "type" ) {
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( types . indexOf ( val . substring ( 0 , 1 ) . toUpperCase ( ) + val . slice ( 1 ) ) , 1 ) ;
} else if ( id === "tier" ) {
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( tiers . indexOf ( val ) , 1 ) ;
} else if ( id === "atkSpd" ) {
2021-03-14 07:55:08 +00:00
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( attackSpeeds . indexOf ( val ) , 1 ) ;
} else if ( id === "classReq" ) {
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( classes . indexOf ( val ) , 1 ) ;
2021-03-08 22:50:47 +00:00
} else {
2021-03-14 07:55:08 +00:00
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( val . replaceAll ( " " , "%20" ) . length , 2 ) + val . replaceAll ( " " , "%20" ) ; //values cannot go above 4096 chars!!!! Is this ok?
2021-03-08 22:50:47 +00:00
}
} else if ( typeof ( val ) === "number" && val != 0 ) {
let len = Math . max ( 1 , Math . ceil ( log ( 64 , Math . abs ( val ) ) ) ) ;
2021-03-14 07:55:08 +00:00
let sign = Boolean ( val / Math . abs ( val ) < 0 ) | 0 ;
//console.log(sign);
2021-03-08 22:50:47 +00:00
//hash += Base64.fromIntN(i,2) + Base64.fromIntN(val,Math.max(1,Math.ceil(log(64,Math.abs(val))))) + "_";
2021-03-14 07:55:08 +00:00
hash += Base64 . fromIntN ( i , 2 ) + Base64 . fromIntN ( len , 2 ) + sign + Base64 . fromIntN ( Math . abs ( val ) , len ) ;
2021-03-08 22:50:47 +00:00
}
}
}
return hash ;
}
2021-03-05 16:28:00 +00:00
return "" ;
}
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 ) ) ] ;
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 ( ) {
/ * E x
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 ) ;
}
}
/ * T o g g l e s O N E b u t t o n
* /
function toggleButton ( buttonId ) {
let elem = document . getElementById ( buttonId ) ;
if ( elem . classList . contains ( "toggleOn" ) ) {
elem . classList . remove ( "toggleOn" ) ;
} else {
elem . classList . add ( "toggleOn" ) ;
}
}
/ * C h a n g e s a n e l e m e n t ' s t e x t c o n t e n t f r o m y e s t o n o o r v i c e v e r s a
* /
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 = "" ;
}
}
}
}
/ * * M a k e a c u s t o m i t e m
*
* @ 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 ) ) ;
}
}
//Take care of durability, duration, and charges.
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 ( ) ;
}
/ * C o p y t h e l i n k
* /
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
/ * R e s e t a l l f i e l d s
* /
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" ) ;
}
}
/ * * T a k e s t h e b a s e v a l u e f o r a n i d a n d a t t e m p t s t o a u t o f i l l t h e c o r r e s p o n d i n g m i n a n d m a x e s .
*
* @ 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.
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 ) ) ;
}
/ * N o o v e r i d i n g m i n / m a x v e r s i o n
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 ) ) ;
}
}
* /
}
}
/ * * T a k e s m i n / m a x v a l u e ( s ) a n d a t t e m p t s t o a u t o f i l l t h e c o r r e s p o n d i n g b a s e a n d m i n / m a x
*
* @ 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 ) ) ;
}
}
}
}
/ * * U s e s t h e b a s e v a l u e i n p u t f i e l d s a n d c h a n g e s t h e b a s e v a l u e s .
*
* /
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 , "" ) ;
}
}
load _init ( init ) ;
load _ing _init ( init ) ;