2021-01-07 02:00:21 +00:00
|
|
|
import json
|
|
|
|
import math
|
|
|
|
import copy
|
|
|
|
|
|
|
|
with open("clean.json") as infile:
|
|
|
|
data = json.load(infile)
|
|
|
|
|
|
|
|
def clean_item(item):
|
|
|
|
if not "displayName" in item:
|
|
|
|
item["displayName"] = item["name"];
|
|
|
|
return item
|
|
|
|
|
|
|
|
items = data["items"]
|
|
|
|
item_map = {clean_item(item)["displayName"]: item for item in items}
|
|
|
|
|
2021-01-07 06:41:41 +00:00
|
|
|
# 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"
|
2021-01-07 02:00:21 +00:00
|
|
|
build_items_names = [
|
2021-01-07 06:41:41 +00:00
|
|
|
"Blue Mask",
|
|
|
|
"Sparkling Plate",
|
|
|
|
"Gemini",
|
2021-01-07 02:00:21 +00:00
|
|
|
"Slayer",
|
2021-01-07 06:41:41 +00:00
|
|
|
"Draoi Fair",
|
2021-01-07 02:00:21 +00:00
|
|
|
"Moon Pool Circlet",
|
2021-01-07 06:41:41 +00:00
|
|
|
"Prowess",
|
|
|
|
"Diamond Fusion Necklace"
|
2021-01-07 02:00:21 +00:00
|
|
|
]
|
2021-01-07 06:41:41 +00:00
|
|
|
build_weapon_name = "Praesidium"
|
2021-01-07 02:00:21 +00:00
|
|
|
build_items = [item_map[item] for item in build_items_names]
|
|
|
|
build_weapon = item_map[build_weapon_name]
|
|
|
|
|
|
|
|
for item in build_items:
|
|
|
|
print(item)
|
|
|
|
print("-------------------------------")
|
|
|
|
|
|
|
|
print(build_weapon)
|
|
|
|
|
2021-01-07 02:02:28 +00:00
|
|
|
# Consolidate skillpoint and req into arrays for ease of processing.
|
2021-01-07 02:00:21 +00:00
|
|
|
def setup(item):
|
|
|
|
item["skillpoints"] = [item["str"], item["dex"], item["int"], item["def"], item["agi"]]
|
|
|
|
item["has_negstat"] = any(x < 0 for x in item["skillpoints"])
|
|
|
|
item["reqs"] = [item["strReq"], item["dexReq"], item["intReq"], item["defReq"], item["agiReq"]]
|
|
|
|
|
|
|
|
fixed = []
|
|
|
|
consider = []
|
2021-01-07 06:41:41 +00:00
|
|
|
noboost = []
|
2021-01-07 02:00:21 +00:00
|
|
|
|
|
|
|
for item in build_items:
|
|
|
|
setup(item)
|
2021-01-07 06:41:41 +00:00
|
|
|
if all(x == 0 for x in item["reqs"]):
|
2021-01-07 02:00:21 +00:00
|
|
|
fixed.append(item)
|
2021-01-07 06:41:41 +00:00
|
|
|
elif all(x == 0 for x in item["skillpoints"]):
|
|
|
|
noboost.append(item)
|
2021-01-07 02:00:21 +00:00
|
|
|
else:
|
|
|
|
consider.append(item)
|
|
|
|
setup(build_weapon)
|
2021-01-07 06:41:41 +00:00
|
|
|
fixed = tuple(fixed)
|
|
|
|
noboost = tuple(noboost)
|
2021-01-07 02:00:21 +00:00
|
|
|
|
2021-01-07 02:02:28 +00:00
|
|
|
# Apply the skillpoints an item gives to the build.
|
2021-01-07 02:00:21 +00:00
|
|
|
def apply_skillpoints(skillpoints, item):
|
2021-01-07 02:02:28 +00:00
|
|
|
for i in range(5):
|
|
|
|
skillpoints[i] += item["skillpoints"][i]
|
2021-01-07 02:00:21 +00:00
|
|
|
|
2021-01-07 06:41:41 +00:00
|
|
|
def remove_skillpoints(skillpoints, item):
|
|
|
|
for i in range(5):
|
|
|
|
skillpoints[i] -= item["skillpoints"][i]
|
|
|
|
|
2021-01-07 02:02:28 +00:00
|
|
|
# Figure out (naively) how many skillpoints need to be applied to get the current item to fit.
|
|
|
|
# Doesn't handle -skp.
|
2021-01-07 02:00:21 +00:00
|
|
|
def apply_to_fit(skillpoints, item):
|
|
|
|
applied = [0, 0, 0, 0, 0]
|
2021-01-07 06:41:41 +00:00
|
|
|
total = 0
|
2021-01-07 02:00:21 +00:00
|
|
|
for i, req, cur in zip(range(5), item["reqs"], skillpoints):
|
2021-01-07 07:08:16 +00:00
|
|
|
if (item["reqs"][i] == 0):
|
|
|
|
continue
|
2021-01-07 02:00:21 +00:00
|
|
|
if req > cur:
|
2021-01-07 06:41:41 +00:00
|
|
|
diff = req - cur
|
|
|
|
applied[i] += diff
|
|
|
|
total += diff
|
|
|
|
return applied, total
|
2021-01-07 02:00:21 +00:00
|
|
|
|
|
|
|
# Permutations in js reference (also cool algorithm):
|
|
|
|
# https://stackoverflow.com/a/41068709
|
|
|
|
|
|
|
|
static_skillpoints_base = [0, 0, 0, 0, 0]
|
|
|
|
|
2021-01-07 02:02:28 +00:00
|
|
|
# Separate out the no req items and add them to the static skillpoint base.
|
2021-01-07 02:00:21 +00:00
|
|
|
for item in fixed:
|
|
|
|
apply_skillpoints(static_skillpoints_base, item)
|
|
|
|
|
|
|
|
best = None
|
2021-01-07 06:41:41 +00:00
|
|
|
final_skillpoints = None
|
2021-01-07 02:00:21 +00:00
|
|
|
best_skillpoints = [0, 0, 0, 0, 0]
|
|
|
|
best_total = math.inf
|
|
|
|
|
2021-01-07 02:02:28 +00:00
|
|
|
# Try every combination and pick the best one.
|
2021-01-07 02:00:21 +00:00
|
|
|
import itertools
|
|
|
|
for permutation in itertools.permutations(consider):
|
|
|
|
|
2021-01-07 06:41:41 +00:00
|
|
|
permutation += noboost
|
2021-01-07 02:00:21 +00:00
|
|
|
|
|
|
|
skillpoints_applied = [0, 0, 0, 0, 0]
|
|
|
|
skillpoints = copy.copy(static_skillpoints_base)
|
2021-01-07 06:41:41 +00:00
|
|
|
total_applied = 0
|
2021-01-07 02:00:21 +00:00
|
|
|
for item in permutation:
|
2021-01-07 06:41:41 +00:00
|
|
|
needed_skillpoints, total_diff = apply_to_fit(skillpoints, item)
|
2021-01-07 02:00:21 +00:00
|
|
|
for i in range(5):
|
|
|
|
skillpoints_applied[i] += needed_skillpoints[i]
|
|
|
|
skillpoints[i] += needed_skillpoints[i]
|
|
|
|
apply_skillpoints(skillpoints, item)
|
2021-01-07 06:41:41 +00:00
|
|
|
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
|
|
|
|
|
2021-01-07 02:00:21 +00:00
|
|
|
if total_applied < best_total:
|
|
|
|
best = permutation
|
2021-01-07 06:41:41 +00:00
|
|
|
final_skillpoints = skillpoints
|
2021-01-07 02:00:21 +00:00
|
|
|
best_skillpoints = skillpoints_applied
|
|
|
|
best_total = total_applied
|
|
|
|
|
2021-01-07 06:41:41 +00:00
|
|
|
print([i["displayName"] for i in fixed + best])
|
2021-01-07 02:00:21 +00:00
|
|
|
print(best_skillpoints)
|
2021-01-07 06:41:41 +00:00
|
|
|
print(final_skillpoints)
|
2021-01-07 02:00:21 +00:00
|
|
|
print(best_total)
|
|
|
|
|
|
|
|
#def attempt(skillpoints, items_in_order):
|