-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
359 lines (333 loc) · 14.1 KB
/
index.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
$(".debug").hide();
let playerHp = 100;
let enemyHp = 160;
let playerMaxHp = 100;
let enemyMaxHp = 160;
let playerExtraDmg = 1;
let playerDef = 0;
let enemyExtraDmg = 1.05;
let enemyDef = 0;
let moveNames = [];
let selectableMoves = [];
let movePool = [];
let movesChosen = 1;
let click = new Audio("click.mp3")
let music = new Audio("Brokemon.wav")
let musicPlaying = false;
console.log("yo hi snooper if somethings red tell me ok? also run playerHp = -2")
let params = window.location.search;
params = new URLSearchParams(params);
let newHp = params.get("hp");
let newDmg = params.get("boost");
newHp = Number(newHp)
newDmg = Number(newDmg)
if (newHp) {
enemyHp = newHp;
enemyMaxHp = newHp;
$("#enemy-hp").html(newHp);
}
if (newDmg) {
enemyExtraDmg = newDmg;
$("#enemyBoost").html(`x${newDmg}`);
};
$('#button-1').prop("disabled", true);
$('#button-2').prop("disabled", true);
$('#button-3').prop("disabled", true);
$('#button-4').prop("disabled", true);
function toggleMusic() {
if (musicPlaying) {
if (music.paused) {
music.play()
} else {
music.pause()
}
}
}
function setDifficulty() {
let diffBoost = $("#enemy-boost-input").val();
let diffHp = $("#enemy-hp-input").val();
diffBoost = Math.max(0, Math.min(100000, Math.round(diffBoost)))
diffHp = Math.max(1, Math.min(10000000, Math.round(diffHp)))
window.location.replace(`index.html?hp=${diffHp}&boost=${diffBoost}`)
}
function setupAi() {
for (i of Array(4).keys()) {
let sNum = Math.random() * selectableMoves.length;
let sSelected = selectableMoves.splice(Math.floor(sNum), 1)[0]
movePool.push(sSelected);
}
}
function debug(key) {
if (key.code === "F7") {
console.log('opened debug HAXOR :O');
$(".debug").show();
}
}
function toggleButtons() {
$('#button-1').prop('disabled', (i, v) => !v);
$('#button-2').prop('disabled', (i, v) => !v);
$('#button-3').prop('disabled', (i, v) => !v);
$('#button-4').prop('disabled', (i, v) => !v);
}
function roundAndUpdate() {
playerHp = Math.round(playerHp);
enemyHp = Math.round(enemyHp);
$("#enemy-hp").html(enemyHp);
$("#player-hp").html(playerHp);
if (enemyHp <= 0) {
$("#enemy-hp").html("<span class='dead'>Dead</span>")
}
if (playerHp <= 0) {
$("#player-hp").html("<span class='dead'>Dead</span>")
}
$("#playerBoost").html(`x${Math.round(playerExtraDmg * 100) / 100}`);
$("#enemyBoost").html(`x${Math.round(enemyExtraDmg * 100) / 100}`);
if (playerExtraDmg < 1) {
$("#playerBoost").switchClass("boost", "nerf", 1000, "easeInOutQuad");
} else if (playerExtraDmg >= 1) {
console.log("cool")
$("#playerBoost").switchClass("nerf", "boost", 1000, "easeInOutQuad");
}
if (enemyExtraDmg < 1) {
$("#enemyBoost").switchClass("boost", "nerf", 1000, "easeInOutQuad");
} else if (enemyExtraDmg >= 1) {
$("#enemyBoost").switchClass("nerf", "boost", 1000, "easeInOutQuad");
}
$("#player-defense").html(playerDef);
$("#enemy-defense").html(enemyDef);
}
function display(top, bottom) {
$("#top-bar").html("| " + top);
$("#bottom-bar").html("| " + bottom);
}
function moveAi() {
let num = Math.random() * movePool.length;
let selected = movePool[Math.floor(num)];
eval(`${selected}.useMove("enemy")`)
}
function loop1() {
if (playerHp > 0 && enemyHp > 0) {
display("Your turn!", "")
toggleButtons()
} else {
setTimeout(handleWin, 1000)
}
}
function loop2() {
if(playerHp > 0 && enemyHp > 0) {
display("Enemy turn!", "")
setTimeout(loop3, 1000)
} else {
setTimeout(handleWin, 1000)
}
}
function loop3() {
moveAi()
setTimeout(loop1, 1500)
}
function handleWin() {
if (playerHp >= enemyHp) {
display("You win!", "Good job!")
} else {
display("You lost.", "sad")
}
}
function evalUse(name, user) {
eval(`${name}.useMove("${user}")`)
}
class Move {
constructor(name, dmg, target, effect, effectType, heal, codeName, specialMsg) {
this.name = name;
this.dmg = dmg;
if (target != "attack") {
this.target = target;
this.effect = effect;
} else {
this.target = "attack";
}
this.heal = heal;
this.effectType = effectType;
this.codeName = codeName;
moveNames.push(codeName);
selectableMoves = [...moveNames];
this.addFunction = `${codeName}.addToMoves()`;
this.useFunction = `${codeName}.useMove("player")`;
$("#key").before(`<button class="move-select" id="add-${codeName}" onclick="${this.addFunction}">${name}</button>`);
if (dmg > 0 && target === "attack") {
$(`#add-${codeName}`).addClass("damageMove");
} else if (dmg > 0) {
$(`#add-${codeName}`).addClass("specialDmgMove");
} else if (target != "attack") {
$(`#add-${codeName}`).addClass("statusMove");
} else if (heal > 0) {
$(`#add-${codeName}`).addClass("healMove");
}
this.specialMsg = specialMsg;
}
addToMoves() {
click.play();
$(`#button-${movesChosen}`).html(this.name);
$(`#button-${movesChosen}`).attr("onclick", `${this.useFunction}`)
movesChosen += 1;
$(`#add-${this.codeName}`).remove();
if (movesChosen === 5) {
$("#moveSelector").remove();
music.play()
music.loop = true;
musicPlaying = true;
loop1();
}
}
useMove(user) {
switch (user) {
case "player":
click.play();
let pDamageDealt = this.dmg * playerExtraDmg;
let randomDamageBoost = Math.random() / 5
randomDamageBoost += 0.9
pDamageDealt *= randomDamageBoost
if (this.dmg > 0) {
console.log("indeedee")
pDamageDealt -= enemyDef
pDamageDealt = Math.max(pDamageDealt, (pDamageDealt + enemyDef) / 2)
}
enemyHp -= pDamageDealt;
playerHp += this.heal * playerExtraDmg;
console.log(this.codeName)
playerHp = Math.min(playerHp, playerMaxHp);
enemyHp = Math.min(enemyHp, enemyMaxHp)
if (this.target === "user") {
if (this.effectType === 1) {
playerExtraDmg += this.effect;
playerExtraDmg = Math.max(playerExtraDmg, 0.5);
} else if (this.effectType === 2) {
playerDef += this.effect;
}
} else if (this.target === "enemy") {
if (this.effectType === 1) {
enemyExtraDmg += this.effect;
enemyExtraDmg = Math.max(enemyExtraDmg, 0.5);
} else if (this.effectType === 2) {
enemyDef += this.effect;
}
}
if (this.dmg > 0 && this.heal >= 0) {
if (this.target != "attack" || this.heal > 0) {
display(`You used ${this.name}!`, `It dealt ${Math.round(pDamageDealt)} damage and some other stuff.`)
} else {
display(`You used ${this.name}!`, `It dealt ${Math.round(pDamageDealt)} damage.`)
}
} else if (this.target === "user") {
if (this.effectType === 1) {
display(`You used ${this.name}!`, `Your attack increased by ${this.effect * 100}%.`)
} else {
display(`You used ${this.name}!`, `Your defense increased by ${this.effect}.`)
}
} else if (this.target === "enemy") {
if (this.effectType === 1) {
display(`You used ${this.name}!`, `The opponent's attack decreased by ${this.effect * -100}%.`)
} else {
display(`You used ${this.name}!`, `The opponent's defense decreased by ${this.effect * -1}.`)
}
} else if (this.heal > 0) {
display(`You used ${this.name}!`, `It brought your HP back up to ${Math.round(playerHp)}.`)
} else if (this.heal < 0) {
display(`You use ${this.name}!`, `It dealt ${Math.round(pDamageDealt)} damage with ${Math.round(this.heal * playerExtraDmg * -1)} recoil.`)
}
if (this.specialMsg) {
console.log("sure")
switch (this.codeName) {
case "beast":
display("MRBEASTTTT", "You healed both yourself and your enemy.");
break;
case "saiyan":
display("SUPER SAIYAN!!!", "*insert japanese here*")
break;
}
}
toggleButtons();
setTimeout(loop2, 1500)
break;
case "enemy":
let eDamageDealt = this.dmg * enemyExtraDmg;
let eRandomDamageBoost = Math.random() / 5
eRandomDamageBoost += 0.9
eDamageDealt *= eRandomDamageBoost
if (this.dmg > 0) {
eDamageDealt -= playerDef;
eDamageDealt = Math.max(eDamageDealt, (eDamageDealt + playerDef) / 2);
};
playerHp -= eDamageDealt;
enemyHp += this.heal * enemyExtraDmg;
enemyHp = Math.min(enemyHp, enemyMaxHp);
playerHp = Math.min(playerHp, playerMaxHp);
if (this.target === "user") {
if (this.effectType === 1) {
enemyExtraDmg += this.effect;
enemyExtraDmg = Math.max(enemyExtraDmg, 0.5);
} else if (this.effectType === 2) {
enemyDef += this.effect;
}
} else if (this.target === "enemy") {
if (this.effectType === 1) {
playerExtraDmg += this.effect;
playerExtraDmg = Math.max(playerExtraDmg, 0.5);
} else if (this.effectType === 2) {
playerDef += this.effect;
}
}
if (this.dmg > 0 && this.heal >= 0) {
if (this.target != "attack" || this.heal > 0) {
display(`The opponent used ${this.name}!`, `It dealt ${Math.round(eDamageDealt)} damage and some other stuff.`)
} else {
display(`The opponent used ${this.name}!`, `It dealt ${Math.round(eDamageDealt)} damage.`)
}
} else if (this.target === "user") {
if (this.effectType === 1) {
display(`The opponent used ${this.name}!`, `The opponent's attack increased by ${this.effect * 100}%.`)
} else {
display(`The opponent used ${this.name}!`, `The opponent's defense increased by ${this.effect * 1}.`)
}
} else if (this.target === "enemy") {
if (this.effectType === 1) {
display(`The opponent used ${this.name}!`, `Your attack decreased by ${this.effect * -100}%.`)
} else {
display(`The opponent used ${this.name}!`, `Your defense decreased by ${this.effect * -1}.`)
}
} else if (this.heal > 0) {
display(`The opponent used ${this.name}!`, `It brought its HP back up to ${Math.round(enemyHp)}.`)
} else if (this.heal < 0) {
display(`The opponent used ${this.name}!`, `It dealt ${Math.round(eDamageDealt)} damage with ${Math.round(this.heal * enemyExtraDmg * -1)} recoil.`)
}
if (this.specialMsg) {
switch (this.codeName) {
case "beast":
display("MRBEASTTTT", "Both the enemy and you were healed.");
break;
case "saiyan":
display("ENEMY GO SUPER SAIYAN!!!", "*insert japanese here*")
break;
}
}
break;
}
roundAndUpdate()
}
}
// let name = new Move("name", dmg, "effectTarget", effectPower, effectType, heal, "codename", hasSpeicalDisplay)
let bonk = new Move("Bonk", 40, "attack", 0, 0, 0, "bonk", false);
let stronk = new Move("Stronkify", 0, "user", 0.15, 1, 0, "stronk", false);
let belittle = new Move("Belittle", 0, "enemy", -0.15, 1, 0, "belittle", false);
let tickle = new Move("Tickle", 10, "enemy", -0.1, 1, 0, "tickle", false);
let lick = new Move("Lick Wounds", 0, "attack", 0, 0, 30, "lick", false);
let hyperbonk = new Move("HYPERBONK", 50, "attack", 0, 0, -40, "hyperbonk", false);
let triangulate = new Move("Triangulate 🤓", 15, "user", 0.05, 1, 10, "triangulate", false);
let munch = new Move("Gremlin Munch", 30, "attack", 0, 0, 15, "munch", false);
let beast = new Move("MRBEASTTTT", -20, "attack", 0, 0, 40, "beast", true);
let saiyan = new Move("Super Saiyan", 0, "user", 0.3, 1, -30, "saiyan", true);
let rock = new Move("El Rock", 0, "user", 5, 2, 0, "rock", false);
let pickaxe = new Move("Diamond Pickaxe", 0, "enemy", -4, 2, 0, "pickaxe", false);
let l = new Move("L", 25, "enemy", -0.05, 1, 0, "l", false);
// Kalob was a special child. He belittled people so they could not lick their wounds using a baseball bat to bonk them
document.addEventListener("keydown", debug);
setupAi()