Compare commits
2 Commits
46cfe43c75
...
20b7a883fa
Author | SHA1 | Date |
---|---|---|
j | 20b7a883fa | |
j | 0107af0a7b |
|
@ -330,19 +330,20 @@ class GameFlow {
|
||||||
// Update gameState based on itemType
|
// Update gameState based on itemType
|
||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case PurchaseOption.OXEN:
|
case PurchaseOption.OXEN:
|
||||||
this.gameState.amountSpentOnAnimals += totalCost * modifier;
|
//Round down after multiplication
|
||||||
|
this.gameState.amountSpentOnAnimals += Math.floor(totalCost * modifier);
|
||||||
break;
|
break;
|
||||||
case PurchaseOption.FOOD:
|
case PurchaseOption.FOOD:
|
||||||
this.gameState.amountSpentOnFood += totalCost * modifier;
|
this.gameState.amountSpentOnFood += Math.floor(totalCost * modifier);
|
||||||
break;
|
break;
|
||||||
case PurchaseOption.AMMO:
|
case PurchaseOption.AMMO:
|
||||||
this.gameState.amountSpentOnAmmunition += totalCost * 50 * modifier;
|
this.gameState.amountSpentOnAmmunition += Math.floor(totalCost * 50 * modifier);
|
||||||
break;
|
break;
|
||||||
case PurchaseOption.CLOTHING:
|
case PurchaseOption.CLOTHING:
|
||||||
this.gameState.amountSpentOnClothing += totalCost * modifier;
|
this.gameState.amountSpentOnClothing += Math.floor(totalCost * modifier);
|
||||||
break;
|
break;
|
||||||
case PurchaseOption.MISC:
|
case PurchaseOption.MISC:
|
||||||
this.gameState.amountSpentOnMiscellaneousSupplies += totalCost * modifier;
|
this.gameState.amountSpentOnMiscellaneousSupplies += Math.floor(totalCost * modifier);
|
||||||
break;
|
break;
|
||||||
// Add cases for other item types
|
// Add cases for other item types
|
||||||
}
|
}
|
||||||
|
@ -460,10 +461,62 @@ class GameFlow {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleTravel(): Promise<void> {
|
private async handleTravel(userInput?: string | number): Promise<void> {
|
||||||
// Logic for handling the travel phase
|
let responseMessage = "";
|
||||||
|
|
||||||
|
if (!userInput || userInput?.toString().toLowerCase() === "start") {
|
||||||
|
responseMessage = "DO YOU WANT TO EAT\n(1) POORLY\n(2) MODERATELY\n(3) WELL: ";
|
||||||
|
this.statusUpdate(responseMessage);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if userInput is a number or can be converted to a valid number
|
||||||
|
if (isNaN(Number(userInput))) {
|
||||||
|
responseMessage = "Invalid input. Please enter a number.\n\n"
|
||||||
|
responseMessage += "DO YOU WANT TO EAT\n(1) POORLY\n(2) MODERATELY\n(3) WELL: ";
|
||||||
|
await this.statusUpdate(responseMessage);
|
||||||
|
return; // Exit if input is not a valid number
|
||||||
|
}
|
||||||
|
|
||||||
|
let eatingChoice: number = parseInt(userInput.toString(), 10);
|
||||||
|
|
||||||
|
// Validate eating choice
|
||||||
|
if (eatingChoice < 1 || eatingChoice > 3) {
|
||||||
|
responseMessage = "Invalid choice.\n\n"
|
||||||
|
responseMessage += "DO YOU WANT TO EAT\n(1) POORLY\n(2) MODERATELY\n(3) WELL: ";
|
||||||
|
await this.statusUpdate(responseMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate potential food consumption without updating the game state yet
|
||||||
|
let potentialAmountSpentOnFood = this.gameState.amountSpentOnFood - (8 + 5 * eatingChoice);
|
||||||
|
|
||||||
|
// Check if the potential amount spent on food is negative
|
||||||
|
if (potentialAmountSpentOnFood < 0) {
|
||||||
|
// If it would result in a negative value, inform the user they can't eat that well
|
||||||
|
responseMessage = "YOU CAN'T EAT THAT WELL\n\n";
|
||||||
|
responseMessage += "DO YOU WANT TO EAT\n(1) POORLY\n(2) MODERATELY\n(3) WELL: ";
|
||||||
|
await this.statusUpdate(responseMessage);
|
||||||
|
return; // Exit the method to prevent further execution
|
||||||
|
} else {
|
||||||
|
// If the amount is sufficient, update the game state with the new amount
|
||||||
|
this.gameState.amountSpentOnFood = potentialAmountSpentOnFood;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate total mileage
|
||||||
|
this.gameState.totalMileageWholeTrip += 200 + (this.gameState.amountSpentOnAnimals - 220) / 5 + 10 * Math.random();
|
||||||
|
this.gameState.blizzardFlag = this.gameState.insufficientClothingFlag = false;
|
||||||
|
|
||||||
|
this.gameState.phase = PHASE_ENUM.RIDERS_ATTACK;
|
||||||
|
|
||||||
|
// Save the game state after making changes
|
||||||
|
await this.gameState.save();
|
||||||
|
|
||||||
|
// Continue with the game flow
|
||||||
|
this.executeCurrentPhase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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, may involve checking userInput for response to attack
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ export class CommentParser {
|
||||||
/**
|
/**
|
||||||
* Parses commands from the body of a single comment triggered by !!Oregon.
|
* Parses commands from the body of a single comment triggered by !!Oregon.
|
||||||
* If the comment contains only "!!Oregon", it treats it as a "start" command.
|
* If the comment contains only "!!Oregon", it treats it as a "start" command.
|
||||||
|
* Additionally, if the command or any argument is a number, it is floored.
|
||||||
* @param comment A single Comment object to be processed.
|
* @param comment A single Comment object to be processed.
|
||||||
* @returns An object containing the command and its arguments, if any.
|
* @returns An object containing the command and its arguments, if any.
|
||||||
*/
|
*/
|
||||||
|
@ -15,8 +16,15 @@ export class CommentParser {
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
// If the command is exactly "!!Oregon" with no additional command word, set command to "start"
|
// If the command is exactly "!!Oregon" with no additional command word, set command to "start"
|
||||||
const command = match[1] ? match[1].toLowerCase() : "start";
|
let command = match[1] ? match[1].toLowerCase() : "start";
|
||||||
const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : [];
|
const numCommand = Number(command);
|
||||||
|
if (!isNaN(numCommand) && isFinite(numCommand)) {
|
||||||
|
command = Math.floor(numCommand).toString();
|
||||||
|
}
|
||||||
|
const args = match[2] ? match[2].split(' ').map(arg => {
|
||||||
|
const numArg = Number(arg);
|
||||||
|
return !isNaN(numArg) && isFinite(numArg) ? Math.floor(numArg).toString() : arg;
|
||||||
|
}) : [];
|
||||||
return { command, args };
|
return { command, args };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue