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.resource.churches?.value ?? 0)
2021-09-05 20:43:11 -05:00
* (state.config.cfgCapacity.churches?.pastors ?? 0);
max += (state.resource.megaChurches?.value ?? 0)
2021-09-05 20:43:11 -05:00
* (state.config.cfgCapacity.megaChurches?.pastors ?? 0);
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.resource.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 {
2021-09-05 20:43:11 -05:00
super.advanceAction(time, state);
2021-08-22 11:07:49 -05:00
this._timeSinceLastTithe += time;
if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) {
const money = state.resource.money;
const plorg = state.resource.playerOrg;
2021-09-05 20:43:11 -05:00
let tithed = Math.floor(this.value
* state.config.cfgPastorTitheCollectionFollowerMax);
if (Math.floor(plorg?.value ?? 0) < tithed)
tithed = Math.floor(plorg?.value ?? 0);
let collected = tithed * state.config.cfgTitheAmount;
2021-09-05 19:20:24 -05:00
if (money?.max !== undefined
&& collected > money.max(state) - money.value)
collected = money.max(state) - money.value;
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;
}
}
}