Beginning riders logic
parent
20b7a883fa
commit
c0d93da687
|
@ -518,7 +518,93 @@ class GameFlow {
|
||||||
|
|
||||||
|
|
||||||
private async handleRidersAttack(userInput?: string | number): Promise<void> {
|
private async handleRidersAttack(userInput?: string | number): Promise<void> {
|
||||||
// Logic for handling a riders attack, may involve checking userInput for response to attack
|
// Logic for handling a riders attack
|
||||||
|
let responseMessage = ''
|
||||||
|
this.gameState.lastPrompt = responseMessage;
|
||||||
|
|
||||||
|
if (!userInput || userInput === "") {
|
||||||
|
// Check for random encounter
|
||||||
|
// Calculate a factor based on total mileage to adjust encounter likelihood.
|
||||||
|
const mileageFactor = this.gameState.totalMileageWholeTrip / 100 - 4;
|
||||||
|
|
||||||
|
// Calculate the chance of encountering riders, scaling non-linearly with mileage.
|
||||||
|
const encounterChance = ((mileageFactor ** 2) + 72) / ((mileageFactor ** 2) + 12) - 1;
|
||||||
|
|
||||||
|
// Generate a random factor to determine if an encounter occurs.
|
||||||
|
const randomFactor = Math.random() * 10;
|
||||||
|
|
||||||
|
// If the random factor exceeds the encounter chance, skip to the next phase.
|
||||||
|
if (randomFactor > encounterChance) {
|
||||||
|
this.gameState.phase = PHASE_ENUM.EVENT;
|
||||||
|
this.gameState.save();
|
||||||
|
return this.executeCurrentPhase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.gameState.hostilityOfRiders = false;
|
||||||
|
if (Math.random() < 0.8) this.gameState.hostilityOfRiders = true;
|
||||||
|
}
|
||||||
|
if (!userInput || userInput === "" || userInput.toString().toLowerCase() === "start") {
|
||||||
|
responseMessage += `RIDERS AHEAD. THEY`
|
||||||
|
if (!this.gameState.hostilityOfRiders) responseMessage += ` DON'T`
|
||||||
|
responseMessage += ` LOOK HOSTILE`;
|
||||||
|
responseMessage += "\n\nTACTICS\n(1) RUN\n(2) ATTACK\n(3) CONTINUE\n(4) CIRCLE WAGONS";
|
||||||
|
|
||||||
|
this.gameState.tacticsChoiceWhenAttacked = 0
|
||||||
|
this.gameState.lastPrompt = responseMessage;
|
||||||
|
this.gameState.save();
|
||||||
|
await this.statusUpdate(responseMessage);
|
||||||
|
} else {
|
||||||
|
//check if its a valid interger between 1 and 4 inclusive
|
||||||
|
if (isNaN(Number(userInput)) || +userInput < 1 && +userInput > 4) {
|
||||||
|
|
||||||
|
responseMessage = "Invalid input. Please enter a number between 1-4.\n\n";
|
||||||
|
responseMessage += this.gameState.lastPrompt;
|
||||||
|
await this.statusUpdate(responseMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Convert to integer in case it's not
|
||||||
|
this.gameState.tacticsChoiceWhenAttacked = Math.floor(+userInput);
|
||||||
|
// Random chance to flip hostility
|
||||||
|
if (Math.random() > 0.2) this.gameState.hostilityOfRiders = !this.gameState.hostilityOfRiders;
|
||||||
|
// Check tactics choice and resolve encounter
|
||||||
|
|
||||||
|
switch (this.gameState.tacticsChoiceWhenAttacked) {
|
||||||
|
case 1: // RUN
|
||||||
|
this.gameState.totalMileageWholeTrip += this.gameState.hostilityOfRiders ? 15 : 20;
|
||||||
|
this.gameState.amountSpentOnAnimals -= this.gameState.hostilityOfRiders ? 10 : 40;
|
||||||
|
this.gameState.amountSpentOnMiscellaneousSupplies -= 15;
|
||||||
|
this.gameState.amountSpentOnAmmunition -= 150;
|
||||||
|
|
||||||
|
this.gameState.phase = PHASE_ENUM.EVENT;
|
||||||
|
this.gameState.save();
|
||||||
|
return this.executeCurrentPhase();
|
||||||
|
case 2: // ATTACK
|
||||||
|
// Placeholder for attack logic, potentially involving a call to handleShooting()
|
||||||
|
this.handleShooting();
|
||||||
|
// Adjust resources based on the outcome of handleShooting()
|
||||||
|
break;
|
||||||
|
case 3: // CONTINUE
|
||||||
|
if (this.gameState.hostilityOfRiders) {
|
||||||
|
this.gameState.totalMileageWholeTrip -= 5;
|
||||||
|
this.gameState.amountSpentOnAmmunition -= 100;
|
||||||
|
}
|
||||||
|
// No additional action if riders are friendly
|
||||||
|
break;
|
||||||
|
case 4: // CIRCLE WAGONS
|
||||||
|
if (this.gameState.hostilityOfRiders) {
|
||||||
|
this.gameState.totalMileageWholeTrip -= 20;
|
||||||
|
} else {
|
||||||
|
// Possibly a smaller penalty or no action if riders are friendly
|
||||||
|
this.gameState.totalMileageWholeTrip -= 10;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Handle unexpected input (should be unreachable due to prior validation)
|
||||||
|
console.log("Unexpected tactics choice.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class GameState {
|
||||||
amountSpentOnItemsAtFort: number = 0;
|
amountSpentOnItemsAtFort: number = 0;
|
||||||
randomEventNumber: number = 0;
|
randomEventNumber: number = 0;
|
||||||
illnessFlag: boolean = false;
|
illnessFlag: boolean = false;
|
||||||
hostilityOfRidersFactor: number = 0;
|
hostilityOfRiders: boolean = false;
|
||||||
shootingWordSelector: string = '';
|
shootingWordSelector: string = '';
|
||||||
shootingWordVariations: string[] = [];
|
shootingWordVariations: string[] = [];
|
||||||
cashLeftAfterInitialPurchases: number = 800;
|
cashLeftAfterInitialPurchases: number = 800;
|
||||||
|
@ -46,6 +46,7 @@ class GameState {
|
||||||
subPhase: number = 0;
|
subPhase: number = 0;
|
||||||
death: DEATH_REASON_ENUM | undefined;
|
death: DEATH_REASON_ENUM | undefined;
|
||||||
deathReason: string | undefined;
|
deathReason: string | undefined;
|
||||||
|
lastPrompt: string | undefined;
|
||||||
|
|
||||||
private constructor(comment: Comment, state?: Partial<GameState>) {
|
private constructor(comment: Comment, state?: Partial<GameState>) {
|
||||||
Object.assign(this, state); // Initialize with loaded state or undefined
|
Object.assign(this, state); // Initialize with loaded state or undefined
|
||||||
|
|
Loading…
Reference in New Issue