Fix double load bug, add ms calc file
This commit is contained in:
parent
450552599e
commit
9e652fd619
3 changed files with 147 additions and 5 deletions
135
aux/ms_simulator.py
Normal file
135
aux/ms_simulator.py
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
theorySpeeds = [4.3, 3.1, 2.5, 2.05, 1.5, 0.83, 0.51]
|
||||||
|
realSpeeds = [] # TODO
|
||||||
|
|
||||||
|
atkSpd = 6
|
||||||
|
|
||||||
|
#spellCycle = [1, 2, 1, 2, 0]
|
||||||
|
#spellDelay = [0.5, 0.5, 0.5, 0.5, 0]
|
||||||
|
spellCycle = [-1, 1, 0, 2, 1, 1]
|
||||||
|
spellDelay = [0.4312345, 0, 0.4, 0.4, 0.4, 0.4]
|
||||||
|
#spellCycle = [9, 0, 9, 0, 10, 0, 0]
|
||||||
|
#spellDelay = [0, 1.4, 0, 1.4, 0, 1.3, 1.3]
|
||||||
|
delayCycle = [1.2, 0, 0.4, 0.4, 0.4, 0.4]
|
||||||
|
spellCycle = spellCycle*8
|
||||||
|
spellDelay = spellDelay*4 + delayCycle + spellDelay*2 + delayCycle
|
||||||
|
|
||||||
|
simulation_end = 100
|
||||||
|
manaRegens = [5, 0, 15]
|
||||||
|
manaSteals = [9, 13, 0]
|
||||||
|
|
||||||
|
import random
|
||||||
|
import math
|
||||||
|
import statistics
|
||||||
|
|
||||||
|
def simulate(manaRegen, manaSteal, spellCycle, spellDelay, simulation_end, atkSpd):
|
||||||
|
realSpeed = theorySpeeds[atkSpd]
|
||||||
|
|
||||||
|
realDt = 1/realSpeed
|
||||||
|
print(realDt)
|
||||||
|
|
||||||
|
stealChance = (1/realSpeed) / 3
|
||||||
|
lastAttackTime = 0
|
||||||
|
lastManaTime = -random.random()
|
||||||
|
lastMRTime = lastManaTime + random.randint(-4, 0)
|
||||||
|
currentTime = 0
|
||||||
|
currentMana = 20
|
||||||
|
|
||||||
|
times = [0]
|
||||||
|
manas = [20]
|
||||||
|
colors = [0]
|
||||||
|
|
||||||
|
numSpells = len(spellCycle)
|
||||||
|
currentSpell = 0
|
||||||
|
|
||||||
|
mrDisabled = False
|
||||||
|
|
||||||
|
failedCasts = 0
|
||||||
|
lost_mana = 0
|
||||||
|
|
||||||
|
while currentTime < simulation_end:
|
||||||
|
spellCost = spellCycle[currentSpell]
|
||||||
|
spellTime = spellDelay[currentSpell]
|
||||||
|
|
||||||
|
currentTime += spellTime
|
||||||
|
if currentTime >= lastManaTime + 1:
|
||||||
|
mana_gained = math.floor(currentTime - lastManaTime)
|
||||||
|
if not mrDisabled:
|
||||||
|
currentMana = min(20, currentMana + mana_gained)
|
||||||
|
else:
|
||||||
|
currentMana = max(0, currentMana - mana_gained)
|
||||||
|
lastManaTime += mana_gained
|
||||||
|
if currentTime >= lastMRTime + 5:
|
||||||
|
mr_proc = math.floor((currentTime - lastMRTime) / 5)
|
||||||
|
if not mrDisabled:
|
||||||
|
mana_nocap = currentMana + mr_proc * manaRegen
|
||||||
|
currentMana = min(20, mana_nocap)
|
||||||
|
lost_mana += mana_nocap - currentMana
|
||||||
|
else:
|
||||||
|
lostMana += mr_proc * manaRegen
|
||||||
|
lastMRTime += 5 * mr_proc
|
||||||
|
times.append(currentTime)
|
||||||
|
manas.append(currentMana)
|
||||||
|
|
||||||
|
if spellCost < 0:
|
||||||
|
mrDisabled = True
|
||||||
|
spellCost *= -1
|
||||||
|
else:
|
||||||
|
mrDisabled = False
|
||||||
|
|
||||||
|
if spellCost == 0:
|
||||||
|
if currentTime - lastAttackTime > realDt:
|
||||||
|
lastAttackTime = currentTime
|
||||||
|
#currentMana = min(20, currentMana + manaSteal * stealChance)
|
||||||
|
if random.random() < stealChance:
|
||||||
|
mana_nocap = currentMana + manaSteal
|
||||||
|
currentMana = min(20, mana_nocap)
|
||||||
|
lost_mana += mana_nocap - currentMana
|
||||||
|
colors.append(0)
|
||||||
|
elif currentMana > spellCost:
|
||||||
|
currentMana -= spellCost
|
||||||
|
colors.append(0)
|
||||||
|
else:
|
||||||
|
failedCasts += 1
|
||||||
|
colors.append(1)
|
||||||
|
currentSpell = (currentSpell + 1) % numSpells
|
||||||
|
return ((times, manas, colors), failedCasts, lost_mana)
|
||||||
|
|
||||||
|
plot = True
|
||||||
|
seeds = list(range(1000))
|
||||||
|
|
||||||
|
results = []
|
||||||
|
results2 = []
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
for (manaRegen, manaSteal) in zip(manaRegens, manaSteals):
|
||||||
|
result = []
|
||||||
|
result2 = []
|
||||||
|
for seed in seeds:
|
||||||
|
random.seed(seed)
|
||||||
|
((times, manas, colors), failedCasts, lost_mana) = simulate(manaRegen, manaSteal, spellCycle, spellDelay, simulation_end, atkSpd)
|
||||||
|
result.append(failedCasts)
|
||||||
|
result2.append(lost_mana)
|
||||||
|
print(f"({manaRegen}+{manaSteal}) Failed {failedCasts} casts!")
|
||||||
|
|
||||||
|
if seed == 0:
|
||||||
|
plt.figure()
|
||||||
|
plt.scatter(times, manas, c=colors)
|
||||||
|
plt.xlabel("Time (seconds)")
|
||||||
|
plt.ylabel("Mana")
|
||||||
|
plt.title(f"Mana steal simulation ({manaRegen} mr {manaSteal} ms)")
|
||||||
|
|
||||||
|
results.append(result)
|
||||||
|
results2.append(result2)
|
||||||
|
|
||||||
|
print("----------------")
|
||||||
|
|
||||||
|
averages = [statistics.mean(result) for result in results]
|
||||||
|
maxs = [min(result) for result in results]
|
||||||
|
mins = [max(result) for result in results]
|
||||||
|
averages2 = [statistics.mean(result) for result in results2]
|
||||||
|
maxs2 = [min(result) for result in results2]
|
||||||
|
mins2 = [max(result) for result in results2]
|
||||||
|
for (manaRegen, manaSteal, failedCasts, maxk, mink, lostMana, minl, maxl) in zip(manaRegens, manaSteals, averages, mins, maxs, averages2, mins2, maxs2):
|
||||||
|
print(f"({manaRegen}+{manaSteal}) on average failed {failedCasts} casts (max {maxk} min {mink}) and lost {lostMana} mana (max {maxl} min {minl})")
|
||||||
|
|
||||||
|
plt.show()
|
8
load.js
8
load.js
|
@ -110,13 +110,17 @@ async function load(init_func) {
|
||||||
}
|
}
|
||||||
add_promises.push(add_tx.complete);
|
add_promises.push(add_tx.complete);
|
||||||
Promise.all(add_promises).then((values) => {
|
Promise.all(add_promises).then((values) => {
|
||||||
db.close();
|
|
||||||
init_maps();
|
init_maps();
|
||||||
init_func();
|
init_func();
|
||||||
});
|
});
|
||||||
|
// DB not closed? idfk man
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_init(init_func) {
|
function load_init(init_func) {
|
||||||
|
if (db) {
|
||||||
|
console.log("Item db already loaded, skipping load sequence");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let request = window.indexedDB.open('item_db', DB_VERSION);
|
let request = window.indexedDB.open('item_db', DB_VERSION);
|
||||||
|
|
||||||
request.onerror = function() {
|
request.onerror = function() {
|
||||||
|
@ -223,4 +227,4 @@ function init_maps() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(itemMap);
|
console.log(itemMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,14 +95,17 @@ async function load_ings(init_func) {
|
||||||
add_promises.push(add_tx2.complete);
|
add_promises.push(add_tx2.complete);
|
||||||
add_promises.push(add_tx3.complete);
|
add_promises.push(add_tx3.complete);
|
||||||
Promise.all(add_promises).then((values) => {
|
Promise.all(add_promises).then((values) => {
|
||||||
idb.close();
|
|
||||||
init_ing_maps();
|
init_ing_maps();
|
||||||
init_func();
|
init_func();
|
||||||
});
|
});
|
||||||
|
// DB not closed? idfk man
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_ing_init(init_func) {
|
function load_ing_init(init_func) {
|
||||||
|
if (idb) {
|
||||||
|
console.log("Ingredient db already loaded, skipping load sequence");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let request = window.indexedDB.open("ing_db", ING_DB_VERSION)
|
let request = window.indexedDB.open("ing_db", ING_DB_VERSION)
|
||||||
request.onerror = function() {
|
request.onerror = function() {
|
||||||
console.log("DB failed to open...");
|
console.log("DB failed to open...");
|
||||||
|
@ -209,4 +212,4 @@ function init_ing_maps() {
|
||||||
recipeList.push(recipe["name"]);
|
recipeList.push(recipe["name"]);
|
||||||
recipeIDMap.set(recipe["id"],recipe["name"]);
|
recipeIDMap.set(recipe["id"],recipe["name"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue