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
|
|
|
|
2021-09-06 12:02:38 -05:00
|
|
|
constructor() {
|
2021-09-06 00:12:05 -05:00
|
|
|
super(
|
2021-09-06 08:51:41 -05:00
|
|
|
'Pastors',
|
2021-09-06 00:12:05 -05:00
|
|
|
'pastor',
|
|
|
|
'pastors',
|
2021-09-06 12:02:38 -05:00
|
|
|
'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-06 12:02:38 -05:00
|
|
|
let max =
|
|
|
|
(state.resource.churches?.value ?? 0) *
|
|
|
|
(state.config.cfgCapacity.churches?.pastors ?? 0);
|
|
|
|
max +=
|
|
|
|
(state.resource.megaChurches?.value ?? 0) *
|
|
|
|
(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
|
|
|
|
2021-09-06 12:02:38 -05:00
|
|
|
public isUnlocked(state: GameState): boolean {
|
2021-08-22 11:07:49 -05:00
|
|
|
if (this._isUnlocked) return true;
|
2021-09-05 18:39:08 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-09-06 12:02:38 -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) {
|
2021-09-05 18:39:08 -05:00
|
|
|
const money = state.resource.money;
|
2021-09-06 00:42:04 -05:00
|
|
|
const followers = state.resource.followers;
|
2021-09-06 12:02:38 -05:00
|
|
|
let tithed = Math.floor(
|
|
|
|
this.value * state.config.cfgPastorTitheCollectionFollowerMax
|
|
|
|
);
|
2021-09-06 00:42:04 -05:00
|
|
|
if (Math.floor(followers?.value ?? 0) < tithed)
|
|
|
|
tithed = Math.floor(followers?.value ?? 0);
|
2021-09-05 15:02:50 -05:00
|
|
|
let collected = tithed * state.config.cfgTitheAmount;
|
2021-09-06 12:02:38 -05:00
|
|
|
if (
|
|
|
|
money?.max !== undefined &&
|
|
|
|
collected > money.max(state) - money.value
|
|
|
|
)
|
2021-09-05 19:20:24 -05:00
|
|
|
collected = money.max(state) - money.value;
|
2021-08-22 11:07:49 -05:00
|
|
|
if (collected > 0) {
|
2021-09-05 17:33:28 -05:00
|
|
|
money?.addValue(collected, state);
|
2021-09-06 00:42:04 -05:00
|
|
|
if (followers !== undefined) {
|
2021-09-06 12:02:38 -05:00
|
|
|
state.log(
|
|
|
|
`Your pastors collected $${formatNumber(
|
|
|
|
collected
|
|
|
|
)} in tithings from ${formatNumber(tithed)} ${
|
|
|
|
tithed > 1 ? followers.pluralName : followers.singularName
|
|
|
|
}.`
|
|
|
|
);
|
2021-09-06 00:42:04 -05:00
|
|
|
}
|
2021-08-22 11:07:49 -05:00
|
|
|
}
|
|
|
|
this._timeSinceLastTithe = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|