Enemy.js (1129B)
1 function Enemy(name, level, hp, minA, maxA, miss) { 2 this.name = name; 3 this.hp = hp; 4 this.totalHp = hp; 5 this.minA = minA; 6 this.maxA = maxA; 7 this.miss = miss; 8 this.level = level; 9 10 AddEnemy(this); 11 12 this.setHp = function(hp) { 13 this.hp = hp; 14 if (this.hp <= 0) { 15 this.hp = 0; 16 SetSlaying(false); 17 } 18 } 19 20 this.doAttack = async function (player, attack, miss) { 21 if (!miss) { 22 console.println("The " + this.name + " hit you and did " + attack + " damage!") 23 await getUserInput(); 24 player.setHp(player.hp - attack); 25 26 } else { 27 console.println(this.name + " missed!") 28 await getUserInput(); 29 } 30 player.resetBlock(); 31 } 32 33 this.attack = function(player) { 34 emiss = false; 35 missc = Math.random() * 100; 36 if(missc < this.miss) { 37 emiss = true; 38 } 39 eattack = Math.floor((Math.random() * maxA) + minA) - player.currentBlock; 40 if(eattack <= 0) { 41 eattack = 0; 42 } 43 this.doAttack(player, eattack, emiss); 44 } 45 }