From 66168728c3a891a6810b3867ac842b6d0a38ff40 Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Mon, 6 Sep 2021 00:42:04 -0500 Subject: [PATCH] using singular/plural distinctions in log messages --- src/model/GameConfig.ts | 8 ++++---- src/model/resource/Follower.ts | 14 +++++++------- src/model/resource/House.ts | 2 +- src/model/resource/Job.ts | 32 ++++++++++++++++++++++++------- src/model/resource/Money.ts | 9 ++++++--- src/model/resource/Pastor.ts | 10 ++++++---- src/model/resource/Purchasable.ts | 2 +- src/model/resource/SharedTypes.ts | 2 +- src/model/resource/Tent.ts | 2 +- 9 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/model/GameConfig.ts b/src/model/GameConfig.ts index 166520d..9659bde 100644 --- a/src/model/GameConfig.ts +++ b/src/model/GameConfig.ts @@ -32,7 +32,7 @@ class GameConfig { cryptoCurrency: 1000, megaChurches: 2, money: 500000, - playerOrg: 5, + followers: 5, tents: 5, }; @@ -62,9 +62,9 @@ class GameConfig { public cfgCapacity: { [key in ResourceKey]?: ResourceNumber } = { churches: { pastors: 2 }, compounds: { churches: 1, houses: 2, money: 500000, tents: 10 }, - houses: { playerOrg: 10 }, + houses: { followers: 10 }, megaChurches: { pastors: 5 }, - tents: { playerOrg: 2 }, + tents: { followers: 2 }, }; public cfgCredibilityFollowerLossRatio = 0.04; @@ -82,7 +82,7 @@ class GameConfig { const state = new GameState(this); // create player organization - state.addResource(ResourceKey.playerOrg, new Follower()); + state.addResource(ResourceKey.followers, new Follower()); // create world religions state.addResource(ResourceKey.christianity, new Religion( diff --git a/src/model/resource/Follower.ts b/src/model/resource/Follower.ts index 7d5c746..56212f1 100644 --- a/src/model/resource/Follower.ts +++ b/src/model/resource/Follower.ts @@ -25,11 +25,11 @@ class Follower implements IResource { private _followerDests: ResourceNumber = { }; public max (state: GameState): number { - let max = state.config.cfgInitialMax.playerOrg ?? 0; + let max = state.config.cfgInitialMax.followers ?? 0; max += (state.resource.tents?.value ?? 0) - * (state.config.cfgCapacity.tents?.playerOrg ?? 0); + * (state.config.cfgCapacity.tents?.followers ?? 0); max += (state.resource.houses?.value ?? 0) - * (state.config.cfgCapacity.houses?.playerOrg ?? 0); + * (state.config.cfgCapacity.houses?.followers ?? 0); return max; } @@ -113,12 +113,12 @@ class Follower implements IResource { const followers = this._followerDests[rkey]; if (religion !== undefined && followers !== undefined) { if (msg !== '') msg += ', '; - msg += `${formatNumber(followers)} to ${religion.pluralName}`; + msg += `${formatNumber(followers)} ${followers > 1 ? religion.pluralName : religion.singularName}`; total += followers; delete this._followerDests[rkey]; } } - state.log(`You lost ${formatNumber(total)} followers: ${msg}`); + state.log(`You lost ${formatNumber(total)} ${total > 1 ? this.pluralName : this.singularName}: ${msg}`); } if (Object.keys(this._followerSources).length > 0) { let msg = ''; @@ -130,12 +130,12 @@ class Follower implements IResource { if (religion !== undefined && followers !== undefined) { if (msg !== '') msg += ', '; msg += - `${formatNumber(followers)} from ${religion.pluralName}`; + `${formatNumber(followers)} ${followers > 1 ? religion.pluralName : religion.singularName}`; total += followers; delete this._followerSources[rkey]; } } - state.log(`You gained ${formatNumber(total)} followers: ${msg}`); + state.log(`You gained ${formatNumber(total)} ${total > 1 ? this.pluralName : this.singularName}: ${msg}`); } this._lastRecruitmentLog = state.now; } diff --git a/src/model/resource/House.ts b/src/model/resource/House.ts index bb9b846..e6efee2 100644 --- a/src/model/resource/House.ts +++ b/src/model/resource/House.ts @@ -5,7 +5,7 @@ class House extends Infrastructure { super( 'house', 'houses', - `Provides room to house ${formatNumber(config.cfgCapacity.houses?.playerOrg ?? 0)} followers.`); + `Provides room to house ${formatNumber(config.cfgCapacity.houses?.followers ?? 0)} followers.`); this.cost.money = config.cfgInitialCost.houses; this._costMultiplier.money = config.cfgCostMultiplier.houses; } diff --git a/src/model/resource/Job.ts b/src/model/resource/Job.ts index fc7b7a2..7e50f62 100644 --- a/src/model/resource/Job.ts +++ b/src/model/resource/Job.ts @@ -20,6 +20,14 @@ abstract class Job implements IResource { this._promoteFollower(state); }, }, + { + name: 'Fire', + description: "You're fired.", + isEnabled: (_state: GameState): boolean => this.value > 0, + performAction: (state: GameState): void => { + this._demoteFollower(state); + }, + }, ]; protected _costMultiplier: { [key in ResourceKey]?: number } = { }; @@ -51,7 +59,7 @@ abstract class Job implements IResource { protected _availableJobs (state: GameState): number { // number of followers minus the number of filled jobs - const followers = state.resource.playerOrg?.value ?? 0; + const followers = state.resource.followers?.value ?? 0; const hired = state.resources.reduce( (tot: number, rkey: ResourceKey): number => { const res = state.resource[rkey]; @@ -64,7 +72,7 @@ abstract class Job implements IResource { protected _totalPayroll (state: GameState): number { // number of followers minus the number of filled jobs - const followers = state.resource.playerOrg?.value ?? 0; + const followers = state.resource.followers?.value ?? 0; const hired = state.resources.reduce( (tot: number, rkey: ResourceKey): number => { const res = state.resource[rkey]; @@ -76,14 +84,13 @@ abstract class Job implements IResource { } protected _hireLog (amount: number, _state: GameState): string { - return `You hired ${amount} x ${this.pluralName}.`; + return amount > 0 + ? `You hired ${amount} ${amount > 1 ? this.pluralName : this.singularName}.` + : `You fired ${amount * -1} ${amount * -1 > 1 ? this.pluralName : this.singularName}.`; } private _promoteFollower (state: GameState): void { - if (this._availableJobs(state) <= 0) { - state.log('You have no unemployed followers to promote.'); - return; - } + if (this._availableJobs(state) <= 0) return; if (this.max !== undefined && this.value < this.max(state) && state.deductCost(this.cost)) { this.addValue(1); @@ -95,4 +102,15 @@ abstract class Job implements IResource { } } } + + private _demoteFollower (state: GameState): void { + if (this.value <= 0) return; + this.addValue(-1); + state.log(this._hireLog(-1, state)); + for (const key in this._costMultiplier) { + const rkey = key; + this.cost[rkey] = + (this.cost[rkey] ?? 0) / (this._costMultiplier[rkey] ?? 1); + } + } } diff --git a/src/model/resource/Money.ts b/src/model/resource/Money.ts index cb3bb5b..3b51e79 100644 --- a/src/model/resource/Money.ts +++ b/src/model/resource/Money.ts @@ -40,7 +40,7 @@ class Money extends Purchasable { }; protected _purchaseAmount (state: GameState): number { - const plorg = state.resource.playerOrg; + const plorg = state.resource.followers; if (plorg === undefined || plorg.value === 0) { state.log('You have no followers to collect from!'); return 0; @@ -56,7 +56,10 @@ class Money extends Purchasable { } protected _purchaseLog (amount: number, state: GameState): string { - const followers = state.resource.playerOrg?.value ?? 0; - return `You collected $${formatNumber(amount)} from ${formatNumber(followers)} followers.`; + const followers = state.resource.followers; + if (followers !== undefined) { + return `You collected $${formatNumber(amount)} from ${formatNumber(followers.value)} ${followers.value > 1 ? followers.pluralName : followers.singularName}.`; + } + return `You collected $${formatNumber(amount)} in tithings.`; } } diff --git a/src/model/resource/Pastor.ts b/src/model/resource/Pastor.ts index 0178e5a..debeddc 100644 --- a/src/model/resource/Pastor.ts +++ b/src/model/resource/Pastor.ts @@ -29,18 +29,20 @@ class Pastor extends Job { this._timeSinceLastTithe += time; if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) { const money = state.resource.money; - const plorg = state.resource.playerOrg; + const followers = state.resource.followers; let tithed = Math.floor(this.value * state.config.cfgPastorTitheCollectionFollowerMax); - if (Math.floor(plorg?.value ?? 0) < tithed) - tithed = Math.floor(plorg?.value ?? 0); + if (Math.floor(followers?.value ?? 0) < tithed) + tithed = Math.floor(followers?.value ?? 0); let collected = tithed * state.config.cfgTitheAmount; if (money?.max !== undefined && collected > money.max(state) - money.value) collected = money.max(state) - money.value; if (collected > 0) { money?.addValue(collected, state); - state.log(`Your pastors collected $${formatNumber(collected)} in tithings from ${formatNumber(tithed)} followers.`); + if (followers !== undefined) { + state.log(`Your pastors collected $${formatNumber(collected)} in tithings from ${formatNumber(tithed)} ${tithed > 1 ? followers.pluralName : followers.singularName}.`); + } } this._timeSinceLastTithe = 0; } diff --git a/src/model/resource/Purchasable.ts b/src/model/resource/Purchasable.ts index c5fc55c..392675a 100644 --- a/src/model/resource/Purchasable.ts +++ b/src/model/resource/Purchasable.ts @@ -53,7 +53,7 @@ abstract class Purchasable implements IResource { } protected _purchaseLog (amount: number, _state: GameState): string { - return `You purchased ${amount} x ${this.pluralName}.`; + return `You purchased ${amount} ${amount > 1 ? this.pluralName : this.singularName}.`; } private _purchase (state: GameState): void { diff --git a/src/model/resource/SharedTypes.ts b/src/model/resource/SharedTypes.ts index 471f195..4228493 100644 --- a/src/model/resource/SharedTypes.ts +++ b/src/model/resource/SharedTypes.ts @@ -10,7 +10,7 @@ enum ResourceType { } enum ResourceKey { - playerOrg = 'playerOrg', + followers = 'followers', christianity = 'christianity', islam = 'islam', hinduism = 'hinduism', diff --git a/src/model/resource/Tent.ts b/src/model/resource/Tent.ts index d6d3e41..468a1ca 100644 --- a/src/model/resource/Tent.ts +++ b/src/model/resource/Tent.ts @@ -5,7 +5,7 @@ class Tent extends Infrastructure { super( 'tent', 'tents', - `Provides room to house ${formatNumber(config.cfgCapacity.tents?.playerOrg ?? 0)} followers.`); + `Provides room to house ${formatNumber(config.cfgCapacity.tents?.followers ?? 0)} followers.`); this.cost.money = config.cfgInitialCost.tents; this._costMultiplier.money = config.cfgCostMultiplier.tents; }