// Holds all functions used in multiple files import { createRequire } from 'module'; const require = createRequire(import.meta.url); var readlineSync = require('readline-sync'); const { exec } = require("child_process"); import { promisify } from "util"; const execPromise = promisify(exec); import './variables.js'; import { inventoryMenuM } from './inventory.js'; import { checkPOI } from './poiscreens.js'; global.isRawModeEnabled = false; // Track whether raw mode is enabled // Used for basic functions, not game specific export function userInput(question) { // Basic user input functions, takes in the question to be asked. let answer = readlineSync.question(question); return(answer); } export function randomNumber(min, max) { // Takes in two parameters, min and max, and returns a random number between those boundries. while (true) { var randNum = Math.floor(Math.random() * (max+1)); if (randNum >= min) { break; } } return randNum; } // Used for game export function healthCapCalc() { // Calculates HP cap given current radPoints healthCap = healthCap-radPoints; if (health > healthCap) { health = healthCap; } } export function radPointsCalc() { // Calculates radPoints given walk/foodrate if (isRadiated == true) { radPoints = radPoints + 0.5 * (radSeverity * 10 + 5 * (walkRate + foodRate)); } } export function eatFood() { // Calculates food amount after a day of eating if (food == 0) { health = health - 0.25*walkRate } else { food = food - walkRate * foodRate } } export function checkLose() { // Checks to see if any lose conditions have been met if (health <= 0 || radPoints >= 100) { death(); } } export function calcLocation() { if (walkRate == 1) { if (path = 0) { location++; } if (path = 1) { locationA++; } if (path = 2) { locationB++; } } if (walkRate == 2) { if (path = 0) { location * 2; } if (path = 1) { locationA * 2; } if (path = 2) { locationB * 2; } } if (walkRate == 3) { if (path = 0) { location * 3; } if (path = 1) { locationA * 3; } if (path = 2) { locationB * 3; } } } export async function sleep(time) { try { await execPromise(`sleep ${time}`); } catch (error) { console.error("Error executing sleep command:", error); } } function death() { let random = randomNumber(1,3); if (random = 1) { death1(); } if (random = 2) { death2(); } if (random = 3) { death3(); } } function death1() { console.log("") } function death2() { } function death3() { } function timeDeath() { // The death screen for passing the time limit console.clear; console.log("Your PIP-Boy starts ringing...\n\n") console.log("BEEP...BEEP...BEEP"); console.log("INCOMING MESAGE FROM: Raven_Rock_Comms-1\n\n"); console.log("|||||||") console.log("|| Enclave Intranet Messager"); console.log("|||||||") console.log("|| Message From: automessager"); console.log("|||||||\n\n") console.log("Dear, "+name+",\n\n"); console.log("You have failed to faithfully execute the tasks laid before you in a timely manner."); console.log("In consequence you have been dishonorably discharged from the Enclave Armed Forces"); console.log("Please return to the nearest active Enclave Military Installation immeditely\n\n"); console.log("Signed, Enclave Internal Messager"); console.clear; } var travelFrame = 0; export function travelScreen() { if (travelFrame < 0 || travelFrame > 3) { travelFrame = 0; } else if (travelFrame == 0) { console.clear(); console.log("┌──────────────────────────────────────┐"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ ◜─◝ │"); console.log("│ ◟_◞ │"); console.log("│ /║\\ │"); console.log("│ \\V/ │"); console.log("│ / \\ │"); console.log("│ ▁\\ ▔╹ │"); console.log("│======================================│"); console.log("│ . . - . . - . . . - │"); console.log("│ - . . . . . . - . .│"); console.log("└──────────────────────────────────────┘"); console.log("Press [ENTER] to open Pip-Boy"); console.log("Current Health: "+health); console.log("Food Amt: "+food); console.log("Distance to next POI: "); travelFrame++ } else if (travelFrame == 1) { console.clear(); console.log("┌──────────────────────────────────────┐"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ ◜─◝ │"); console.log("│ ◟_◞ │"); console.log("│ /║\\ │"); console.log("│ \\V/ │"); console.log("│ \\ │"); console.log("│ ▁│▔╹ │"); console.log("│======================================│"); console.log("│ - . - . . . - . - . │"); console.log("│ - . . - . . . - .│"); console.log("└──────────────────────────────────────┘"); console.log("Press [ENTER] to open Pip-Boy"); console.log("Current Health: "+health); console.log("Food Amt: "+food); console.log("Distance to next POI: "); travelFrame++ } else if (travelFrame == 2) { console.clear(); console.log("┌──────────────────────────────────────┐"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ ◜─◝ │"); console.log("│ ◟_◞ │"); console.log("│ /║\\ │"); console.log("│ \\V/ │"); console.log("│ ╳ │"); console.log("│ _/_\\ │"); console.log("│======================================│"); console.log("│ - . - . . . - . - . │"); console.log("│ - . . - . . . - .│"); console.log("└──────────────────────────────────────┘"); console.log("Press [ENTER] to open Pip-Boy"); console.log("Current Health: "+health); console.log("Food Amt: "+food); console.log("Distance to next POI: "); travelFrame++ } else if (travelFrame == 3) { console.clear(); console.log("┌──────────────────────────────────────┐"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ │"); console.log("│ ◜─◝ │"); console.log("│ ◟_◞ │"); console.log("│ /║\\ │"); console.log("│ \\V/ │"); console.log("│ \\ │"); console.log("│ ▁│▔╹ │"); console.log("│======================================│"); console.log("│ - . - . . . - . - . │"); console.log("│ - . . - . . . - .│"); console.log("└──────────────────────────────────────┘"); console.log("Press [ENTER] to open Pip-Boy"); console.log("Current Health: "+health); console.log("Food Amt: "+food); console.log("Distance to next POI: "); travelFrame=0; } } export async function walkPathA() { enableRawMode(); if (paused) { disableRawMode(); pauseScreen(); enableRawMode(); } if (location > 255) { disableRawMode(); return; } calcLocation(); radPointsCalc(); healthCapCalc(); checkLose(); travelScreen(); checkPOI(); eatFood(); //await sleep(0.5); walkPathA(); } process.stdin.resume(); process.stdin.on('data', (key) => { if (key.toString() === ' ') { paused = true; // Pause the game } else if (key.toString() === '\u0003') { // Handle Ctrl+C (ASCII code for Ctrl+C) console.log("\nExiting game..."); process.exit(); // Exit the program } }); export function enableRawMode() { if (!isRawModeEnabled) { process.stdin.setRawMode(true); process.stdin.resume(); isRawModeEnabled = true; } } export function disableRawMode() { if (isRawModeEnabled) { process.stdin.setRawMode(false); process.stdin.pause(); isRawModeEnabled = false; } } var paused = false; export function pauseScreen() { console.clear(); console.log ("What would you like to do?"); console.log ("--------------------------"); console.log ("1) Resume"); console.log ("2) View Inventory"); console.log ("3) View Distances"); console.log ("4) View Stats"); console.log ("5) Scavenge"); let pauseInput = userInput("Enter: "); switch(pauseInput) { case "1": paused = false; break; case "2": inventoryMenuM(); break; case "3": console.clear(); console.log("Current Location: "+location); if (path == 0) { console.log("Current Path: Main"); } if (path == 1) { console.log("Current Path: A (Southern)"); } if (path == 2) { console.log("Current Path: B (Northern)"); } console.log("------------------------"); for (let i = 0; i < 7; i++) { if (pois[i].visited == true) { console.log(pois[i].name+" - "+visited[i]); } if (pois[i].visited == false) { console.log("??? "+pois[i].location-location+" location points away"); } } if (path == 1) { for (let i = poiCounter; i < 14; i++) { if (pois[i].visited == true) { console.log(pois[i].name+" - "+visited[i]); } if (pois[i].visited == false) { console.log("??? "+pois[i].location-location+" location points away"); } } } if (path == 2) { for (let i = poiCounter; i < pois.length; i++) { if (pois[i].visited == true) { console.log(pois[i].name+" - "+visited[i]); } if (pois[i].visited == false) { console.log("??? "+pois[i].location-location+" location points away"); } } } userInput("\n[Press Enter to return]"); break; case "4": 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("Current Location: "+location); console.log("Current Path: "+path); userInput("\n[Press Enter to return]"); break; case "5": scavenge(); break; } }