using singular/plural distinctions in log messages
This commit is contained in:
parent
1bc4206a32
commit
66168728c3
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 = <ResourceKey>key;
|
||||
this.cost[rkey] =
|
||||
(this.cost[rkey] ?? 0) / (this._costMultiplier[rkey] ?? 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -10,7 +10,7 @@ enum ResourceType {
|
|||
}
|
||||
|
||||
enum ResourceKey {
|
||||
playerOrg = 'playerOrg',
|
||||
followers = 'followers',
|
||||
christianity = 'christianity',
|
||||
islam = 'islam',
|
||||
hinduism = 'hinduism',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Reference in New Issue