From 55ba7f4fc221392e0b9a3dfe5ca9f11389350701 Mon Sep 17 00:00:00 2001 From: b Date: Thu, 7 Jan 2021 00:41:41 -0600 Subject: [PATCH] Skillpoints engine --- build.js | 19 +++++-- compress.py | 2 +- index.html | 53 ++++++++++++++---- load.js | 5 +- skillpoint_test.py | 90 +++++++++++++++++++++++++------ skillpoints.js | 131 +++++++++++++++++++++++++++++++++++++++++++++ styles.css | 4 +- test.js | 104 ++++++++++++++++++++++------------- utils.js | 31 +++++++++++ 9 files changed, 365 insertions(+), 74 deletions(-) create mode 100644 skillpoints.js create mode 100644 utils.js diff --git a/build.js b/build.js index 3c62161..4961b26 100644 --- a/build.js +++ b/build.js @@ -99,16 +99,25 @@ class Build{ }else{ this.level = level; } - this.skillpoints = levelToSkillPoints(this.level) + this.availableSkillpoints = levelToSkillPoints(this.level); + this.equipment = [ helmet, chestplate, leggings, boots, ring1, ring2, bracelet, necklace ]; + + // return [equip_order, best_skillpoints, final_skillpoints, best_total]; + let result = calculate_skillpoints(this.equipment, weapon); + console.log(result); + this.equip_order = result[0]; + this.base_skillpoints = result[1]; + this.total_skillpoints = result[2]; + this.assigned_skillpoints = result[3]; } /*Returns build in string format - */ TODO + */ toString(){ return this.helmet.name + ", " + this.chestplate.name + ", " + this.leggings.name + ", " + this.boots.name + ", " + this.ring1.name + ", " + this.ring2.name + ", " + this.bracelet.name + ", " + this.necklace.name + ", " + this.weapon.name; } - /* Getters */ TODO + /* Getters */ getHealth(){ health = parseInt(this.helmet.hp,10) + parseInt(this.helmet.hpBonus,10) + parseInt(this.chestplate.hp,10) + parseInt(this.chestplate.hpBonus,10) + parseInt(this.leggings.hp,10) + parseInt(this.leggings.hpBonus,10) + parseInt(this.boots.hp,10) + parseInt(this.boots.hpBonus,10) + parseInt(this.ring1.hp,10) + parseInt(this.ring1.hpBonus,10) + parseInt(this.ring2.hp,10) + parseInt(this.ring2.hpBonus,10) + parseInt(this.bracelet.hp,10) + parseInt(this.bracelet.hpBonus,10) + parseInt(this.necklace.hp,10) + parseInt(this.necklace.hpBonus,10) + parseInt(this.weapon.hp,10) + parseInt(this.weapon.hpBonus,10) + levelToHPBase(this.level); if(health<5){ @@ -117,6 +126,8 @@ class Build{ return health; } } - /* Setters */ TODO + + /* Setters */ + } diff --git a/compress.py b/compress.py index c548def..9ed4a1c 100644 --- a/compress.py +++ b/compress.py @@ -55,7 +55,7 @@ translate_mappings = { "agilityPoints": "agi", "defensePoints": "def", #"thorns": "thorns", - #"exploding": "expoding", + #"exploding": "exploding", "speed": "spd", "attackSpeedBonus": "atkTier", #"poison": "poison", diff --git a/index.html b/index.html index 4917f46..2cfa710 100644 --- a/index.html +++ b/index.html @@ -123,24 +123,49 @@
- - +
+ + +
+
+ Original Value: 0 +
- - +
+ + +
+
+ Original Value: 0 +
- - +
+ + +
+
+ Original Value: 0 +
- - +
+ + +
+
+ Original Value: 0 +
- - +
+ + +
+
+ Original Value: 0 +
@@ -162,10 +187,16 @@
-
+
+
+
+
+
+ + diff --git a/load.js b/load.js index 868c01b..0a09f60 100644 --- a/load.js +++ b/load.js @@ -1,4 +1,4 @@ -const DB_VERSION = 2; +const DB_VERSION = 3; // @See https://github.com/mdn/learning-area/blob/master/javascript/apis/client-side-storage/indexeddb/video-store/index.js let db; @@ -31,6 +31,9 @@ function clean_item(item) { if (item.displayName === undefined) { item.displayName = item.name; } + item.skillpoints = [item.str, item.dex, item.int, item.def, item.agi]; + item.has_negstat = item.str < 0 || item.dex < 0 || item.int < 0 || item.def < 0 || item.agi < 0; + item.reqs = [item.strReq, item.dexReq, item.intReq, item.defReq, item.agiReq]; } /* diff --git a/skillpoint_test.py b/skillpoint_test.py index 0e768cc..5e8e681 100644 --- a/skillpoint_test.py +++ b/skillpoint_test.py @@ -13,18 +13,40 @@ def clean_item(item): items = data["items"] item_map = {clean_item(item)["displayName"]: item for item in items} +# build_items_names = [ +# "Cumulonimbus", +# "Soulflare", +# "Leictreach Makani", +# "Slayer", +# "Intensity", +# "Moon Pool Circlet", +# "Diamond Static Bracelet", +# "Royal Stormy Amulet" +# ] +# build_weapon_name = "Fatal" +# build_items_names = [ +# "Morph-Stardust", +# "Morph-Steel", +# "Morph-Iron", +# "Morph-Gold", +# "Morph-Topaz", +# "Morph-Emerald", +# "Morph-Amethyst", +# "Morph-Ruby" +# ] +# build_weapon_name = "Cascade" build_items_names = [ - "Cumulonimbus", - "Soulflare", - "Leictreach Makani", + "Blue Mask", + "Sparkling Plate", + "Gemini", "Slayer", - "Intensity", + "Draoi Fair", "Moon Pool Circlet", - "Diamond Static Bracelet", - "Royal Stormy Amulet" + "Prowess", + "Diamond Fusion Necklace" ] +build_weapon_name = "Praesidium" build_items = [item_map[item] for item in build_items_names] -build_weapon_name = "Fatal" build_weapon = item_map[build_weapon_name] for item in build_items: @@ -33,9 +55,6 @@ for item in build_items: print(build_weapon) -def is_reqless(item): - return all(x == 0 for x in item["reqs"]) - # Consolidate skillpoint and req into arrays for ease of processing. def setup(item): item["skillpoints"] = [item["str"], item["dex"], item["int"], item["def"], item["agi"]] @@ -44,28 +63,40 @@ def setup(item): fixed = [] consider = [] +noboost = [] for item in build_items: setup(item) - if (is_reqless(item)): + if all(x == 0 for x in item["reqs"]): fixed.append(item) + elif all(x == 0 for x in item["skillpoints"]): + noboost.append(item) else: consider.append(item) setup(build_weapon) +fixed = tuple(fixed) +noboost = tuple(noboost) # Apply the skillpoints an item gives to the build. def apply_skillpoints(skillpoints, item): for i in range(5): skillpoints[i] += item["skillpoints"][i] +def remove_skillpoints(skillpoints, item): + for i in range(5): + skillpoints[i] -= item["skillpoints"][i] + # Figure out (naively) how many skillpoints need to be applied to get the current item to fit. # Doesn't handle -skp. def apply_to_fit(skillpoints, item): applied = [0, 0, 0, 0, 0] + total = 0 for i, req, cur in zip(range(5), item["reqs"], skillpoints): if req > cur: - applied[i] += req - cur - return applied + diff = req - cur + applied[i] += diff + total += diff + return applied, total # Permutations in js reference (also cool algorithm): # https://stackoverflow.com/a/41068709 @@ -77,6 +108,7 @@ for item in fixed: apply_skillpoints(static_skillpoints_base, item) best = None +final_skillpoints = None best_skillpoints = [0, 0, 0, 0, 0] best_total = math.inf @@ -84,24 +116,48 @@ best_total = math.inf import itertools for permutation in itertools.permutations(consider): - permutation += ( build_weapon, ) + permutation += noboost skillpoints_applied = [0, 0, 0, 0, 0] skillpoints = copy.copy(static_skillpoints_base) + total_applied = 0 for item in permutation: - needed_skillpoints = apply_to_fit(skillpoints, item) + needed_skillpoints, total_diff = apply_to_fit(skillpoints, item) for i in range(5): skillpoints_applied[i] += needed_skillpoints[i] skillpoints[i] += needed_skillpoints[i] apply_skillpoints(skillpoints, item) - total_applied = sum(skillpoints_applied) + total_applied += total_diff + if total_applied >= best_total: + break + if total_applied < best_total: + for item in permutation: + remove_skillpoints(skillpoints, item) + needed_skillpoints, total_diff = apply_to_fit(skillpoints, item) + for i in range(5): + skillpoints_applied[i] += needed_skillpoints[i] + skillpoints[i] += needed_skillpoints[i] + apply_skillpoints(skillpoints, item) + total_applied += total_diff + if total_applied >= best_total: + break + + needed_skillpoints, total_diff = apply_to_fit(skillpoints, build_weapon) + for i in range(5): + skillpoints_applied[i] += needed_skillpoints[i] + skillpoints[i] += needed_skillpoints[i] + apply_skillpoints(skillpoints, build_weapon) + total_applied += total_diff + if total_applied < best_total: best = permutation + final_skillpoints = skillpoints best_skillpoints = skillpoints_applied best_total = total_applied -print([i["displayName"] for i in fixed + list(best)]) +print([i["displayName"] for i in fixed + best]) print(best_skillpoints) +print(final_skillpoints) print(best_total) #def attempt(skillpoints, items_in_order): diff --git a/skillpoints.js b/skillpoints.js new file mode 100644 index 0000000..3c78f42 --- /dev/null +++ b/skillpoints.js @@ -0,0 +1,131 @@ +function calculate_skillpoints(equipment, weapon) { + // Calculate equipment equipping order and required skillpoints. + // Return value: [equip_order, best_skillpoints, final_skillpoints, best_total]; + + let fixed = []; + let consider = []; + let noboost = []; + for (const item of equipment) { + if (item.reqs.every(x => x === 0)) { + fixed.push(item); + } + else if (item.skillpoints.every(x => x === 0)) { + noboost.push(item); + } + else { + consider.push(item); + } + } + function apply_skillpoints(skillpoints, item) { + for (let i = 0; i < 5; i++) { + skillpoints[i] += item.skillpoints[i]; + } + } + + function remove_skillpoints(skillpoints, item) { + for (let i = 0; i < 5; i++) { + skillpoints[i] -= item.skillpoints[i]; + } + } + + // Figure out (naively) how many skillpoints need to be applied to get the current item to fit. + // Doesn't handle -skp. + function apply_to_fit(skillpoints, item) { + let applied = [0, 0, 0, 0, 0]; + let total = 0; + for (let i = 0; i < 5; i++) { + const req = item.reqs[i]; + const cur = skillpoints[i]; + if (req > cur) { + const diff = req - cur; + applied[i] += diff; + total += diff; + } + } + return [applied, total]; + } + + // Separate out the no req items and add them to the static skillpoint base. + let static_skillpoints_base = [0, 0, 0, 0, 0] + for (const item of fixed) { + apply_skillpoints(static_skillpoints_base, item); + } + + let best = null; + let final_skillpoints = null; + let best_skillpoints = [0, 0, 0, 0, 0]; + let best_total = Infinity; + + if (consider.length > 0 || noboost.length > 0) { + // Try every combination and pick the best one. + for (let permutation of perm(consider)) { + permutation = permutation.concat(noboost); + console.log(permutation); + + let skillpoints_applied = [0, 0, 0, 0, 0]; + // Complete slice is a shallow copy. + let skillpoints = static_skillpoints_base.slice(); + + let total_applied = 0; + + let result; + let needed_skillpoints; + let total_diff; + for (const item of permutation) { + result = apply_to_fit(skillpoints, item); + 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); + total_applied += total_diff; + if (total_applied >= best_total) { + break; + } + } + if (total_applied < best_total) { + for (const item of permutation) { + remove_skillpoints(skillpoints, item); + result = apply_to_fit(skillpoints, item); + 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); + total_applied += total_diff; + if (total_applied >= best_total) { + break; + } + } + } + result = apply_to_fit(skillpoints, weapon); + 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, weapon); + total_applied += total_diff; + + if (total_applied < best_total) { + best = permutation; + final_skillpoints = skillpoints; + best_skillpoints = skillpoints_applied; + best_total = total_applied; + } + } + + let equip_order = fixed.concat(best); + return [equip_order, best_skillpoints, final_skillpoints, best_total]; + } + else { + return [fixed.concat(noboost), best_skillpoints, static_skillpoints_base, 0]; + } +} diff --git a/styles.css b/styles.css index d5487f6..b91120f 100644 --- a/styles.css +++ b/styles.css @@ -29,5 +29,5 @@ grid-template-columns: repeat(4, 1fr); gap: 10px; grid-auto-rows: minmax(60px, auto); - width: 100vw; -} \ No newline at end of file + /* width: 100vw; */ +} diff --git a/test.js b/test.js index b295dfe..fd8cb5d 100644 --- a/test.js +++ b/test.js @@ -39,16 +39,32 @@ function populateItemList(type) { */ function init() { let noneItems = [ - {displayName:"No Helmet", name: "No Helmet", category: "armor", type: "helmet", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Chestplate", name: "No Chesptlate", category: "armor", type: "chestplate", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Leggings", name: "No Leggings", category: "armor", type: "leggings", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Boots", name: "No Boots", category: "armor", type: "boots", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Ring 1", name: "No Ring 1", category: "accessory", type: "ring", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Ring 2", name: "No Ring 2", category: "accessory", type: "ring", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Bracelet", name: "No Bracelet", category: "accessory", type: "bracelet", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Necklace", name: "No Necklace", category: "accessory", type: "necklace", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0}, - {displayName:"No Weapon", name: "No Weapon", category: "weapon", type: "wand", aDamPct: 0 ,aDef: 0, aDefPct: 0, agi: 0, agiReq: 0, atkTier: 0, classReq: null, def: 0, defReq: 0, dex: 0, dexReq: 0, drop: "never", eDamPct: 0, eDef: 0, eDefPct: 0, eSteal: 0, exploding: 0, fDamPct: 0, fDef: 0, fDefPct: 0, fixID: true, gSpd: 0, gXp: 0, hp: 0, hpBonus: 0, hprPct: 0, hprRaw: 0, int: 0, intReq: 0, jh: 0, lb: 0, lq: 0, ls: 0, lvl: 0, material: null, mdPct: 0, mdRaw: 0, mr: 0, ms: 0, poison: 0, quest: null, rainbowRaw: 0, ref: 0, sdPct: 0, sdRaw: 0, set: null, slots: 0, spPct1: 0, spPct2: 0, spPct3: 0, spPct4: 0, spRaw1: 0, spRaw2: 0, spRaw3: 0, spRaw4: 0, spRegen: 0, spd: 0, sprintReg: 0, str: 0, strReq: 0, tDamPct: 0, tDef: 0, tDefPct: 0, thorns: 0, tier: null, wDamPct: 0, wDef: 0, wDefPct: 0, xpb: 0} - ] + ["helmet", "No Helmet"], + ["chestplate", "No Chestplate"], + ["leggings", "No Leggings"], + ["boots", "No Boots"], + ["ring", "No Ring 1"], + ["ring", "No Ring 2"], + ["bracelet", "No Bracelet"], + ["necklace", "No Necklace"], + ["wand", "No Weapon"], + ]; + for (let i = 0; i < 9; i++) { + let item = Object(); + for (const field of item_fields) { + item[field] = 0; + } + item.type = noneItems[i][0]; + item.name = noneItems[i][1]; + item.displayName = item.name; + item.set = null; + item.quest = null; + item.skillpoints = [0, 0, 0, 0, 0]; + item.has_negstat = false; + item.reqs = [0, 0, 0, 0, 0]; + + noneItems[i] = item; + } items = items.concat(noneItems); console.log(items); for (const item of items) { @@ -162,37 +178,49 @@ function calculateBuild(){ itemMap.get(weapon), ); console.log(player_build.toString()); - document.getElementById("build-helmet").innerHTML = player_build.helmet.name; - document.getElementById("build-chestplate").innerHTML = player_build.chestplate.name; - document.getElementById("build-leggings").innerHTML = player_build.helmet.name; - document.getElementById("build-boots").innerHTML = player_build.helmet.name; - document.getElementById("build-ring1").innerHTML = player_build.ring1.name; - document.getElementById("build-ring2").innerHTML = player_build.ring2.name; - document.getElementById("build-bracelet").innerHTML = player_build.bracelet.name; - document.getElementById("build-necklace").innerHTML = player_build.necklace.name; - document.getElementById("build-weapon").innerHTML = player_build.weapon.name; + + player_build.equip_order; + player_build.base_skillpoints; + let skillpoints = player_build.total_skillpoints; + setValue("str-skp", skillpoints[0]); + setValue("dex-skp", skillpoints[1]); + setValue("int-skp", skillpoints[2]); + setValue("def-skp", skillpoints[3]); + setValue("agi-skp", skillpoints[4]); + console.log(skillpoints); + player_build.assigned_skillpoints; + + setHTML("build-helmet", player_build.helmet.name); + setHTML("build-chestplate", player_build.chestplate.name); + setHTML("build-leggings", player_build.helmet.name); + setHTML("build-boots", player_build.helmet.name); + setHTML("build-ring1", player_build.ring1.name); + setHTML("build-ring2", player_build.ring2.name); + setHTML("build-bracelet", player_build.bracelet.name); + setHTML("build-necklace", player_build.necklace.name); + setHTML("build-weapon", player_build.weapon.name); } function resetFields(){ - document.getElementById("helmet-choice").value = ""; - document.getElementById("helmet-powder").value = ""; - document.getElementById("chestplate-choice").value = ""; - document.getElementById("chestplate-powder").value = ""; - document.getElementById("leggings-choice").value = ""; - document.getElementById("leggings-powder").value = ""; - document.getElementById("boots-choice").value = ""; - document.getElementById("boots-powder").value = ""; - document.getElementById("ring1-choice").value = ""; - document.getElementById("ring2-choice").value = ""; - document.getElementById("bracelet-choice").value = ""; - document.getElementById("necklace-choice").value = ""; - document.getElementById("weapon-choice").value = ""; - document.getElementById("weapon-powder").value = ""; - document.getElementById("str-skp").value = ""; - document.getElementById("dex-skp").value = ""; - document.getElementById("int-skp").value = ""; - document.getElementById("def-skp").value = ""; - document.getElementById("agi-skp").value = ""; + setValue("helmet-choice", ""); + setValue("helmet-powder", ""); + setValue("chestplate-choice", ""); + setValue("chestplate-powder", ""); + setValue("leggings-choice", ""); + setValue("leggings-powder", ""); + setValue("boots-choice", ""); + setValue("boots-powder", ""); + setValue("ring1-choice", ""); + setValue("ring2-choice", ""); + setValue("bracelet-choice", ""); + setValue("necklace-choice", ""); + setValue("weapon-choice", ""); + setValue("weapon-powder", ""); + setValue("str-skp", ""); + setValue("dex-skp", ""); + setValue("int-skp", ""); + setValue("def-skp", ""); + setValue("agi-skp", ""); } load_init(init); diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..aad01db --- /dev/null +++ b/utils.js @@ -0,0 +1,31 @@ +// Permutations in js reference (also cool algorithm): +// https://stackoverflow.com/a/41068709 +function perm(a){ + if (a.length == 0) return [[]]; + var r = [[a[0]]], + t = [], + s = []; + if (a.length == 1) return r; + for (var i = 1, la = a.length; i < la; i++){ + for (var j = 0, lr = r.length; j < lr; j++){ + r[j].push(a[i]); + t.push(r[j]); + for(var k = 1, lrj = r[j].length; k < lrj; k++){ + for (var l = 0; l < lrj; l++) s[l] = r[j][(k+l)%lrj]; + t[t.length] = s; + s = []; + } + } + r = t; + t = []; + } + return r; +} + +function setHTML(id, html) { + document.getElementById(id).innerHTML = html; +} + +function setValue(id, value) { + document.getElementById(id).value = value; +}