-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetspellbook.js
71 lines (57 loc) · 1.77 KB
/
getspellbook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function setup() {
wlSlider = createSlider(1,20,1);
wlSlider.parent("test")
wlSlider.position(20,20);
button = createButton('Generate Level '+ wlSlider.elt.value+' book.');
button.parent("test")
button.position(wlSlider.x + wlSlider.width + 20);
button.mousePressed(prod);
}
Array.prototype.sample = function(){
return this[Math.floor(Math.random()*this.length)];
}
function get_spell_levels(wizlevel){
max_level = Math.min(9,Math.floor((wizlevel+1)/2));
var spell_levels = {}
for (i = 1; i < max_level + 1; i++){
numspells = (1/(i/wizlevel))/1.1;
spell_levels[i] = Math.round(numspells);
if (i == 1 ){
numspells += 6
}
spell_levels[i] = Math.round(numspells);
spell_levels.length = i
}
return spell_levels
}
function draw(){
button.elt.innerHTML = 'Generate Level '+ wlSlider.elt.value+' book.'
}
function prod(){
for (i = 1; i < 9 +1; i++){
document.getElementById("L"+ i +"_Title").innerHTML = " ";
document.getElementById("L"+ i).innerHTML = " ";
}
const wl = wlSlider.value();
spells_by_level = get_spell_levels(wl)
console.log(spells_by_level[1])
let max_spell = get_spell_levels(wl).length
var i;
for (i = 1; i < max_spell +1; i++){
spells_chosen = get_spells(i,spells_by_level[i])
document.getElementById("L"+ i +"_Title").innerHTML = "Level "+i+" Spells";
document.getElementById("L"+ i).innerHTML = spells_chosen;
}
}
function get_spells(level,num){
var spells=[];
for (i = 1; i < num +1; i++){
choice = spell_list[level].sample();
if (spells.includes(choice)){
}
else{
spells.push(choice);
}
}
return spells
}