Fix minor bug in skillpoint engine, add assign skillpoint

This commit is contained in:
b 2021-01-07 20:40:12 -06:00
parent f3c2cefd5a
commit 00f380fe87
4 changed files with 35 additions and 10 deletions

View file

@ -130,6 +130,9 @@
</div> </div>
<div class="skillpoints"> <div class="skillpoints">
<div class="center" style="grid-column:1;grid-row:1"> <div class="center" style="grid-column:1;grid-row:1">
<div id="str-skp-assign">
Before Boosts: 0
</div>
<div> <div>
<label for="str-skp">Strength:</label> <label for="str-skp">Strength:</label>
<input type="number" id="str-skp" name="str-skp" value="0"/> <input type="number" id="str-skp" name="str-skp" value="0"/>
@ -139,6 +142,9 @@
</div> </div>
</div> </div>
<div class="center" style="grid-column:2;grid-row:1"> <div class="center" style="grid-column:2;grid-row:1">
<div id="dex-skp-assign">
Before Boosts: 0
</div>
<div> <div>
<label for="dex-skp">Dexterity:</label> <label for="dex-skp">Dexterity:</label>
<input type="number" id="dex-skp" name="dex-skp" value="0"/> <input type="number" id="dex-skp" name="dex-skp" value="0"/>
@ -148,6 +154,9 @@
</div> </div>
</div> </div>
<div class="center" style="grid-column:3;grid-row:1"> <div class="center" style="grid-column:3;grid-row:1">
<div id="int-skp-assign">
Before Boosts: 0
</div>
<div> <div>
<label for="int-skp">Intelligence:</label> <label for="int-skp">Intelligence:</label>
<input type="number" id="int-skp" name="int-skp" value="0"/> <input type="number" id="int-skp" name="int-skp" value="0"/>
@ -157,6 +166,9 @@
</div> </div>
</div> </div>
<div class="center" style="grid-column:4;grid-row:1"> <div class="center" style="grid-column:4;grid-row:1">
<div id="def-skp-assign">
Before Boosts: 0
</div>
<div> <div>
<label for="def-skp">Defense:</label> <label for="def-skp">Defense:</label>
<input type="number" id="def-skp" name="def-skp" value="0"/> <input type="number" id="def-skp" name="def-skp" value="0"/>
@ -166,6 +178,9 @@
</div> </div>
</div> </div>
<div class="center" style="grid-column:5;grid-row:1"> <div class="center" style="grid-column:5;grid-row:1">
<div id="agi-skp-assign">
Before Boosts: 0
</div>
<div> <div>
<label for="agi-skp">Agility:</label> <label for="agi-skp">Agility:</label>
<input type="number" id="agi-skp" name="agi-skp" value="0"/> <input type="number" id="agi-skp" name="agi-skp" value="0"/>

View file

@ -5,14 +5,8 @@ function calculate_skillpoints(equipment, weapon) {
let fixed = []; let fixed = [];
let consider = []; let consider = [];
let noboost = []; let noboost = [];
let has_skillpoint = [false, false, false, false, false];
for (const item of equipment) { for (const item of equipment) {
for (let i = 0; i < 5; ++i) {
if (item.reqs[i] > 0) {
has_skillpoint[i] = true;
}
}
if (item.reqs.every(x => x === 0)) { if (item.reqs.every(x => x === 0)) {
fixed.push(item); fixed.push(item);
} }
@ -46,6 +40,7 @@ function calculate_skillpoints(equipment, weapon) {
total -= item.skillpoints[i]; total -= item.skillpoints[i];
} }
if (item.reqs[i] == 0) continue; if (item.reqs[i] == 0) continue;
skillpoint_filter[i] = true;
const req = item.reqs[i]; const req = item.reqs[i];
const cur = skillpoints[i]; const cur = skillpoints[i];
if (req > cur) { if (req > cur) {
@ -71,6 +66,8 @@ function calculate_skillpoints(equipment, weapon) {
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 has_skillpoint = [false, false, false, false, false];
permutation = permutation.concat(noboost); permutation = permutation.concat(noboost);
console.log(permutation); console.log(permutation);

17
test.js
View file

@ -268,17 +268,26 @@ function calculateBuild(){
} }
setHTML("build-order", equip_order_text); setHTML("build-order", equip_order_text);
player_build.base_skillpoints; let assigned = player_build.base_skillpoints;
setText("str-skp-assign", "Before Boosts: " + assigned[0]);
setText("dex-skp-assign", "Before Boosts: " + assigned[1]);
setText("int-skp-assign", "Before Boosts: " + assigned[2]);
setText("def-skp-assign", "Before Boosts: " + assigned[3]);
setText("agi-skp-assign", "Before Boosts: " + assigned[4]);
let skillpoints = player_build.total_skillpoints; let skillpoints = player_build.total_skillpoints;
setValue("str-skp", skillpoints[0]); setValue("str-skp", skillpoints[0]);
setValue("dex-skp", skillpoints[1]); setValue("dex-skp", skillpoints[1]);
setValue("int-skp", skillpoints[2]); setValue("int-skp", skillpoints[2]);
setValue("def-skp", skillpoints[3]); setValue("def-skp", skillpoints[3]);
setValue("agi-skp", skillpoints[4]); setValue("agi-skp", skillpoints[4]);
console.log(skillpoints); setText("str-skp-base", "Original Value: " + skillpoints[0]);
player_build.assigned_skillpoints; setText("dex-skp-base", "Original Value: " + skillpoints[1]);
setText("int-skp-base", "Original Value: " + skillpoints[2]);
setText("def-skp-base", "Original Value: " + skillpoints[3]);
setText("agi-skp-base", "Original Value: " + skillpoints[4]);
setHTML("summary-box", "Summary: Assigned "+player_build.assigned_skillpoints+" skillpoints."); setText("summary-box", "Summary: Assigned "+player_build.assigned_skillpoints+" skillpoints.");
displayExpandedItem(expandItem(player_build.helmet), "build-helmet"); displayExpandedItem(expandItem(player_build.helmet), "build-helmet");
displayExpandedItem(expandItem(player_build.chestplate), "build-chestplate"); displayExpandedItem(expandItem(player_build.chestplate), "build-chestplate");

View file

@ -22,6 +22,10 @@ function perm(a){
return r; return r;
} }
function setText(id, text) {
document.getElementById(id).textContent = text;
}
function setHTML(id, html) { function setHTML(id, html) {
document.getElementById(id).innerHTML = html; document.getElementById(id).innerHTML = html;
} }