Apply set bonuses during skillpoint calculation
This commit is contained in:
parent
ad355127d4
commit
9508ab81ad
5 changed files with 65 additions and 75 deletions
28
build.js
28
build.js
|
@ -133,6 +133,7 @@ class Build{
|
||||||
this.base_skillpoints = result[1];
|
this.base_skillpoints = result[1];
|
||||||
this.total_skillpoints = result[2];
|
this.total_skillpoints = result[2];
|
||||||
this.assigned_skillpoints = result[3];
|
this.assigned_skillpoints = result[3];
|
||||||
|
this.activeSetCounts = result[4];
|
||||||
|
|
||||||
// For strength boosts like warscream, vanish, etc.
|
// For strength boosts like warscream, vanish, etc.
|
||||||
this.damageMultiplier = 1.0;
|
this.damageMultiplier = 1.0;
|
||||||
|
@ -197,29 +198,11 @@ class Build{
|
||||||
return damages_results.concat([totalDamNorm,totalDamCrit,normDPS,critDPS,avgDPS,adjAtkSpd]);
|
return damages_results.concat([totalDamNorm,totalDamCrit,normDPS,critDPS,avgDPS,adjAtkSpd]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Gets a list of active sets and set counts.
|
|
||||||
*/
|
|
||||||
getSetBonuses() {
|
|
||||||
let activeSetCounts = new Map()
|
|
||||||
for (const item of this.items) {
|
|
||||||
console.log(item.get("name"));
|
|
||||||
const setName = setMap.get(item.get("name"));
|
|
||||||
if (setName) { // undefined/null means no set.
|
|
||||||
activeSetCounts.set(setName, (activeSetCounts.get(setName) || 0) + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return activeSetCounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get all stats for this build. Stores in this.statMap.
|
/* Get all stats for this build. Stores in this.statMap.
|
||||||
@pre The build itself should be valid. No checking of validity of pieces is done here.
|
@pre The build itself should be valid. No checking of validity of pieces is done here.
|
||||||
*/
|
*/
|
||||||
initBuildStats(){
|
initBuildStats(){
|
||||||
|
|
||||||
let activeSetCounts = this.getSetBonuses();
|
|
||||||
this.activeSetCounts = activeSetCounts;
|
|
||||||
|
|
||||||
let staticIDs = ["hp", "eDef", "tDef", "wDef", "fDef", "aDef"];
|
let staticIDs = ["hp", "eDef", "tDef", "wDef", "fDef", "aDef"];
|
||||||
|
|
||||||
//Create a map of this build's stats
|
//Create a map of this build's stats
|
||||||
|
@ -239,10 +222,15 @@ class Build{
|
||||||
if (item.get(staticID)) { statMap.set(staticID, statMap.get(staticID) + item.get(staticID)); }
|
if (item.get(staticID)) { statMap.set(staticID, statMap.get(staticID) + item.get(staticID)); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const [setName, count] of activeSetCounts) {
|
for (const [setName, count] of this.activeSetCounts) {
|
||||||
const bonus = sets[setName].bonuses[count-1];
|
const bonus = sets[setName].bonuses[count-1];
|
||||||
for (const id in bonus) {
|
for (const id in bonus) {
|
||||||
statMap.set(id,(statMap.get(id) || 0)+bonus[id]);
|
if (skp_order.includes(id)) {
|
||||||
|
// pass. Don't include skillpoints in ids
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
statMap.set(id,(statMap.get(id) || 0)+bonus[id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,5 @@ Damage calculator checking: https://its0x7.cf/build/
|
||||||
Theme and overall inspiration: Wynndata (Dukio)
|
Theme and overall inspiration: Wynndata (Dukio)
|
||||||
- https://wynndata.tk
|
- https://wynndata.tk
|
||||||
|
|
||||||
|
Additional Contributors:
|
||||||
|
- QuantumNep (Layout code/layout ideas)
|
||||||
|
|
|
@ -250,16 +250,12 @@
|
||||||
<div class = "center build-weapon" id = "build-weapon" style = "grid-column:1;grid-row:3">
|
<div class = "center build-weapon" id = "build-weapon" style = "grid-column:1;grid-row:3">
|
||||||
<div class = "center" id = "build-weapon-stats"></div>
|
<div class = "center" id = "build-weapon-stats"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class = "center build-overall" id = "build-overall" style = "grid-column:4;grid-row:3">
|
|
||||||
<p class="itemcenter">Overall Build Stats:<p>
|
|
||||||
<div class = "center" id = "build-overall-stats"></div>
|
|
||||||
</div>
|
|
||||||
<div class = "center build-melee-stats" id = "build-melee-stats" style = "grid-column:3;grid-row:3">
|
<div class = "center build-melee-stats" id = "build-melee-stats" style = "grid-column:3;grid-row:3">
|
||||||
</div>
|
</div>
|
||||||
<div class = "center build-order" id = "build-order" style = "grid-column:2;grid-row:3">
|
<div class = "center build-order" id = "build-order" style = "grid-column:2;grid-row:3">
|
||||||
</div>
|
</div>
|
||||||
<!--div class = "center" id = "build-defense-stats" style = "grid-column:4;grid-row:3">
|
<div class = "center" id = "build-defense-stats" style = "grid-column:4;grid-row:3">
|
||||||
</div-->
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class = "spells">
|
<div class = "spells">
|
||||||
<div class = "center spell-info" id = "spell0" style = "grid-column:1;grid-row:1">
|
<div class = "center spell-info" id = "spell0" style = "grid-column:1;grid-row:1">
|
||||||
|
|
|
@ -10,32 +10,47 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
if (item.get("reqs").every(x => x === 0)) {
|
if (item.get("reqs").every(x => x === 0)) {
|
||||||
fixed.push(item);
|
fixed.push(item);
|
||||||
}
|
}
|
||||||
else if (item.get("skillpoints").every(x => x === 0)) {
|
// TODO hack: We will treat ALL set items as unsafe :(
|
||||||
|
else if (item.get("skillpoints").every(x => x === 0) && item.get("set") === null) {
|
||||||
noboost.push(item);
|
noboost.push(item);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
consider.push(item);
|
consider.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function apply_skillpoints(skillpoints, item) {
|
function apply_skillpoints(skillpoints, item, activeSetCounts) {
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
skillpoints[i] += item.get("skillpoints")[i];
|
skillpoints[i] += item.get("skillpoints")[i];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function remove_skillpoints(skillpoints, item) {
|
const setName = item.get("set");
|
||||||
for (let i = 0; i < 5; i++) {
|
if (setName) { // undefined/null means no set.
|
||||||
skillpoints[i] -= item.get("skillpoints")[i];
|
let setCount = activeSetCounts.get(setName);
|
||||||
|
let old_bonus = {};
|
||||||
|
if (setCount) {
|
||||||
|
old_bonus = sets[setName].bonuses[setCount-1];
|
||||||
|
activeSetCounts.set(setName, setCount + 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setCount = 0;
|
||||||
|
activeSetCounts.set(setName, 1);
|
||||||
|
}
|
||||||
|
const new_bonus = sets[setName].bonuses[setCount];
|
||||||
|
//let skp_order = ["str","dex","int","def","agi"];
|
||||||
|
for (const i in skp_order) {
|
||||||
|
const delta = (new_bonus[skp_order[i]] || 0) - (old_bonus[skp_order[i]] || 0);
|
||||||
|
skillpoints[i] += delta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out (naively) how many skillpoints need to be applied to get the current item to fit.
|
// Figure out (naively) how many skillpoints need to be applied to get the current item to fit.
|
||||||
// Doesn't handle -skp.
|
// Doesn't handle -skp.
|
||||||
function apply_to_fit(skillpoints, item, skillpoint_filter) {
|
function apply_to_fit(skillpoints, item, skillpoint_filter, activeSetCounts) {
|
||||||
let applied = [0, 0, 0, 0, 0];
|
let applied = [0, 0, 0, 0, 0];
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
if (item.get("skillpoints")[i] < 0 && skillpoint_filter[i] === true) {
|
if (item.get("skillpoints")[i] < 0 && skillpoint_filter[i]) {
|
||||||
applied[i] -= item.get("skillpoints")[i];
|
applied[i] -= item.get("skillpoints")[i];
|
||||||
total -= item.get("skillpoints")[i];
|
total -= item.get("skillpoints")[i];
|
||||||
}
|
}
|
||||||
|
@ -49,24 +64,46 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
total += diff;
|
total += diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setName = item.get("set");
|
||||||
|
if (setName) { // undefined/null means no set.
|
||||||
|
const setCount = activeSetCounts.get(setName);
|
||||||
|
if (setCount) {
|
||||||
|
const old_bonus = sets[setName].bonuses[setCount-1];
|
||||||
|
const new_bonus = sets[setName].bonuses[setCount];
|
||||||
|
//let skp_order = ["str","dex","int","def","agi"];
|
||||||
|
for (const i in skp_order) {
|
||||||
|
const delta = (new_bonus[skp_order[i]] || 0) - (old_bonus[skp_order[i]] || 0);
|
||||||
|
if (delta < 0 && skillpoint_filter[i]) {
|
||||||
|
applied[i] -= delta;
|
||||||
|
total -= delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [applied, total];
|
return [applied, total];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separate out the no req items and add them to the static skillpoint base.
|
// Separate out the no req items and add them to the static skillpoint base.
|
||||||
let static_skillpoints_base = [0, 0, 0, 0, 0]
|
let static_skillpoints_base = [0, 0, 0, 0, 0]
|
||||||
|
let static_activeSetCounts = new Map()
|
||||||
for (const item of fixed) {
|
for (const item of fixed) {
|
||||||
apply_skillpoints(static_skillpoints_base, item);
|
apply_skillpoints(static_skillpoints_base, item, static_activeSetCounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
let best = consider.concat(noboost);
|
let best = consider.concat(noboost);
|
||||||
let final_skillpoints = static_skillpoints_base.slice();
|
let final_skillpoints = static_skillpoints_base.slice();
|
||||||
let best_skillpoints = [0, 0, 0, 0, 0];
|
let best_skillpoints = [0, 0, 0, 0, 0];
|
||||||
let best_total = Infinity;
|
let best_total = Infinity;
|
||||||
|
let best_activeSetCounts = static_activeSetCounts;
|
||||||
|
|
||||||
let allFalse = [false, false, false, false, false];
|
let allFalse = [false, false, false, false, false];
|
||||||
if (consider.length > 0 || noboost.length > 0) {
|
if (consider.length > 0 || noboost.length > 0) {
|
||||||
// Try every combination and pick the best one.
|
// Try every combination and pick the best one.
|
||||||
for (let permutation of perm(consider)) {
|
for (let permutation of perm(consider)) {
|
||||||
|
let activeSetCounts = new Map(static_activeSetCounts);
|
||||||
|
|
||||||
let has_skillpoint = allFalse.slice();
|
let has_skillpoint = allFalse.slice();
|
||||||
|
|
||||||
permutation = permutation.concat(noboost);
|
permutation = permutation.concat(noboost);
|
||||||
|
@ -81,7 +118,7 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
let needed_skillpoints;
|
let needed_skillpoints;
|
||||||
let total_diff;
|
let total_diff;
|
||||||
for (const item of permutation) {
|
for (const item of permutation) {
|
||||||
result = apply_to_fit(skillpoints, item, has_skillpoint);
|
result = apply_to_fit(skillpoints, item, has_skillpoint, activeSetCounts);
|
||||||
needed_skillpoints = result[0];
|
needed_skillpoints = result[0];
|
||||||
total_diff = result[1];
|
total_diff = result[1];
|
||||||
|
|
||||||
|
@ -89,40 +126,14 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
skillpoints_applied[i] += needed_skillpoints[i];
|
skillpoints_applied[i] += needed_skillpoints[i];
|
||||||
skillpoints[i] += needed_skillpoints[i];
|
skillpoints[i] += needed_skillpoints[i];
|
||||||
}
|
}
|
||||||
apply_skillpoints(skillpoints, item);
|
apply_skillpoints(skillpoints, item, activeSetCounts);
|
||||||
total_applied += total_diff;
|
total_applied += total_diff;
|
||||||
if (total_applied >= best_total) {
|
if (total_applied >= best_total) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (total_applied < best_total) {
|
|
||||||
// console.log(total_applied);
|
|
||||||
// console.log(skillpoints_applied);
|
|
||||||
// console.log("Iteration 2");
|
|
||||||
// for (const item of permutation) {
|
|
||||||
// console.log(item);
|
|
||||||
//
|
|
||||||
// remove_skillpoints(skillpoints, item);
|
|
||||||
// console.log(skillpoints);
|
|
||||||
// result = apply_to_fit(skillpoints, item, has_skillpoint);
|
|
||||||
// needed_skillpoints = result[0];
|
|
||||||
// total_diff = result[1];
|
|
||||||
// for (let i = 0; i < 5; ++i) {
|
|
||||||
// skillpoints_applied[i] += needed_skillpoints[i];
|
|
||||||
// skillpoints[i] += needed_skillpoints[i];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// apply_skillpoints(skillpoints, item);
|
|
||||||
// console.log(skillpoints);
|
|
||||||
// console.log(total_diff);
|
|
||||||
// total_applied += total_diff;
|
|
||||||
// if (total_applied >= best_total) {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
let pre = skillpoints.slice();
|
let pre = skillpoints.slice();
|
||||||
result = apply_to_fit(skillpoints, weapon, allFalse.slice());
|
result = apply_to_fit(skillpoints, weapon, allFalse.slice(), activeSetCounts);
|
||||||
needed_skillpoints = result[0];
|
needed_skillpoints = result[0];
|
||||||
total_diff = result[1];
|
total_diff = result[1];
|
||||||
for (let i = 0; i < 5; ++i) {
|
for (let i = 0; i < 5; ++i) {
|
||||||
|
@ -130,7 +141,7 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
skillpoints[i] += needed_skillpoints[i];
|
skillpoints[i] += needed_skillpoints[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
apply_skillpoints(skillpoints, weapon);
|
apply_skillpoints(skillpoints, weapon, activeSetCounts);
|
||||||
total_applied += total_diff;
|
total_applied += total_diff;
|
||||||
|
|
||||||
if (total_applied < best_total) {
|
if (total_applied < best_total) {
|
||||||
|
@ -140,13 +151,14 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
final_skillpoints = skillpoints;
|
final_skillpoints = skillpoints;
|
||||||
best_skillpoints = skillpoints_applied;
|
best_skillpoints = skillpoints_applied;
|
||||||
best_total = total_applied;
|
best_total = total_applied;
|
||||||
|
best_activeSetCounts = activeSetCounts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
best_total = 0;
|
best_total = 0;
|
||||||
result = apply_to_fit(final_skillpoints, weapon, allFalse.slice());
|
result = apply_to_fit(final_skillpoints, weapon, allFalse.slice(), best_activeSetCounts);
|
||||||
needed_skillpoints = result[0];
|
needed_skillpoints = result[0];
|
||||||
total_diff = result[1];
|
total_diff = result[1];
|
||||||
for (let i = 0; i < 5; ++i) {
|
for (let i = 0; i < 5; ++i) {
|
||||||
|
@ -157,5 +169,5 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
best_total += total_diff;
|
best_total += total_diff;
|
||||||
}
|
}
|
||||||
let equip_order = fixed.concat(best);
|
let equip_order = fixed.concat(best);
|
||||||
return [equip_order, best_skillpoints, final_skillpoints, best_total];
|
return [equip_order, best_skillpoints, final_skillpoints, best_total, best_activeSetCounts];
|
||||||
}
|
}
|
||||||
|
|
8
test.js
8
test.js
|
@ -97,7 +97,6 @@ for (const it of itemTypes) {
|
||||||
}
|
}
|
||||||
let itemMap = new Map();
|
let itemMap = new Map();
|
||||||
/* Mapping from item names to set names. */
|
/* Mapping from item names to set names. */
|
||||||
let setMap = new Map();
|
|
||||||
let idMap = new Map();
|
let idMap = new Map();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -161,13 +160,6 @@ function init() {
|
||||||
itemMap.set(item.displayName, item);
|
itemMap.set(item.displayName, item);
|
||||||
idMap.set(item.id, item.displayName);
|
idMap.set(item.id, item.displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const setName in sets) {
|
|
||||||
const set = sets[setName];
|
|
||||||
for (const itemName of set.items) {
|
|
||||||
setMap.set(itemName, setName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const armorType of armorTypes) {
|
for (const armorType of armorTypes) {
|
||||||
populateItemList(armorType);
|
populateItemList(armorType);
|
||||||
|
|
Loading…
Reference in a new issue