From 975c0faa1fc6bb6f995a6d2c230d0b3b462d4476 Mon Sep 17 00:00:00 2001 From: hppeng Date: Sun, 26 Jun 2022 00:08:02 -0700 Subject: [PATCH] Fix crafter page, fix damage calculation for crafted and normal items (no longer rounded powder damage) --- crafter/index.html | 2 -- item/index.html | 2 -- items_adv/index.html | 2 -- js/build_utils.js | 2 +- js/builder_graph.js | 11 ++++-- js/crafter.js | 15 +++++--- js/damage_calc.js | 86 +++++++++++++++++++++++++++++--------------- js/display.js | 15 ++++++++ 8 files changed, 91 insertions(+), 44 deletions(-) diff --git a/crafter/index.html b/crafter/index.html index 76f6cf3..0359611 100644 --- a/crafter/index.html +++ b/crafter/index.html @@ -301,8 +301,6 @@ - - diff --git a/item/index.html b/item/index.html index 758c902..00cfade 100644 --- a/item/index.html +++ b/item/index.html @@ -62,8 +62,6 @@ - - diff --git a/items_adv/index.html b/items_adv/index.html index fb9da0f..fd5d749 100644 --- a/items_adv/index.html +++ b/items_adv/index.html @@ -79,8 +79,6 @@ - - diff --git a/js/build_utils.js b/js/build_utils.js index 80db2f1..430d55c 100644 --- a/js/build_utils.js +++ b/js/build_utils.js @@ -58,7 +58,7 @@ const baseDamageMultiplier = [ 0.51, 0.83, 1.5, 2.05, 2.5, 3.1, 4.3 ]; const classes = ["Warrior", "Assassin", "Mage", "Archer", "Shaman"]; const wep_to_class = new Map([["dagger", "Assassin"], ["spear", "Warrior"], ["wand", "Mage"], ["bow", "Archer"], ["relik", "Shaman"]]) const tiers = ["Normal", "Unique", "Rare", "Legendary", "Fabled", "Mythic", "Set", "Crafted"] //I'm not sure why you would make a custom crafted but if you do you should be able to use it w/ the correct powder formula -const types = armorTypes.concat(accessoryTypes).concat(weaponTypes).concat(consumableTypes).concat(tome_types).map(x => x.substring(0,1).toUpperCase() + x.substring(1)); +const all_types = armorTypes.concat(accessoryTypes).concat(weaponTypes).concat(consumableTypes).concat(tome_types).map(x => x.substring(0,1).toUpperCase() + x.substring(1)); //weaponTypes.push("sword"); //console.log(types) let itemTypes = armorTypes.concat(accessoryTypes).concat(weaponTypes).concat(tome_types); diff --git a/js/builder_graph.js b/js/builder_graph.js index 63d08d1..7eae496 100644 --- a/js/builder_graph.js +++ b/js/builder_graph.js @@ -204,8 +204,13 @@ class ItemInputNode extends InputNode { type_match = item.statMap.get('type') === this.none_item.statMap.get('type'); } if (type_match) { - if (item.statMap.get('category') === 'armor' && powdering !== undefined) { - applyArmorPowders(item.statMap, powdering); + if (powdering !== undefined) { + if (item.statMap.get('category') === 'armor') { + applyArmorPowders(item.statMap, powdering); + } + else if (item.statMap.get('category') === 'weapon') { + apply_weapon_powders(item.statMap, powdering); + } } return item; } @@ -330,7 +335,7 @@ class WeaponInputDisplayNode extends ComputeNode { dps = dps[1]; if (isNaN(dps)) dps = 0; } - this.dps_field.textContent = dps; + this.dps_field.textContent = Math.round(dps); //as of now, we NEED to have the dropdown tab visible/not hidden in order to properly display atree stuff. if (!document.getElementById("toggle-atree").classList.contains("toggleOn")) { diff --git a/js/crafter.js b/js/crafter.js index 66b9087..bb40c7e 100644 --- a/js/crafter.js +++ b/js/crafter.js @@ -172,16 +172,17 @@ function calculateCraft() { document.getElementById("mat-2").textContent = recipe.get("materials")[1].get("item").split(" ").slice(1).join(" ") + " Tier:"; //Display Recipe Stats - displaysq2RecipeStats(player_craft, "recipe-stats"); + displayRecipeStats(player_craft, "recipe-stats"); //Display Craft Stats // displayCraftStats(player_craft, "craft-stats"); let mock_item = player_craft.statMap; - displaysq2ExpandedItem(mock_item, "craft-stats"); + apply_weapon_powders(mock_item); + displayExpandedItem(mock_item, "craft-stats"); //Display Ingredients' Stats for (let i = 1; i < 7; i++) { - displaysq2ExpandedIngredient(player_craft.ingreds[i-1] , "ing-"+i+"-stats"); + displayExpandedIngredient(player_craft.ingreds[i-1] , "ing-"+i+"-stats"); } //Display Warnings - only ingred type warnings for now let warning_elem = document.getElementById("craft-warnings"); @@ -341,7 +342,7 @@ function toggleMaterial(buttonId) { */ function updateCraftedImage() { let input = document.getElementById("recipe-choice"); - if (item_types.includes(input.value)) { + if (all_types.includes(input.value)) { document.getElementById("recipe-img").src = "../media/items/" + (newIcons ? "new/":"old/") + "generic-" + input.value.toLowerCase() + ".png"; } @@ -364,4 +365,8 @@ function resetFields() { calculateCraft(); } -load_ing_init(init_crafter); +(async function() { + let load_promises = [ load_ing_init() ]; + await Promise.all(load_promises); + init_crafter(); +})(); diff --git a/js/damage_calc.js b/js/damage_calc.js index 058ba96..856743d 100644 --- a/js/damage_calc.js +++ b/js/damage_calc.js @@ -1,34 +1,25 @@ const damageMultipliers = new Map([ ["allytotem", .15], ["yourtotem", .35], ["vanish", 0.80], ["warscream", 0.10], ["bash", 0.50] ]); -// GRR THIS MUTATES THE ITEM +const damage_keys = [ "nDam_", "eDam_", "tDam_", "wDam_", "fDam_", "aDam_" ]; +const damage_present_key = 'damagePresent'; function get_base_dps(item) { const attack_speed_mult = baseDamageMultiplier[attackSpeeds.indexOf(item.get("atkSpd"))]; //SUPER JANK @HPP PLS FIX - let damage_keys = [ "nDam_", "eDam_", "tDam_", "wDam_", "fDam_", "aDam_" ]; if (item.get("tier") !== "Crafted") { - let weapon_result = apply_weapon_powder(item); - let damages = weapon_result[0]; let total_damage = 0; - for (const i in damage_keys) { - total_damage += damages[i][0] + damages[i][1]; - item.set(damage_keys[i], damages[i][0]+"-"+damages[i][1]); + for (const damage_k of damage_keys) { + damages = item.get(damage_k); + total_damage += damages[0] + damages[1]; } - total_damage = total_damage / 2; - return total_damage * attack_speed_mult; - } else { - let base_low = [item.get("nDamBaseLow"),item.get("eDamBaseLow"),item.get("tDamBaseLow"),item.get("wDamBaseLow"),item.get("fDamBaseLow"),item.get("aDamBaseLow")]; - let results_low = apply_weapon_powder(item, base_low); - let damage_low = results_low[2]; - let base_high = [item.get("nDamBaseHigh"),item.get("eDamBaseHigh"),item.get("tDamBaseHigh"),item.get("wDamBaseHigh"),item.get("fDamBaseHigh"),item.get("aDamBaseHigh")]; - let results_high = apply_weapon_powder(item, base_high); - let damage_high = results_high[2]; - + return total_damage * attack_speed_mult / 2; + } + else { let total_damage_min = 0; let total_damage_max = 0; - for (const i in damage_keys) { - total_damage_min += damage_low[i][0] + damage_low[i][1]; - total_damage_max += damage_high[i][0] + damage_high[i][1]; - item.set(damage_keys[i], damage_low[i][0]+"-"+damage_low[i][1]+"\u279c"+damage_high[i][0]+"-"+damage_high[i][1]); + for (const damage_k of damage_keys) { + damages = item.get(damage_k); + total_damage_min += damages[0][0] + damages[0][1]; + total_damage_max += damages[1][0] + damages[1][1]; } total_damage_min = attack_speed_mult * total_damage_min / 2; total_damage_max = attack_speed_mult * total_damage_max / 2; @@ -36,11 +27,38 @@ function get_base_dps(item) { } } +// THIS MUTATES THE ITEM +function apply_weapon_powders(item) { + let present; + if (item.get("tier") !== "Crafted") { + let weapon_result = calc_weapon_powder(item); + let damages = weapon_result[0]; + present = weapon_result[1]; + for (const i in damage_keys) { + item.set(damage_keys[i], damages[i]); + } + } else { + let base_low = [item.get("nDamBaseLow"),item.get("eDamBaseLow"),item.get("tDamBaseLow"),item.get("wDamBaseLow"),item.get("fDamBaseLow"),item.get("aDamBaseLow")]; + let results_low = calc_weapon_powder(item, base_low); + let damage_low = results_low[0]; + let base_high = [item.get("nDamBaseHigh"),item.get("eDamBaseHigh"),item.get("tDamBaseHigh"),item.get("wDamBaseHigh"),item.get("fDamBaseHigh"),item.get("aDamBaseHigh")]; + let results_high = calc_weapon_powder(item, base_high); + let damage_high = results_high[0]; + present = results_high[1]; + + for (const i in damage_keys) { + item.set(damage_keys[i], [damage_low[i], damage_high[i]]); + } + } + console.log(item); + item.set(damage_present_key, present); +} + /** * weapon: Weapon to apply powder to * damageBases: used by crafted */ -function apply_weapon_powder(weapon, damageBases) { +function calc_weapon_powder(weapon, damageBases) { let powders = weapon.get("powders").slice(); // Array of neutral + ewtfa damages. Each entry is a pair (min, max). @@ -86,10 +104,15 @@ function apply_weapon_powder(weapon, damageBases) { if (neutralRemainingRaw[1] > 0) { let min_diff = Math.min(neutralRemainingRaw[0], conversionRatio * neutralBase[0]); let max_diff = Math.min(neutralRemainingRaw[1], conversionRatio * neutralBase[1]); - damages[element+1][0] = Math.floor(round_near(damages[element+1][0] + min_diff)); - damages[element+1][1] = Math.floor(round_near(damages[element+1][1] + max_diff)); - neutralRemainingRaw[0] = Math.floor(round_near(neutralRemainingRaw[0] - min_diff)); - neutralRemainingRaw[1] = Math.floor(round_near(neutralRemainingRaw[1] - max_diff)); + + //damages[element+1][0] = Math.floor(round_near(damages[element+1][0] + min_diff)); + //damages[element+1][1] = Math.floor(round_near(damages[element+1][1] + max_diff)); + //neutralRemainingRaw[0] = Math.floor(round_near(neutralRemainingRaw[0] - min_diff)); + //neutralRemainingRaw[1] = Math.floor(round_near(neutralRemainingRaw[1] - max_diff)); + damages[element+1][0] += min_diff; + damages[element+1][1] += max_diff; + neutralRemainingRaw[0] -= min_diff; + neutralRemainingRaw[1] -= max_diff; } damages[element+1][0] += powder.min; damages[element+1][1] += powder.max; @@ -111,9 +134,14 @@ function calculateSpellDamage(stats, weapon, conversions, use_spell_damage, igno // Array of neutral + ewtfa damages. Each entry is a pair (min, max). // 1. Get weapon damage (with powders). - let weapon_result = apply_weapon_powder(weapon); - let weapon_damages = weapon_result[0]; - let present = weapon_result[1]; + let weapon_damages; + if (weapon.get('tier') === 'Crafted') { + weapon_damages = damage_keys.map(x => weapon.get(x)[1]); + } + else { + weapon_damages = damage_keys.map(x => weapon.get(x)); + } + let present = weapon.get(damage_present_key); // 2. Conversions. // 2.1. First, apply neutral conversion (scale weapon damage). Keep track of total weapon damage here. diff --git a/js/display.js b/js/display.js index 631f0c0..a45eae1 100644 --- a/js/display.js +++ b/js/display.js @@ -173,6 +173,7 @@ function displayExpandedItem(item, parent_id){ // #commands create a new element. // !elemental is some janky hack for elemental damage. // normals just display a thing. + item = new Map(item); // shallow copy if (item.get("category") === "weapon") { item.set('basedps', get_base_dps(item)); } else if (item.get("category") === "armor") { @@ -341,7 +342,21 @@ function displayExpandedItem(item, parent_id){ bckgrd.appendChild(img); } } else { + if (id.endsWith('Dam_')) { + // TODO: kinda jank but replacing lists with txt at this step + let damages = item.get(id); + if (item.get("tier") !== "Crafted") { + damages = damages.map(x => Math.round(x)); + item.set(id, damages[0]+"-"+damages[1]); + } + else { + damages = damages.map(x => x.map(y => Math.round(y))); + item.set(id, damages[0][0]+"-"+damages[0][1]+"\u279c"+damages[1][0]+"-"+damages[1][1]); + } + } + let p_elem; + // TODO: wtf is this if statement if ( !(item.get("tier") === "Crafted" && item.get("category") === "armor" && id === "hp") && (!skp_order.includes(id)) || (skp_order.includes(id) && item.get("tier") !== "Crafted" && parent_div.nodeName === "table") ) { //skp warp p_elem = displayFixedID(parent_div, id, item.get(id), elemental_format); } else if (item.get("tier") === "Crafted" && item.get("category") === "armor" && id === "hp") {