From e6963bd6e5e55fd8c75f29575d5fed9bf1109270 Mon Sep 17 00:00:00 2001 From: blujai831 Date: Thu, 10 Oct 2024 21:38:43 -0700 Subject: [PATCH] Correct the cost deductions reported when buying upgrades now that the prices change with each purchase. This suffices to complete "step 7" as defined by the school assignment for which purpose this fork is maintained. (Strictly speaking, the previous commit would also have sufficed, if I wanted to be an insufferable smartass about it, but I don't especially.) --- src/GameState.ts | 8 ++++---- src/GameUpgrade.ts | 4 ++-- src/IGameUpgrade.ts | 4 ++-- src/upgrades.ts | 26 ++++++++++++++++---------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/GameState.ts b/src/GameState.ts index e99391e0..2cd56dfe 100644 --- a/src/GameState.ts +++ b/src/GameState.ts @@ -91,21 +91,21 @@ export class GameState implements IGameState { let upgrade: IGameUpgrade = upgrades[what]; if (upgrade.canPurchase(this)) { upgrade.doPostPurchase(this); + if (upgrade.purchaseAckMessage !== undefined) { + this._notice(upgrade.purchaseAckMessage(this)); + } let qty: number | undefined = this._upgradeAmounts[what]; if (qty === undefined) { qty = 0; } qty += 1; this._upgradeAmounts[what] = qty; - if (upgrade.purchaseAckMessage !== undefined) { - this._notice(upgrade.purchaseAckMessage); - } this._playerSpeedNeedsRecalc = true; this._showInventoryList(); return true; } else { if (upgrade.purchaseNakMessage !== undefined) { - this._notice(upgrade.purchaseNakMessage); + this._notice(upgrade.purchaseNakMessage(this)); } return false; } diff --git a/src/GameUpgrade.ts b/src/GameUpgrade.ts index fc5f5407..8af09dfb 100644 --- a/src/GameUpgrade.ts +++ b/src/GameUpgrade.ts @@ -20,11 +20,11 @@ export class GameUpgrade implements IGameUpgrade { /** * See IGameUpgrade.purchaseAckMessage. */ - public purchaseAckMessage?: string; + public purchaseAckMessage?: (gameState: IGameState) => string; /** * See IGameUpgrade.purchaseNakMessage. */ - public purchaseNakMessage?: string; + public purchaseNakMessage?: (gameState: IGameState) => string; /** * Callback to be invoked to implement doPostPurchase. */ diff --git a/src/IGameUpgrade.ts b/src/IGameUpgrade.ts index 47f2b597..3e57db90 100644 --- a/src/IGameUpgrade.ts +++ b/src/IGameUpgrade.ts @@ -32,13 +32,13 @@ export interface IGameUpgrade { * If this property exists, it should be used as the message for a notice * to be displayed when the player successfully purchases this upgrade. */ - purchaseAckMessage?: string; + purchaseAckMessage?: (gameState: IGameState) => string; /** * If this property exists, it should be used as the message for a notice * to be displayed when the player tries and fails to purchase * this upgrade. */ - purchaseNakMessage?: string; + purchaseNakMessage?: (gameState: IGameState) => string; /** * Does any modifications to the game state consistent with purchasing * this upgrade, other than increasing the player's possessed quantity diff --git a/src/upgrades.ts b/src/upgrades.ts index 97310f46..829824d9 100644 --- a/src/upgrades.ts +++ b/src/upgrades.ts @@ -18,8 +18,11 @@ export const upgrades: {[upgradeName: string]: IGameUpgrade} = { purchaseCondition: (gameState: IGameState): boolean => gameState.playerPlaceCounter >= getPrice('beabnsies', gameState, 10), - purchaseAckMessage: "backtracked 10 blocks to find a beabnsy", - purchaseNakMessage: + purchaseAckMessage: (gameState: IGameState): string => + "backtracked " + + `${getPrice('beabnsies', gameState, 10)} ` + + "blocks to find a beabnsy", + purchaseNakMessage: (_dontCare: IGameState): string => "you aren't far enough to backtrack enough " + "to find a beabnsy", postPurchaseEffect: (gameState: IGameState): void => { @@ -33,10 +36,12 @@ export const upgrades: {[upgradeName: string]: IGameUpgrade} = { purchaseCondition: (gameState: IGameState): boolean => gameState.playerPlaceCounter >= getPrice('roket', gameState, 100), - purchaseAckMessage: - "picked up tarsh for the past 100 blocks " + - "to build a roket", - purchaseNakMessage: "ther not enough trarsh to built an raocket", + purchaseAckMessage: (gameState: IGameState): string => + "picked up tarsh for the past " + + `${getPrice('roket', gameState, 100)} ` + + "bloks to build a roket", + purchaseNakMessage: (_dontCare: IGameState): string => + "ther not enough trarsh to built an raocket", postPurchaseEffect: (gameState: IGameState): void => { gameState.playerPlaceCounter -= getPrice('roket', gameState, 100); @@ -48,10 +53,11 @@ export const upgrades: {[upgradeName: string]: IGameUpgrade} = { purchaseCondition: (gameState: IGameState): boolean => gameState.playerPlaceCounter >= getPrice('bigrkt', gameState, 1000), - purchaseAckMessage: - "pikkocked oup tfarsh for the apst 1000 bloks " + - "too bfilt an BIGRKT WOA WOA", - purchaseNakMessage: + purchaseAckMessage: (gameState: IGameState): string => + "pikkocked oup tfarsh for the apst " + + `${getPrice('bigrkt', gameState, 1000)} ` + + "blks too bfilt an BIGRKT WOA WOA", + purchaseNakMessage: (_dontCare: IGameState): string => "got go frther " + "theres not ef trarash bakc ther yet", postPurchaseEffect: (gameState: IGameState): void => {