add id map
This commit is contained in:
parent
ef96d77b2f
commit
86bd75833e
8 changed files with 10740 additions and 3578 deletions
2
TODO.txt
2
TODO.txt
|
@ -9,7 +9,7 @@ Damage calculation
|
||||||
- Poison calculations
|
- Poison calculations
|
||||||
|
|
||||||
Skillpoint engine
|
Skillpoint engine
|
||||||
- Make it work...
|
- Make it work... DONE! SURPRISINGLY!
|
||||||
|
|
||||||
Build encoding
|
Build encoding
|
||||||
- Allow exporting/importing builds to strings
|
- Allow exporting/importing builds to strings
|
||||||
|
|
10635
clean.json
10635
clean.json
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
19
compress.py
19
compress.py
|
@ -107,6 +107,14 @@ delete_keys = [
|
||||||
"material"
|
"material"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
import os
|
||||||
|
if os.path.exists("id_map.json"):
|
||||||
|
with open("id_map.json","r") as id_mapfile:
|
||||||
|
id_map = json.load(id_mapfile)
|
||||||
|
else:
|
||||||
|
id_map = {item["name"]: i for i, item in enumerate(items)}
|
||||||
|
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
for key in delete_keys:
|
for key in delete_keys:
|
||||||
if key in item:
|
if key in item:
|
||||||
|
@ -117,9 +125,16 @@ for item in items:
|
||||||
item[v] = item[k]
|
item[v] = item[k]
|
||||||
del item[k]
|
del item[k]
|
||||||
|
|
||||||
|
if not (item["name"] in id_map):
|
||||||
|
id_ma[item["name"]] = len(id_map)
|
||||||
|
print(f'New item: {item["name"]}')
|
||||||
|
item["id"] = id_map[item["name"]]
|
||||||
|
|
||||||
item["type"] = item["type"].lower()
|
item["type"] = item["type"].lower()
|
||||||
|
|
||||||
|
with open("id_map.json","w") as id_mapfile:
|
||||||
|
json.dump(id_map, id_mapfile, indent=2)
|
||||||
with open("clean.json", "w") as outfile:
|
with open("clean.json", "w") as outfile:
|
||||||
outfile.write(json.dumps(data, indent=2))
|
json.dump(data, outfile, indent=2)
|
||||||
with open("compress.json", "w") as outfile:
|
with open("compress.json", "w") as outfile:
|
||||||
outfile.write(json.dumps(data))
|
json.dump(data, outfile)
|
||||||
|
|
3547
id_map.json
Normal file
3547
id_map.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,14 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -30,10 +37,14 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
|
|
||||||
// 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) {
|
function apply_to_fit(skillpoints, item, skillpoint_filter) {
|
||||||
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.skillpoints[i] < 0 && skillpoint_filter[i]) {
|
||||||
|
applied[i] -= item.skillpoints[i];
|
||||||
|
total -= item.skillpoints[i];
|
||||||
|
}
|
||||||
if (item.reqs[i] == 0) continue;
|
if (item.reqs[i] == 0) continue;
|
||||||
const req = item.reqs[i];
|
const req = item.reqs[i];
|
||||||
const cur = skillpoints[i];
|
const cur = skillpoints[i];
|
||||||
|
@ -73,7 +84,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);
|
result = apply_to_fit(skillpoints, item, has_skillpoint);
|
||||||
needed_skillpoints = result[0];
|
needed_skillpoints = result[0];
|
||||||
total_diff = result[1];
|
total_diff = result[1];
|
||||||
|
|
||||||
|
@ -87,32 +98,32 @@ function calculate_skillpoints(equipment, weapon) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (total_applied < best_total) {
|
// if (total_applied < best_total) {
|
||||||
console.log(total_applied);
|
// console.log(total_applied);
|
||||||
console.log(skillpoints_applied);
|
// console.log(skillpoints_applied);
|
||||||
console.log("Iteration 2");
|
// console.log("Iteration 2");
|
||||||
for (const item of permutation) {
|
// for (const item of permutation) {
|
||||||
console.log(item);
|
// console.log(item);
|
||||||
|
//
|
||||||
remove_skillpoints(skillpoints, item);
|
// remove_skillpoints(skillpoints, item);
|
||||||
console.log(skillpoints);
|
// console.log(skillpoints);
|
||||||
result = apply_to_fit(skillpoints, item);
|
// result = apply_to_fit(skillpoints, item, has_skillpoint);
|
||||||
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) {
|
||||||
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);
|
||||||
console.log(skillpoints);
|
// console.log(skillpoints);
|
||||||
console.log(total_diff);
|
// console.log(total_diff);
|
||||||
total_applied += total_diff;
|
// total_applied += total_diff;
|
||||||
if (total_applied >= best_total) {
|
// if (total_applied >= best_total) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
result = apply_to_fit(skillpoints, weapon);
|
result = apply_to_fit(skillpoints, weapon);
|
||||||
needed_skillpoints = result[0];
|
needed_skillpoints = result[0];
|
||||||
total_diff = result[1];
|
total_diff = result[1];
|
||||||
|
|
8
test.js
8
test.js
|
@ -179,7 +179,12 @@ function calculateBuild(){
|
||||||
);
|
);
|
||||||
console.log(player_build.toString());
|
console.log(player_build.toString());
|
||||||
|
|
||||||
player_build.equip_order;
|
let equip_order_text = "Equip order: <br>";
|
||||||
|
for (const item of player_build.equip_order) {
|
||||||
|
equip_order_text += item.displayName + "<br>";
|
||||||
|
}
|
||||||
|
setHTML("build-order", equip_order_text);
|
||||||
|
|
||||||
player_build.base_skillpoints;
|
player_build.base_skillpoints;
|
||||||
let skillpoints = player_build.total_skillpoints;
|
let skillpoints = player_build.total_skillpoints;
|
||||||
setValue("str-skp", skillpoints[0]);
|
setValue("str-skp", skillpoints[0]);
|
||||||
|
@ -190,6 +195,7 @@ function calculateBuild(){
|
||||||
console.log(skillpoints);
|
console.log(skillpoints);
|
||||||
player_build.assigned_skillpoints;
|
player_build.assigned_skillpoints;
|
||||||
|
|
||||||
|
|
||||||
setHTML("summary-box", "Summary: Assigned " + player_build.assigned_skillpoints + " skillpoints.");
|
setHTML("summary-box", "Summary: Assigned " + player_build.assigned_skillpoints + " skillpoints.");
|
||||||
|
|
||||||
setHTML("build-helmet", player_build.helmet.name);
|
setHTML("build-helmet", player_build.helmet.name);
|
||||||
|
|
38
utils.js
38
utils.js
|
@ -29,3 +29,41 @@ function setHTML(id, html) {
|
||||||
function setValue(id, value) {
|
function setValue(id, value) {
|
||||||
document.getElementById(id).value = value;
|
document.getElementById(id).value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base 64 encoding tools
|
||||||
|
// https://stackoverflow.com/a/27696695
|
||||||
|
|
||||||
|
Base64 = (function () {
|
||||||
|
var digitsStr =
|
||||||
|
// 0 8 16 24 32 40 48 56 63
|
||||||
|
// v v v v v v v v v
|
||||||
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-";
|
||||||
|
var digits = digitsStr.split('');
|
||||||
|
var digitsMap = {};
|
||||||
|
for (var i = 0; i < digits.length; i++) {
|
||||||
|
digitsMap[digits[i]] = i;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
fromInt: function(int32) {
|
||||||
|
var result = '';
|
||||||
|
while (true) {
|
||||||
|
result = digits[int32 & 0x3f] + result;
|
||||||
|
int32 >>>= 6;
|
||||||
|
if (int32 === 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
toInt: function(digitsStr) {
|
||||||
|
var result = 0;
|
||||||
|
var digits = digitsStr.split('');
|
||||||
|
for (var i = 0; i < digits.length; i++) {
|
||||||
|
result = (result << 6) + digitsMap[digits[i]];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Base64.fromInt(-2147483648); // gives "200000"
|
||||||
|
// Base64.toInt("200000"); // gives -2147483648
|
||||||
|
|
Loading…
Reference in a new issue