Crafter encode and decode

This commit is contained in:
b 2021-01-30 05:06:16 -06:00
parent 409e5b332d
commit 21fefa73f0
4 changed files with 100 additions and 95 deletions

View file

@ -113,7 +113,7 @@ class Build{
const helmet = itemMap.get(equipment[0]);
this.powders[0] = this.powders[0].slice(0,helmet.slots);
this.helmet = expandItem(helmet, this.powders[0]);
}else{
} else {
try {
let helmet = getCraftFromHash(equipment[0]);
this.powders[0] = this.powders[0].slice(0,helmet.statMap.slots);
@ -133,7 +133,7 @@ class Build{
const chestplate = itemMap.get(equipment[1]);
this.powders[1] = this.powders[1].slice(0,chestplate.slots);
this.chestplate = expandItem(chestplate, this.powders[1]);
}else{
} else {
try {
let chestplate = getCraftFromHash(equipment[1]);
this.powders[1] = this.powders[1].slice(0,chestplate.statMap.slots);
@ -148,11 +148,11 @@ class Build{
errors.push(new ItemNotFound(equipment[1], "chestplate", true));
}
}
if(itemMap.get(equipment[2]) && itemMap.get(equipment[2]).type === "leggings") {
if (itemMap.get(equipment[2]) && itemMap.get(equipment[2]).type === "leggings") {
const leggings = itemMap.get(equipment[2]);
this.powders[2] = this.powders[2].slice(0,leggings.slots);
this.leggings = expandItem(leggings, this.powders[2]);
}else{
} else {
try {
let leggings = getCraftFromHash(equipment[2]);
this.powders[2] = this.powders[2].slice(0,leggings.statMap.slots);
@ -167,11 +167,11 @@ class Build{
errors.push(new ItemNotFound(equipment[2], "leggings", true));
}
}
if(itemMap.get(equipment[3]) && itemMap.get(equipment[3]).type === "boots") {
if (itemMap.get(equipment[3]) && itemMap.get(equipment[3]).type === "boots") {
const boots = itemMap.get(equipment[3]);
this.powders[3] = this.powders[3].slice(0,boots.slots);
this.boots = expandItem(boots, this.powders[3]);
}else{
} else {
try {
let boots = getCraftFromHash(equipment[3]);
this.powders[3] = this.powders[3].slice(0,boots.statMap.slots);

View file

@ -3,7 +3,7 @@ const url_tag = location.hash.slice(1);
console.log(url_base);
console.log(url_tag);
const BUILD_VERSION = "6.9.20";
const BUILD_VERSION = "6.9.21";
function setTitle() {
let text;
@ -220,6 +220,29 @@ function getItemNameFromID(id) {
return idMap.get(id);
}
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;
}
/*
* Populate fields based on url, and calculate build.
*/
@ -235,86 +258,54 @@ function decodeBuild(url_tag) {
if (version === "0" || version === "1" || version === "2" || version === "3") {
let equipments = info[1];
for (let i = 0; i < 9; ++i ) {
equipment[i] = getItemNameFromID(Base64.toInt(equipments.slice(i*3,i*3+3)));
let equipment_str = equipments.slice(i*3,i*3+3);
equipment[i] = getItemNameFromID(Base64.toInt(equipment_str));
}
} else if (version === "1") {
let powder_info = info[1].slice(27);
console.log(powder_info);
// TODO: Make this run in linear instead of quadratic time... ew
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);
info[1] = equipments.slice(27);
}
if (version === "4") {
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;
}
powdering[i] = powders;
}
info[1] = info_str.slice(start_idx);
}
if (version === "1") {
let powder_info = info[1];
powdering = parsePowdering(powder_info);
} else if (version === "2") {
save_skp = true;
let skillpoint_info = info[1].slice(27, 37);
let skillpoint_info = info[1].slice(0, 10);
for (let i = 0; i < 5; ++i ) {
skillpoints[i] = Base64.toIntSigned(skillpoint_info.slice(i*2,i*2+2));
}
let powder_info = info[1].slice(37);
console.log(powder_info);
// TODO: Make this run in linear instead of quadratic time...
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;
}
} else if (version === "3"){
level = Base64.toInt(info[1].slice(37,39));
let powder_info = info[1].slice(10);
powdering = parsePowdering(powder_info);
} else if (version === "3" || version === "4"){
level = Base64.toInt(info[1].slice(10,12));
setValue("level-choice",level);
save_skp = true;
let skillpoint_info = info[1].slice(27, 37);
let skillpoint_info = info[1].slice(0, 10);
for (let i = 0; i < 5; ++i ) {
skillpoints[i] = Base64.toIntSigned(skillpoint_info.slice(i*2,i*2+2));
}
let powder_info = info[1].slice(39);
// TODO: Make this run in linear instead of quadratic time...
for (let i = 0; i < 5; ++i) {
let powders = "";
let n_blocks = Base64.toInt(powder_info.charAt(0));
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;
}
} else if (version === "4") { //crafted support
//@hpp
let powder_info = info[1].slice(12);
powdering = parsePowdering(powder_info);
}
for (let i in powderInputs) {
setValue(powderInputs[i], powdering[i]);
}
@ -330,15 +321,26 @@ function decodeBuild(url_tag) {
function encodeBuild() {
if (player_build) {
//@hpp update for 4_
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);
let 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])
}
else {
build_string += Base64.fromIntN(item.get("id"), 3);
}
}
// 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);
for (const skp of skp_order) {
build_string += Base64.fromIntN(getValue(skp + "-skp"), 2); // Maximum skillpoints: 2048
@ -793,7 +795,7 @@ function calculateBuildStats() {
let baditem = document.createElement("p");
baditem.classList.add("nocolor");
baditem.classList.add("itemp");
baditem.textContent = item.get("name") + " requires level " + item.get("lvl") + " to use.";
baditem.textContent = item.get("displayName") + " requires level " + item.get("lvl") + " to use.";
lvlWarning.appendChild(baditem);
}
}

View file

@ -369,6 +369,8 @@ class Craft{
statMap.get("maxRolls").set(id,0);
}
}
statMap.set("crafted", true);
this.statMap = statMap;
}
}
}

View file

@ -202,8 +202,9 @@ function calculateCraft() {
//create the craft
player_craft = new Craft(recipe,mat_tiers,ingreds,atkSpd,"");
location.hash = encodeCraft();
player_craft.setHash(encodeCraft());
let craft_str = encodeCraft(player_craft);
location.hash = craft_str;
player_craft.setHash(craft_str);
console.log(player_craft);
/*console.log(recipe)
console.log(levelrange)
@ -239,19 +240,19 @@ function calculateCraft() {
}
function encodeCraft() {
if (player_craft) {
function encodeCraft(craft) {
if (craft) {
let atkSpds = ["SLOW","NORMAL","FAST"];
let craft_string = "1" +
Base64.fromIntN(player_craft.ingreds[0].get("id"), 2) +
Base64.fromIntN(player_craft.ingreds[1].get("id"), 2) +
Base64.fromIntN(player_craft.ingreds[2].get("id"), 2) +
Base64.fromIntN(player_craft.ingreds[3].get("id"), 2) +
Base64.fromIntN(player_craft.ingreds[4].get("id"), 2) +
Base64.fromIntN(player_craft.ingreds[5].get("id"), 2) +
Base64.fromIntN(player_craft.recipe.get("id"),2) +
Base64.fromIntN(player_craft.mat_tiers[0] + (player_craft.mat_tiers[1]-1)*3, 1) + //this maps tiers [a,b] to a+3b.
Base64.fromIntN(atkSpds.indexOf(player_craft["atkSpd"]),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 "";