-
Notifications
You must be signed in to change notification settings - Fork 0
/
mostroscript.js
272 lines (248 loc) · 12.1 KB
/
mostroscript.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// https://dantezunino.github.io/mostros/mostros.xml
// CORS avoid: https://cors-anywhere.herokuapp.com/
// xml-link working: https://cors-anywhere.herokuapp.com/https://raw.githubusercontent.com/dantezunino/mostros/master/mostros.xml
//Var to find Monster
var monster = null;
//Load monster static info
function loadDoc1() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "https://dantezunino.github.io/mostros/mostros.xml", true);
xhttp.send();
}
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("BICHO")[monster];
//take XML values, put them in the HTML
//Stats
document.getElementById("str_mostro").innerHTML = x.getElementsByTagName("STR")[0].childNodes[0].nodeValue;
document.getElementById("dex_mostro").innerHTML = x.getElementsByTagName("DEX")[0].childNodes[0].nodeValue;
document.getElementById("con_mostro").innerHTML = x.getElementsByTagName("CON")[0].childNodes[0].nodeValue;
document.getElementById("int_mostro").innerHTML = x.getElementsByTagName("INT")[0].childNodes[0].nodeValue;
document.getElementById("wis_mostro").innerHTML = x.getElementsByTagName("WIS")[0].childNodes[0].nodeValue;
document.getElementById("chr_mostro").innerHTML = x.getElementsByTagName("CHR")[0].childNodes[0].nodeValue;
//Stats Mods
document.getElementById("str_mod").innerHTML = x.getElementsByTagName("STRMOD")[0].childNodes[0].nodeValue;
document.getElementById("dex_mod").innerHTML = x.getElementsByTagName("DEXMOD")[0].childNodes[0].nodeValue;
document.getElementById("con_mod").innerHTML = x.getElementsByTagName("CONMOD")[0].childNodes[0].nodeValue;
document.getElementById("int_mod").innerHTML = x.getElementsByTagName("INTMOD")[0].childNodes[0].nodeValue;
document.getElementById("wis_mod").innerHTML = x.getElementsByTagName("WISMOD")[0].childNodes[0].nodeValue;
document.getElementById("chr_mod").innerHTML = x.getElementsByTagName("CHRMOD")[0].childNodes[0].nodeValue;
//Name, AC and HP and so and so
document.getElementById("nombre_mostro").innerHTML = x.getElementsByTagName("NAME")[0].childNodes[0].nodeValue;
document.getElementById("align_mostro").innerHTML = x.getElementsByTagName("ALIGNMENT")[0].childNodes[0].nodeValue;
document.getElementById("ac_mostro").innerHTML = x.getElementsByTagName("AC")[0].childNodes[0].nodeValue;
document.getElementById("hp_mostro").innerHTML = x.getElementsByTagName("HP")[0].childNodes[0].nodeValue;
document.getElementById("speed_mostro").innerHTML = x.getElementsByTagName("SPEED")[0].childNodes[0].nodeValue;
document.getElementById("size_mostro").innerHTML = x.getElementsByTagName("SIZE")[0].childNodes[0].nodeValue;
document.getElementById("height_mostro").innerHTML = x.getElementsByTagName("HEIGHT")[0].childNodes[0].nodeValue;
document.getElementById("weight_mostro").innerHTML = x.getElementsByTagName("WEIGHT")[0].childNodes[0].nodeValue;
document.getElementById("challenge_mostro").innerHTML = x.getElementsByTagName("CHALLENGE")[0].childNodes[0].nodeValue;
//Habilities and Attacks
document.getElementById("attack1_mostro").innerHTML = x.getElementsByTagName("ACTION_1")[0].childNodes[0].nodeValue;
document.getElementById("attack2_mostro").innerHTML = x.getElementsByTagName("ACTION_2")[0].childNodes[0].nodeValue;
document.getElementById("attack3_mostro").innerHTML = x.getElementsByTagName("ACTION_3")[0].childNodes[0].nodeValue;
document.getElementById("attack4_mostro").innerHTML = x.getElementsByTagName("ACTION_4")[0].childNodes[0].nodeValue;
document.getElementById("skill1_mostro").innerHTML = x.getElementsByTagName("POWER_1")[0].childNodes[0].nodeValue;
document.getElementById("skill2_mostro").innerHTML = x.getElementsByTagName("POWER_2")[0].childNodes[0].nodeValue;
document.getElementById("skill3_mostro").innerHTML = x.getElementsByTagName("POWER_3")[0].childNodes[0].nodeValue;
document.getElementById("skill4_mostro").innerHTML = x.getElementsByTagName("POWER_4")[0].childNodes[0].nodeValue;
document.getElementById("attackDes_mostro").innerHTML = x.getElementsByTagName("ACTION_DES")[0].childNodes[0].nodeValue;
//Attacking Dice
document.getElementById("rollMod").innerHTML = x.getElementsByTagName("ATTACK")[0].childNodes[0].nodeValue;
document.getElementById("dado_attack_1").innerHTML = x.getElementsByTagName("ACTIONDADOS_1")[0].childNodes[0].nodeValue;
document.getElementById("dado_attack_2").innerHTML = x.getElementsByTagName("ACTIONDADOS_2")[0].childNodes[0].nodeValue;
document.getElementById("dado_attack_3").innerHTML = x.getElementsByTagName("ACTIONDADOS_3")[0].childNodes[0].nodeValue;
document.getElementById("dado_attack_4").innerHTML = x.getElementsByTagName("ACTIONDADOS_4")[0].childNodes[0].nodeValue;
document.getElementById("valor_attack_1").innerHTML = x.getElementsByTagName("ACTIONVALOR_1")[0].childNodes[0].nodeValue;
document.getElementById("valor_attack_2").innerHTML = x.getElementsByTagName("ACTIONVALOR_2")[0].childNodes[0].nodeValue;
document.getElementById("valor_attack_3").innerHTML = x.getElementsByTagName("ACTIONVALOR_3")[0].childNodes[0].nodeValue;
document.getElementById("valor_attack_4").innerHTML = x.getElementsByTagName("ACTIONVALOR_4")[0].childNodes[0].nodeValue;
document.getElementById("modi_attack_1").innerHTML = x.getElementsByTagName("ACTIONMODI_1")[0].childNodes[0].nodeValue;
document.getElementById("modi_attack_2").innerHTML = x.getElementsByTagName("ACTIONMODI_2")[0].childNodes[0].nodeValue;
document.getElementById("modi_attack_3").innerHTML = x.getElementsByTagName("ACTIONMODI_3")[0].childNodes[0].nodeValue;
document.getElementById("modi_attack_4").innerHTML = x.getElementsByTagName("ACTIONMODI_4")[0].childNodes[0].nodeValue;
}
//Saving rolls
function str() {
var numero = document.getElementById("str_mod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("strSave").innerHTML = numeroNum + roll;
}
function dex() {
var numero = document.getElementById("dex_mod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("dexSave").innerHTML = numeroNum + roll;
}
function con() {
var numero = document.getElementById("con_mod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("conSave").innerHTML = numeroNum + roll;
}
function int() {
var numero = document.getElementById("int_mod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("intSave").innerHTML = numeroNum + roll;
}
function wis() {
var numero = document.getElementById("wis_mod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("wisSave").innerHTML = numeroNum + roll;
}
function chr() {
var numero = document.getElementById("chr_mod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("chrSave").innerHTML = numeroNum + roll;
}
//Attack Rolls
function rollAttack(){
var numero = document.getElementById("rollMod").innerHTML;
var numeroNum = numero*1;
var roll = Math.floor((Math.random()*20)+1);
document.getElementById("rolly").innerHTML = numeroNum + roll;
}
function atk1(){
var htdados = document.getElementById("dado_attack_1").innerHTML;
var htvalor = document.getElementById("valor_attack_1").innerHTML;
var htmodi = document.getElementById("modi_attack_1").innerHTML;
var dados = htdados*1;
var valor = htvalor*1;
var modi = htmodi*1;
var subtotal = 0;
for(var i=0; i<dados; i++){
var roll = Math.floor((Math.random()*valor)+1);
subtotal += roll;
}
var total = subtotal + modi;
document.getElementById("tk1").innerHTML = total;
if(document.getElementById("tk1").innerHTML === "NaN"){document.getElementById("tk1").innerHTML = "*";}
}
function atk2(){
var htdados = document.getElementById("dado_attack_2").innerHTML;
var htvalor = document.getElementById("valor_attack_2").innerHTML;
var htmodi = document.getElementById("modi_attack_2").innerHTML;
var dados = htdados*1;
var valor = htvalor*1;
var modi = htmodi*1;
var subtotal = 0;
for(var i=0; i<dados; i++){
var roll = Math.floor((Math.random()*valor)+1);
subtotal += roll;
}
var total = subtotal + modi;
document.getElementById("tk2").innerHTML = total;
if(document.getElementById("tk2").innerHTML === "NaN"){document.getElementById("tk2").innerHTML = "*";}
}
function atk3(){
var htdados = document.getElementById("dado_attack_3").innerHTML;
var htvalor = document.getElementById("valor_attack_3").innerHTML;
var htmodi = document.getElementById("modi_attack_3").innerHTML;
var dados = htdados*1;
var valor = htvalor*1;
var modi = htmodi*1;
var subtotal = 0;
for(var i=0; i<dados; i++){
var roll = Math.floor((Math.random()*valor)+1);
subtotal += roll;
}
var total = subtotal + modi;
document.getElementById("tk3").innerHTML = total;
if(document.getElementById("tk3").innerHTML === "NaN"){document.getElementById("tk3").innerHTML = "*";}
}
function atk4(){
var htdados = document.getElementById("dado_attack_4").innerHTML;
var htvalor = document.getElementById("valor_attack_4").innerHTML;
var htmodi = document.getElementById("modi_attack_4").innerHTML;
var dados = htdados*1;
var valor = htvalor*1;
var modi = htmodi*1;
var subtotal = 0;
for(var i=0; i<dados; i++){
var roll = Math.floor((Math.random()*valor)+1);
subtotal += roll;
}
var total = subtotal + modi;
document.getElementById("tk4").innerHTML = total;
if(document.getElementById("tk4").innerHTML === "NaN"){document.getElementById("tk4").innerHTML = "*";}
}
//Search Engine
function loadDoc2() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
nave(this);
}
};
xhttp.open("GET", "https://dantezunino.github.io/mostros/mostros.xml", true);
xhttp.send();
}
function nave(xml){
var xmlDoc = xml.responseXML;
var inputo = document.getElementById("select_monster").value;
for(var i=0; i<19; i++) {
if(xmlDoc.getElementsByTagName("BICHO")[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue === inputo){
monster = i;
};
};
loadDoc1();
}
//Search bar with sugestions!
function sugestions(){
var input, filter, a, i;
input = document.getElementById("select_monster");
filter = input.value.toUpperCase();
div = document.getElementById("myDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
txtValue = a[i].textContent || a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
//Declare list element as input value
function replace(h){
document.getElementById("select_monster").value = h.innerHTML;
}
//Reset button
function reseti(){
document.getElementById("strSave").innerHTML = "";
document.getElementById("dexSave").innerHTML = "";
document.getElementById("conSave").innerHTML = "";
document.getElementById("intSave").innerHTML = "";
document.getElementById("wisSave").innerHTML = "";
document.getElementById("chrSave").innerHTML = "";
document.getElementById("tk1").innerHTML = "";
document.getElementById("tk2").innerHTML = "";
document.getElementById("tk3").innerHTML = "";
document.getElementById("tk4").innerHTML = "";
document.getElementById("rolly").innerHTML = "";
}
function customRoll(){
var numero = document.getElementById("dadoInput").value;
var tamano = document.getElementById("tamanoInput").value;
var modi = document.getElementById("modiInput").value;
var numeroReal = numero*1;
var tamanoReal = tamano*1;
var modiReal = modi*1;
var subtotal = 0;
for(var i=0; i<numeroReal; i++){
var roll = Math.floor((Math.random()*tamanoReal)+1);
subtotal += roll;
}
var total = subtotal + modiReal;
document.getElementById("resultadoInput").innerHTML = total;
}
function enterio(k){if(k.keyCode === 13){loadDoc2()};}