81 lines
3.8 KiB
TypeScript
81 lines
3.8 KiB
TypeScript
import GameFlow from '../game/gameFlow';
|
|
import GameState, { PHASE_ENUM } from '../game/gameState';
|
|
|
|
export class MountainPhase {
|
|
static async handleMountain(gameState: GameState): Promise<void> {
|
|
// If the total mileage is less than 950, return an empty string (no mountain encounter)
|
|
if (gameState.totalMileageWholeTrip <= 950) {
|
|
return;
|
|
}
|
|
|
|
let responseMessage = "**🏔️ Mountain Passage 🏔️**\n";
|
|
let encounter = false;
|
|
|
|
let randomFactor = Math.random() * 10;
|
|
// Calculate the mountain difficulty based on the total mileage traveled
|
|
// The difficulty peaks around 1500 miles and decreases as you get closer or further away
|
|
// Example: If totalMileageWholeTrip is 1500, mountainDifficulty will be 9
|
|
|
|
const milesFromPeak = gameState.totalMileageWholeTrip / 100 - 15;
|
|
const numerator = milesFromPeak ** 2 + 72;
|
|
const denominator = milesFromPeak ** 2 + 12;
|
|
let mountainDifficulty = 9 - (numerator / denominator);
|
|
|
|
|
|
// Check if a mountain encounter occurs based on the random factor and difficulty
|
|
if (randomFactor > mountainDifficulty) {
|
|
encounter = true;
|
|
responseMessage += "Rugged mountains make your journey difficult.\n";
|
|
|
|
// Randomly determine the type of mountain encounter
|
|
if (Math.random() > 0.1) {
|
|
gameState.totalMileageWholeTrip -= 60;
|
|
responseMessage += "🔍 You got lost—losing valuable time trying to find the trail!\n";
|
|
} else if (Math.random() > 0.11) {
|
|
gameState.amountSpentOnMiscellaneousSupplies -= 5;
|
|
gameState.amountSpentOnAmmunition -= 200;
|
|
gameState.totalMileageWholeTrip -= 20 + Math.random() * 30;
|
|
responseMessage += "🛠️ Wagon damaged!—Lose time and supplies.\n";
|
|
} else {
|
|
gameState.totalMileageWholeTrip -= 45 + Math.random() / 0.02;
|
|
responseMessage += "🐢 The going gets slow.\n";
|
|
}
|
|
}
|
|
|
|
// Check if the South Pass has been cleared
|
|
if (!gameState.clearSouthPassFlag) {
|
|
gameState.clearSouthPassFlag = true;
|
|
if (Math.random() < 0.8) {
|
|
encounter = true;
|
|
responseMessage += "✅ You made it safely through South Pass—no snow.\n";
|
|
}
|
|
}
|
|
|
|
// Check if the Blue Mountains have been cleared
|
|
if (gameState.totalMileageWholeTrip >= 1700 && !gameState.clearBlueMountainsFlag) {
|
|
gameState.clearBlueMountainsFlag = true;
|
|
if (Math.random() < 0.7) {
|
|
encounter = true;
|
|
gameState.blizzardFlag = true;
|
|
gameState.amountSpentOnFood -= 25;
|
|
gameState.amountSpentOnMiscellaneousSupplies -= 10;
|
|
gameState.amountSpentOnAmmunition -= 300;
|
|
gameState.totalMileageWholeTrip -= 30 + Math.random() * 40;
|
|
responseMessage += "❄️ Blizzard in mountain pass—time and supplies lost.\n";
|
|
|
|
// Check if the player has enough clothing for the cold
|
|
if (gameState.amountSpentOnClothing < 18 + Math.random() * 2) {
|
|
responseMessage += "❄️🧣 Not enough clothing for the cold. This could be dire.\n";
|
|
// Add logic to affect player health or trigger a death sequence.
|
|
}
|
|
}
|
|
}
|
|
|
|
// Return the encounter message or a default message if no encounter occurred
|
|
gameState.lastPrompt = encounter ? responseMessage : "The mountains are distant... for now.\n";
|
|
gameState.phase = PHASE_ENUM.START_TURN;
|
|
gameState.subPhase = 0
|
|
await gameState.save();
|
|
await GameFlow.executeCurrentPhase(gameState);
|
|
}
|
|
} |