Loot-Quest

Dungeon crawler game made in js
Log | Files | Refs | README | LICENSE

Player.js (2939B)


      1 function Player(hp, gold) {
      2 
      3 	this.gold = 0;
      4 	this.hp = hp;
      5 	this.totalHp = hp;
      6 	this.currentBlock = this.block;
      7 
      8 	this.equipWeapon = function (weapon) {
      9 		this.equip = weapon.name;
     10 		this.minA = weapon.minA;
     11 		this.maxA = weapon.maxA;
     12 		this.miss = weapon.miss;
     13 	}
     14 
     15 	this.equipArmor = function (clothes) {
     16 		this.armor = clothes.name;
     17 		this.block = clothes.block;
     18 		this.currentBlock = this.block;
     19 		this.blockAdd = clothes.blockAdd;
     20 	}
     21 
     22 	this.setHp = function (hp) {
     23 		this.hp = hp;
     24 		if (this.hp <= 0) {
     25 			this.hp = 0;
     26 			SetSlaying(false);
     27 		}
     28 	}
     29 
     30 	this.setGold = function (gold) {
     31 		this.gold = gold;
     32 	}
     33 
     34 	this.setPower = function (power) {
     35 		this.power = power;
     36 	}
     37 
     38 	this.resetBlock = function () {
     39 		this.currentBlock = this.block;
     40 	}
     41 
     42 	this.hardscope = function(){
     43 		this.power += 1;
     44 		return Math.floor((Math.random() * this.maxA) + this.minA);
     45 
     46 	}
     47 
     48 	this.noscope = function() {
     49 		this.power -= 2;
     50 		return Math.floor(((Math.random() * 3 * this.minA) + this.maxA) + this.minA);
     51 
     52 	}
     53 
     54 	this.blockr = function() {
     55 		this.power += 1;
     56 		this.currentBlock = this.block + this.blockAdd;
     57 		console.println("You brace for an attack of magnitude " + this.currentBlock + "!");
     58 	}
     59 
     60 
     61 	this.doAttack = async function(enemy, dam, miss, type) {
     62 		if (!miss) {
     63 			console.println("You " + type + " the " + enemy.name + " with your " + this.equip + " and do " + dam + " damage!");
     64 			enemy.setHp(enemy.hp - dam);
     65 
     66 		} else {
     67 			console.println("You missed!");
     68 			await getUserInput();
     69 		}
     70 	}
     71 
     72 	this.attack = function (enemy) {	
     73 		inputLoop = true;
     74 		pmiss = false;
     75 		missc = Math.random() * 100;
     76 		if (missc < this.miss) {
     77 			pmiss = true;
     78 		}
     79 
     80 		if (this.power > 2) {
     81 			while (inputLoop) {
     82 				inputLoop = false;
     83 				fight = console.input("[H]ardscope, [B]lock or [N]oScope: ").toLowerCase();
     84 				switch (fight) {
     85 					case "hardscope":
     86 						this.doAttack(enemy, this.hardscope(), pmiss, "hardscope");
     87 					break;
     88 					case "h":
     89 						this.doAttack(enemy, this.hardscope(), pmiss, "hardscope");
     90 					break;
     91 					case "block":
     92 						this.blockr();
     93 					break;
     94 					case "b":
     95 						this.blockr();
     96 					break;
     97 					case "noscope":
     98 						this.doAttack(enemy, this.noscope(), pmiss, "noscope");
     99 					break;
    100 					case "n":
    101 						this.doAttack(enemy, this.noscope(), pmiss, "noscope");
    102 					break;
    103 					default:
    104 					inputLoop = true;
    105 					console.println("Invalid input!");
    106 					break;
    107 				}
    108 			}
    109 		} else {
    110 			while (inputLoop) {
    111 				inputLoop = false;
    112 				fight = console.input("[H]ardscope or [B]lock: ").toLowerCase();
    113 				switch (fight) {
    114 					case "hardscope":
    115 						this.doAttack(enemy, this.hardscope(), pmiss, "hardscope");
    116 					break;
    117 					case "h":
    118 						this.doAttack(enemy, this.hardscope(), pmiss, "hardscope");
    119 					break;;
    120 					case "block":
    121 						this.blockr();
    122 					break;
    123 					case "b":
    124 						this.blockr();
    125 					break;
    126 					default:
    127 					inputLoop = true;
    128 					console.println("Invalid input!");
    129 					break;
    130 				}
    131 			}
    132 		}
    133 
    134 	}
    135 }