This repository has been archived on 2022-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
irreligious/src/model/resource/Pastor.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

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) => {
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;
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) {
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);
let collected = tithed * state.config.cfgTitheAmount;
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) {
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;
}
}
}