Compare commits
3 Commits
8b630c45c9
...
4d0f4a7589
Author | SHA1 | Date |
---|---|---|
j | 4d0f4a7589 | |
j | 9f136525a0 | |
j | 321f3d25e0 |
|
@ -1,11 +1,8 @@
|
||||||
import GameState from "./gameState";
|
import GameFlow from "./gameFlow";
|
||||||
|
import GameState, { PHASE_ENUM } from "./gameState";
|
||||||
|
|
||||||
class GameEvents {
|
export class EventPhase {
|
||||||
private randomEvents: OregonEvent[];
|
private static randomEvents: OregonEvent[] = [
|
||||||
private totalThreshold: number;
|
|
||||||
constructor() {
|
|
||||||
// Initialize the events and their thresholds.
|
|
||||||
this.randomEvents = [
|
|
||||||
{
|
{
|
||||||
name: "Wagon Breakdown",
|
name: "Wagon Breakdown",
|
||||||
threshold: 10, // Probability weight
|
threshold: 10, // Probability weight
|
||||||
|
@ -99,87 +96,30 @@ class GameEvents {
|
||||||
// Add more events here...
|
// Add more events here...
|
||||||
];
|
];
|
||||||
|
|
||||||
this.totalThreshold = this.randomEvents.reduce((acc, event) => acc + event.threshold, 0);
|
private static totalThreshold: number = EventPhase.randomEvents.reduce((acc, event) => acc + event.threshold, 0);
|
||||||
}
|
|
||||||
|
|
||||||
generateRandomEvent(gameState: GameState): string {
|
public static async handleRandomEvent(gameState: GameState): Promise<void> {
|
||||||
const randomEventNumber = Math.random() * this.totalThreshold;
|
const randomEventNumber = Math.random() * EventPhase.totalThreshold;
|
||||||
let cumulativeThreshold = 0;
|
let cumulativeThreshold = 0;
|
||||||
|
let responseMessage = "";
|
||||||
for (let event of this.randomEvents) {
|
for (let event of EventPhase.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}`);
|
||||||
return event.action(gameState);
|
responseMessage = event.action(gameState);
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
gameState.lastPrompt = responseMessage;
|
||||||
|
gameState.phase = PHASE_ENUM.MOUNTAIN;
|
||||||
|
gameState.subPhase = 0
|
||||||
|
await gameState.save();
|
||||||
|
await GameFlow.executeCurrentPhase(gameState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface OregonEvent {
|
interface OregonEvent {
|
||||||
name: string,
|
name: string;
|
||||||
threshold: number,
|
threshold: number;
|
||||||
action: (gameState: GameState) => string
|
action: (gameState: GameState) => string;
|
||||||
}
|
}
|
|
@ -6,6 +6,8 @@ import { HuntPhase } from '../phases/hunt';
|
||||||
import { HandleSetup as SetupPhase } from '../phases/setup';
|
import { HandleSetup as SetupPhase } from '../phases/setup';
|
||||||
import { travelPhase as TravelPhase } from '../phases/travel';
|
import { travelPhase as TravelPhase } from '../phases/travel';
|
||||||
import { ActionPhase } from '../phases/action';
|
import { ActionPhase } from '../phases/action';
|
||||||
|
import { EventPhase } from './gameEvents';
|
||||||
|
import { MountainPhase } from '../phases/mountain';
|
||||||
|
|
||||||
class GameFlow {
|
class GameFlow {
|
||||||
|
|
||||||
|
@ -41,9 +43,11 @@ class GameFlow {
|
||||||
break;
|
break;
|
||||||
case PHASE_ENUM.EVENT:
|
case PHASE_ENUM.EVENT:
|
||||||
// Handle random events that can occur
|
// Handle random events that can occur
|
||||||
|
await EventPhase.handleRandomEvent(gameState);
|
||||||
break;
|
break;
|
||||||
case PHASE_ENUM.MOUNTAIN:
|
case PHASE_ENUM.MOUNTAIN:
|
||||||
// Handle mountain traversal challenges
|
// Handle mountain traversal challenges
|
||||||
|
await MountainPhase.handleMountain(gameState);
|
||||||
break;
|
break;
|
||||||
case PHASE_ENUM.DEATH:
|
case PHASE_ENUM.DEATH:
|
||||||
// Check if conditions leading to the player's death have been met
|
// Check if conditions leading to the player's death have been met
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loadingā¦
Reference in New Issue