Revert removal of ndam_ and such -- needed for spacing and backwards compat

Also: Refactor crafter.js functions into craft.js, likewise for customizer and custom.jss
This commit is contained in:
b 2021-04-30 03:36:25 -07:00
parent c6d0913c0e
commit 64206d661d
8 changed files with 110 additions and 105 deletions

View file

@ -158,6 +158,7 @@ class Build{
this.craftedItems.push(chestplate);
}
} catch (Error) {
console.log(Error);
const chestplate = itemMap.get("No Chestplate");
this.powders[1] = this.powders[1].slice(0,chestplate.slots);
this.chestplate = expandItem(chestplate, this.powders[1]);

View file

@ -925,4 +925,8 @@ function toggleID() {
}
}
load_init(init);
// TODO: Learn and use await
function init2() {
load_ing_init(init);
}
load_init(init2);

View file

@ -1,4 +1,24 @@
let recipeTypes = ["HELMET","CHESTPLATE","LEGGINGS","BOOTS","RELIK","WAND","SPEAR","DAGGER","BOW","RING","NECKLACE","BRACELET","SCROLL","FOOD","POTION"];
let levelTypes = ["1-3","3-5","5-7","7-9","10-13","13-15","15-17","17-19","20-23","23-25","25-27","27-29","30-33","33-35","35-37","37-39","40-43","43-45","45-47","47-49","50-53","53-55","55-57","57-59","60-63","63-65","65-67","67-69","70-73","73-75","75-77","77-79","80-83","83-85","85-87","87-89","90-93","93-95","95-97","97-99","100-103","103-105",]
let ingFields = ["fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct", "hprPct", "mr", "sdPct", "mdPct", "ls", "ms", "xpb", "lb", "lq", "ref", "str", "dex", "int", "agi", "def", "thorns", "expd", "spd", "atkTier", "poison", "hpBonus", "spRegen", "eSteal", "hprRaw", "sdRaw", "mdRaw", "fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct", "spPct1", "spRaw1", "spPct2", "spRaw2", "spPct3", "spRaw3", "spPct4", "spRaw4", "jh", "sprint", "sprintReg", "gXp", "gSpd"];
function encodeCraft(craft) {
if (craft) {
let atkSpds = ["SLOW","NORMAL","FAST"];
let craft_string = "1" +
Base64.fromIntN(craft.ingreds[0].get("id"), 2) +
Base64.fromIntN(craft.ingreds[1].get("id"), 2) +
Base64.fromIntN(craft.ingreds[2].get("id"), 2) +
Base64.fromIntN(craft.ingreds[3].get("id"), 2) +
Base64.fromIntN(craft.ingreds[4].get("id"), 2) +
Base64.fromIntN(craft.ingreds[5].get("id"), 2) +
Base64.fromIntN(craft.recipe.get("id"),2) +
Base64.fromIntN(craft.mat_tiers[0] + (craft.mat_tiers[1]-1)*3, 1) + //this maps tiers [a,b] to a+3b.
Base64.fromIntN(atkSpds.indexOf(craft["atkSpd"]),1);
return craft_string;
}
return "";
}
//constructs a craft from a hash 'CR-qwoefsabaoe' or 'qwoefsaboe'
function getCraftFromHash(hash) {
@ -28,6 +48,7 @@ function getCraftFromHash(hash) {
return new Craft(recipe,mat_tiers,ingreds,attackSpeed,"1"+name);
}
} catch (error) {
console.log(error);
return undefined;
}

View file

@ -20,9 +20,6 @@ const ING_BUILD_VERSION = "7.0.1";
Double powders
Integrate to normal builder
*/
let recipeTypes = ["HELMET","CHESTPLATE","LEGGINGS","BOOTS","RELIK","WAND","SPEAR","DAGGER","BOW","RING","NECKLACE","BRACELET","SCROLL","FOOD","POTION"];
let levelTypes = ["1-3","3-5","5-7","7-9","10-13","13-15","15-17","17-19","20-23","23-25","25-27","27-29","30-33","33-35","35-37","37-39","40-43","43-45","45-47","47-49","50-53","53-55","55-57","57-59","60-63","63-65","65-67","67-69","70-73","73-75","75-77","77-79","80-83","83-85","85-87","87-89","90-93","93-95","95-97","97-99","100-103","103-105",]
let ingFields = ["fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct", "hprPct", "mr", "sdPct", "mdPct", "ls", "ms", "xpb", "lb", "lq", "ref", "str", "dex", "int", "agi", "def", "thorns", "expd", "spd", "atkTier", "poison", "hpBonus", "spRegen", "eSteal", "hprRaw", "sdRaw", "mdRaw", "fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct", "spPct1", "spRaw1", "spPct2", "spRaw2", "spPct3", "spRaw3", "spPct4", "spRaw4", "jh", "sprint", "sprintReg", "gXp", "gSpd"];
let player_craft;
function setTitle() {
@ -171,24 +168,6 @@ function calculateCraft() {
}
function encodeCraft(craft) {
if (craft) {
let atkSpds = ["SLOW","NORMAL","FAST"];
let craft_string = "1" +
Base64.fromIntN(craft.ingreds[0].get("id"), 2) +
Base64.fromIntN(craft.ingreds[1].get("id"), 2) +
Base64.fromIntN(craft.ingreds[2].get("id"), 2) +
Base64.fromIntN(craft.ingreds[3].get("id"), 2) +
Base64.fromIntN(craft.ingreds[4].get("id"), 2) +
Base64.fromIntN(craft.ingreds[5].get("id"), 2) +
Base64.fromIntN(craft.recipe.get("id"),2) +
Base64.fromIntN(craft.mat_tiers[0] + (craft.mat_tiers[1]-1)*3, 1) + //this maps tiers [a,b] to a+3b.
Base64.fromIntN(atkSpds.indexOf(craft["atkSpd"]),1);
return craft_string;
}
return "";
}
function decodeCraft(ing_url_tag) {
if (ing_url_tag) {
if (ing_url_tag.slice(0,3) === "CR-") {

View file

@ -1,13 +1,84 @@
const ci_save_order = ["name", "lore", "tier", "set", "slots", "type", "material", "drop", "quest", "nDam", "fDam", "wDam", "aDam", "tDam", "eDam", "atkSpd", "hp", "fDef", "wDef", "aDef", "tDef", "eDef", "lvl", "classReq", "strReq", "dexReq", "intReq", "defReq", "agiReq","str", "dex", "int", "agi", "def", "id", "skillpoints", "reqs", "majorIds", "hprPct", "mr", "sdPct", "mdPct", "ls", "ms", "xpb", "lb", "ref", "thorns", "expd", "spd", "atkTier", "poison", "hpBonus", "spRegen", "eSteal", "hprRaw", "sdRaw", "mdRaw", "fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct", "fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct", "spPct1", "spRaw1", "spPct2", "spRaw2", "spPct3", "spRaw3", "spPct4", "spRaw4", "rainbowRaw", "sprint", "sprintReg", "jh", "lq", "gXp", "gSpd","durability","duration","charges"];
const nonRolled_strings = ["name","lore", "tier","set","type","material","drop","quest","majorIds","classReq","atkSpd","displayName", "nDam", "fDam", "wDam", "aDam", "tDam", "eDam", "durability", "duration"];
const ci_save_order = ["name", "lore", "tier", "set", "slots", "type", "material", "drop", "quest", "nDam", "fDam", "wDam", "aDam", "tDam", "eDam", "atkSpd", "hp", "fDef", "wDef", "aDef", "tDef", "eDef", "lvl", "classReq", "strReq", "dexReq", "intReq", "defReq", "agiReq","str", "dex", "int", "agi", "def", "id", "skillpoints", "reqs", "nDam_", "fDam_", "wDam_", "aDam_", "tDam_", "eDam_", "majorIds", "hprPct", "mr", "sdPct", "mdPct", "ls", "ms", "xpb", "lb", "ref", "thorns", "expd", "spd", "atkTier", "poison", "hpBonus", "spRegen", "eSteal", "hprRaw", "sdRaw", "mdRaw", "fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct", "fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct", "spPct1", "spRaw1", "spPct2", "spRaw2", "spPct3", "spRaw3", "spPct4", "spRaw4", "rainbowRaw", "sprint", "sprintReg", "jh", "lq", "gXp", "gSpd","durability","duration","charges"];
const nonRolled_strings = ["name","lore", "tier","set","type","material","drop","quest","majorIds","classReq","atkSpd","displayName", "nDam", "fDam", "wDam", "aDam", "tDam", "eDam", "nDam_", "fDam_", "wDam_", "aDam_", "tDam_", "eDam_", "durability", "duration"];
//omitted restrict - it's always "Custom Item"
//omitted displayName - either it's the same as name (repetitive) or it's "Custom Item"
//omitted category - can always get this from type
//omitted fixId - we will denote this early in the string.
//omitted "nDam_", "fDam_", "wDam_", "aDam_", "tDam_", "eDam_" - will be calculated on display
/**
* @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) {
if (custom.statMap) {
custom = custom.statMap;
}
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;
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);
let min_len = Math.max(1,Math.ceil(log(64,Math.abs(val_min)+1)));
let max_len = Math.max(1,Math.ceil(log(64,Math.abs(val_max)+1)));
let len = Math.max(min_len,max_len);
val_min = Math.abs(val_min);
val_max = Math.abs(val_max);
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")) {
hash += Base64.fromIntN(i,2) + Base64.fromIntN(len,2) + sign + Base64.fromIntN(val_min, len);
} else {
hash += Base64.fromIntN(i,2) + Base64.fromIntN(len,2) + sign + Base64.fromIntN(val_min, len) + Base64.fromIntN(val_max,len);
}
}
} else {
let damages = ["nDam", "eDam", "tDam", "wDam", "fDam", "aDam"]; //"nDam_", "eDam_", "tDam_", "wDam_", "fDam_", "aDam_"
let val = custom.get(id);
if (typeof(val) === "string" && val !== "") {
if ((damages.includes(id) && val === "0-0") || (!verbose && ["lore","majorIds","quest","materials","drop","set"].includes(id))) { continue; }
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") {
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);
} else {
hash += Base64.fromIntN(i,2) + Base64.fromIntN(val.replaceAll(" ", "%20").length,2) + val.replaceAll(" ", "%20"); //values cannot go above 4096 chars!!!! Is this ok?
}
} else if (typeof(val) === "number" && val != 0) {
let len = Math.max(1,Math.ceil(log(64,Math.abs(val))));
let sign = Boolean(val / Math.abs(val) < 0) | 0;
//console.log(sign);
//hash += Base64.fromIntN(i,2) + Base64.fromIntN(val,Math.max(1,Math.ceil(log(64,Math.abs(val))))) + "_";
hash += Base64.fromIntN(i,2) + Base64.fromIntN(len,2) + sign + Base64.fromIntN(Math.abs(val),len);
}
}
}
return hash;
}
return "";
}
function getCustomFromHash(hash) {
let name = hash.slice();
let statMap;
@ -30,8 +101,10 @@ function getCustomFromHash(hash) {
if (fixID) {
statMap.set("fixID", true);
}
console.log(",,");
while (tag !== "") {
let id = ci_save_order[Base64.toInt(tag.slice(0,2))];
console.log(tag.slice(0, 2) + ": " + id);
let len = Base64.toInt(tag.slice(2,4));
if (rolledIDs.includes(id)) {
let sign = parseInt(tag.slice(4,5),10);

View file

@ -211,76 +211,6 @@ function calculateCustom() {
}
/**
* @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) {
if (custom.statMap) {
custom = custom.statMap;
}
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;
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);
let min_len = Math.max(1,Math.ceil(log(64,Math.abs(val_min)+1)));
let max_len = Math.max(1,Math.ceil(log(64,Math.abs(val_max)+1)));
let len = Math.max(min_len,max_len);
val_min = Math.abs(val_min);
val_max = Math.abs(val_max);
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")) {
hash += Base64.fromIntN(i,2) + Base64.fromIntN(len,2) + sign + Base64.fromIntN(val_min, len);
} else {
hash += Base64.fromIntN(i,2) + Base64.fromIntN(len,2) + sign + Base64.fromIntN(val_min, len) + Base64.fromIntN(val_max,len);
}
}
} else {
let damages = ["nDam", "eDam", "tDam", "wDam", "fDam", "aDam"]; //"nDam_", "eDam_", "tDam_", "wDam_", "fDam_", "aDam_"
let val = custom.get(id);
if (typeof(val) === "string" && val !== "") {
if ((damages.includes(id) && val === "0-0") || (!verbose && ["lore","majorIds","quest","materials","drop","set"].includes(id))) { continue; }
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") {
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);
} else {
hash += Base64.fromIntN(i,2) + Base64.fromIntN(val.replaceAll(" ", "%20").length,2) + val.replaceAll(" ", "%20"); //values cannot go above 4096 chars!!!! Is this ok?
}
} else if (typeof(val) === "number" && val != 0) {
let len = Math.max(1,Math.ceil(log(64,Math.abs(val))));
let sign = Boolean(val / Math.abs(val) < 0) | 0;
//console.log(sign);
//hash += Base64.fromIntN(i,2) + Base64.fromIntN(val,Math.max(1,Math.ceil(log(64,Math.abs(val))))) + "_";
hash += Base64.fromIntN(i,2) + Base64.fromIntN(len,2) + sign + Base64.fromIntN(Math.abs(val),len);
}
}
}
return hash;
}
return "";
}
function decodeCustom(custom_url_tag) {
if (custom_url_tag) {
if (custom_url_tag.slice(0,3) === "CI-") {
@ -304,6 +234,7 @@ function decodeCustom(custom_url_tag) {
}
while (tag !== "") {
let id = ci_save_order[Base64.toInt(tag.slice(0,2))];
console.log(tag.slice(0, 2) + ": " + id);
let len = Base64.toInt(tag.slice(2,4));
if (rolledIDs.includes(id)) {
let sign = parseInt(tag.slice(4,5),10);

View file

@ -992,9 +992,9 @@
<script type="text/javascript" src="load.js"></script>
<script type="text/javascript" src="load_ing.js"></script>
<script type="text/javascript" src="custom.js"></script>
<script type="text/javascript" src="customizer.js"></script>
<!--script type="text/javascript" src="customizer.js"></script-->
<script type="text/javascript" src="craft.js"></script>
<script type="text/javascript" src="crafter.js"></script>
<!--script type="text/javascript" src="crafter.js"></script-->
<script type="text/javascript" src="build.js"></script>
<script type="text/javascript" src="builder.js"></script>
</body>

View file

@ -248,19 +248,15 @@ function copyTextToClipboard(text) {
});
}
/** Generates a random color using the #(R)(G)(B) format. Not written by wynnbuilder devs.
*
/**
* Generates a random color using the #(R)(G)(B) format.
*/
function randomColor() {
var letters = '0123456789abcdef';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
return '#' + Math.round(Math.random() * 0xFFFFFF).toString(16);
}
/** Generates a random color, but lightning must be relatively high (>0.5).
/**
* Generates a random color, but lightning must be relatively high (>0.5).
*
* @returns a random color in RGB 6-bit form.
*/