2021-01-07 10:23:54 +00:00
const url _tag = location . hash . slice ( 1 ) ;
2021-04-02 17:44:54 +00:00
// console.log(url_base);
// console.log(url_tag);
2021-01-07 00:36:11 +00:00
2021-04-01 04:38:07 +00:00
2021-09-06 20:49:12 +00:00
const BUILD _VERSION = "7.0.19" ;
2021-01-07 10:30:23 +00:00
2021-01-12 23:14:12 +00:00
function setTitle ( ) {
2021-01-20 06:22:55 +00:00
let text ;
if ( url _base . includes ( "hppeng-wynn" ) ) {
text = "WynnBuilder UNSTABLE version " + BUILD _VERSION + " (db version " + DB _VERSION + ")" ;
}
else {
text = "WynnBuilder version " + BUILD _VERSION + " (db version " + DB _VERSION + ")" ;
document . getElementById ( "header" ) . classList . add ( "funnynumber" ) ;
}
document . getElementById ( "header" ) . textContent = text ;
2021-01-12 23:14:12 +00:00
}
setTitle ( ) ;
2021-01-07 10:30:23 +00:00
2021-01-07 00:04:16 +00:00
let player _build ;
2021-01-30 08:50:25 +00:00
2021-01-09 03:53:57 +00:00
// THIS IS SUPER DANGEROUS, WE SHOULD NOT BE KEEPING THIS IN SO MANY PLACES
2021-01-18 14:18:14 +00:00
let editable _item _fields = [ "sdPct" , "sdRaw" , "mdPct" , "mdRaw" , "poison" , "fDamPct" , "wDamPct" , "aDamPct" , "tDamPct" , "eDamPct" , "fDefPct" , "wDefPct" , "aDefPct" , "tDefPct" , "eDefPct" , "hprRaw" , "hprPct" , "hpBonus" , "atkTier" , "spPct1" , "spRaw1" , "spPct2" , "spRaw2" , "spPct3" , "spRaw3" , "spPct4" , "spRaw4" ] ;
2021-01-09 08:52:58 +00:00
2021-01-19 11:56:09 +00:00
let editable _elems = [ ] ;
for ( let i of editable _item _fields ) {
let elem = document . getElementById ( i ) ;
elem . addEventListener ( "change" , ( event ) => {
elem . classList . add ( "highlight" ) ;
} ) ;
editable _elems . push ( elem ) ;
}
for ( let i of skp _order ) {
let elem = document . getElementById ( i + "-skp" ) ;
elem . addEventListener ( "change" , ( event ) => {
elem . classList . add ( "highlight" ) ;
} ) ;
editable _elems . push ( elem ) ;
}
function clear _highlights ( ) {
for ( let i of editable _elems ) {
i . classList . remove ( "highlight" ) ;
}
}
2021-01-18 20:23:37 +00:00
2021-01-08 20:17:37 +00:00
2021-01-09 03:53:57 +00:00
let equipment _fields = [
"helmet" ,
"chestplate" ,
"leggings" ,
"boots" ,
"ring1" ,
"ring2" ,
"bracelet" ,
"necklace" ,
"weapon"
] ;
let equipment _names = [
"Helmet" ,
"Chestplate" ,
"Leggings" ,
"Boots" ,
"Ring 1" ,
"Ring 2" ,
"Bracelet" ,
"Necklace" ,
"Weapon"
] ;
let equipmentInputs = equipment _fields . map ( x => x + "-choice" ) ;
let buildFields = equipment _fields . map ( x => "build-" + x ) ;
2021-01-08 20:17:37 +00:00
let powderInputs = [
"helmet-powder" ,
"chestplate-powder" ,
"leggings-powder" ,
"boots-powder" ,
"weapon-powder" ,
] ;
2021-01-11 06:49:52 +00:00
2021-03-14 07:55:08 +00:00
2021-01-06 12:48:41 +00:00
2021-01-06 22:51:02 +00:00
/ *
* Function that takes an item list and populates its corresponding dropdown .
* Used for armors and bracelet / necklace .
* /
2021-01-06 12:48:41 +00:00
function populateItemList ( type ) {
let item _list = document . getElementById ( type + "-items" ) ;
for ( const item of itemLists . get ( type ) ) {
2021-03-19 10:00:01 +00:00
let item _obj = itemMap . get ( item ) ;
if ( item _obj [ "restrict" ] && item _obj [ "restrict" ] === "DEPRECATED" ) {
continue ;
}
2021-01-06 12:48:41 +00:00
let el = document . createElement ( "option" ) ;
el . value = item ;
item _list . appendChild ( el ) ;
}
}
2021-01-06 22:51:02 +00:00
/ *
* Populate dropdowns , add listeners , etc .
* /
2021-01-06 12:48:41 +00:00
function init ( ) {
2021-04-02 22:07:15 +00:00
console . log ( "builder.js init" ) ;
2021-01-06 12:48:41 +00:00
for ( const armorType of armorTypes ) {
populateItemList ( armorType ) ;
2021-01-06 22:51:02 +00:00
// Add change listener to update armor slots.
2021-01-06 12:48:41 +00:00
document . getElementById ( armorType + "-choice" ) . addEventListener ( "change" , ( event ) => {
2021-02-04 10:55:15 +00:00
let item _name = event . target . value ;
let nSlots = undefined ;
if ( itemMap . has ( item _name ) ) {
let item = itemMap . get ( item _name ) ;
nSlots = item [ "slots" ] ;
2021-03-14 07:55:08 +00:00
//console.log(item);
2021-02-04 10:55:15 +00:00
}
else {
2021-03-14 07:55:08 +00:00
let crafted _custom _item = getCraftFromHash ( item _name ) !== undefined ? getCraftFromHash ( item _name ) : ( getCustomFromHash ( item _name ) !== undefined ? getCustomFromHash ( item _name ) : undefined ) ;
if ( crafted _custom _item !== undefined ) {
nSlots = crafted _custom _item . statMap . get ( "slots" ) ;
}
2021-02-04 10:55:15 +00:00
}
if ( nSlots !== undefined ) {
document . getElementById ( armorType + "-slots" ) . textContent = nSlots + " slots" ;
2021-01-06 12:48:41 +00:00
}
else {
document . getElementById ( armorType + "-slots" ) . textContent = "X slots" ;
}
} ) ;
}
let ring1 _list = document . getElementById ( "ring1-items" ) ;
let ring2 _list = document . getElementById ( "ring2-items" ) ;
for ( const ring of itemLists . get ( "ring" ) ) {
2021-03-19 10:00:01 +00:00
let item _obj = itemMap . get ( ring ) ;
if ( item _obj [ "restrict" ] && item _obj [ "restrict" ] === "DEPRECATED" ) {
continue ;
}
2021-01-06 12:48:41 +00:00
let el1 = document . createElement ( "option" ) ;
let el2 = document . createElement ( "option" ) ;
el1 . value = ring ;
el2 . value = ring ;
ring1 _list . appendChild ( el1 ) ;
ring2 _list . appendChild ( el2 ) ;
}
populateItemList ( "bracelet" ) ;
populateItemList ( "necklace" ) ;
let weapon _list = document . getElementById ( "weapon-items" ) ;
for ( const weaponType of weaponTypes ) {
for ( const weapon of itemLists . get ( weaponType ) ) {
2021-03-19 10:00:01 +00:00
let item _obj = itemMap . get ( weapon ) ;
if ( item _obj [ "restrict" ] && item _obj [ "restrict" ] === "DEPRECATED" ) {
continue ;
}
2021-01-06 12:48:41 +00:00
let el = document . createElement ( "option" ) ;
el . value = weapon ;
weapon _list . appendChild ( el ) ;
}
}
2021-01-06 22:51:02 +00:00
// Add change listener to update weapon slots.
2021-01-06 12:48:41 +00:00
document . getElementById ( "weapon-choice" ) . addEventListener ( "change" , ( event ) => {
2021-03-14 07:55:08 +00:00
let item _name = event . target . value ;
let item = itemMap . has ( item _name ) ? itemMap . get ( item _name ) : ( getCraftFromHash ( item _name ) ? getCraftFromHash ( item _name ) : ( getCustomFromHash ( item _name ) ? getCustomFromHash ( item _name ) : undefined ) ) ;
2021-01-30 08:50:25 +00:00
if ( item !== undefined && event . target . value !== "" ) {
2021-03-14 07:55:08 +00:00
document . getElementById ( "weapon-slots" ) . textContent = ( item [ "slots" ] ? item [ "slots" ] : ( item . statMap !== undefined ? ( item . statMap . has ( "slots" ) ? item . statMap . get ( "slots" ) : 0 ) : 0 ) ) + " slots" ;
2021-01-30 08:50:25 +00:00
} else {
2021-01-06 12:48:41 +00:00
document . getElementById ( "weapon-slots" ) . textContent = "X slots" ;
}
} ) ;
2021-01-07 10:23:54 +00:00
2021-01-11 12:09:58 +00:00
decodeBuild ( url _tag ) ;
2021-10-01 02:00:11 +00:00
populateBuildList ( ) ;
2021-01-07 10:23:54 +00:00
}
2021-01-23 10:53:24 +00:00
function getItemNameFromID ( id ) {
if ( redirectMap . has ( id ) ) {
return getItemNameFromID ( redirectMap . get ( id ) ) ;
}
return idMap . get ( id ) ;
}
2021-01-30 11:06:16 +00:00
function parsePowdering ( powder _info ) {
// TODO: Make this run in linear instead of quadratic time... ew
let powdering = [ ] ;
for ( let i = 0 ; i < 5 ; ++ i ) {
let powders = "" ;
let n _blocks = Base64 . toInt ( powder _info . charAt ( 0 ) ) ;
console . log ( n _blocks + " blocks" ) ;
powder _info = powder _info . slice ( 1 ) ;
for ( let j = 0 ; j < n _blocks ; ++ j ) {
let block = powder _info . slice ( 0 , 5 ) ;
console . log ( block ) ;
let six _powders = Base64 . toInt ( block ) ;
for ( let k = 0 ; k < 6 && six _powders != 0 ; ++ k ) {
powders += powderNames . get ( ( six _powders & 0x1f ) - 1 ) ;
six _powders >>>= 5 ;
}
powder _info = powder _info . slice ( 5 ) ;
}
powdering [ i ] = powders ;
}
return powdering ;
}
2021-01-07 10:23:54 +00:00
/ *
* Populate fields based on url , and calculate build .
* /
2021-01-11 12:09:58 +00:00
function decodeBuild ( url _tag ) {
2021-01-07 10:23:54 +00:00
if ( url _tag ) {
2021-01-09 03:53:57 +00:00
let equipment = [ null , null , null , null , null , null , null , null , null ] ;
2021-01-08 20:17:37 +00:00
let powdering = [ "" , "" , "" , "" , "" ] ;
2021-01-07 10:30:23 +00:00
let info = url _tag . split ( "_" ) ;
2021-01-07 10:23:54 +00:00
let version = info [ 0 ] ;
2021-01-09 08:52:58 +00:00
let save _skp = false ;
let skillpoints = [ 0 , 0 , 0 , 0 , 0 ] ;
2021-01-11 00:08:14 +00:00
let level = 106 ;
if ( version === "0" || version === "1" || version === "2" || version === "3" ) {
2021-01-07 10:23:54 +00:00
let equipments = info [ 1 ] ;
2021-01-09 03:53:57 +00:00
for ( let i = 0 ; i < 9 ; ++ i ) {
2021-01-30 11:06:16 +00:00
let equipment _str = equipments . slice ( i * 3 , i * 3 + 3 ) ;
equipment [ i ] = getItemNameFromID ( Base64 . toInt ( equipment _str ) ) ;
2021-01-09 03:53:57 +00:00
}
2021-01-30 11:06:16 +00:00
info [ 1 ] = equipments . slice ( 27 ) ;
}
2021-03-14 07:55:08 +00:00
if ( version === "4" ) {
2021-01-30 11:06:16 +00:00
let info _str = info [ 1 ] ;
let start _idx = 0 ;
for ( let i = 0 ; i < 9 ; ++ i ) {
if ( info _str . charAt ( start _idx ) === "-" ) {
equipment [ i ] = "CR-" + info _str . slice ( start _idx + 1 , start _idx + 18 ) ;
start _idx += 18 ;
}
else {
let equipment _str = info _str . slice ( start _idx , start _idx + 3 ) ;
equipment [ i ] = getItemNameFromID ( Base64 . toInt ( equipment _str ) ) ;
start _idx += 3 ;
2021-01-08 20:17:37 +00:00
}
}
2021-01-30 11:06:16 +00:00
info [ 1 ] = info _str . slice ( start _idx ) ;
}
2021-03-14 07:55:08 +00:00
if ( version === "5" ) {
let info _str = info [ 1 ] ;
let start _idx = 0 ;
for ( let i = 0 ; i < 9 ; ++ i ) {
if ( info _str . slice ( start _idx , start _idx + 3 ) === "CR-" ) {
equipment [ i ] = info _str . slice ( start _idx , start _idx + 20 ) ;
start _idx += 20 ;
} else if ( info _str . slice ( start _idx + 3 , start _idx + 6 ) === "CI-" ) {
let len = Base64 . toInt ( info _str . slice ( start _idx , start _idx + 3 ) ) ;
equipment [ i ] = info _str . slice ( start _idx + 3 , start _idx + 3 + len ) ;
start _idx += ( 3 + len ) ;
} else {
let equipment _str = info _str . slice ( start _idx , start _idx + 3 ) ;
equipment [ i ] = getItemNameFromID ( Base64 . toInt ( equipment _str ) ) ;
start _idx += 3 ;
}
}
info [ 1 ] = info _str . slice ( start _idx ) ;
}
2021-01-30 11:06:16 +00:00
if ( version === "1" ) {
let powder _info = info [ 1 ] ;
powdering = parsePowdering ( powder _info ) ;
2021-01-30 08:50:25 +00:00
} else if ( version === "2" ) {
2021-01-09 08:52:58 +00:00
save _skp = true ;
2021-01-30 11:06:16 +00:00
let skillpoint _info = info [ 1 ] . slice ( 0 , 10 ) ;
2021-01-09 08:52:58 +00:00
for ( let i = 0 ; i < 5 ; ++ i ) {
2021-01-09 09:09:47 +00:00
skillpoints [ i ] = Base64 . toIntSigned ( skillpoint _info . slice ( i * 2 , i * 2 + 2 ) ) ;
2021-01-09 08:52:58 +00:00
}
2021-01-30 11:06:16 +00:00
let powder _info = info [ 1 ] . slice ( 10 ) ;
powdering = parsePowdering ( powder _info ) ;
2021-03-14 07:55:08 +00:00
} else if ( version === "3" || version === "4" || version === "5" ) {
2021-01-30 11:06:16 +00:00
level = Base64 . toInt ( info [ 1 ] . slice ( 10 , 12 ) ) ;
2021-01-11 00:08:14 +00:00
setValue ( "level-choice" , level ) ;
save _skp = true ;
2021-01-30 11:06:16 +00:00
let skillpoint _info = info [ 1 ] . slice ( 0 , 10 ) ;
2021-01-11 00:08:14 +00:00
for ( let i = 0 ; i < 5 ; ++ i ) {
skillpoints [ i ] = Base64 . toIntSigned ( skillpoint _info . slice ( i * 2 , i * 2 + 2 ) ) ;
}
2021-01-07 10:23:54 +00:00
2021-01-30 11:06:16 +00:00
let powder _info = info [ 1 ] . slice ( 12 ) ;
powdering = parsePowdering ( powder _info ) ;
2021-01-11 00:08:14 +00:00
}
2021-01-30 11:06:16 +00:00
2021-01-09 03:53:57 +00:00
for ( let i in powderInputs ) {
setValue ( powderInputs [ i ] , powdering [ i ] ) ;
}
for ( let i in equipment ) {
setValue ( equipmentInputs [ i ] , equipment [ i ] ) ;
}
2021-01-09 08:52:58 +00:00
calculateBuild ( save _skp , skillpoints ) ;
2021-01-07 10:23:54 +00:00
}
}
2021-01-12 07:11:20 +00:00
/ * S t o r e s t h e e n t i r e b u i l d i n a s t r i n g u s i n g B 6 4 e n c r y p t i o n a n d a d d s i t t o t h e U R L .
* /
2021-01-07 10:23:54 +00:00
function encodeBuild ( ) {
2021-03-24 05:48:49 +00:00
2021-01-07 10:23:54 +00:00
if ( player _build ) {
2021-03-24 05:48:49 +00:00
let build _string ;
if ( player _build . customItems . length > 0 ) { //v5 encoding
build _string = "5_" ;
let crafted _idx = 0 ;
let custom _idx = 0 ;
for ( const item of player _build . items ) {
if ( item . get ( "custom" ) ) {
let custom = "CI-" + encodeCustom ( player _build . customItems [ custom _idx ] , true ) ;
build _string += Base64 . fromIntN ( custom . length , 3 ) + custom ;
custom _idx += 1 ;
} else if ( item . get ( "crafted" ) ) {
build _string += "CR-" + encodeCraft ( player _build . craftedItems [ crafted _idx ] ) ;
crafted _idx += 1 ;
} else {
build _string += Base64 . fromIntN ( item . get ( "id" ) , 3 ) ;
}
2021-01-30 11:06:16 +00:00
}
2021-03-24 05:48:49 +00:00
for ( const skp of skp _order ) {
build _string += Base64 . fromIntN ( getValue ( skp + "-skp" ) , 2 ) ; // Maximum skillpoints: 2048
}
build _string += Base64 . fromIntN ( player _build . level , 2 ) ;
for ( const _powderset of player _build . powders ) {
let n _bits = Math . ceil ( _powderset . length / 6 ) ;
build _string += Base64 . fromIntN ( n _bits , 1 ) ; // Hard cap of 378 powders.
// Slice copy.
let powderset = _powderset . slice ( ) ;
while ( powderset . length != 0 ) {
let firstSix = powderset . slice ( 0 , 6 ) . reverse ( ) ;
let powder _hash = 0 ;
for ( const powder of firstSix ) {
powder _hash = ( powder _hash << 5 ) + 1 + powder ; // LSB will be extracted first.
}
build _string += Base64 . fromIntN ( powder _hash , 5 ) ;
powderset = powderset . slice ( 6 ) ;
}
}
} else { //v4 encoding
build _string = "4_" ;
let crafted _idx = 0 ;
for ( const item of player _build . items ) {
if ( item . get ( "crafted" ) ) {
build _string += "-" + encodeCraft ( player _build . craftedItems [ crafted _idx ] ) ;
crafted _idx += 1 ;
} else {
build _string += Base64 . fromIntN ( item . get ( "id" ) , 3 ) ;
}
}
for ( const skp of skp _order ) {
build _string += Base64 . fromIntN ( getValue ( skp + "-skp" ) , 2 ) ; // Maximum skillpoints: 2048
}
build _string += Base64 . fromIntN ( player _build . level , 2 ) ;
for ( const _powderset of player _build . powders ) {
let n _bits = Math . ceil ( _powderset . length / 6 ) ;
build _string += Base64 . fromIntN ( n _bits , 1 ) ; // Hard cap of 378 powders.
// Slice copy.
let powderset = _powderset . slice ( ) ;
while ( powderset . length != 0 ) {
let firstSix = powderset . slice ( 0 , 6 ) . reverse ( ) ;
let powder _hash = 0 ;
for ( const powder of firstSix ) {
powder _hash = ( powder _hash << 5 ) + 1 + powder ; // LSB will be extracted first.
}
build _string += Base64 . fromIntN ( powder _hash , 5 ) ;
powderset = powderset . slice ( 6 ) ;
2021-01-08 20:17:37 +00:00
}
}
}
2021-01-07 10:23:54 +00:00
return build _string ;
}
2021-03-24 05:48:49 +00:00
// this.equipment = [ this.helmet, this.chestplate, this.leggings, this.boots, this.ring1, this.ring2, this.bracelet, this.necklace ];
// let build_string = "3_" + Base64.fromIntN(player_build.helmet.get("id"), 3) +
// Base64.fromIntN(player_build.chestplate.get("id"), 3) +
// Base64.fromIntN(player_build.leggings.get("id"), 3) +
// Base64.fromIntN(player_build.boots.get("id"), 3) +
// Base64.fromIntN(player_build.ring1.get("id"), 3) +
// Base64.fromIntN(player_build.ring2.get("id"), 3) +
// Base64.fromIntN(player_build.bracelet.get("id"), 3) +
// Base64.fromIntN(player_build.necklace.get("id"), 3) +
// Base64.fromIntN(player_build.weapon.get("id"), 3);
2021-01-07 10:23:54 +00:00
return "" ;
2021-01-06 12:48:41 +00:00
}
2021-01-09 08:52:58 +00:00
function calculateBuild ( save _skp , skp ) {
2021-01-12 23:14:12 +00:00
try {
2021-03-14 08:28:24 +00:00
let specialNames = [ "Quake" , "Chain_Lightning" , "Curse" , "Courage" , "Wind_Prison" ] ;
2021-01-13 19:55:13 +00:00
for ( const sName of specialNames ) {
for ( let i = 1 ; i < 6 ; i ++ ) {
let elem = document . getElementById ( sName + "-" + i ) ;
let name = sName . replace ( "_" , " " ) ;
if ( elem . classList . contains ( "toggleOn" ) ) { //toggle the pressed button off
elem . classList . remove ( "toggleOn" ) ;
}
}
}
if ( player _build ) {
2021-01-19 17:50:34 +00:00
updateBoosts ( "skip" , false ) ;
updatePowderSpecials ( "skip" , false ) ;
2021-01-13 19:55:13 +00:00
}
2021-02-17 07:17:09 +00:00
let weaponName = getValue ( equipmentInputs [ 8 ] ) ;
if ( weaponName . startsWith ( "Morph-" ) ) {
let equipment = [ "Morph-Stardust" , "Morph-Steel" , "Morph-Iron" , "Morph-Gold" , "Morph-Topaz" , "Morph-Emerald" , "Morph-Amethyst" , "Morph-Ruby" , weaponName . substring ( 6 ) ] ;
for ( let i in equipment ) {
setValue ( equipmentInputs [ i ] , equipment [ i ] ) ;
}
}
2021-01-13 19:55:13 +00:00
//updatePowderSpecials("skip"); //jank pt 1
2021-01-12 23:14:12 +00:00
save _skp = ( typeof save _skp !== 'undefined' ) ? save _skp : false ;
/ * T O D O : i m p l e m e n t l e v e l c h a n g i n g
Make this entire function prettier
* /
let equipment = [ null , null , null , null , null , null , null , null , null ] ;
for ( let i in equipment ) {
2021-05-01 14:19:33 +00:00
let equip = getValue ( equipmentInputs [ i ] ) . trim ( ) ;
2021-05-01 14:22:16 +00:00
if ( equip === "" ) {
equip = "No " + equipment _names [ i ]
}
else {
setValue ( equipmentInputs [ i ] , equip ) ;
}
2021-01-12 23:14:12 +00:00
equipment [ i ] = equip ;
}
let powderings = [ ] ;
2021-01-17 21:01:20 +00:00
let errors = [ ] ;
2021-01-12 23:14:12 +00:00
for ( const i in powderInputs ) {
// read in two characters at a time.
// TODO: make this more robust.
2021-05-01 14:19:33 +00:00
let input = getValue ( powderInputs [ i ] ) . trim ( ) ;
2021-01-12 23:14:12 +00:00
let powdering = [ ] ;
2021-01-18 04:32:58 +00:00
let errorederrors = [ ] ;
2021-01-12 23:14:12 +00:00
while ( input ) {
let first = input . slice ( 0 , 2 ) ;
let powder = powderIDs . get ( first ) ;
console . log ( powder ) ;
if ( powder === undefined ) {
2021-01-18 04:32:58 +00:00
errorederrors . push ( first ) ;
} else {
powdering . push ( powder ) ;
2021-01-12 23:14:12 +00:00
}
input = input . slice ( 2 ) ;
}
2021-01-18 04:32:58 +00:00
if ( errorederrors . length > 0 ) {
if ( errorederrors . length > 1 )
errors . push ( new IncorrectInput ( errorederrors . join ( "" ) , "t6w6" , powderInputs [ i ] ) ) ;
else
errors . push ( new IncorrectInput ( errorederrors [ 0 ] , "t6 or e3" , powderInputs [ i ] ) ) ;
2021-01-17 21:01:20 +00:00
}
2021-03-14 07:55:08 +00:00
//console.log("POWDERING: " + powdering);
2021-01-12 23:14:12 +00:00
powderings . push ( powdering ) ;
}
2021-01-17 21:01:20 +00:00
2021-01-11 00:08:14 +00:00
2021-01-30 08:50:25 +00:00
let level = document . getElementById ( "level-choice" ) . value ;
player _build = new Build ( level , equipment , powderings , new Map ( ) , errors ) ;
console . log ( player _build ) ;
2021-01-14 02:13:41 +00:00
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" ;
2021-01-18 10:14:08 +00:00
}
2021-01-13 01:38:13 +00:00
2021-01-12 23:14:12 +00:00
console . log ( player _build . toString ( ) ) ;
displayEquipOrder ( document . getElementById ( "build-order" ) , player _build . equip _order ) ;
2021-01-07 06:41:41 +00:00
2021-01-12 23:14:12 +00:00
2021-01-09 11:21:46 +00:00
2021-01-12 23:14:12 +00:00
const assigned = player _build . base _skillpoints ;
const skillpoints = player _build . total _skillpoints ;
for ( let i in skp _order ) { //big bren
setText ( skp _order [ i ] + "-skp-base" , "Original Value: " + skillpoints [ i ] ) ;
}
2021-01-18 14:18:14 +00:00
for ( let id of editable _item _fields ) {
setValue ( id , player _build . statMap . get ( id ) ) ;
setText ( id + "-base" , "Original Value: " + player _build . statMap . get ( id ) ) ;
}
2021-01-12 23:14:12 +00:00
if ( save _skp ) {
// TODO: reduce duplicated code, @updateStats
let skillpoints = player _build . total _skillpoints ;
let delta _total = 0 ;
for ( let i in skp _order ) {
let manual _assigned = skp [ i ] ;
let delta = manual _assigned - skillpoints [ i ] ;
skillpoints [ i ] = manual _assigned ;
player _build . base _skillpoints [ i ] += delta ;
delta _total += delta ;
}
player _build . assigned _skillpoints += delta _total ;
}
calculateBuildStats ( ) ;
setTitle ( ) ;
2021-01-17 21:01:20 +00:00
if ( player _build . errored )
throw new ListError ( player _build . errors ) ;
2021-01-11 23:43:04 +00:00
}
2021-01-12 23:14:12 +00:00
catch ( error ) {
2021-07-27 10:04:12 +00:00
handleBuilderError ( error ) ;
}
}
function handleBuilderError ( error ) {
if ( error instanceof ListError ) {
for ( let i of error . errors ) {
if ( i instanceof ItemNotFound ) {
i . element . textContent = i . message ;
} else if ( i instanceof IncorrectInput ) {
if ( document . getElementById ( i . id ) !== null ) {
document . getElementById ( i . id ) . parentElement . querySelectorAll ( "p.error" ) [ 0 ] . textContent = i . message ;
2021-01-17 21:01:20 +00:00
}
2021-07-27 10:04:12 +00:00
} else {
let msg = i . 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-01-17 21:01:20 +00:00
}
2021-01-09 08:52:58 +00:00
}
2021-07-27 10:04:12 +00:00
} else {
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-01-09 08:52:58 +00:00
}
}
2021-01-12 07:11:20 +00:00
/ * U p d a t e s a l l b u i l d s t a t i s t i c s b a s e d o n ( f o r n o w ) t h e s k i l l p o i n t i n p u t f i e l d s a n d t h e n c a l c u l a t e s b u i l d s t a t s .
* /
2021-01-09 08:52:58 +00:00
function updateStats ( ) {
2021-01-15 18:20:17 +00:00
2021-03-14 08:28:24 +00:00
let specialNames = [ "Quake" , "Chain_Lightning" , "Curse" , "Courage" , "Wind_Prison" ] ;
2021-01-14 03:17:01 +00:00
for ( const sName of specialNames ) {
for ( let i = 1 ; i < 6 ; i ++ ) {
let elem = document . getElementById ( sName + "-" + i ) ;
let name = sName . replace ( "_" , " " ) ;
if ( elem . classList . contains ( "toggleOn" ) ) { //toggle the pressed button off
elem . classList . remove ( "toggleOn" ) ;
let special = powderSpecialStats [ specialNames . indexOf ( sName ) ] ;
console . log ( special ) ;
if ( special [ "weaponSpecialEffects" ] . has ( "Damage Boost" ) ) {
if ( name === "Courage" || name === "Curse" ) { //courage is universal damage boost
//player_build.damageMultiplier -= special.weaponSpecialEffects.get("Damage Boost")[i-1]/100;
player _build . externalStats . set ( "sdPct" , player _build . externalStats . get ( "sdPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
player _build . externalStats . set ( "mdPct" , player _build . externalStats . get ( "mdPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
2021-01-14 06:58:32 +00:00
player _build . externalStats . set ( "poisonPct" , player _build . externalStats . get ( "poisonPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
2021-03-14 08:28:24 +00:00
} else if ( name === "Wind Prison" ) {
2021-01-14 03:17:01 +00:00
player _build . externalStats . set ( "aDamPct" , player _build . externalStats . get ( "aDamPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
player _build . externalStats . get ( "damageBonus" ) [ 4 ] -= special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ;
}
}
}
}
}
2021-01-15 18:20:17 +00:00
2021-01-14 03:17:01 +00:00
2021-02-20 05:22:19 +00:00
2021-01-09 08:52:58 +00:00
let skillpoints = player _build . total _skillpoints ;
let delta _total = 0 ;
for ( let i in skp _order ) {
2021-01-14 06:58:32 +00:00
let value = document . getElementById ( skp _order [ i ] + "-skp" ) . value ;
2021-04-18 00:19:42 +00:00
if ( value === "" ) { value = 0 ; setValue ( skp _order [ i ] + "-skp" , value ) }
2021-01-14 06:58:32 +00:00
let manual _assigned = 0 ;
if ( value . includes ( "+" ) ) {
let skp = value . split ( "+" ) ;
for ( const s of skp ) {
manual _assigned += parseInt ( s , 10 ) ;
}
2021-01-14 08:10:46 +00:00
} else {
2021-01-14 06:58:32 +00:00
manual _assigned = parseInt ( value , 10 ) ;
}
2021-01-09 08:52:58 +00:00
let delta = manual _assigned - skillpoints [ i ] ;
skillpoints [ i ] = manual _assigned ;
player _build . base _skillpoints [ i ] += delta ;
delta _total += delta ;
}
player _build . assigned _skillpoints += delta _total ;
2021-01-15 18:20:17 +00:00
if ( player _build ) {
2021-01-18 14:18:14 +00:00
updatePowderSpecials ( "skip" , false ) ;
updateBoosts ( "skip" , false ) ;
2021-01-15 18:20:17 +00:00
}
2021-01-18 14:18:14 +00:00
for ( let id of editable _item _fields ) {
player _build . statMap . set ( id , parseInt ( getValue ( id ) ) ) ;
2021-01-15 18:20:17 +00:00
}
2021-01-18 14:18:14 +00:00
player _build . aggregateStats ( ) ;
console . log ( player _build . statMap ) ;
calculateBuildStats ( ) ;
2021-01-09 08:52:58 +00:00
}
2021-01-12 21:07:03 +00:00
/ * U p d a t e s a l l s p e l l b o o s t s
2021-01-12 07:11:20 +00:00
* /
2021-01-18 14:18:14 +00:00
function updateBoosts ( buttonId , recalcStats ) {
2021-01-15 18:20:17 +00:00
let elem = document . getElementById ( buttonId ) ;
let name = buttonId . split ( "-" ) [ 0 ] ;
if ( buttonId !== "skip" ) {
2021-01-13 19:55:13 +00:00
if ( elem . classList . contains ( "toggleOn" ) ) {
2021-01-14 06:58:32 +00:00
player _build . damageMultiplier -= damageMultipliers . get ( name ) ;
if ( name === "warscream" ) {
2021-01-18 07:43:57 +00:00
player _build . defenseMultiplier -= . 20 ;
2021-01-14 06:58:32 +00:00
}
2021-07-11 16:22:34 +00:00
if ( name === "vanish" ) {
player _build . defenseMultiplier -= . 15 ;
}
2021-01-13 19:55:13 +00:00
elem . classList . remove ( "toggleOn" ) ;
} else {
2021-01-14 06:58:32 +00:00
player _build . damageMultiplier += damageMultipliers . get ( name ) ;
if ( name === "warscream" ) {
2021-01-18 07:43:57 +00:00
player _build . defenseMultiplier += . 20 ;
2021-01-14 06:58:32 +00:00
}
2021-07-11 16:22:34 +00:00
if ( name === "vanish" ) {
player _build . defenseMultiplier += . 15 ;
}
2021-01-13 19:55:13 +00:00
elem . classList . add ( "toggleOn" ) ;
}
2021-01-20 05:35:25 +00:00
updatePowderSpecials ( "skip" , false ) ; //jank pt 1
2021-01-15 18:20:17 +00:00
} else {
for ( const [ key , value ] of damageMultipliers ) {
let elem = document . getElementById ( key + "-boost" )
if ( elem . classList . contains ( "toggleOn" ) ) {
elem . classList . remove ( "toggleOn" ) ;
player _build . damageMultiplier -= value ;
2021-01-18 07:43:57 +00:00
if ( key === "warscream" ) { player _build . defenseMultiplier -= . 20 }
2021-07-11 16:22:34 +00:00
if ( key === "vanish" ) { player _build . defenseMultiplier -= . 15 }
2021-01-15 18:20:17 +00:00
}
}
}
2021-01-18 14:18:14 +00:00
if ( recalcStats ) {
calculateBuildStats ( ) ;
}
2021-01-12 07:11:20 +00:00
}
2021-01-09 08:52:58 +00:00
2021-01-12 21:07:03 +00:00
/ * U p d a t e s a l l p o w d e r s p e c i a l b o o s t s
* /
2021-01-18 14:18:14 +00:00
function updatePowderSpecials ( buttonId , recalcStats ) {
2021-01-14 03:17:01 +00:00
//console.log(player_build.statMap);
2021-01-15 18:20:17 +00:00
2021-01-12 21:07:03 +00:00
let name = ( buttonId ) . split ( "-" ) [ 0 ] ;
2021-01-13 19:55:13 +00:00
let power = ( buttonId ) . split ( "-" ) [ 1 ] ; // [1, 5]
2021-03-14 08:28:24 +00:00
let specialNames = [ "Quake" , "Chain Lightning" , "Curse" , "Courage" , "Wind Prison" ] ;
2021-01-12 21:07:03 +00:00
let powderSpecials = [ ] ; // [ [special, power], [special, power]]
2021-01-13 19:55:13 +00:00
2021-01-13 08:30:55 +00:00
if ( name !== "skip" ) {
let elem = document . getElementById ( buttonId ) ;
2021-01-13 19:55:13 +00:00
if ( elem . classList . contains ( "toggleOn" ) ) { //toggle the pressed button off
2021-01-13 08:30:55 +00:00
elem . classList . remove ( "toggleOn" ) ;
2021-01-13 19:55:13 +00:00
let special = powderSpecialStats [ specialNames . indexOf ( name . replace ( "_" , " " ) ) ] ;
if ( special . weaponSpecialEffects . has ( "Damage Boost" ) ) {
name = name . replace ( "_" , " " ) ;
2021-01-14 03:17:01 +00:00
if ( name === "Courage" || name === "Curse" ) { //courage and curse are universal damage boost
player _build . externalStats . set ( "sdPct" , player _build . externalStats . get ( "sdPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
player _build . externalStats . set ( "mdPct" , player _build . externalStats . get ( "mdPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
2021-01-14 06:58:32 +00:00
player _build . externalStats . set ( "poisonPct" , player _build . externalStats . get ( "poisonPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
2021-01-14 03:17:01 +00:00
//poison?
2021-03-14 08:28:24 +00:00
} else if ( name === "Wind Prison" ) {
2021-01-14 03:17:01 +00:00
player _build . externalStats . set ( "aDamPct" , player _build . externalStats . get ( "aDamPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
player _build . externalStats . get ( "damageBonus" ) [ 4 ] -= special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ;
2021-01-13 19:55:13 +00:00
}
2021-01-13 08:30:55 +00:00
}
2021-01-13 19:55:13 +00:00
} else {
for ( let i = 1 ; i < 6 ; i ++ ) { //toggle all pressed buttons of the same powder special off
//name is same, power is i
if ( document . getElementById ( name . replace ( " " , "_" ) + "-" + i ) . classList . contains ( "toggleOn" ) ) {
document . getElementById ( name . replace ( " " , "_" ) + "-" + i ) . classList . remove ( "toggleOn" ) ;
let special = powderSpecialStats [ specialNames . indexOf ( name . replace ( "_" , " " ) ) ] ;
if ( special . weaponSpecialEffects . has ( "Damage Boost" ) ) {
name = name . replace ( "_" , " " ) ; //might be redundant
2021-01-14 03:17:01 +00:00
if ( name === "Courage" || name === "Curse" ) { //courage is universal damage boost
//player_build.damageMultiplier -= special.weaponSpecialEffects.get("Damage Boost")[i-1]/100;
player _build . externalStats . set ( "sdPct" , player _build . externalStats . get ( "sdPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
player _build . externalStats . set ( "mdPct" , player _build . externalStats . get ( "mdPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
2021-01-14 06:58:32 +00:00
player _build . externalStats . set ( "poisonPct" , player _build . externalStats . get ( "poisonPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
2021-03-14 08:28:24 +00:00
} else if ( name === "Wind Prison" ) {
2021-01-14 03:17:01 +00:00
player _build . externalStats . set ( "aDamPct" , player _build . externalStats . get ( "aDamPct" ) - special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ) ;
player _build . externalStats . get ( "damageBonus" ) [ 4 ] -= special . weaponSpecialEffects . get ( "Damage Boost" ) [ i - 1 ] ;
2021-01-13 19:55:13 +00:00
}
}
}
}
//toggle the pressed button on
elem . classList . add ( "toggleOn" ) ;
2021-01-12 21:07:03 +00:00
}
}
2021-01-13 08:30:55 +00:00
2021-01-12 21:07:03 +00:00
for ( const sName of specialNames ) {
for ( let i = 1 ; i < 6 ; i ++ ) {
if ( document . getElementById ( sName . replace ( " " , "_" ) + "-" + i ) . classList . contains ( "toggleOn" ) ) {
let powderSpecial = powderSpecialStats [ specialNames . indexOf ( sName . replace ( "_" , " " ) ) ] ;
powderSpecials . push ( [ powderSpecial , i ] ) ;
break ;
}
}
}
2021-01-14 03:17:01 +00:00
2021-01-13 19:55:13 +00:00
if ( name !== "skip" ) {
let elem = document . getElementById ( buttonId ) ;
if ( elem . classList . contains ( "toggleOn" ) ) {
let special = powderSpecialStats [ specialNames . indexOf ( name . replace ( "_" , " " ) ) ] ;
if ( special [ "weaponSpecialEffects" ] . has ( "Damage Boost" ) ) {
let name = special [ "weaponSpecialName" ] ;
2021-01-14 03:17:01 +00:00
if ( name === "Courage" || name === "Curse" ) { //courage and curse are is universal damage boost
player _build . externalStats . set ( "sdPct" , player _build . externalStats . get ( "sdPct" ) + special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
player _build . externalStats . set ( "mdPct" , player _build . externalStats . get ( "mdPct" ) + special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
2021-01-14 06:58:32 +00:00
player _build . externalStats . set ( "poisonPct" , player _build . externalStats . get ( "poisonPct" ) + special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
2021-03-14 08:28:24 +00:00
} else if ( name === "Wind Prison" ) {
2021-01-14 03:17:01 +00:00
player _build . externalStats . set ( "aDamPct" , player _build . externalStats . get ( "aDamPct" ) + special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ) ;
player _build . externalStats . get ( "damageBonus" ) [ 4 ] += special . weaponSpecialEffects . get ( "Damage Boost" ) [ power - 1 ] ;
2021-01-13 19:55:13 +00:00
}
}
}
}
2021-01-18 14:18:14 +00:00
if ( recalcStats ) {
calculateBuildStats ( ) ;
}
2021-01-14 03:17:01 +00:00
displayPowderSpecials ( document . getElementById ( "powder-special-stats" ) , powderSpecials , player _build ) ;
2021-01-12 21:07:03 +00:00
}
2021-01-12 07:11:20 +00:00
/ * C a l c u l a t e s a l l b u i l d s t a t i s t i c s a n d u p d a t e s t h e e n t i r e d i s p l a y .
* /
2021-01-09 08:52:58 +00:00
function calculateBuildStats ( ) {
2021-01-08 05:36:57 +00:00
const assigned = player _build . base _skillpoints ;
const skillpoints = player _build . total _skillpoints ;
2021-01-08 20:14:23 +00:00
let skp _effects = [ "% more damage dealt." , "% chance to crit." , "% spell cost reduction." , "% less damage taken." , "% chance to dodge." ] ;
for ( let i in skp _order ) { //big bren
2021-01-09 11:21:46 +00:00
setText ( skp _order [ i ] + "-skp-assign" , "Manually Assigned: " + assigned [ i ] ) ;
2021-01-08 20:14:23 +00:00
setValue ( skp _order [ i ] + "-skp" , skillpoints [ i ] ) ;
2021-01-11 17:52:21 +00:00
let linebreak = document . createElement ( "br" ) ;
linebreak . classList . add ( "itemp" ) ;
2021-01-11 23:43:04 +00:00
document . getElementById ( skp _order [ i ] + "-skp-label" ) ;
2021-01-08 20:21:31 +00:00
setText ( skp _order [ i ] + "-skp-pct" , ( skillPointsToPercentage ( skillpoints [ i ] ) * 100 ) . toFixed ( 1 ) . concat ( skp _effects [ i ] ) ) ;
2021-01-11 17:52:21 +00:00
if ( assigned [ i ] > 100 ) {
let skp _warning = document . createElement ( "p" ) ;
skp _warning . classList . add ( "warning" ) ;
skp _warning . textContent += "WARNING: Cannot assign " + assigned [ i ] + " skillpoints in " + [ "Strength" , "Dexterity" , "Intelligence" , "Defense" , "Agility" ] [ i ] + " manually." ;
document . getElementById ( skp _order [ i ] + "-skp-pct" ) . appendChild ( skp _warning ) ;
}
2021-01-08 20:14:23 +00:00
}
2021-01-09 08:52:58 +00:00
2021-01-11 00:08:14 +00:00
let summarybox = document . getElementById ( "summary-box" ) ;
summarybox . textContent = "" ;
2021-01-14 03:17:01 +00:00
let skpRow = document . createElement ( "p" ) ;
let td = document . createElement ( "p" ) ;
2021-01-11 02:58:39 +00:00
2021-01-14 03:17:01 +00:00
let remainingSkp = document . createElement ( "p" ) ;
remainingSkp . classList . add ( "center" ) ;
2021-01-11 17:52:21 +00:00
let remainingSkpTitle = document . createElement ( "b" ) ;
2021-01-20 12:10:25 +00:00
remainingSkpTitle . textContent = "Assigned " + player _build . assigned _skillpoints + " skillpoints. Remaining skillpoints: " ;
2021-01-11 17:52:21 +00:00
let remainingSkpContent = document . createElement ( "b" ) ;
2021-01-15 23:34:21 +00:00
remainingSkpContent . textContent = "" + ( levelToSkillPoints ( player _build . level ) - player _build . assigned _skillpoints ) ;
2021-01-11 17:52:21 +00:00
remainingSkpContent . classList . add ( levelToSkillPoints ( player _build . level ) - player _build . assigned _skillpoints < 0 ? "negative" : "positive" ) ;
remainingSkp . appendChild ( remainingSkpTitle ) ;
remainingSkp . appendChild ( remainingSkpContent ) ;
2021-01-11 02:58:39 +00:00
summarybox . append ( skpRow ) ;
2021-01-14 03:17:01 +00:00
summarybox . append ( remainingSkp ) ;
2021-01-08 20:14:23 +00:00
if ( player _build . assigned _skillpoints > levelToSkillPoints ( player _build . level ) ) {
2021-01-11 00:08:14 +00:00
let skpWarning = document . createElement ( "p" ) ;
2021-01-11 17:52:21 +00:00
//skpWarning.classList.add("itemp");
skpWarning . classList . add ( "warning" ) ;
2021-01-11 00:08:14 +00:00
skpWarning . classList . add ( "itemp" ) ;
skpWarning . textContent = "WARNING: Too many skillpoints need to be assigned!" ;
let skpCount = document . createElement ( "p" ) ;
skpCount . classList . add ( "itemp" ) ;
2021-01-11 17:52:21 +00:00
skpCount . textContent = "For level " + ( player _build . level > 101 ? "101+" : player _build . level ) + ", there are only " + levelToSkillPoints ( player _build . level ) + " skill points available." ;
2021-01-11 00:08:14 +00:00
summarybox . append ( skpWarning ) ;
summarybox . append ( skpCount ) ;
}
2021-01-11 17:52:21 +00:00
let lvlWarning ;
for ( const item of player _build . items ) {
2021-02-04 10:55:15 +00:00
let item _lvl ;
if ( item . get ( "crafted" ) ) {
2021-03-14 07:55:08 +00:00
//item_lvl = item.get("lvlLow") + "-" + item.get("lvl");
item _lvl = item . get ( "lvlLow" ) ;
2021-02-04 10:55:15 +00:00
}
else {
item _lvl = item . get ( "lvl" ) ;
}
if ( player _build . level < item _lvl ) {
2021-01-11 17:52:21 +00:00
if ( ! lvlWarning ) {
lvlWarning = document . createElement ( "p" ) ;
lvlWarning . classList . add ( "itemp" ) ;
lvlWarning . classList . add ( "warning" ) ;
2021-01-26 03:28:57 +00:00
lvlWarning . textContent = "WARNING: A level " + player _build . level + " player cannot use some piece(s) of this build."
2021-01-11 17:52:21 +00:00
}
let baditem = document . createElement ( "p" ) ;
baditem . classList . add ( "nocolor" ) ;
baditem . classList . add ( "itemp" ) ;
2021-01-30 11:06:16 +00:00
baditem . textContent = item . get ( "displayName" ) + " requires level " + item . get ( "lvl" ) + " to use." ;
2021-01-11 17:52:21 +00:00
lvlWarning . appendChild ( baditem ) ;
2021-01-11 00:08:14 +00:00
}
2021-01-08 20:14:23 +00:00
}
2021-01-11 17:52:21 +00:00
if ( lvlWarning ) {
summarybox . append ( lvlWarning ) ;
}
2021-02-04 10:55:15 +00:00
for ( const [ setName , count ] of player _build . activeSetCounts ) {
const bonus = sets [ setName ] . bonuses [ count - 1 ] ;
2021-02-27 21:07:28 +00:00
// console.log(setName);
2021-02-04 10:55:15 +00:00
if ( bonus [ "illegal" ] ) {
2021-11-24 16:30:44 +00:00
console . log ( "mmmm" ) ;
2021-02-04 10:55:15 +00:00
let setWarning = document . createElement ( "p" ) ;
setWarning . classList . add ( "itemp" ) ;
setWarning . classList . add ( "warning" ) ;
setWarning . textContent = "WARNING: illegal item combination: " + setName
summarybox . append ( setWarning ) ;
}
}
2021-01-07 08:34:31 +00:00
2021-01-09 03:53:57 +00:00
for ( let i in player _build . items ) {
displayExpandedItem ( player _build . items [ i ] , buildFields [ i ] ) ;
}
2021-01-08 20:17:37 +00:00
2021-01-15 18:20:17 +00:00
displayBuildStats ( "build-overall-stats" , player _build ) ;
displaySetBonuses ( "set-info" , player _build ) ;
displayNextCosts ( "int-info" , player _build ) ;
2021-01-09 12:47:25 +00:00
2021-01-08 02:34:07 +00:00
let meleeStats = player _build . getMeleeStats ( ) ;
2021-01-10 21:01:59 +00:00
displayMeleeDamage ( document . getElementById ( "build-melee-stats" ) , document . getElementById ( "build-melee-statsAvg" ) , meleeStats ) ;
2021-01-10 10:02:23 +00:00
2021-01-11 22:25:55 +00:00
displayDefenseStats ( document . getElementById ( "build-defense-stats" ) , player _build ) ;
2021-01-09 23:30:05 +00:00
2021-01-11 07:05:23 +00:00
displayPoisonDamage ( document . getElementById ( "build-poison-stats" ) , player _build ) ;
2021-01-09 08:52:58 +00:00
let spells = spell _table [ player _build . weapon . get ( "type" ) ] ;
for ( let i = 0 ; i < 4 ; ++ i ) {
let parent _elem = document . getElementById ( "spell" + i + "-info" ) ;
2021-01-10 21:01:59 +00:00
let overallparent _elem = document . getElementById ( "spell" + i + "-infoAvg" ) ;
displaySpellDamage ( parent _elem , overallparent _elem , player _build , spells [ i ] , i + 1 ) ;
2021-01-09 08:52:58 +00:00
}
2021-01-07 10:23:54 +00:00
location . hash = encodeBuild ( ) ;
2021-01-19 11:56:09 +00:00
clear _highlights ( ) ;
2022-01-14 06:18:06 +00:00
updateOGP ( ) ;
2021-01-07 08:11:54 +00:00
}
2021-01-08 03:15:02 +00:00
2021-01-11 11:08:10 +00:00
function copyBuild ( ) {
2021-01-11 12:09:58 +00:00
if ( player _build ) {
copyTextToClipboard ( url _base + location . hash ) ;
document . getElementById ( "copy-button" ) . textContent = "Copied!" ;
}
}
function shareBuild ( ) {
if ( player _build ) {
let text = url _base + location . hash + "\n" +
"WynnBuilder build:\n" +
2021-01-11 21:34:59 +00:00
"> " + player _build . helmet . get ( "displayName" ) + "\n" +
"> " + player _build . chestplate . get ( "displayName" ) + "\n" +
"> " + player _build . leggings . get ( "displayName" ) + "\n" +
"> " + player _build . boots . get ( "displayName" ) + "\n" +
"> " + player _build . ring1 . get ( "displayName" ) + "\n" +
"> " + player _build . ring2 . get ( "displayName" ) + "\n" +
"> " + player _build . bracelet . get ( "displayName" ) + "\n" +
"> " + player _build . necklace . get ( "displayName" ) + "\n" +
"> " + player _build . weapon . get ( "displayName" ) + " [" + player _build . weapon . get ( "powders" ) . map ( x => powderNames . get ( x ) ) . join ( "" ) + "]" ;
2021-01-11 12:09:58 +00:00
copyTextToClipboard ( text ) ;
document . getElementById ( "share-button" ) . textContent = "Copied!" ;
}
2021-01-11 11:08:10 +00:00
}
2021-10-01 02:00:11 +00:00
function populateBuildList ( ) {
const buildList = document . getElementById ( "build-choice" ) ;
const savedBuilds = window . localStorage . getItem ( "builds" ) === null ? { } : JSON . parse ( window . localStorage . getItem ( "builds" ) ) ;
for ( const buildName of Object . keys ( savedBuilds ) . sort ( ) ) {
const buildOption = document . createElement ( "option" ) ;
buildOption . setAttribute ( "value" , buildName ) ;
buildList . appendChild ( buildOption ) ;
}
}
2021-09-12 06:18:20 +00:00
function saveBuild ( ) {
if ( player _build ) {
2021-10-01 02:00:11 +00:00
const savedBuilds = window . localStorage . getItem ( "builds" ) === null ? { } : JSON . parse ( window . localStorage . getItem ( "builds" ) ) ;
const saveName = document . getElementById ( "build-name" ) . value ;
const encodedBuild = encodeBuild ( ) ;
2021-09-25 17:22:04 +00:00
if ( ( ! Object . keys ( savedBuilds ) . includes ( saveName )
|| document . getElementById ( "saved-error" ) . textContent !== "" ) && encodedBuild !== "" ) {
2021-09-17 20:56:29 +00:00
savedBuilds [ saveName ] = encodedBuild . replace ( "#" , "" ) ;
2021-09-12 06:18:20 +00:00
window . localStorage . setItem ( "builds" , JSON . stringify ( savedBuilds ) ) ;
document . getElementById ( "saved-error" ) . textContent = "" ;
2021-10-01 02:00:11 +00:00
document . getElementById ( "saved-build" ) . textContent = "Build saved locally" ;
const buildList = document . getElementById ( "build-choice" ) ;
const buildOption = document . createElement ( "option" ) ;
buildOption . setAttribute ( "value" , saveName ) ;
buildList . appendChild ( buildOption ) ;
2021-09-12 06:18:20 +00:00
} else {
2021-09-25 17:22:04 +00:00
document . getElementById ( "saved-build" ) . textContent = "" ;
if ( encodedBuild === "" ) {
2021-09-12 06:18:20 +00:00
document . getElementById ( "saved-error" ) . textContent = "Empty build" ;
2021-09-25 17:22:04 +00:00
}
else {
2021-09-12 06:18:20 +00:00
document . getElementById ( "saved-error" ) . textContent = "Exists. Overwrite?" ;
2021-09-25 17:22:04 +00:00
}
2021-09-12 06:18:20 +00:00
}
}
}
function loadBuild ( ) {
let savedBuilds = window . localStorage . getItem ( "builds" ) === null ? { } : JSON . parse ( window . localStorage . getItem ( "builds" ) ) ;
let saveName = document . getElementById ( "build-name" ) . value ;
if ( Object . keys ( savedBuilds ) . includes ( saveName ) ) {
decodeBuild ( savedBuilds [ saveName ] )
2021-09-25 17:22:04 +00:00
document . getElementById ( "loaded-error" ) . textContent = "" ;
2021-09-12 06:18:20 +00:00
document . getElementById ( "loaded-build" ) . textContent = "Build loaded" ;
2021-09-25 17:22:04 +00:00
} else {
document . getElementById ( "loaded-build" ) . textContent = "" ;
2021-09-12 06:18:20 +00:00
document . getElementById ( "loaded-error" ) . textContent = "Build doesn't exist" ;
2021-09-25 17:22:04 +00:00
}
2021-09-12 06:18:20 +00:00
}
2021-01-06 20:54:15 +00:00
function resetFields ( ) {
2021-01-09 03:53:57 +00:00
for ( let i in powderInputs ) {
setValue ( powderInputs [ i ] , "" ) ;
}
2021-01-09 08:52:58 +00:00
for ( let i in equipmentInputs ) {
2021-01-09 03:53:57 +00:00
setValue ( equipmentInputs [ i ] , "" ) ;
}
2021-01-07 10:23:54 +00:00
setValue ( "str-skp" , "0" ) ;
setValue ( "dex-skp" , "0" ) ;
setValue ( "int-skp" , "0" ) ;
setValue ( "def-skp" , "0" ) ;
setValue ( "agi-skp" , "0" ) ;
2021-01-29 22:13:52 +00:00
setValue ( "level-choice" , "106" ) ;
2021-01-08 01:16:06 +00:00
location . hash = "" ;
2021-01-14 03:17:01 +00:00
calculateBuild ( ) ;
2021-01-06 22:46:00 +00:00
}
2021-01-18 14:18:14 +00:00
function toggleID ( ) {
let button = document . getElementById ( "show-id-button" ) ;
let targetDiv = document . getElementById ( "id-edit" ) ;
if ( button . classList . contains ( "toggleOn" ) ) { //toggle the pressed button off
targetDiv . style . display = "none" ;
button . classList . remove ( "toggleOn" ) ;
}
else {
targetDiv . style . display = "block" ;
button . classList . add ( "toggleOn" ) ;
}
}
2021-07-27 10:04:12 +00:00
function optimizeStrDex ( ) {
const remaining = levelToSkillPoints ( player _build . level ) - player _build . assigned _skillpoints ;
const base _skillpoints = player _build . base _skillpoints ;
const max _str _boost = 100 - base _skillpoints [ 0 ] ;
const max _dex _boost = 100 - base _skillpoints [ 1 ] ;
2021-10-23 14:31:09 +00:00
if ( Math . min ( remaining , max _str _boost , max _dex _boost ) < 0 ) return ; // Unwearable
2021-07-27 10:04:12 +00:00
const base _total _skillpoints = player _build . total _skillpoints ;
let str _bonus = remaining ;
let dex _bonus = 0 ;
let best _skillpoints = player _build . total _skillpoints ;
let best _damage = 0 ;
for ( let i = 0 ; i <= remaining ; ++ i ) {
let total _skillpoints = base _total _skillpoints . slice ( ) ;
total _skillpoints [ 0 ] += Math . min ( max _str _boost , str _bonus ) ;
total _skillpoints [ 1 ] += Math . min ( max _dex _boost , dex _bonus ) ;
// Calculate total 3rd spell damage
let spell = spell _table [ player _build . weapon . get ( "type" ) ] [ 2 ] ;
const stats = player _build . statMap ;
let critChance = skillPointsToPercentage ( total _skillpoints [ 1 ] ) ;
let save _damages = [ ] ;
let spell _parts ;
if ( spell . parts ) {
spell _parts = spell . parts ;
}
else {
spell _parts = spell . variants . DEFAULT ;
for ( const majorID of stats . get ( "activeMajorIDs" ) ) {
if ( majorID in spell . variants ) {
spell _parts = spell . variants [ majorID ] ;
break ;
}
}
}
let total _damage = 0 ;
for ( const part of spell _parts ) {
if ( part . type === "damage" ) {
let _results = calculateSpellDamage ( stats , part . conversion ,
stats . get ( "sdRaw" ) , stats . get ( "sdPct" ) + player _build . externalStats . get ( "sdPct" ) ,
part . multiplier / 100 , player _build . weapon , total _skillpoints ,
player _build . damageMultiplier , player _build . externalStats ) ;
let totalDamNormal = _results [ 0 ] ;
let totalDamCrit = _results [ 1 ] ;
let results = _results [ 2 ] ;
let tooltipinfo = _results [ 3 ] ;
for ( let i = 0 ; i < 6 ; ++ i ) {
for ( let j in results [ i ] ) {
results [ i ] [ j ] = results [ i ] [ j ] . toFixed ( 2 ) ;
}
}
let nonCritAverage = ( totalDamNormal [ 0 ] + totalDamNormal [ 1 ] ) / 2 || 0 ;
let critAverage = ( totalDamCrit [ 0 ] + totalDamCrit [ 1 ] ) / 2 || 0 ;
let averageDamage = ( 1 - critChance ) * nonCritAverage + critChance * critAverage || 0 ;
save _damages . push ( averageDamage ) ;
if ( part . summary == true ) {
total _damage = averageDamage ;
}
} else if ( part . type === "total" ) {
total _damage = 0 ;
for ( let i in part . factors ) {
total _damage += save _damages [ i ] * part . factors [ i ] ;
}
}
} // END Calculate total 3rd spell damage (total_damage)
if ( total _damage > best _damage ) {
best _damage = total _damage ;
best _skillpoints = total _skillpoints . slice ( ) ;
}
str _bonus -= 1 ;
dex _bonus += 1 ;
}
// TODO: reduce duplicated code, @calculateBuild
let skillpoints = player _build . total _skillpoints ;
let delta _total = 0 ;
for ( let i in skp _order ) {
let manual _assigned = best _skillpoints [ i ] ;
let delta = manual _assigned - skillpoints [ i ] ;
skillpoints [ i ] = manual _assigned ;
player _build . base _skillpoints [ i ] += delta ;
delta _total += delta ;
}
player _build . assigned _skillpoints += delta _total ;
try {
calculateBuildStats ( ) ;
setTitle ( ) ;
if ( player _build . errored )
throw new ListError ( player _build . errors ) ;
}
catch ( error ) {
handleBuilderError ( error ) ;
}
}
2021-04-30 10:36:25 +00:00
// TODO: Learn and use await
function init2 ( ) {
load _ing _init ( init ) ;
}
load _init ( init2 ) ;
2022-01-14 05:52:54 +00:00
updateOGP ( ) ;