The Final commit before turn-in (hopefully)
This commit is contained in:
parent
44a4cf65bd
commit
77cb3f4613
8 changed files with 265 additions and 148 deletions
107
files/combat.js
107
files/combat.js
|
|
@ -1,5 +1,6 @@
|
|||
import './variables.js';
|
||||
import {userInput} from './functions.js';
|
||||
import { randomNumber, userInput } from './functions.js';
|
||||
import { inventoryMenuM } from './inventory.js';
|
||||
|
||||
function initCombat(enemy) {
|
||||
if (enemy.minLevel > level) {
|
||||
|
|
@ -23,53 +24,127 @@ function initCombat(enemy) {
|
|||
function combat(enemy) {
|
||||
console.clear();
|
||||
console.log("You enter combat with "+enemy.name+"...");
|
||||
console.log("What would you like to do?");
|
||||
console.log("-----------------------");
|
||||
console.log("1) Attack");
|
||||
console.log("2) Check your Inventory");
|
||||
console.log("3) View Stats");
|
||||
var combatInput = userInput("Enter: ");
|
||||
switch(combatInput) {
|
||||
case "1":
|
||||
|
||||
let combatInput;
|
||||
while (true) {
|
||||
console.log("What would you like to do?");
|
||||
console.log("-----------------------");
|
||||
console.log("1) Attack");
|
||||
console.log("2) Check your Inventory");
|
||||
console.log("3) View Stats");
|
||||
combatInput = userInput("Enter: ");
|
||||
|
||||
if (combatInput != "1" && combatInput != "2" && combatInput != "3") {
|
||||
console.log("Invalid input. Please enter 1, 2, or 3.");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(combatInput) {
|
||||
case "1":
|
||||
console.log("You attack "+enemy.name+" with your "+equippedWeapon.name+"!");
|
||||
sleep(2);
|
||||
let attackRoll = randomNumber(1,100);
|
||||
if (attackRoll <= 10) {
|
||||
console.log("You critically hit "+enemy.name+" dealing "+damageCalc(player, true)+" damage!");
|
||||
sleep(2);
|
||||
} else if (attackRoll <= 50) {
|
||||
console.log("You hit "+enemy.name+" dealing "+damageCalc(player, false)+" damage!");
|
||||
sleep(2);
|
||||
} else if (attackRoll <= 90) {
|
||||
console.log("You miss "+enemy.name+"!");
|
||||
sleep(2);
|
||||
} else {
|
||||
console.log("You critically miss "+enemy.name+", dealing 3 damage to yourself!");
|
||||
health-3;
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
console.log(enemy.name+" Attacks you with thier "+enemyStats.weapon.name+"!");
|
||||
sleep(2);
|
||||
let enemyRoll = randomNumber(1,100);
|
||||
if (attackRoll <= 10) {
|
||||
console.log(enemy.name+" critically hit you dealing "+damageCalc(enemy, true)+" damage!");
|
||||
sleep(2);
|
||||
} else if (attackRoll <= 50) {
|
||||
console.log(enemy.name+" hit you dealing "+damageCalc(player, false)+" damage!");
|
||||
sleep(2);
|
||||
} else if (attackRoll <= 90) {
|
||||
console.log(enemy.name+" misses you!");
|
||||
sleep(2);
|
||||
} else {
|
||||
console.log(enemy.name+" critically misses, dealing 3 damage to themself!");
|
||||
enemyStats.health-3;
|
||||
sleep(2);
|
||||
}
|
||||
case "2":
|
||||
inventoryMenuM();
|
||||
break;
|
||||
case "3":
|
||||
console.clear();
|
||||
console.log("Player Stats");
|
||||
console.log("-------------");
|
||||
console.log("Name: "+name);
|
||||
console.log("Level: "+level);
|
||||
console.log("Current Health: "+health+"/"+healthCap);
|
||||
console.log("Radiation Points: "+radPoints);
|
||||
console.log("Radiation Severity: "+radSeverity);
|
||||
console.log("Walk Rate: "+walkRate);
|
||||
console.log("Food Amt: "+food);
|
||||
console.log("Food Rate: "+foodRate);
|
||||
console.log("Distance to next POI: " + pois[poiCounter].location-location);
|
||||
console.log("Current Path: "+path);
|
||||
userInput("\n[Press Enter to return]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function damageCalc(attacker) {
|
||||
function damageCalc(attacker, crit) {
|
||||
if (attacker = player) {
|
||||
if (playerStats.chem == "psycho") {
|
||||
var damageOutput = playerStats.weapon.damage*1.5;
|
||||
} else {
|
||||
var damageOutput = playerStats.weapon.damage;
|
||||
}
|
||||
if (crit) {
|
||||
damageOutput+3;
|
||||
}
|
||||
|
||||
if (enemyStats.armorUnit == "dr"){
|
||||
enemyStats.health = enemyStats.health-(damageOutput-(enemyStats.armor.value/100));
|
||||
let drDamage = damageOutput-(enemyStats.armor.value/100);
|
||||
enemyStats.health = enemyStats.health-drDamage;
|
||||
return drDamage;
|
||||
}
|
||||
if (enemyStats.armorUnit == "dt") {
|
||||
let dtDamage = enemyStats.health-(damageOutput-armor);
|
||||
if (dtDamage < 0) {
|
||||
dtDamage = 0;
|
||||
}
|
||||
enemyStats.health - dtDamage
|
||||
enemyStats.health - dtDamage;
|
||||
return dtDamage;
|
||||
}
|
||||
} else {
|
||||
if (playerStats.chem == "medx") {
|
||||
var damageOutput = enemyStats.weapon.damage*(-1.5);
|
||||
} else {
|
||||
var damageOutput = enemyStats.weapon.damage;
|
||||
} if (playerStats.armorUnit == "dr"){
|
||||
playerStats.health = playerStats.health-(damageOutput-(playerStats.armor.value/100));
|
||||
}
|
||||
if (crit) {
|
||||
damageOutput+3;
|
||||
}
|
||||
if (playerStats.armorUnit == "dr"){
|
||||
let drDamage = damageOutput-(playerStats.armor.value/100)
|
||||
playerStats.health = playerStats.health-drDamage;
|
||||
return drDamage;
|
||||
}
|
||||
if (playerStats.armorUnit == "dt") {
|
||||
let dtDamage = playerStats.health-(damageOutput-armor);
|
||||
if (dtDamage < 0) {
|
||||
dtDamage = 0;
|
||||
}
|
||||
playerStats.health - dtDamage
|
||||
playerStats.health - dtDamage;
|
||||
return dtDamage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue