added handling for mountains

master
j 2024-03-26 22:50:32 -04:00
parent 01a2825fc0
commit 0087c3523d
1 changed files with 64 additions and 5 deletions

View File

@ -1,11 +1,11 @@
import GameState from "./gameState"; import GameState from "./gameState";
class GameEvents { class GameEvents {
private events: OregonEvent[]; private randomEvents: OregonEvent[];
private totalThreshold: number; private totalThreshold: number;
constructor() { constructor() {
// Initialize the events and their thresholds. // Initialize the events and their thresholds.
this.events = [ this.randomEvents = [
{ {
name: "Wagon Breakdown", name: "Wagon Breakdown",
threshold: 10, // Probability weight threshold: 10, // Probability weight
@ -99,14 +99,14 @@ class GameEvents {
// Add more events here... // Add more events here...
]; ];
this.totalThreshold = this.events.reduce((acc, event) => acc + event.threshold, 0); this.totalThreshold = this.randomEvents.reduce((acc, event) => acc + event.threshold, 0);
} }
generateEvent(gameState: GameState): string { generateRandomEvent(gameState: GameState): string {
const randomEventNumber = Math.random() * this.totalThreshold; const randomEventNumber = Math.random() * this.totalThreshold;
let cumulativeThreshold = 0; let cumulativeThreshold = 0;
for (let event of this.events) { for (let event of this.randomEvents) {
cumulativeThreshold += event.threshold; cumulativeThreshold += event.threshold;
if (randomEventNumber < cumulativeThreshold) { if (randomEventNumber < cumulativeThreshold) {
console.log(`Event triggered: ${event.name}`); console.log(`Event triggered: ${event.name}`);
@ -115,6 +115,65 @@ class GameEvents {
} }
return ""; return "";
} }
mountains(gameState: GameState): string {
if (gameState.totalMileageWholeTrip <= 950) {
return '';
}
let message = "**🏔️ Mountain Passage 🏔️**\n";
let encounter = false;
let randomFactor = Math.random() * 10;
let mountainDifficulty = 9 - ((gameState.totalMileageWholeTrip / 100 - 15) ** 2 + 72) / ((gameState.totalMileageWholeTrip / 100 - 15) ** 2 + 12);
if (randomFactor > mountainDifficulty) {
encounter = true;
message += "Rugged mountains make your journey difficult.\n";
if (Math.random() > 0.1) {
gameState.totalMileageWholeTrip -= 60;
message += "🔍 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;
message += "🛠️ Wagon damaged!—Lose time and supplies.\n";
} else {
gameState.totalMileageWholeTrip -= 45 + Math.random() / 0.02;
message += "🐢 The going gets slow.\n";
}
}
if (!gameState.clearSouthPassFlag) {
gameState.clearSouthPassFlag = true;
if (Math.random() < 0.8) {
encounter = true;
message += "✅ You made it safely through South Pass—no snow.\n";
}
}
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;
message += "❄️ Blizzard in mountain pass—time and supplies lost.\n";
if (gameState.amountSpentOnClothing < 18 + Math.random() * 2) {
message += "❄️🧣 Not enough clothing for the cold. This could be dire.\n";
// Add logic to affect player health or trigger a death sequence.
}
}
}
return encounter ? message : "The mountains are distant... for now.\n";
}
} }
export default GameEvents; export default GameEvents;