collecting tithes via increment

This commit is contained in:
Rudis Muiznieks 2021-09-11 22:45:52 -05:00
parent f03489b506
commit abac90bdfa
7 changed files with 35 additions and 86 deletions

View File

@ -44,12 +44,6 @@ The game's source code on <a href='https://github.com/rudism/irreligious'>Github
((): void => {
const config = new GameConfig(versionMajor, versionMinor);
// debug values to make the game play faster while testing
config.cfgCredibilityRestoreRate = 5;
config.cfgPastorRecruitRate = 0.5;
config.cfgTimeBetweenTithes = 5000;
config.cfgTitheAmount = 1000;
const renderer = new DebugRenderer();
renderer.onInitialRender = initialRender;
const state = config.generateState();

View File

@ -59,8 +59,7 @@ class GameConfig {
};
public cfgSalary: ResourceNumber = {
pastors: 250,
compoundManagers: 1000,
compoundManagers: 100,
};
public cfgCapacity: { [key in ResourceKey]?: ResourceNumber } = {
@ -85,8 +84,6 @@ class GameConfig {
},
};
public cfgCredibilityFollowerLossRatio = 0.04;
public cfgCredibilityFollowerLossTime = 10000;
public cfgCredibilityRestoreRate = 0.25;
public cfgCryptoCurrencyMinimumValue = 1;
public cfgCryptoMarketAdjustAmount = 0.1;
@ -98,9 +95,8 @@ class GameConfig {
public cfgNoMoneyQuitTime = 10000;
public cfgPassiveMax = 100;
public cfgPastorRecruitRate = 0.01;
public cfgPastorTitheCollectionFollowerMax = 100;
public cfgTimeBetweenTithes = 30000;
public cfgTitheAmount = 10;
public cfgTimeBetweenTithes = 10000;
public cfgTitheAmount = 10000;
public cfgTitheCredibilityHitFactor = 3;
constructor(public versionMajor: number, public versionMinor: number) {}

View File

@ -11,8 +11,8 @@ class CompoundManager extends Job {
}
public max: (state: GameState) => number = (state) => {
return Math.floor(
(state.resource.compounds?.value ?? 0) *
return (
Math.floor(state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.compoundManagers ?? 0)
);
};

View File

@ -11,6 +11,17 @@ class Credibility extends Passive {
this.value = config.cfgPassiveMax;
}
public static ratio(state: GameState): number {
const cred = state.resource.credibility;
return cred === undefined
? 0
: cred.max === undefined
? 0
: cred.max(state) === 0
? 0
: cred.value / cred.max(state);
}
public max: (state: GameState) => number = (state) =>
state.config.cfgPassiveMax;

View File

@ -31,10 +31,10 @@ class Follower implements IResource {
public max(state: GameState): number {
let max = state.config.cfgInitialMax.followers ?? 0;
max +=
(state.resource.tents?.value ?? 0) *
Math.floor(state.resource.tents?.value ?? 0) *
(state.config.cfgCapacity.tents?.followers ?? 0);
max +=
(state.resource.houses?.value ?? 0) *
Math.floor(state.resource.houses?.value ?? 0) *
(state.config.cfgCapacity.houses?.followers ?? 0);
return max;
}
@ -87,26 +87,6 @@ class Follower implements IResource {
}
public advanceAction(time: number, state: GameState): void {
// chance to lose some followers if credibility < 100%
this._timeSinceLastLost += time;
if (this._timeSinceLastLost > state.config.cfgCredibilityFollowerLossTime) {
if (this.value > 0) {
const creds = state.resource.credibility;
if (creds?.max !== undefined) {
const ratio = Math.ceil(creds.value) / creds.max(state);
if (Math.random() > ratio) {
const lost = Math.ceil(
this.value *
state.config.cfgCredibilityFollowerLossRatio *
(1 - ratio)
);
this.addValue(lost * -1, state);
}
}
}
this._timeSinceLastLost = 0;
}
// chance for some followers to quit their jobs if money === 0
const money = state.resource.money;
const totalJobs = Job.totalJobs(state);

View File

@ -42,13 +42,17 @@ class Money implements IResource {
public inc: (state: GameState) => number = (state) => {
let inc = 0;
// tithings
inc +=
(Math.floor(state.resource.pastors?.value ?? 0) *
Math.floor(state.resource.followers?.value ?? 0) *
(state.config.cfgTitheAmount ?? 0) *
Credibility.ratio(state)) /
state.config.cfgTimeBetweenTithes;
// salaries
inc -=
(state.resource.pastors?.value ?? 0) *
(state.config.cfgSalary.pastors ?? 0);
inc -=
(state.resource.compoundManagers?.value ?? 0) *
Math.floor(state.resource.compoundManagers?.value ?? 0) *
(state.config.cfgSalary.compoundManagers ?? 0);
return inc;
@ -57,7 +61,11 @@ class Money implements IResource {
protected _collectTithes(state: GameState): void {
if (this.value >= this.max(state)) return;
const followers = state.resource.followers?.value ?? 0;
// can't tithe your pastors
const followers =
(state.resource.followers?.value ?? 0) -
(state.resource.pastors?.value ?? 0);
if (followers <= 0) return;
// collecting too frequently hurts credibility

View File

@ -1,8 +1,6 @@
/// <reference path="./Job.ts" />
class Pastor extends Job {
private _timeSinceLastTithe = 0;
constructor() {
super(
'Pastors',
@ -14,10 +12,10 @@ class Pastor extends Job {
public max: (state: GameState) => number = (state) => {
let max =
(state.resource.churches?.value ?? 0) *
Math.floor(state.resource.churches?.value ?? 0) *
(state.config.cfgCapacity.churches?.pastors ?? 0);
max +=
(state.resource.megaChurches?.value ?? 0) *
Math.floor(state.resource.megaChurches?.value ?? 0) *
(state.config.cfgCapacity.megaChurches?.pastors ?? 0);
return Math.floor(max);
};
@ -27,42 +25,4 @@ class Pastor extends Job {
this._isUnlocked = state.resource.churches?.isUnlocked(state) === true;
return this._isUnlocked;
}
public advanceAction(time: number, state: GameState): void {
super.advanceAction(time, state);
this._timeSinceLastTithe += time;
if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) {
const money = state.resource.money;
const followers = state.resource.followers;
let tithable = Math.floor((followers?.value ?? 0) - this.value);
// bad credibility makes people not tithe
const creds = state.resource.credibility;
if (creds?.max !== undefined) {
tithable = Math.floor(tithable * (creds.value / creds.max(state)));
}
let tithed = Math.floor(
this.value * state.config.cfgPastorTitheCollectionFollowerMax
);
if (tithable < tithed) tithed = tithable;
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);
if (followers !== undefined) {
state.log(
`Your pastors collected $${formatNumber(
collected
)} in tithings from ${formatNumber(tithed)} ${
tithed > 1 ? followers.pluralName : followers.singularName
}.`
);
}
}
this._timeSinceLastTithe = 0;
}
}
}