2021-08-22 11:07:49 -05:00
|
|
|
/// <reference path="./Job.ts" />
|
|
|
|
|
|
|
|
class Pastor extends Job {
|
2021-09-04 22:21:14 -05:00
|
|
|
private _timeSinceLastTithe = 0;
|
2021-08-22 11:07:49 -05:00
|
|
|
|
|
|
|
constructor () {
|
2021-08-22 13:08:41 -05:00
|
|
|
super('Pastors',
|
|
|
|
'Collect tithings for you and recruit new members from other faiths automatically.');
|
2021-08-22 11:07:49 -05:00
|
|
|
}
|
|
|
|
|
2021-09-05 14:45:37 -05:00
|
|
|
public max: (state: GameState) => number = (state) => {
|
2021-09-05 17:33:28 -05:00
|
|
|
let max = (state.getResource(ResourceKey.churches)?.value ?? 0)
|
|
|
|
* state.config.cfgChurchPastorCapacity;
|
|
|
|
max += (state.getResource(ResourceKey.megaChurches)?.value ?? 0)
|
|
|
|
* state.config.cfgMegaChurchPastorCapacity;
|
2021-09-04 23:16:32 -05:00
|
|
|
return max;
|
2021-09-05 14:45:37 -05:00
|
|
|
};
|
2021-08-22 11:07:49 -05:00
|
|
|
|
|
|
|
public isUnlocked (state: GameState): boolean {
|
|
|
|
if (this._isUnlocked) return true;
|
2021-09-05 17:33:28 -05:00
|
|
|
this._isUnlocked = state.getResource(
|
|
|
|
ResourceKey.churches)?.isUnlocked(state) === true;
|
2021-09-04 23:11:13 -05:00
|
|
|
return this._isUnlocked;
|
2021-08-22 11:07:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public advanceAction (time: number, state: GameState): void {
|
|
|
|
this._timeSinceLastTithe += time;
|
|
|
|
if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) {
|
2021-09-05 17:33:28 -05:00
|
|
|
const money = state.getResource(ResourceKey.money);
|
|
|
|
const plorg = state.getResource(ResourceKey.playerOrg);
|
|
|
|
let tithed = this.value
|
|
|
|
* state.config.cfgPastorTitheCollectionFollowerMax;
|
|
|
|
if (Math.floor(plorg?.value ?? 0) < tithed)
|
|
|
|
tithed = Math.floor(plorg?.value ?? 0);
|
2021-09-05 15:02:50 -05:00
|
|
|
let collected = tithed * state.config.cfgTitheAmount;
|
2021-09-05 17:33:28 -05:00
|
|
|
if (money?.max !== null
|
|
|
|
&& collected > (money?.max(state) ?? 0) - (money?.value ?? 0))
|
|
|
|
collected = (money?.max(state) ?? 0) - (money?.value ?? 0);
|
2021-08-22 11:07:49 -05:00
|
|
|
if (collected > 0) {
|
2021-09-05 17:33:28 -05:00
|
|
|
money?.addValue(collected, state);
|
|
|
|
state.log(`Your pastors collected $${state.config.formatNumber(collected)} in tithings from ${state.config.formatNumber(tithed)} followers.`);
|
2021-08-22 11:07:49 -05:00
|
|
|
}
|
|
|
|
this._timeSinceLastTithe = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|