using singular/plural distinctions in log messages

This commit is contained in:
Rudis Muiznieks 2021-09-06 00:42:04 -05:00
parent 1bc4206a32
commit 66168728c3
9 changed files with 52 additions and 29 deletions

View File

@ -32,7 +32,7 @@ class GameConfig {
cryptoCurrency: 1000, cryptoCurrency: 1000,
megaChurches: 2, megaChurches: 2,
money: 500000, money: 500000,
playerOrg: 5, followers: 5,
tents: 5, tents: 5,
}; };
@ -62,9 +62,9 @@ class GameConfig {
public cfgCapacity: { [key in ResourceKey]?: ResourceNumber } = { public cfgCapacity: { [key in ResourceKey]?: ResourceNumber } = {
churches: { pastors: 2 }, churches: { pastors: 2 },
compounds: { churches: 1, houses: 2, money: 500000, tents: 10 }, compounds: { churches: 1, houses: 2, money: 500000, tents: 10 },
houses: { playerOrg: 10 }, houses: { followers: 10 },
megaChurches: { pastors: 5 }, megaChurches: { pastors: 5 },
tents: { playerOrg: 2 }, tents: { followers: 2 },
}; };
public cfgCredibilityFollowerLossRatio = 0.04; public cfgCredibilityFollowerLossRatio = 0.04;
@ -82,7 +82,7 @@ class GameConfig {
const state = new GameState(this); const state = new GameState(this);
// create player organization // create player organization
state.addResource(ResourceKey.playerOrg, new Follower()); state.addResource(ResourceKey.followers, new Follower());
// create world religions // create world religions
state.addResource(ResourceKey.christianity, new Religion( state.addResource(ResourceKey.christianity, new Religion(

View File

@ -25,11 +25,11 @@ class Follower implements IResource {
private _followerDests: ResourceNumber = { }; private _followerDests: ResourceNumber = { };
public max (state: GameState): number { 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) max += (state.resource.tents?.value ?? 0)
* (state.config.cfgCapacity.tents?.playerOrg ?? 0); * (state.config.cfgCapacity.tents?.followers ?? 0);
max += (state.resource.houses?.value ?? 0) max += (state.resource.houses?.value ?? 0)
* (state.config.cfgCapacity.houses?.playerOrg ?? 0); * (state.config.cfgCapacity.houses?.followers ?? 0);
return max; return max;
} }
@ -113,12 +113,12 @@ class Follower implements IResource {
const followers = this._followerDests[rkey]; const followers = this._followerDests[rkey];
if (religion !== undefined && followers !== undefined) { if (religion !== undefined && followers !== undefined) {
if (msg !== '') msg += ', '; if (msg !== '') msg += ', ';
msg += `${formatNumber(followers)} to ${religion.pluralName}`; msg += `${formatNumber(followers)} ${followers > 1 ? religion.pluralName : religion.singularName}`;
total += followers; total += followers;
delete this._followerDests[rkey]; 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) { if (Object.keys(this._followerSources).length > 0) {
let msg = ''; let msg = '';
@ -130,12 +130,12 @@ class Follower implements IResource {
if (religion !== undefined && followers !== undefined) { if (religion !== undefined && followers !== undefined) {
if (msg !== '') msg += ', '; if (msg !== '') msg += ', ';
msg += msg +=
`${formatNumber(followers)} from ${religion.pluralName}`; `${formatNumber(followers)} ${followers > 1 ? religion.pluralName : religion.singularName}`;
total += followers; total += followers;
delete this._followerSources[rkey]; 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; this._lastRecruitmentLog = state.now;
} }

View File

@ -5,7 +5,7 @@ class House extends Infrastructure {
super( super(
'house', 'house',
'houses', '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.cost.money = config.cfgInitialCost.houses;
this._costMultiplier.money = config.cfgCostMultiplier.houses; this._costMultiplier.money = config.cfgCostMultiplier.houses;
} }

View File

@ -20,6 +20,14 @@ abstract class Job implements IResource {
this._promoteFollower(state); 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 } = { }; protected _costMultiplier: { [key in ResourceKey]?: number } = { };
@ -51,7 +59,7 @@ abstract class Job implements IResource {
protected _availableJobs (state: GameState): number { protected _availableJobs (state: GameState): number {
// number of followers minus the number of filled jobs // 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( const hired = state.resources.reduce(
(tot: number, rkey: ResourceKey): number => { (tot: number, rkey: ResourceKey): number => {
const res = state.resource[rkey]; const res = state.resource[rkey];
@ -64,7 +72,7 @@ abstract class Job implements IResource {
protected _totalPayroll (state: GameState): number { protected _totalPayroll (state: GameState): number {
// number of followers minus the number of filled jobs // 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( const hired = state.resources.reduce(
(tot: number, rkey: ResourceKey): number => { (tot: number, rkey: ResourceKey): number => {
const res = state.resource[rkey]; const res = state.resource[rkey];
@ -76,14 +84,13 @@ abstract class Job implements IResource {
} }
protected _hireLog (amount: number, _state: GameState): string { 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 { private _promoteFollower (state: GameState): void {
if (this._availableJobs(state) <= 0) { if (this._availableJobs(state) <= 0) return;
state.log('You have no unemployed followers to promote.');
return;
}
if (this.max !== undefined && this.value < this.max(state) if (this.max !== undefined && this.value < this.max(state)
&& state.deductCost(this.cost)) { && state.deductCost(this.cost)) {
this.addValue(1); 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 = <ResourceKey>key;
this.cost[rkey] =
(this.cost[rkey] ?? 0) / (this._costMultiplier[rkey] ?? 1);
}
}
} }

View File

@ -40,7 +40,7 @@ class Money extends Purchasable {
}; };
protected _purchaseAmount (state: GameState): number { protected _purchaseAmount (state: GameState): number {
const plorg = state.resource.playerOrg; const plorg = state.resource.followers;
if (plorg === undefined || plorg.value === 0) { if (plorg === undefined || plorg.value === 0) {
state.log('You have no followers to collect from!'); state.log('You have no followers to collect from!');
return 0; return 0;
@ -56,7 +56,10 @@ class Money extends Purchasable {
} }
protected _purchaseLog (amount: number, state: GameState): string { protected _purchaseLog (amount: number, state: GameState): string {
const followers = state.resource.playerOrg?.value ?? 0; const followers = state.resource.followers;
return `You collected $${formatNumber(amount)} from ${formatNumber(followers)} 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.`;
} }
} }

View File

@ -29,18 +29,20 @@ class Pastor extends Job {
this._timeSinceLastTithe += time; this._timeSinceLastTithe += time;
if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) { if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) {
const money = state.resource.money; const money = state.resource.money;
const plorg = state.resource.playerOrg; const followers = state.resource.followers;
let tithed = Math.floor(this.value let tithed = Math.floor(this.value
* state.config.cfgPastorTitheCollectionFollowerMax); * state.config.cfgPastorTitheCollectionFollowerMax);
if (Math.floor(plorg?.value ?? 0) < tithed) if (Math.floor(followers?.value ?? 0) < tithed)
tithed = Math.floor(plorg?.value ?? 0); tithed = Math.floor(followers?.value ?? 0);
let collected = tithed * state.config.cfgTitheAmount; let collected = tithed * state.config.cfgTitheAmount;
if (money?.max !== undefined if (money?.max !== undefined
&& collected > money.max(state) - money.value) && collected > money.max(state) - money.value)
collected = money.max(state) - money.value; collected = money.max(state) - money.value;
if (collected > 0) { if (collected > 0) {
money?.addValue(collected, state); 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; this._timeSinceLastTithe = 0;
} }

View File

@ -53,7 +53,7 @@ abstract class Purchasable implements IResource {
} }
protected _purchaseLog (amount: number, _state: GameState): string { 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 { private _purchase (state: GameState): void {

View File

@ -10,7 +10,7 @@ enum ResourceType {
} }
enum ResourceKey { enum ResourceKey {
playerOrg = 'playerOrg', followers = 'followers',
christianity = 'christianity', christianity = 'christianity',
islam = 'islam', islam = 'islam',
hinduism = 'hinduism', hinduism = 'hinduism',

View File

@ -5,7 +5,7 @@ class Tent extends Infrastructure {
super( super(
'tent', 'tent',
'tents', '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.cost.money = config.cfgInitialCost.tents;
this._costMultiplier.money = config.cfgCostMultiplier.tents; this._costMultiplier.money = config.cfgCostMultiplier.tents;
} }